Skip to content

Commit

Permalink
[JIT-1713] Fix bundle's blockspace preallocation (Backport to 1.16) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
esemeniuc authored Dec 8, 2023
1 parent 1534ac6 commit f5b3610
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions core/src/bundle_stage/bundle_reserved_space_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl BundleReservedSpaceManager {

/// return true if the bank is still in the period where block_cost_limits is reduced
pub fn is_in_reserved_tick_period(&self, bank: &Bank) -> bool {
bank.tick_height() < self.reserved_ticks
bank.tick_height() % bank.ticks_per_slot() < self.reserved_ticks
}

/// return the block_cost_limits as determined by the tick height of the bank
Expand All @@ -82,8 +82,10 @@ impl BundleReservedSpaceManager {
mod tests {
use {
crate::bundle_stage::bundle_reserved_space_manager::BundleReservedSpaceManager,
solana_ledger::genesis_utils::create_genesis_config, solana_runtime::bank::Bank,
solana_sdk::hash::Hash, std::sync::Arc,
solana_ledger::genesis_utils::create_genesis_config,
solana_runtime::bank::Bank,
solana_sdk::{hash::Hash, pubkey::Pubkey},
std::sync::Arc,
};

#[test]
Expand Down Expand Up @@ -186,4 +188,52 @@ mod tests {
block_cost_limits
);
}

#[test]
fn test_block_limits_after_first_slot() {
const BUNDLE_BLOCK_COST_LIMITS_RESERVATION: u64 = 100;
const RESERVED_TICKS: u64 = 5;
let genesis_config_info = create_genesis_config(100);
let bank = Arc::new(Bank::new_for_tests(&genesis_config_info.genesis_config));

for _ in 0..genesis_config_info.genesis_config.ticks_per_slot {
bank.register_tick(&Hash::default());
}
assert!(bank.is_complete());
bank.freeze();
assert_eq!(
bank.read_cost_tracker().unwrap().block_cost_limit(),
solana_runtime::block_cost_limits::MAX_BLOCK_UNITS,
);

let bank1 = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 1));
assert_eq!(bank1.slot(), 1);
assert_eq!(bank1.tick_height(), 64);
assert_eq!(bank1.max_tick_height(), 128);

// reserve space
let block_cost_limits = bank1.read_cost_tracker().unwrap().block_cost_limit();
let mut reserved_space = BundleReservedSpaceManager::new(
block_cost_limits,
BUNDLE_BLOCK_COST_LIMITS_RESERVATION,
RESERVED_TICKS,
);
reserved_space.tick(&bank1);

// wait for reservation to be over
(0..RESERVED_TICKS).for_each(|_| {
bank1.register_tick(&Hash::default());
assert_eq!(
bank1.read_cost_tracker().unwrap().block_cost_limit(),
block_cost_limits - BUNDLE_BLOCK_COST_LIMITS_RESERVATION
);
});
reserved_space.tick(&bank1);

// after reservation, revert back to normal limit
assert_eq!(
bank1.read_cost_tracker().unwrap().block_cost_limit(),
solana_runtime::block_cost_limits::MAX_BLOCK_UNITS,
);
}
}

0 comments on commit f5b3610

Please sign in to comment.