Fix fee mismatch on snapshot deserialize (#12697)
Co-authored-by: Carl Lin <carl@solana.com>
This commit is contained in:
@ -156,7 +156,7 @@ mod tests {
|
|||||||
.get(&deserialized_bank.slot())
|
.get(&deserialized_bank.slot())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.clone();
|
.clone();
|
||||||
bank.compare_bank(&deserialized_bank);
|
assert!(*bank == deserialized_bank);
|
||||||
|
|
||||||
let slot_snapshot_paths = snapshot_utils::get_snapshot_paths(&snapshot_path);
|
let slot_snapshot_paths = snapshot_utils::get_snapshot_paths(&snapshot_path);
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ pub type Epoch = u64;
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Serialize, Deserialize, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
#[derive(Serialize, Debug, Deserialize, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
pub struct Pubkey([u8; 32]);
|
pub struct Pubkey([u8; 32]);
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
@ -164,7 +164,7 @@ impl Stake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Clone, Copy)]
|
#[derive(Serialize, Debug, Deserialize, PartialEq, Clone, Copy)]
|
||||||
pub struct Delegation {
|
pub struct Delegation {
|
||||||
/// to whom the stake is delegated
|
/// to whom the stake is delegated
|
||||||
voter_pubkey: Pubkey,
|
voter_pubkey: Pubkey,
|
||||||
|
@ -448,6 +448,7 @@ pub(crate) struct BankFieldsToDeserialize {
|
|||||||
// This is separated from BankFieldsToDeserialize to avoid cloning by using refs.
|
// This is separated from BankFieldsToDeserialize to avoid cloning by using refs.
|
||||||
// So, sync fields with BankFieldsToDeserialize!
|
// So, sync fields with BankFieldsToDeserialize!
|
||||||
// all members are made public to remain Bank private and to make versioned serializer workable on this
|
// all members are made public to remain Bank private and to make versioned serializer workable on this
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) struct BankFieldsToSerialize<'a> {
|
pub(crate) struct BankFieldsToSerialize<'a> {
|
||||||
pub(crate) blockhash_queue: &'a RwLock<BlockhashQueue>,
|
pub(crate) blockhash_queue: &'a RwLock<BlockhashQueue>,
|
||||||
pub(crate) ancestors: &'a Ancestors,
|
pub(crate) ancestors: &'a Ancestors,
|
||||||
@ -482,6 +483,46 @@ pub(crate) struct BankFieldsToSerialize<'a> {
|
|||||||
pub(crate) is_delta: bool,
|
pub(crate) is_delta: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Can't derive PartialEq because RwLock doesn't implement PartialEq
|
||||||
|
impl PartialEq for Bank {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
if ptr::eq(self, other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*self.blockhash_queue.read().unwrap() == *other.blockhash_queue.read().unwrap()
|
||||||
|
&& self.ancestors == other.ancestors
|
||||||
|
&& *self.hash.read().unwrap() == *other.hash.read().unwrap()
|
||||||
|
&& self.parent_hash == other.parent_hash
|
||||||
|
&& self.parent_slot == other.parent_slot
|
||||||
|
&& *self.hard_forks.read().unwrap() == *other.hard_forks.read().unwrap()
|
||||||
|
&& self.transaction_count.load(Relaxed) == other.transaction_count.load(Relaxed)
|
||||||
|
&& self.tick_height.load(Relaxed) == other.tick_height.load(Relaxed)
|
||||||
|
&& self.signature_count.load(Relaxed) == other.signature_count.load(Relaxed)
|
||||||
|
&& self.capitalization.load(Relaxed) == other.capitalization.load(Relaxed)
|
||||||
|
&& self.max_tick_height == other.max_tick_height
|
||||||
|
&& self.hashes_per_tick == other.hashes_per_tick
|
||||||
|
&& self.ticks_per_slot == other.ticks_per_slot
|
||||||
|
&& self.ns_per_slot == other.ns_per_slot
|
||||||
|
&& self.genesis_creation_time == other.genesis_creation_time
|
||||||
|
&& self.slots_per_year == other.slots_per_year
|
||||||
|
&& self.unused == other.unused
|
||||||
|
&& self.slot == other.slot
|
||||||
|
&& self.epoch == other.epoch
|
||||||
|
&& self.block_height == other.block_height
|
||||||
|
&& self.collector_id == other.collector_id
|
||||||
|
&& self.collector_fees.load(Relaxed) == other.collector_fees.load(Relaxed)
|
||||||
|
&& self.fee_calculator == other.fee_calculator
|
||||||
|
&& self.fee_rate_governor == other.fee_rate_governor
|
||||||
|
&& self.collected_rent.load(Relaxed) == other.collected_rent.load(Relaxed)
|
||||||
|
&& self.rent_collector == other.rent_collector
|
||||||
|
&& self.epoch_schedule == other.epoch_schedule
|
||||||
|
&& *self.inflation.read().unwrap() == *other.inflation.read().unwrap()
|
||||||
|
&& *self.stakes.read().unwrap() == *other.stakes.read().unwrap()
|
||||||
|
&& self.epoch_stakes == other.epoch_stakes
|
||||||
|
&& self.is_delta.load(Relaxed) == other.is_delta.load(Relaxed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize, AbiExample, Default, Clone, Copy)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize, AbiExample, Default, Clone, Copy)]
|
||||||
pub struct RewardInfo {
|
pub struct RewardInfo {
|
||||||
pub lamports: i64, // Reward amount
|
pub lamports: i64, // Reward amount
|
||||||
@ -883,7 +924,11 @@ impl Bank {
|
|||||||
);
|
);
|
||||||
assert_eq!(bank.epoch_schedule, genesis_config.epoch_schedule);
|
assert_eq!(bank.epoch_schedule, genesis_config.epoch_schedule);
|
||||||
assert_eq!(bank.epoch, bank.epoch_schedule.get_epoch(bank.slot));
|
assert_eq!(bank.epoch, bank.epoch_schedule.get_epoch(bank.slot));
|
||||||
|
bank.fee_rate_governor.lamports_per_signature = bank.fee_calculator.lamports_per_signature;
|
||||||
|
assert_eq!(
|
||||||
|
bank.fee_rate_governor.create_fee_calculator(),
|
||||||
|
bank.fee_calculator
|
||||||
|
);
|
||||||
bank
|
bank
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3652,51 +3697,6 @@ impl Bank {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compare_bank(&self, dbank: &Bank) {
|
|
||||||
if ptr::eq(self, dbank) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
assert_eq!(self.slot, dbank.slot);
|
|
||||||
assert_eq!(self.collector_id, dbank.collector_id);
|
|
||||||
assert_eq!(self.epoch_schedule, dbank.epoch_schedule);
|
|
||||||
assert_eq!(self.hashes_per_tick, dbank.hashes_per_tick);
|
|
||||||
assert_eq!(self.ticks_per_slot, dbank.ticks_per_slot);
|
|
||||||
assert_eq!(self.parent_hash, dbank.parent_hash);
|
|
||||||
assert_eq!(
|
|
||||||
self.tick_height.load(Relaxed),
|
|
||||||
dbank.tick_height.load(Relaxed)
|
|
||||||
);
|
|
||||||
assert_eq!(self.is_delta.load(Relaxed), dbank.is_delta.load(Relaxed));
|
|
||||||
|
|
||||||
{
|
|
||||||
let bh = self.hash.read().unwrap();
|
|
||||||
let dbh = dbank.hash.read().unwrap();
|
|
||||||
assert_eq!(*bh, *dbh);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let st = self.stakes.read().unwrap();
|
|
||||||
let dst = dbank.stakes.read().unwrap();
|
|
||||||
assert_eq!(*st, *dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let bhq = self.blockhash_queue.read().unwrap();
|
|
||||||
let dbhq = dbank.blockhash_queue.read().unwrap();
|
|
||||||
assert_eq!(*bhq, *dbhq);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let sc = self.src.status_cache.read().unwrap();
|
|
||||||
let dsc = dbank.src.status_cache.read().unwrap();
|
|
||||||
assert_eq!(*sc, *dsc);
|
|
||||||
}
|
|
||||||
assert_eq!(
|
|
||||||
self.rc.accounts.bank_hash_at(self.slot),
|
|
||||||
dbank.rc.accounts.bank_hash_at(dbank.slot)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clean_accounts(&self, skip_last: bool) {
|
pub fn clean_accounts(&self, skip_last: bool) {
|
||||||
let max_clean_slot = if skip_last {
|
let max_clean_slot = if skip_last {
|
||||||
// Don't clean the slot we're snapshotting because it may have zero-lamport
|
// Don't clean the slot we're snapshotting because it may have zero-lamport
|
||||||
|
@ -13,7 +13,7 @@ struct HashAge {
|
|||||||
|
|
||||||
/// Low memory overhead, so can be cloned for every checkpoint
|
/// Low memory overhead, so can be cloned for every checkpoint
|
||||||
#[frozen_abi(digest = "EwaoLA34VN18E95GvjmkeStUpWqTeBd7FGpd7mppLmEw")]
|
#[frozen_abi(digest = "EwaoLA34VN18E95GvjmkeStUpWqTeBd7FGpd7mppLmEw")]
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, AbiExample)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, AbiExample)]
|
||||||
pub struct BlockhashQueue {
|
pub struct BlockhashQueue {
|
||||||
/// updated whenever an hash is registered
|
/// updated whenever an hash is registered
|
||||||
hash_height: u64,
|
hash_height: u64,
|
||||||
|
@ -7,13 +7,13 @@ use std::{collections::HashMap, sync::Arc};
|
|||||||
pub type NodeIdToVoteAccounts = HashMap<Pubkey, NodeVoteAccounts>;
|
pub type NodeIdToVoteAccounts = HashMap<Pubkey, NodeVoteAccounts>;
|
||||||
pub type EpochAuthorizedVoters = HashMap<Pubkey, Pubkey>;
|
pub type EpochAuthorizedVoters = HashMap<Pubkey, Pubkey>;
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Debug, Deserialize, Default, PartialEq, AbiExample)]
|
#[derive(Clone, Serialize, Debug, Deserialize, Default, PartialEq, Eq, AbiExample)]
|
||||||
pub struct NodeVoteAccounts {
|
pub struct NodeVoteAccounts {
|
||||||
pub vote_accounts: Vec<Pubkey>,
|
pub vote_accounts: Vec<Pubkey>,
|
||||||
pub total_stake: u64,
|
pub total_stake: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize, AbiExample)]
|
#[derive(Clone, Debug, Serialize, Deserialize, AbiExample, PartialEq)]
|
||||||
pub struct EpochStakes {
|
pub struct EpochStakes {
|
||||||
stakes: Arc<Stakes>,
|
stakes: Arc<Stakes>,
|
||||||
total_stake: u64,
|
total_stake: u64,
|
||||||
|
@ -219,7 +219,7 @@ fn test_bank_serialize_style(serde_style: SerdeStyle) {
|
|||||||
assert_eq!(dbank.get_balance(&key1.pubkey()), 0);
|
assert_eq!(dbank.get_balance(&key1.pubkey()), 0);
|
||||||
assert_eq!(dbank.get_balance(&key2.pubkey()), 10);
|
assert_eq!(dbank.get_balance(&key2.pubkey()), 10);
|
||||||
assert_eq!(dbank.get_balance(&key3.pubkey()), 0);
|
assert_eq!(dbank.get_balance(&key3.pubkey()), 0);
|
||||||
bank2.compare_bank(&dbank);
|
assert!(bank2 == dbank);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -68,7 +68,7 @@ pub struct FeeRateGovernor {
|
|||||||
// The current cost of a signature This amount may increase/decrease over time based on
|
// The current cost of a signature This amount may increase/decrease over time based on
|
||||||
// cluster processing load.
|
// cluster processing load.
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
lamports_per_signature: u64,
|
pub lamports_per_signature: u64,
|
||||||
|
|
||||||
// The target cost of a signature when the cluster is operating around target_signatures_per_slot
|
// The target cost of a signature when the cluster is operating around target_signatures_per_slot
|
||||||
// signatures
|
// signatures
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use solana_sdk::clock::Slot;
|
use solana_sdk::clock::Slot;
|
||||||
|
|
||||||
#[derive(Default, Clone, Deserialize, Serialize, AbiExample)]
|
#[derive(Default, Clone, Debug, Deserialize, Serialize, AbiExample, PartialEq, Eq)]
|
||||||
pub struct HardForks {
|
pub struct HardForks {
|
||||||
hard_forks: Vec<(Slot, usize)>,
|
hard_forks: Vec<(Slot, usize)>,
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use std::ops::Deref;
|
|||||||
|
|
||||||
pub const MAX_ENTRIES: usize = 512; // it should never take as many as 512 epochs to warm up or cool down
|
pub const MAX_ENTRIES: usize = 512; // it should never take as many as 512 epochs to warm up or cool down
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Default, Clone, AbiExample)]
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, Clone, AbiExample)]
|
||||||
pub struct StakeHistoryEntry {
|
pub struct StakeHistoryEntry {
|
||||||
pub effective: u64, // effective stake at this epoch
|
pub effective: u64, // effective stake at this epoch
|
||||||
pub activating: u64, // sum of portion of stakes not fully warmed up
|
pub activating: u64, // sum of portion of stakes not fully warmed up
|
||||||
@ -16,7 +16,7 @@ pub struct StakeHistoryEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Default, Clone, AbiExample)]
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, Clone, AbiExample)]
|
||||||
pub struct StakeHistory(Vec<(Epoch, StakeHistoryEntry)>);
|
pub struct StakeHistory(Vec<(Epoch, StakeHistoryEntry)>);
|
||||||
|
|
||||||
impl StakeHistory {
|
impl StakeHistory {
|
||||||
|
Reference in New Issue
Block a user