Skip to content

Commit

Permalink
Supports deserializing accounts lt hash in snapshots (#2994)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Sep 27, 2024
1 parent cc141d1 commit 690fad0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions accounts-db/src/accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,10 @@ pub struct AccountLtHash(pub LtHash);
pub const ZERO_LAMPORT_ACCOUNT_LT_HASH: AccountLtHash =
AccountLtHash(LtHash([0; LtHash::NUM_ELEMENTS]));

/// Lattice hash of all accounts
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct AccountsLtHash(pub LtHash);

/// Hash of accounts
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum AccountsHashKind {
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ regex = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_derive = { workspace = true }
serde_json = { workspace = true }
serde_with = { workspace = true }
solana-accounts-db = { workspace = true }
solana-address-lookup-table-program = { workspace = true }
solana-bpf-loader-program = { workspace = true }
Expand All @@ -63,6 +64,7 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [
"frozen-abi",
] }
solana-inline-spl = { workspace = true }
solana-lattice-hash = { workspace = true }
solana-loader-v4-program = { workspace = true }
solana-measure = { workspace = true }
solana-metrics = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ use {
thread::Builder,
},
storage::SerializableStorage,
types::SerdeAccountsLtHash,
};

mod storage;
mod tests;
mod types;
mod utils;

pub(crate) use {
Expand Down Expand Up @@ -400,6 +402,9 @@ struct ExtraFieldsToDeserialize {
epoch_accounts_hash: Option<Hash>,
#[serde(deserialize_with = "default_on_eof")]
versioned_epoch_stakes: HashMap<u64, VersionedEpochStakes>,
#[serde(deserialize_with = "default_on_eof")]
#[allow(dead_code)]
accounts_lt_hash: Option<SerdeAccountsLtHash>,
}

/// Extra fields that are serialized at the end of snapshots.
Expand Down Expand Up @@ -441,6 +446,7 @@ where
incremental_snapshot_persistence,
epoch_accounts_hash,
versioned_epoch_stakes,
accounts_lt_hash: _,
} = extra_fields;

bank_fields.fee_rate_governor = bank_fields
Expand Down
22 changes: 22 additions & 0 deletions runtime/src/serde_snapshot/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use {solana_accounts_db::accounts_hash::AccountsLtHash, solana_lattice_hash::lt_hash::LtHash};

/// Snapshot serde-safe AccountsLtHash
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[serde_with::serde_as]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct SerdeAccountsLtHash(
// serde only has array support up to 32 elements; anything larger needs to be handled manually
// see https://github.com/serde-rs/serde/issues/1937 for more information
#[serde_as(as = "[_; LtHash::NUM_ELEMENTS]")] pub [u16; LtHash::NUM_ELEMENTS],
);

impl From<SerdeAccountsLtHash> for AccountsLtHash {
fn from(accounts_lt_hash: SerdeAccountsLtHash) -> Self {
Self(LtHash(accounts_lt_hash.0))
}
}
impl From<AccountsLtHash> for SerdeAccountsLtHash {
fn from(accounts_lt_hash: AccountsLtHash) -> Self {
Self(accounts_lt_hash.0 .0)
}
}

0 comments on commit 690fad0

Please sign in to comment.