solana icon indicating copy to clipboard operation
solana copied to clipboard

Add feature for tracking dynamic reserved account set

Open jstarry opened this issue 1 year ago • 8 comments

Problem

There's no way to add new builtin programs and sysvars to the list of read-only reserved accounts.

Summary of Changes

Bank now tracks a dynamic set of reserved account keys which gets updated on epoch boundaries with feature activations. The set of reserved account keys needs to get passed to all the transaction and message constructors and then we take advantage of the is_writable cache to avoid passing the reserved account set to is_writable everywhere. It's inevitable that a change like this will result in breaking changes unfortunately. There is an option of moving towards using more internal sdk crates (like solana-runtime-transactions) for core types rather than thrashing the external sdk whenever internal needs change, but that's a pretty big effort.

Detailed changes

https://github.com/solana-labs/solana/pull/34901/commits/b02c297872be782401375e36d2f595149716cc95: refactors tests to minimize diff size when plumbing reserved accounts https://github.com/solana-labs/solana/pull/34901/commits/c02bbb11cb63b55d66d26aae072351c78552877f: adds the zk token module to the sdk so that reserved accounts can reference the program id https://github.com/solana-labs/solana/pull/34901/commits/7db755cea0537ee57228ac6992ca26e779dff052: removes the TryFrom<Message> impl for SanitizedMessage and replaces it with SanitizedMessage::try_from_legacy_message which will allow plumbing the reserved accounts through https://github.com/solana-labs/solana/pull/34901/commits/c7f27d490e993830bdd983fa3cc270044dc3ee9a: adds Message::is_maybe_writable for times when the reserved accounts set is not available but we want a rough guess still (cli output, durable nonce checking in rpc, etc) https://github.com/solana-labs/solana/pull/34901/commits/7b7cf251cc79fe461abb66d4ff8b5fb171ea22fe: is the meat of the change, it introduces the reserved accounts module, adds it to bank, and plumbs the reserved accounts set everywhere https://github.com/solana-labs/solana/pull/34901/commits/8685df2ce940c510c6ffbca3164710023e3c4daa: deprecates uses of static lists of sysvars and builtins. Unfortunately the lists themselves can't be deprecated due to use of lazy_static

  • Deprecated solana_program::message::is_builtin_key_or_sysvar function
  • Deprecated solana_program::sysvar::is_sysvar_id function
  • Bigtable uploader used to skip indexing sysvars, now it skips all reserved keys
  • Replaced some usages of is_sysvar_id which a check for owner equal to sysvar
  • Snapshot minimizer logic now adds all active and inactive reserved account keys to the minimized snapshot

Breaking changes:

  • Renamed solana_rpc_client::rpc_client::SerializableTransaction::uses_durable_nonce to maybe_uses_durable_nonce to prevent misuse
  • Renamed solana_sdk::transaction::uses_durable_nonce to maybe_uses_durable_nonce to prevent misuse
  • Renamed solana_sdk::transaction::VersionedTransaction::uses_durable_nonce to maybe_uses_durable_nonce to prevent misuse
  • solana_sdk::transaction::SanitizedTransaction::try_from_legacy_transaction has a new reserved_account_keys argument
  • solana_sdk::transaction::SanitizedTransaction::try_create has a new reserved_account_keys argument
  • solana_sdk::transaction::SanitizedTransaction::try_new has a new reserved_account_keys argument
  • solana_program::message::Message::is_writable has a new reserved_account_keys argument
  • solana_program::message::Message::get_account_keys_by_lock_type has a new reserved_account_keys argument
  • solana_program::message::LegacyMessage::new has a new reserved_account_keys argument
  • solana_program::message::SanitizedMessage::try_new has a new reserved_account_keys argument
  • solana_program::message::LoadedMessage::new has a new reserved_account_keys argument
  • solana_program::message::LoadedMessage::new_borrowed has a new reserved_account_keys argument
  • solana_program::message::SanitizedMessage no longer implements TryFrom<Message> (I added a try_from_legacy_message method instead in order to pass the reserved_account_keys argument)

Feature Gate Issue: https://github.com/solana-labs/solana/issues/34899

jstarry avatar Jan 23 '24 12:01 jstarry

oof. the number of touch points here begs a refactor... i'm going to have to look at it more closely :thinking:

t-nelson avatar Jan 23 '24 17:01 t-nelson

I don't disagree that a refactor of transaction / message types should be done at some point but I would like to point out that the plumbing for reserved_account_keys is pretty similar to how address lookup tables are loaded since both are bank specific. I think the current approach in this PR already minimizes touch points as much as is possible.

jstarry avatar Jan 24 '24 03:01 jstarry

Codecov Report

Attention: Patch coverage is 91.09415% with 35 lines in your changes are missing coverage. Please review.

Project coverage is 81.7%. Comparing base (bf2e8ee) to head (ea9e3ca). Report is 6 commits behind head on master.

:exclamation: Current head ea9e3ca differs from pull request most recent head 9f6432b. Consider uploading reports for the commit 9f6432b to get more accurate results

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #34901     +/-   ##
=========================================
- Coverage    81.7%    81.7%   -0.1%     
=========================================
  Files         834      830      -4     
  Lines      224232   224570    +338     
=========================================
+ Hits       183382   183476     +94     
- Misses      40850    41094    +244     

codecov[bot] avatar Jan 24 '24 05:01 codecov[bot]

Is it possible to break this up into logical commits? Right now, review is horrible.

CriesofCarrots avatar Jan 24 '24 19:01 CriesofCarrots

Is it possible to break this up into logical commits? Right now, review is horrible.

I split it up.. apologies for not doing that earlier! The PR description includes a detailed breakdown of each commit as well.

jstarry avatar Jan 25 '24 03:01 jstarry

Would you prefer I open a pr for each individual commit? Also, considering that 2.0 is coming soon, breaking changes should be an issue?

jstarry avatar Feb 08 '24 02:02 jstarry

@CriesofCarrots @t-nelson ping on this!

jstarry avatar Feb 21 '24 09:02 jstarry

Sorry for the delay. This is on my list for tomorrow. Is it worth waiting on a rebase at this point?

CriesofCarrots avatar Feb 22 '24 04:02 CriesofCarrots

@CriesofCarrots I just rebased!

jstarry avatar Feb 27 '24 01:02 jstarry

This repository is no longer in use. Please re-open this pull request in the agave repo: https://github.com/anza-xyz/agave

willhickey avatar Mar 03 '24 04:03 willhickey