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

Serialize lamports per signature in snapshots #25181

Merged
merged 2 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion runtime/src/serde_snapshot/newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct DeserializableVersionedBank {
unused_accounts: UnusedAccounts,
epoch_stakes: HashMap<Epoch, EpochStakes>,
is_delta: bool,
#[serde(deserialize_with = "default_on_eof")]
lamports_per_signature: u64,
}

impl From<DeserializableVersionedBank> for BankFieldsToDeserialize {
Expand Down Expand Up @@ -88,7 +90,9 @@ impl From<DeserializableVersionedBank> for BankFieldsToDeserialize {
collector_id: dvb.collector_id,
collector_fees: dvb.collector_fees,
fee_calculator: dvb.fee_calculator,
fee_rate_governor: dvb.fee_rate_governor,
fee_rate_governor: dvb
.fee_rate_governor
.clone_with_lamports_per_signature(dvb.lamports_per_signature),
collected_rent: dvb.collected_rent,
rent_collector: dvb.rent_collector,
epoch_schedule: dvb.epoch_schedule,
Expand Down Expand Up @@ -137,10 +141,12 @@ struct SerializableVersionedBank<'a> {
unused_accounts: UnusedAccounts,
epoch_stakes: &'a HashMap<Epoch, EpochStakes>,
is_delta: bool,
lamports_per_signature: u64,
}

impl<'a> From<crate::bank::BankFieldsToSerialize<'a>> for SerializableVersionedBank<'a> {
fn from(rhs: crate::bank::BankFieldsToSerialize<'a>) -> Self {
let lamports_per_signature = rhs.fee_rate_governor.lamports_per_signature;
Self {
blockhash_queue: rhs.blockhash_queue,
ancestors: rhs.ancestors,
Expand Down Expand Up @@ -174,6 +180,7 @@ impl<'a> From<crate::bank::BankFieldsToSerialize<'a>> for SerializableVersionedB
unused_accounts: UnusedAccounts::default(),
epoch_stakes: rhs.epoch_stakes,
is_delta: rhs.is_delta,
lamports_per_signature,
}
}
}
Expand Down Expand Up @@ -311,6 +318,7 @@ impl<'a> TypeContext<'a> for Context {
let rhs = bank_fields;
let blockhash_queue = RwLock::new(rhs.blockhash_queue.clone());
let hard_forks = RwLock::new(rhs.hard_forks.clone());
let lamports_per_signature = rhs.fee_rate_governor.lamports_per_signature;
let bank = SerializableVersionedBank {
blockhash_queue: &blockhash_queue,
ancestors: &rhs.ancestors,
Expand Down Expand Up @@ -344,6 +352,7 @@ impl<'a> TypeContext<'a> for Context {
unused_accounts: UnusedAccounts::default(),
epoch_stakes: &rhs.epoch_stakes,
is_delta: rhs.is_delta,
lamports_per_signature,
};

bincode::serialize_into(stream_writer, &(bank, accounts_db_fields))
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 @@ -367,7 +367,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 = "HT9yewU4zJ6ZAgJ7aDSbHPtzZGZqASpq6rkq6ET42Kki")]
#[frozen_abi(digest = "3PiYioYfEPzm2u64FZLsLx1SUTGE3NUvALXvwqhxZuRF")]
#[derive(Serialize, AbiExample)]
pub struct BankAbiTestWrapperNewer {
#[serde(serialize_with = "wrapper_newer")]
Expand Down
7 changes: 7 additions & 0 deletions sdk/program/src/fee_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ impl FeeRateGovernor {
me
}

pub fn clone_with_lamports_per_signature(&self, lamports_per_signature: u64) -> Self {
Self {
lamports_per_signature,
..*self
}
}

/// calculate unburned fee from a fee total, returns (unburned, burned)
pub fn burn(&self, fees: u64) -> (u64, u64) {
let burned = fees * u64::from(self.burn_percent) / 100;
Expand Down