Add LeaderScheduler constructor to Bank
By passing a config and not a Arc'ed LeaderScheduler, callers need to use `Bank::leader_scheduler` to access the scheduler. By using the new constructor, there should be no incentive to reach into the bank for that object.
This commit is contained in:
parent
1809277e05
commit
643384e1ec
18
src/bank.rs
18
src/bank.rs
|
@ -121,20 +121,28 @@ impl Default for Bank {
|
|||
}
|
||||
|
||||
impl Bank {
|
||||
pub fn new_with_leader_scheduler_config(
|
||||
pub fn new_with_leader_scheduler(
|
||||
genesis_block: &GenesisBlock,
|
||||
leader_scheduler_config: &LeaderSchedulerConfig,
|
||||
leader_scheduler: Arc<RwLock<LeaderScheduler>>,
|
||||
) -> Self {
|
||||
let mut bank = Self::default();
|
||||
bank.leader_scheduler =
|
||||
Arc::new(RwLock::new(LeaderScheduler::new(leader_scheduler_config)));
|
||||
bank.leader_scheduler = leader_scheduler;
|
||||
bank.process_genesis_block(genesis_block);
|
||||
bank.add_builtin_programs();
|
||||
bank
|
||||
}
|
||||
|
||||
pub fn new_with_leader_scheduler_config(
|
||||
genesis_block: &GenesisBlock,
|
||||
leader_scheduler_config: &LeaderSchedulerConfig,
|
||||
) -> Self {
|
||||
let leader_scheduler = Arc::new(RwLock::new(LeaderScheduler::new(leader_scheduler_config)));
|
||||
Self::new_with_leader_scheduler(genesis_block, leader_scheduler)
|
||||
}
|
||||
|
||||
pub fn new(genesis_block: &GenesisBlock) -> Self {
|
||||
Self::new_with_leader_scheduler_config(genesis_block, &LeaderSchedulerConfig::default())
|
||||
let leader_scheduler = Arc::new(RwLock::new(LeaderScheduler::default()));
|
||||
Self::new_with_leader_scheduler(genesis_block, leader_scheduler)
|
||||
}
|
||||
|
||||
pub fn set_subscriptions(&self, subscriptions: Arc<RpcSubscriptions>) {
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::cluster_info::{ClusterInfo, Node, NodeInfo};
|
|||
use crate::counter::Counter;
|
||||
use crate::genesis_block::GenesisBlock;
|
||||
use crate::gossip_service::GossipService;
|
||||
use crate::leader_scheduler::LeaderSchedulerConfig;
|
||||
use crate::leader_scheduler::{LeaderScheduler, LeaderSchedulerConfig};
|
||||
use crate::poh_service::PohServiceConfig;
|
||||
use crate::rpc::JsonRpcService;
|
||||
use crate::rpc_pubsub::PubSubService;
|
||||
|
@ -122,6 +122,9 @@ impl Fullnode {
|
|||
let id = keypair.pubkey();
|
||||
assert_eq!(id, node.info.id);
|
||||
|
||||
let leader_scheduler = Arc::new(RwLock::new(LeaderScheduler::new(
|
||||
&config.leader_scheduler_config,
|
||||
)));
|
||||
let (
|
||||
bank,
|
||||
entry_height,
|
||||
|
@ -129,11 +132,7 @@ impl Fullnode {
|
|||
blocktree,
|
||||
ledger_signal_sender,
|
||||
ledger_signal_receiver,
|
||||
) = new_bank_from_ledger(
|
||||
ledger_path,
|
||||
&config.ledger_config(),
|
||||
&config.leader_scheduler_config,
|
||||
);
|
||||
) = new_bank_from_ledger(ledger_path, &config.ledger_config(), &leader_scheduler);
|
||||
|
||||
info!("node info: {:?}", node.info);
|
||||
info!("node entrypoint_info: {:?}", entrypoint_info_option);
|
||||
|
@ -456,14 +455,14 @@ impl Fullnode {
|
|||
pub fn new_bank_from_ledger(
|
||||
ledger_path: &str,
|
||||
ledger_config: &BlocktreeConfig,
|
||||
leader_scheduler_config: &LeaderSchedulerConfig,
|
||||
leader_scheduler: &Arc<RwLock<LeaderScheduler>>,
|
||||
) -> (Bank, u64, Hash, Blocktree, SyncSender<bool>, Receiver<bool>) {
|
||||
let (blocktree, ledger_signal_sender, ledger_signal_receiver) =
|
||||
Blocktree::open_with_config_signal(ledger_path, ledger_config)
|
||||
.expect("Expected to successfully open database ledger");
|
||||
let genesis_block =
|
||||
GenesisBlock::load(ledger_path).expect("Expected to successfully open genesis block");
|
||||
let bank = Bank::new_with_leader_scheduler_config(&genesis_block, leader_scheduler_config);
|
||||
let bank = Bank::new_with_leader_scheduler(&genesis_block, leader_scheduler.clone());
|
||||
|
||||
let now = Instant::now();
|
||||
info!("processing ledger...");
|
||||
|
@ -824,7 +823,7 @@ mod tests {
|
|||
let (bank, entry_height, _, _, _, _) = new_bank_from_ledger(
|
||||
&validator_ledger_path,
|
||||
&BlocktreeConfig::default(),
|
||||
&LeaderSchedulerConfig::default(),
|
||||
&Arc::new(RwLock::new(LeaderScheduler::default())),
|
||||
);
|
||||
|
||||
assert!(bank.tick_height() >= bank.leader_scheduler.read().unwrap().ticks_per_epoch);
|
||||
|
|
|
@ -368,7 +368,9 @@ mod test {
|
|||
use crate::entry::{next_entry_mut, Entry};
|
||||
use crate::fullnode::new_bank_from_ledger;
|
||||
use crate::genesis_block::GenesisBlock;
|
||||
use crate::leader_scheduler::{make_active_set_entries, LeaderSchedulerConfig};
|
||||
use crate::leader_scheduler::{
|
||||
make_active_set_entries, LeaderScheduler, LeaderSchedulerConfig,
|
||||
};
|
||||
use crate::replay_stage::ReplayStage;
|
||||
use crate::voting_keypair::VotingKeypair;
|
||||
use solana_sdk::hash::Hash;
|
||||
|
@ -395,6 +397,8 @@ mod test {
|
|||
// Set up the LeaderScheduler so that my_id becomes the leader for epoch 1
|
||||
let ticks_per_slot = 16;
|
||||
let leader_scheduler_config = LeaderSchedulerConfig::new(ticks_per_slot, 1, ticks_per_slot);
|
||||
let leader_scheduler =
|
||||
Arc::new(RwLock::new(LeaderScheduler::new(&leader_scheduler_config)));
|
||||
|
||||
// Create a ledger
|
||||
let (
|
||||
|
@ -446,7 +450,7 @@ mod test {
|
|||
// Set up the bank
|
||||
let blocktree_config = BlocktreeConfig::new(ticks_per_slot);
|
||||
let (bank, _entry_height, last_entry_id, blocktree, l_sender, l_receiver) =
|
||||
new_bank_from_ledger(&my_ledger_path, &blocktree_config, &leader_scheduler_config);
|
||||
new_bank_from_ledger(&my_ledger_path, &blocktree_config, &leader_scheduler);
|
||||
|
||||
// Set up the replay stage
|
||||
let (rotation_sender, rotation_receiver) = channel();
|
||||
|
@ -553,7 +557,7 @@ mod test {
|
|||
new_bank_from_ledger(
|
||||
&my_ledger_path,
|
||||
&BlocktreeConfig::default(),
|
||||
&LeaderSchedulerConfig::default(),
|
||||
&Arc::new(RwLock::new(LeaderScheduler::default())),
|
||||
);
|
||||
|
||||
let bank = Arc::new(bank);
|
||||
|
@ -663,6 +667,8 @@ mod test {
|
|||
|
||||
let leader_scheduler_config =
|
||||
LeaderSchedulerConfig::new(ticks_per_slot, slots_per_epoch, active_window_tick_length);
|
||||
let leader_scheduler =
|
||||
Arc::new(RwLock::new(LeaderScheduler::new(&leader_scheduler_config)));
|
||||
|
||||
// Set up the cluster info
|
||||
let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone())));
|
||||
|
@ -672,7 +678,7 @@ mod test {
|
|||
let exit = Arc::new(AtomicBool::new(false));
|
||||
{
|
||||
let (bank, _entry_height, last_entry_id, blocktree, l_sender, l_receiver) =
|
||||
new_bank_from_ledger(&my_ledger_path, &blocktree_config, &leader_scheduler_config);
|
||||
new_bank_from_ledger(&my_ledger_path, &blocktree_config, &leader_scheduler);
|
||||
|
||||
let meta = blocktree
|
||||
.meta(0)
|
||||
|
|
|
@ -8,7 +8,7 @@ use solana::cluster_info::{Node, NodeInfo};
|
|||
use solana::entry::{reconstruct_entries_from_blobs, Entry};
|
||||
use solana::fullnode::{new_bank_from_ledger, Fullnode, FullnodeConfig, FullnodeReturnType};
|
||||
use solana::gossip_service::{converge, make_listening_node};
|
||||
use solana::leader_scheduler::{make_active_set_entries, LeaderSchedulerConfig};
|
||||
use solana::leader_scheduler::{make_active_set_entries, LeaderScheduler, LeaderSchedulerConfig};
|
||||
use solana::result;
|
||||
use solana::service::Service;
|
||||
use solana::thin_client::{poll_gossip_for_leader, retry_get_balance};
|
||||
|
@ -1010,7 +1010,7 @@ fn test_leader_to_validator_transition() {
|
|||
let bank = new_bank_from_ledger(
|
||||
&leader_ledger_path,
|
||||
&BlocktreeConfig::default(),
|
||||
&LeaderSchedulerConfig::default(),
|
||||
&Arc::new(RwLock::new(LeaderScheduler::default())),
|
||||
)
|
||||
.0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue