Skip to content

Conversation

MicaiahReid
Copy link

@MicaiahReid MicaiahReid commented Apr 16, 2025

This PR updates the expire_blockhash function store recent blockhashes in the RecentBlockhashes sysvar, rather than throwing them all out every time a new blockhash is created. At most MAX_RECENT_BLOCKHASHES hashes are stored.

Additionally, transaction validation is updated to check if the recent_blockhash in the transaction method is in the set of recent blockhashes, rather than just checking if it is equal to the latest blockhash.

@MicaiahReid MicaiahReid changed the title Fix/recent-blockhashes Keep recent blockhashes in litesvm state Apr 16, 2025
@Aursen Aursen self-requested a review April 16, 2025 18:02
Copy link
Collaborator

@Aursen Aursen left a comment

Choose a reason for hiding this comment

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

Seems good to me, you just need to run cargo-fmt

)]));
{
let blockhashes = self.get_sysvar::<RecentBlockhashes>();
let mut entries = vec![];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to init with capacity, something like this:

let max_entries_len = blockhashes.len().min(MAX_RECENT_BLOCKHASHES);
let mut entries = Vec::with_capacity(max_entries_len);

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should initialise it in LiteSVM::new and store it as a field on the LiteSVM struct

Copy link
Author

Choose a reason for hiding this comment

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

@Aursen @kevinheavey, I've implemented Aursen's suggested change and run cargo fmt. I'm not quite understanding Kevin's suggestion - is that something either of you will have time to knock out?

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.

3 participants