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

Serialize lamports per signature#25364

Merged
AshwinSekar merged 2 commits intosolana-labs:masterfrom
AshwinSekar:lamps-per-sig
Jun 6, 2022
Merged

Serialize lamports per signature#25364
AshwinSekar merged 2 commits intosolana-labs:masterfrom
AshwinSekar:lamps-per-sig

Conversation

@AshwinSekar
Copy link
Copy Markdown
Contributor

@AshwinSekar AshwinSekar commented May 19, 2022

Problem

The FeeRateGovernor in a bank does not serialize its current lamports_per_signature on snapshot. This causes issues if the block that we start a snapshot from is lined up with a fee increase, it is possible for this lamports_per_signature to be invalid.

Summary of Changes

Serialize and deserialize this field by accessing it from the FeeRateGovernor

To avoid the same issue as #25181, we manually serialize it as an extra field at the end of the snapshot. The issue with the previous solution was that we serialized it as part of the bank which caused problems as the accounts db fields were serialized after it.

Fixes #23545

@AshwinSekar AshwinSekar force-pushed the lamps-per-sig branch 3 times, most recently from cc9ea02 to 76cf6fe Compare May 20, 2022 06:18
@AshwinSekar AshwinSekar marked this pull request as ready for review May 25, 2022 18:49
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2022

Codecov Report

Merging #25364 (5baba2c) into master (f9f6b94) will increase coverage by 0.0%.
The diff coverage is 78.9%.

@@            Coverage Diff            @@
##           master   #25364     +/-   ##
=========================================
  Coverage    82.0%    82.0%             
=========================================
  Files         655      620     -35     
  Lines      171822   170582   -1240     
  Branches      335        0    -335     
=========================================
- Hits       140972   140027    -945     
+ Misses      30734    30555    -179     
+ Partials      116        0    -116     

Copy link
Copy Markdown
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! Sorry about the long review delay...

Comment thread runtime/src/genesis_utils.rs
Comment thread runtime/src/serde_snapshot/newer.rs
Comment thread runtime/src/serde_snapshot/tests.rs
@AshwinSekar AshwinSekar requested a review from brooksprumo June 5, 2022 03:44
Copy link
Copy Markdown
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the previous replies; this PR looks good.

One last question is on the decision to put lamports_per_signature as a new field in the returned tuple from serialize_bank_and_storage():

// Additional fields, we manually store the lamps per signature here so that
// we can grab it on restart.
// TODO: if we do a snapshot version bump, consider moving this out.
lamports_per_signature,

Instead, would it be possible to put lamports_per_signature at the end of DeserializableVersionedBank with the serde default_on_eof?

    #[serde(deserialize_with = "default_on_eof")]
    lamports_per_signature: u64,

struct DeserializableVersionedBank {
blockhash_queue: BlockhashQueue,
ancestors: AncestorsForSerialization,
hash: Hash,
parent_hash: Hash,
parent_slot: Slot,
hard_forks: HardForks,
transaction_count: u64,
tick_height: u64,
signature_count: u64,
capitalization: u64,
max_tick_height: u64,
hashes_per_tick: Option<u64>,
ticks_per_slot: u64,
ns_per_slot: u128,
genesis_creation_time: UnixTimestamp,
slots_per_year: f64,
accounts_data_len: u64,
slot: Slot,
epoch: Epoch,
block_height: u64,
collector_id: Pubkey,
collector_fees: u64,
fee_calculator: FeeCalculator,
fee_rate_governor: FeeRateGovernor,
collected_rent: u64,
rent_collector: RentCollector,
epoch_schedule: EpochSchedule,
inflation: Inflation,
stakes: Stakes<Delegation>,
#[allow(dead_code)]
unused_accounts: UnusedAccounts,
epoch_stakes: HashMap<Epoch, EpochStakes>,
is_delta: bool,
}

That's how historical_roots is handled for AccountsDbFields:

struct AccountsDbFields<T>(
HashMap<Slot, Vec<T>>,
StoredMetaWriteVersion,
Slot,
BankHashInfo,
/// all slots that were roots within the last epoch
#[serde(deserialize_with = "default_on_eof")]
Vec<Slot>,
/// slots that were roots within the last epoch for which we care about the hash value
#[serde(deserialize_with = "default_on_eof")]
Vec<(Slot, Hash)>,
);

That may make the impl simpler. Sorry if you already tried doing this but I missed it!

@AshwinSekar
Copy link
Copy Markdown
Contributor Author

AshwinSekar commented Jun 6, 2022

That was actually my initial approach see here (https://github.com/solana-labs/solana/pull/25181/files). Turns out it doesn't
work because both the bank and accounts db are serialized in the same file with the bank being serialized first

https://github.com/solana-labs/solana/blob/master/runtime/src/serde_snapshot/newer.rs#L199

Because of this default_on_eof doesn't work as it ends up picking up part of the accounts db data.

@AshwinSekar AshwinSekar requested a review from brooksprumo June 6, 2022 19:35
Copy link
Copy Markdown
Contributor

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@AshwinSekar AshwinSekar merged commit 8caced6 into solana-labs:master Jun 6, 2022
mergify Bot pushed a commit that referenced this pull request Jun 6, 2022
* Serialize lamports per signature

* Add full snapshot archive test, enable features in previous tests

(cherry picked from commit 8caced6)

# Conflicts:
#	runtime/src/serde_snapshot.rs
#	runtime/src/serde_snapshot/newer.rs
#	runtime/src/serde_snapshot/tests.rs
AshwinSekar added a commit that referenced this pull request Jun 7, 2022
* Serialize lamports per signature

* Add full snapshot archive test, enable features in previous tests

(cherry picked from commit 8caced6)

# Conflicts:
#	runtime/src/serde_snapshot.rs
#	runtime/src/serde_snapshot/newer.rs
#	runtime/src/serde_snapshot/tests.rs
AshwinSekar added a commit that referenced this pull request Jun 22, 2022
This allows us to deserialize v1.11 snapshots

Original:
Serialize lamports per signature (#25364)

* Serialize lamports per signature

* Add full snapshot archive test, enable features in previous tests

(cherry picked from commit 8caced6)
AshwinSekar added a commit that referenced this pull request Jun 22, 2022
This allows us to deserialize v1.11 snapshots

Original:
Serialize lamports per signature (#25364)

* Serialize lamports per signature

* Add full snapshot archive test, enable features in previous tests

(cherry picked from commit 8caced6)
mergify Bot added a commit that referenced this pull request Jun 22, 2022
…25805)

This allows us to deserialize v1.11 snapshots

Original:
Serialize lamports per signature (#25364)

* Serialize lamports per signature

* Add full snapshot archive test, enable features in previous tests

(cherry picked from commit 8caced6)

Co-authored-by: Ashwin Sekar <ashwin@solana.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bank hash mismatch when a validator is offline for more than 512 slots (Slot hashes max entries)

2 participants