Skip to content

factor out SysvarGet from Sysvar #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kevinheavey
Copy link
Contributor

Problem: the Sysvar trait relies on bincode, but most of the time people just want Sysvar::get which doesn't rely on bincode

Solution: make a SysvarGet trait that has one method: get. Make the Sysvar trait use SysvarGet::get. Annoyingly this is still technically a breaking change because we are adding a constraint to Sysvar, but for the vast majority of users nothing should break

Copy link
Contributor

@febo febo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is great! I wonder if we could take the opportunity of this breaking change to do a bigger refactoring. Ideally we should move the implementation of each sysvar to their own individual crate, instead of having all of them as a dependency on this one.

So solana-sysvar has the trait definitions and macros only. What do you think?

Another alternative is to move the trait definitions and macros to a new crate (solana-define-sysvar?), move the implementation to each individual sysvar crate and keep this one re-exporting everything to "minimize" the breaking change.

@kevinheavey
Copy link
Contributor Author

Sounds like another PR to me

@febo
Copy link
Contributor

febo commented Apr 2, 2025

Sounds like another PR to me

Yeah, definitely. I was mentioning to get an idea if this is an approach that makes sense. I am inclined to go for the solana-define-sysvar option, which in a way mimics the syscalls approach.

@kevinheavey
Copy link
Contributor Author

The solana-define-sysvar approach is a bit awkward because of the orphan rule. We'd have to move the trait impls to the existing crates like solana-clock. But maybe that's pretty cheap once we have this lightweight SysvarGet trait

@febo
Copy link
Contributor

febo commented Apr 4, 2025

The solana-define-sysvar approach is a bit awkward because of the orphan rule. We'd have to move the trait impls to the existing crates like solana-clock. But maybe that's pretty cheap once we have this lightweight SysvarGet trait

Yeah, the new trait is lightweight and the impl could be behind a feature on the individual crates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants