-
Notifications
You must be signed in to change notification settings - Fork 257
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
SDK: Slot Hashes: Add queries using sol_get_sysvar
#1622
SDK: Slot Hashes: Add queries using sol_get_sysvar
#1622
Conversation
@2501babe I based this off of your implementation for I think we can also maybe share the first commit if you are interested, since our methods |
@joncinque @2501babe Requesting initial review as a draft before adding tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting this up! It's good to see its potential usage
031ac38
to
f904e15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is starting to look very nice, just a few more bits to refine it
e4258b7
to
aba85df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two last nits, then this is good to go! I'm a big fan of how it's turned out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
late to the party while i close out the new stake instructions but i love this, im going to rearrange my stake history stuff to also use your |
* sysvars: add `get_sysvar` handler * sysvars: add `SlotHashesSysvar` trait * use bytemuck slices for binary search * refactor get_sysvar API * add tests * add pointer alignment check * make the API a struct * move allocation check * use `PodSlotHash` for layout * cleanup
Problem
Some Core BPF programs - such as Address Lookup Table - will need to be able to query
for a slot's corresponding hash or position in the
SlotHashes
sysvar.Thanks to #1307, we can leverage the new
sol_get_sysvar
to enable thisfunctionality for BPF programs.
Summary of Changes
First add a general helper API for working with
sol_get_sysvar
. This can be used bymany sysvar APIs.
Next add a new API -
SlotHashesSysvar
- offering two queries:get
andposition
.Example Usage
A Note on Use of
sol_get_sysvar
It turns out it was actually cheaper on compute to load the entire buffer for
SlotHashes
without deserializing, and implement binary search on the raw data. Working with chunks
at a time was more expensive on compute.