Refactor state PDA accessors - #118
Merged
Merged
Conversation
kaze-cow
requested changes
Aug 26, 2026
kaze-cow
left a comment
Contributor
There was a problem hiding this comment.
I love this change. tbh this is kind of the direction I was hoping for before!
based on what I have seen here, I would be in favor of later refactoring the order PDA similarly, as we can still benefit from zero copy reads there.
kaze-cow
approved these changes
Aug 27, 2026
kaze-cow
left a comment
Contributor
There was a problem hiding this comment.
only one followup thing to review, otherwise all addressed.
Merged
fedgiac
added a commit
that referenced
this pull request
Aug 27, 2026
Unfortunately, I merged #118 too quickly and I left some fields not properly renamed. Interesting that one of the missing renames is in a dev docs. The reason our dev docs CI didn't catch it is that the bad docs is in the test. According to Claude (I don't think it's worth investigating further) there's no stable way to also check the test docs, so I'm going to keep CI as is and accept that the test docs may be broken. ## How to test Eyeball the changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
First step for introducing the management of solver accounts. Nothing change in the code behavior yet, it's just a refactor in preparation for new code.
Right now, the handling of the state PDA is awkward: we have an
EncodedStateAccountthat takes ownership of the data and a lot of accessors likeEncodedStateAccount::authority(bytes, role)that take abytesarray to edit in place.With these changes, we drop
EncodedStateAccountand replace it withStateAccount. Notably,StateAccountdoesn't own its data but it takes a reference. This allows us to access the data with things likestate.authority(role), which reads very naturally and allows us to drop the bytes accessor and gives us a type-safe way to store the state account bytes.The nicest trick in these changes is making the implementation generic in the Deref'ed type:
This means that if we use
StateAccount(&bytes)then we only access read-only methods, whileStateAccount(&mut bytes)also gives access to mutable functions on the ref. The code duplication between&and&mutis something we struggled with in the past and is imho nicely resolved by this code. All write and read accesses are, naturally, zero copy. This will work nicely for the code that updates solvers.Note also that the state account now has a header. In this PR, the header is the state account. Once we add solvers, they will not be part of the header, and we can keep most of the remaining code unchanged. The layout doesn't change, yet, though it theoretically now supports extra padding bytes (ignored).
Role::ALLI added
Role::ALLbecause it was helpful in a test. It isn't used outside of tests but I still decided to make it part of the interface since it's properly tested and can be helpful. I also used it in other parts of the code where it would be helpful.Tests
Updated tests work.