Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
(Bank/Snapshot) Add prior_roots to bank fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
yhchiang-sol committed Mar 8, 2022
1 parent e790d0f commit 6cbe253
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 29 deletions.
4 changes: 4 additions & 0 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ mod tests {
tempfile::TempDir,
};

DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_3_0, Development, V1_3_0_Development);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_3_0, Devnet, V1_3_0_Devnet);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_3_0, Testnet, V1_3_0_Testnet);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_3_0, MainnetBeta, V1_3_0_MainnetBeta);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Development, V1_2_0_Development);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Devnet, V1_2_0_Devnet);
DEFINE_SNAPSHOT_VERSION_PARAMETERIZED_TEST_FUNCTIONS!(V1_2_0, Testnet, V1_2_0_Testnet);
Expand Down
23 changes: 19 additions & 4 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,13 @@ pub(crate) struct BankFieldsToDeserialize {
pub(crate) stakes: Stakes,
pub(crate) epoch_stakes: HashMap<Epoch, EpochStakes>,
pub(crate) is_delta: bool,
pub(crate) prior_roots: Vec<Slot>,
}

// Bank's common fields shared by all supported snapshot versions for serialization.
// This is separated from BankFieldsToDeserialize to avoid cloning by using refs.
// So, sync fields with BankFieldsToDeserialize!
// all members are made public to keep Bank private and to make versioned serializer workable on this
/// Bank's common fields shared by all supported snapshot versions for serialization.
/// This is separated from BankFieldsToDeserialize to avoid cloning by using refs.
/// So, sync fields with BankFieldsToDeserialize!
/// all members are made public to keep Bank private and to make versioned serializer workable on this
#[derive(Debug)]
pub(crate) struct BankFieldsToSerialize<'a> {
pub(crate) blockhash_queue: &'a RwLock<BlockhashQueue>,
Expand Down Expand Up @@ -957,6 +958,7 @@ pub(crate) struct BankFieldsToSerialize<'a> {
pub(crate) stakes: &'a StakesCache,
pub(crate) epoch_stakes: &'a HashMap<Epoch, EpochStakes>,
pub(crate) is_delta: bool,
pub(crate) prior_roots: Vec<Slot>,
}

// Can't derive PartialEq because RwLock doesn't implement PartialEq
Expand Down Expand Up @@ -995,6 +997,7 @@ impl PartialEq for Bank {
&& *self.stakes_cache.stakes() == *other.stakes_cache.stakes()
&& self.epoch_stakes == other.epoch_stakes
&& self.is_delta.load(Relaxed) == other.is_delta.load(Relaxed)
&& self.prior_roots == other.prior_roots
}
}

Expand Down Expand Up @@ -1179,6 +1182,14 @@ pub struct Bank {
/// stream for the slot == self.slot
is_delta: AtomicBool,

/// The list of roots which are no longer roots in the current bank instance.
/// As we eliminate rewrites/ancient append vec, we need to the ability to
/// remember slots within that last epoch that WERE roots even if they no
/// longer contain any accounts. Without remembering those prior roots,
/// accounts that we skip rewrites might have their rent collection time
/// point to the incorrect roots as their correct roots were removed.
pub prior_roots: Vec<Slot>,

/// The builtin programs
builtin_programs: BuiltinPrograms,

Expand Down Expand Up @@ -1352,6 +1363,7 @@ impl Bank {
stakes_cache: StakesCache::default(),
epoch_stakes: HashMap::<Epoch, EpochStakes>::default(),
is_delta: AtomicBool::default(),
prior_roots: Vec::<Slot>::default(),
builtin_programs: BuiltinPrograms::default(),
compute_budget: Option::<ComputeBudget>::default(),
builtin_feature_transitions: Arc::<Vec<BuiltinFeatureTransition>>::default(),
Expand Down Expand Up @@ -1668,6 +1680,7 @@ impl Bank {
ancestors: Ancestors::default(),
hash: RwLock::new(Hash::default()),
is_delta: AtomicBool::new(false),
prior_roots: parent.prior_roots.clone(),
tick_height: AtomicU64::new(parent.tick_height.load(Relaxed)),
signature_count: AtomicU64::new(0),
builtin_programs,
Expand Down Expand Up @@ -1964,6 +1977,7 @@ impl Bank {
stakes_cache: StakesCache::new(fields.stakes),
epoch_stakes: fields.epoch_stakes,
is_delta: AtomicBool::new(fields.is_delta),
prior_roots: fields.prior_roots,
builtin_programs: new(),
compute_budget: None,
builtin_feature_transitions: new(),
Expand Down Expand Up @@ -2066,6 +2080,7 @@ impl Bank {
stakes: &self.stakes_cache,
epoch_stakes: &self.epoch_stakes,
is_delta: self.is_delta.load(Relaxed),
prior_roots: self.prior_roots.clone(),
}
}

Expand Down
4 changes: 4 additions & 0 deletions runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use {
};

mod newer;
mod older;
mod storage;
mod tests;
mod utils;
Expand All @@ -57,6 +58,7 @@ pub(crate) use tests::reconstruct_accounts_db_via_serialization;
#[derive(Copy, Clone, Eq, PartialEq)]
pub(crate) enum SerdeStyle {
Newer,
Older,
}

const MAX_STREAM_SIZE: u64 = 32 * 1024 * 1024 * 1024;
Expand Down Expand Up @@ -237,6 +239,7 @@ where
}
match serde_style {
SerdeStyle::Newer => INTO!(newer),
SerdeStyle::Older => INTO!(older),
}
.map_err(|err| {
warn!("bankrc_from_stream error: {:?}", err);
Expand Down Expand Up @@ -267,6 +270,7 @@ where
}
match serde_style {
SerdeStyle::Newer => INTO!(newer),
SerdeStyle::Older => INTO!(older),
}
.map_err(|err| {
warn!("bankrc_to_stream error: {:?}", err);
Expand Down
23 changes: 7 additions & 16 deletions runtime/src/serde_snapshot/newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ use {
},
crate::{ancestors::AncestorsForSerialization, stakes::StakesCache},
solana_measure::measure::Measure,
std::{cell::RefCell, collections::HashSet, sync::RwLock},
solana_sdk::deserialize_utils::default_on_eof,
std::{cell::RefCell, sync::RwLock},
};

type AccountsDbFields = super::AccountsDbFields<SerializableAccountStorageEntry>;

#[derive(Default, Clone, PartialEq, Debug, Deserialize, Serialize, AbiExample)]
struct UnusedAccounts {
unused1: HashSet<Pubkey>,
unused2: HashSet<Pubkey>,
unused3: HashMap<Pubkey, u64>,
}

// Deserializable version of Bank which need not be serializable,
// because it's handled by SerializableVersionedBank.
// So, sync fields with it!
Expand All @@ -39,8 +33,6 @@ struct DeserializableVersionedBank {
ns_per_slot: u128,
genesis_creation_time: UnixTimestamp,
slots_per_year: f64,
#[allow(dead_code)]
unused: u64,
slot: Slot,
epoch: Epoch,
block_height: u64,
Expand All @@ -53,10 +45,10 @@ struct DeserializableVersionedBank {
epoch_schedule: EpochSchedule,
inflation: Inflation,
stakes: Stakes,
#[allow(dead_code)]
unused_accounts: UnusedAccounts,
epoch_stakes: HashMap<Epoch, EpochStakes>,
is_delta: bool,
#[serde(deserialize_with = "default_on_eof")]
prior_roots: Vec<Slot>,
}

impl From<DeserializableVersionedBank> for BankFieldsToDeserialize {
Expand Down Expand Up @@ -92,6 +84,7 @@ impl From<DeserializableVersionedBank> for BankFieldsToDeserialize {
stakes: dvb.stakes,
epoch_stakes: dvb.epoch_stakes,
is_delta: dvb.is_delta,
prior_roots: dvb.prior_roots,
}
}
}
Expand All @@ -116,7 +109,6 @@ struct SerializableVersionedBank<'a> {
ns_per_slot: u128,
genesis_creation_time: UnixTimestamp,
slots_per_year: f64,
unused: u64,
slot: Slot,
epoch: Epoch,
block_height: u64,
Expand All @@ -129,9 +121,9 @@ struct SerializableVersionedBank<'a> {
epoch_schedule: EpochSchedule,
inflation: Inflation,
stakes: &'a StakesCache,
unused_accounts: UnusedAccounts,
epoch_stakes: &'a HashMap<Epoch, EpochStakes>,
is_delta: bool,
prior_roots: Vec<Slot>,
}

impl<'a> From<crate::bank::BankFieldsToSerialize<'a>> for SerializableVersionedBank<'a> {
Expand All @@ -153,7 +145,6 @@ impl<'a> From<crate::bank::BankFieldsToSerialize<'a>> for SerializableVersionedB
ns_per_slot: rhs.ns_per_slot,
genesis_creation_time: rhs.genesis_creation_time,
slots_per_year: rhs.slots_per_year,
unused: u64::default(),
slot: rhs.slot,
epoch: rhs.epoch,
block_height: rhs.block_height,
Expand All @@ -166,9 +157,9 @@ impl<'a> From<crate::bank::BankFieldsToSerialize<'a>> for SerializableVersionedB
epoch_schedule: rhs.epoch_schedule,
inflation: rhs.inflation,
stakes: rhs.stakes,
unused_accounts: UnusedAccounts::default(),
epoch_stakes: rhs.epoch_stakes,
is_delta: rhs.is_delta,
prior_roots: rhs.prior_roots,
}
}
}
Expand Down
Loading

0 comments on commit 6cbe253

Please sign in to comment.