This repository was archived by the owner on Mar 11, 2025. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since we now have an upgradeable loader, we'll need to properly handle any updates to state structures. The approach here is to use the excellent
enum_dispatch
crate https://docs.rs/enum_dispatch/0.3.4/enum_dispatch/ to have multiple structs implement the same interface, and then use these structs as trait objects in processors. This seemed like the best approach to minimize code bloat in the current case. Note that this won't cover every possible case for backwards compatibility. For example, we might end up adding a field that won't have a good backwards-compatible default, requiring us to have different versions of instruction processors. Let's hope that doesn't happen too soon.Since this approach requires dynamic dispatch on trait objects, I measured the number of BPF instructions before and after this PR on every swap instruction, along with the number of dynamic dispatch calls in each program instruction. Here are the results:
There's a small impact of ~250 BPF instructions, so this could be a viable approach for all programs! Any suggestions or comments are very appreciated.
cc @aeyakovenko @jstarry @mvines