From 2b1e4ff447571d653e3402b604f666c1da1357d4 Mon Sep 17 00:00:00 2001 From: steviez Date: Thu, 7 Jul 2022 15:04:42 -0400 Subject: [PATCH] Backport writing new fields to snapshot (#26394) Backport writing serialized fields to snapshot Serializing and storing lamports_per_signature field is critical to avoid issues when a snapshot is taken at a slot with a non-default lamports_per_signature value. In order to keep compatibility between v1.10 and newer snapshots, we also need to serialize default values for several AccountsDB fields. --- runtime/src/serde_snapshot/newer.rs | 21 +++++++++++++++++++-- runtime/src/serde_snapshot/tests.rs | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/runtime/src/serde_snapshot/newer.rs b/runtime/src/serde_snapshot/newer.rs index d1aac9d015d69c..8537079ac956e6 100644 --- a/runtime/src/serde_snapshot/newer.rs +++ b/runtime/src/serde_snapshot/newer.rs @@ -188,9 +188,9 @@ impl<'a> TypeContext<'a> for Context { where Self: std::marker::Sized, { - // ONLY FOR THE BACKPORT, extra field is serialized on master let ancestors = HashMap::from(&serializable_bank.bank.ancestors); let fields = serializable_bank.bank.get_fields_to_serialize(&ancestors); + let lamports_per_signature = fields.fee_rate_governor.lamports_per_signature; ( SerializableVersionedBank::from(fields), SerializableAccountsDb::<'a, Self> { @@ -199,6 +199,9 @@ impl<'a> TypeContext<'a> for Context { account_storage_entries: serializable_bank.snapshot_storages, phantom: std::marker::PhantomData::default(), }, + // Field that isn't part SerializableVersionedBank, but that we want to + // be able to store / read back on restart + lamports_per_signature, ) .serialize(serializer) } @@ -262,7 +265,21 @@ impl<'a> TypeContext<'a> for Context { .clone(); let mut serialize_account_storage_timer = Measure::start("serialize_account_storage_ms"); - let result = (entries, version, slot, hash).serialize(serializer); + + // Serialize historical_roots and historical_roots_with_hash default data; defaults are + // used for the sake of being able to backport serializing lamports_per_signature while + // keeping snapshots produced by v1.10 and master/v1.11 clients compatible + let historical_roots = Vec::::default(); + let historical_roots_with_hash = Vec::<(Slot, Hash)>::default(); + let result = ( + entries, + version, + slot, + hash, + historical_roots, + historical_roots_with_hash, + ) + .serialize(serializer); serialize_account_storage_timer.stop(); datapoint_info!( "serialize_account_storage_ms", diff --git a/runtime/src/serde_snapshot/tests.rs b/runtime/src/serde_snapshot/tests.rs index c38ef6cdcfd004..81b86102972f70 100644 --- a/runtime/src/serde_snapshot/tests.rs +++ b/runtime/src/serde_snapshot/tests.rs @@ -365,7 +365,7 @@ mod test_bank_serialize { // This some what long test harness is required to freeze the ABI of // Bank's serialization due to versioned nature - #[frozen_abi(digest = "ERbJJzaQD39td9tiE4FPAud374S2Hvk6pvsxejm6quWf")] + #[frozen_abi(digest = "dU93dNba5nEH7o8KR4QbTT6SYRfDFdjXrZdqQjNGzKa")] #[derive(Serialize, AbiExample)] pub struct BankAbiTestWrapperNewer { #[serde(serialize_with = "wrapper_newer")]