Skip to content

Commit

Permalink
Backport writing new fields to snapshot (#26394)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
steviez authored Jul 7, 2022
1 parent 2955fc4 commit 2b1e4ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions runtime/src/serde_snapshot/newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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::<Slot>::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",
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 2b1e4ff

Please sign in to comment.