Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMD-0207: Fix for loading bank from snapshot #4109

Closed
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
33 changes: 24 additions & 9 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6829,6 +6829,9 @@ impl Bank {
Arc::new(reserved_keys)
};

// Update the cost-tracker's block limits.
self.update_block_limits();

if new_feature_activations.contains(&feature_set::pico_inflation::id()) {
*self.inflation.write().unwrap() = Inflation::pico();
self.fee_rate_governor.burn_percent = 50; // 50% fee burn
Expand Down Expand Up @@ -6917,15 +6920,6 @@ impl Bank {
);
}
}

if new_feature_activations.contains(&feature_set::raise_block_limits_to_50m::id()) {
let (account_cost_limit, block_cost_limit, vote_cost_limit) = simd_0207_block_limits();
self.write_cost_tracker().unwrap().set_limits(
account_cost_limit,
block_cost_limit,
vote_cost_limit,
);
}
}

fn apply_updated_hashes_per_tick(&mut self, hashes_per_tick: u64) {
Expand All @@ -6937,6 +6931,27 @@ impl Bank {
self.hashes_per_tick = Some(hashes_per_tick);
}

fn update_block_limits(&self) {
let mut cost_tracker = self.write_cost_tracker().unwrap();

// For tests and benches, if the limit is set to maximum then skip
// setting feature-specific limits.
#[cfg(feature = "dev-context-only-utils")]
{
if cost_tracker.get_block_limit() == u64::MAX {
return;
}
}

if self
.feature_set
.is_active(&feature_set::raise_block_limits_to_50m::id())
{
let (account_cost_limit, block_cost_limit, vote_cost_limit) = simd_0207_block_limits();
cost_tracker.set_limits(account_cost_limit, block_cost_limit, vote_cost_limit);
}
}

fn adjust_sysvar_balance_for_rent(&self, account: &mut AccountSharedData) {
account.set_lamports(
self.get_minimum_balance_for_rent_exemption(account.data().len())
Expand Down
22 changes: 22 additions & 0 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8031,6 +8031,28 @@ fn test_block_limits() {
MAX_BLOCK_UNITS_SIMD_0207,
"child bank should have new limit"
);

// If we manually set limits to some other value,
// they will get reset upon new_from_parent for new epoch.
bank.write_cost_tracker().unwrap().set_limits(1, 2, 0);
let slots_per_epoch = bank.epoch_schedule().slots_per_epoch;
let bank = Bank::new_from_parent(Arc::new(bank), &Pubkey::default(), slots_per_epoch);
Comment on lines +8038 to +8039

Choose a reason for hiding this comment

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

fwiw, there is a helper function, new_from_parent_next_epoch(), that could also be used here.

assert_eq!(
bank.read_cost_tracker().unwrap().get_block_limit(),
MAX_BLOCK_UNITS_SIMD_0207,
"child bank ignores parent, uses feature-set to derive limits"
);

// Test that for tests/benches if set to u64::MAX, the limits will not reset on the epoch.
bank.write_cost_tracker()
.unwrap()
.set_limits(u64::MAX, u64::MAX, u64::MAX);
let bank = Bank::new_from_parent(Arc::new(bank), &Pubkey::default(), 2 * slots_per_epoch);
assert_eq!(
bank.read_cost_tracker().unwrap().get_block_limit(),
u64::MAX,
"child bank should have the same limit"
);
}

#[test]
Expand Down
Loading