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

Commit ab606c6

Browse files
committed
Fix fee mismatch on snapshot deserialize (#12697)
Co-authored-by: Carl Lin <carl@solana.com> (cherry picked from commit c879e7c)
1 parent 033c87e commit ab606c6

File tree

10 files changed

+65
-59
lines changed

10 files changed

+65
-59
lines changed

core/tests/bank_forks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mod tests {
153153
.get(&deserialized_bank.slot())
154154
.unwrap()
155155
.clone();
156-
bank.compare_bank(&deserialized_bank);
156+
assert!(*bank == deserialized_bank);
157157

158158
let slot_snapshot_paths = snapshot_utils::get_snapshot_paths(&snapshot_path);
159159

explorer/wasm/src/stake_account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub type Epoch = u64;
113113

114114
#[wasm_bindgen]
115115
#[repr(transparent)]
116-
#[derive(Serialize, Deserialize, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
116+
#[derive(Serialize, Debug, Deserialize, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
117117
pub struct Pubkey([u8; 32]);
118118

119119
#[wasm_bindgen]
@@ -164,7 +164,7 @@ impl Stake {
164164
}
165165

166166
#[wasm_bindgen]
167-
#[derive(Serialize, Deserialize, PartialEq, Clone, Copy)]
167+
#[derive(Serialize, Debug, Deserialize, PartialEq, Clone, Copy)]
168168
pub struct Delegation {
169169
/// to whom the stake is delegated
170170
voter_pubkey: Pubkey,

programs/bpf/tests/programs.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ fn process_transaction_and_record_inner(
105105
let signature = tx.signatures.get(0).unwrap().clone();
106106
let txs = vec![tx];
107107
let tx_batch = bank.prepare_batch(&txs, None);
108-
let (mut results, _, mut inner, _transaction_logs) =
109-
bank.load_execute_and_commit_transactions(&tx_batch, MAX_PROCESSING_AGE, false, true, false);
108+
let (mut results, _, mut inner, _transaction_logs) = bank.load_execute_and_commit_transactions(
109+
&tx_batch,
110+
MAX_PROCESSING_AGE,
111+
false,
112+
true,
113+
false,
114+
);
110115
let inner_instructions = inner.swap_remove(0);
111116
let result = results
112117
.fee_collection_results

runtime/src/bank.rs

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ pub(crate) struct BankFieldsToDeserialize {
448448
// This is separated from BankFieldsToDeserialize to avoid cloning by using refs.
449449
// So, sync fields with BankFieldsToDeserialize!
450450
// all members are made public to remain Bank private and to make versioned serializer workable on this
451+
#[derive(Debug)]
451452
pub(crate) struct BankFieldsToSerialize<'a> {
452453
pub(crate) blockhash_queue: &'a RwLock<BlockhashQueue>,
453454
pub(crate) ancestors: &'a Ancestors,
@@ -505,6 +506,47 @@ impl fmt::Display for RewardType {
505506
}
506507
}
507508

509+
#[derive(Debug, PartialEq, Serialize, Deserialize, AbiExample, Clone, Copy)]
510+
// Can't derive PartialEq because RwLock doesn't implement PartialEq
511+
impl PartialEq for Bank {
512+
fn eq(&self, other: &Self) -> bool {
513+
if ptr::eq(self, other) {
514+
return true;
515+
}
516+
*self.blockhash_queue.read().unwrap() == *other.blockhash_queue.read().unwrap()
517+
&& self.ancestors == other.ancestors
518+
&& *self.hash.read().unwrap() == *other.hash.read().unwrap()
519+
&& self.parent_hash == other.parent_hash
520+
&& self.parent_slot == other.parent_slot
521+
&& *self.hard_forks.read().unwrap() == *other.hard_forks.read().unwrap()
522+
&& self.transaction_count.load(Relaxed) == other.transaction_count.load(Relaxed)
523+
&& self.tick_height.load(Relaxed) == other.tick_height.load(Relaxed)
524+
&& self.signature_count.load(Relaxed) == other.signature_count.load(Relaxed)
525+
&& self.capitalization.load(Relaxed) == other.capitalization.load(Relaxed)
526+
&& self.max_tick_height == other.max_tick_height
527+
&& self.hashes_per_tick == other.hashes_per_tick
528+
&& self.ticks_per_slot == other.ticks_per_slot
529+
&& self.ns_per_slot == other.ns_per_slot
530+
&& self.genesis_creation_time == other.genesis_creation_time
531+
&& self.slots_per_year == other.slots_per_year
532+
&& self.unused == other.unused
533+
&& self.slot == other.slot
534+
&& self.epoch == other.epoch
535+
&& self.block_height == other.block_height
536+
&& self.collector_id == other.collector_id
537+
&& self.collector_fees.load(Relaxed) == other.collector_fees.load(Relaxed)
538+
&& self.fee_calculator == other.fee_calculator
539+
&& self.fee_rate_governor == other.fee_rate_governor
540+
&& self.collected_rent.load(Relaxed) == other.collected_rent.load(Relaxed)
541+
&& self.rent_collector == other.rent_collector
542+
&& self.epoch_schedule == other.epoch_schedule
543+
&& *self.inflation.read().unwrap() == *other.inflation.read().unwrap()
544+
&& *self.stakes.read().unwrap() == *other.stakes.read().unwrap()
545+
&& self.epoch_stakes == other.epoch_stakes
546+
&& self.is_delta.load(Relaxed) == other.is_delta.load(Relaxed)
547+
}
548+
}
549+
508550
#[derive(Debug, PartialEq, Serialize, Deserialize, AbiExample, Clone, Copy)]
509551
pub struct RewardInfo {
510552
pub reward_type: RewardType,
@@ -907,7 +949,11 @@ impl Bank {
907949
);
908950
assert_eq!(bank.epoch_schedule, genesis_config.epoch_schedule);
909951
assert_eq!(bank.epoch, bank.epoch_schedule.get_epoch(bank.slot));
910-
952+
bank.fee_rate_governor.lamports_per_signature = bank.fee_calculator.lamports_per_signature;
953+
assert_eq!(
954+
bank.fee_rate_governor.create_fee_calculator(),
955+
bank.fee_calculator
956+
);
911957
bank
912958
}
913959

@@ -3699,51 +3745,6 @@ impl Bank {
36993745
}
37003746
}
37013747

3702-
pub fn compare_bank(&self, dbank: &Bank) {
3703-
if ptr::eq(self, dbank) {
3704-
return;
3705-
}
3706-
assert_eq!(self.slot, dbank.slot);
3707-
assert_eq!(self.collector_id, dbank.collector_id);
3708-
assert_eq!(self.epoch_schedule, dbank.epoch_schedule);
3709-
assert_eq!(self.hashes_per_tick, dbank.hashes_per_tick);
3710-
assert_eq!(self.ticks_per_slot, dbank.ticks_per_slot);
3711-
assert_eq!(self.parent_hash, dbank.parent_hash);
3712-
assert_eq!(
3713-
self.tick_height.load(Relaxed),
3714-
dbank.tick_height.load(Relaxed)
3715-
);
3716-
assert_eq!(self.is_delta.load(Relaxed), dbank.is_delta.load(Relaxed));
3717-
3718-
{
3719-
let bh = self.hash.read().unwrap();
3720-
let dbh = dbank.hash.read().unwrap();
3721-
assert_eq!(*bh, *dbh);
3722-
}
3723-
3724-
{
3725-
let st = self.stakes.read().unwrap();
3726-
let dst = dbank.stakes.read().unwrap();
3727-
assert_eq!(*st, *dst);
3728-
}
3729-
3730-
{
3731-
let bhq = self.blockhash_queue.read().unwrap();
3732-
let dbhq = dbank.blockhash_queue.read().unwrap();
3733-
assert_eq!(*bhq, *dbhq);
3734-
}
3735-
3736-
{
3737-
let sc = self.src.status_cache.read().unwrap();
3738-
let dsc = dbank.src.status_cache.read().unwrap();
3739-
assert_eq!(*sc, *dsc);
3740-
}
3741-
assert_eq!(
3742-
self.rc.accounts.bank_hash_at(self.slot),
3743-
dbank.rc.accounts.bank_hash_at(dbank.slot)
3744-
);
3745-
}
3746-
37473748
pub fn clean_accounts(&self) {
37483749
self.rc.accounts.accounts_db.clean_accounts();
37493750
}

runtime/src/blockhash_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct HashAge {
1313

1414
/// Low memory overhead, so can be cloned for every checkpoint
1515
#[frozen_abi(digest = "EwaoLA34VN18E95GvjmkeStUpWqTeBd7FGpd7mppLmEw")]
16-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, AbiExample)]
16+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, AbiExample)]
1717
pub struct BlockhashQueue {
1818
/// updated whenever an hash is registered
1919
hash_height: u64,

runtime/src/epoch_stakes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use std::{collections::HashMap, sync::Arc};
77
pub type NodeIdToVoteAccounts = HashMap<Pubkey, NodeVoteAccounts>;
88
pub type EpochAuthorizedVoters = HashMap<Pubkey, Pubkey>;
99

10-
#[derive(Clone, Serialize, Debug, Deserialize, Default, PartialEq, AbiExample)]
10+
#[derive(Clone, Serialize, Debug, Deserialize, Default, PartialEq, Eq, AbiExample)]
1111
pub struct NodeVoteAccounts {
1212
pub vote_accounts: Vec<Pubkey>,
1313
pub total_stake: u64,
1414
}
1515

16-
#[derive(Clone, Serialize, Deserialize, AbiExample)]
16+
#[derive(Clone, Debug, Serialize, Deserialize, AbiExample, PartialEq)]
1717
pub struct EpochStakes {
1818
stakes: Arc<Stakes>,
1919
total_stake: u64,

runtime/src/serde_snapshot/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn test_bank_serialize_style(serde_style: SerdeStyle) {
219219
assert_eq!(dbank.get_balance(&key1.pubkey()), 0);
220220
assert_eq!(dbank.get_balance(&key2.pubkey()), 10);
221221
assert_eq!(dbank.get_balance(&key3.pubkey()), 0);
222-
bank2.compare_bank(&dbank);
222+
assert!(bank2 == dbank);
223223
}
224224

225225
#[cfg(test)]

sdk/src/fee_calculator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct FeeRateGovernor {
6868
// The current cost of a signature This amount may increase/decrease over time based on
6969
// cluster processing load.
7070
#[serde(skip)]
71-
lamports_per_signature: u64,
71+
pub lamports_per_signature: u64,
7272

7373
// The target cost of a signature when the cluster is operating around target_signatures_per_slot
7474
// signatures

sdk/src/hard_forks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use byteorder::{ByteOrder, LittleEndian};
55
use solana_sdk::clock::Slot;
66

7-
#[derive(Default, Clone, Deserialize, Serialize, AbiExample)]
7+
#[derive(Default, Clone, Debug, Deserialize, Serialize, AbiExample, PartialEq, Eq)]
88
pub struct HardForks {
99
hard_forks: Vec<(Slot, usize)>,
1010
}

sdk/src/stake_history.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use std::ops::Deref;
88

99
pub const MAX_ENTRIES: usize = 512; // it should never take as many as 512 epochs to warm up or cool down
1010

11-
#[derive(Debug, Serialize, Deserialize, PartialEq, Default, Clone, AbiExample)]
11+
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, Clone, AbiExample)]
1212
pub struct StakeHistoryEntry {
1313
pub effective: u64, // effective stake at this epoch
1414
pub activating: u64, // sum of portion of stakes not fully warmed up
1515
pub deactivating: u64, // requested to be cooled down, not fully deactivated yet
1616
}
1717

1818
#[repr(C)]
19-
#[derive(Debug, Serialize, Deserialize, PartialEq, Default, Clone, AbiExample)]
19+
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, Clone, AbiExample)]
2020
pub struct StakeHistory(Vec<(Epoch, StakeHistoryEntry)>);
2121

2222
impl StakeHistory {

0 commit comments

Comments
 (0)