Consolidate fullnode ledger helpers
This commit is contained in:
parent
2e23b03f94
commit
f789038baa
|
@ -116,13 +116,17 @@ impl Fullnode {
|
|||
config: &FullnodeConfig,
|
||||
) -> Self {
|
||||
let id = keypair.pubkey();
|
||||
let (genesis_block, db_ledger, ledger_signal_sender, ledger_signal_receiver) =
|
||||
Self::make_db_ledger(ledger_path);
|
||||
let (bank, entry_height, last_entry_id) = Self::new_bank_from_db_ledger(
|
||||
&genesis_block,
|
||||
&db_ledger,
|
||||
Some(&config.leader_scheduler_config),
|
||||
);
|
||||
assert_eq!(id, node.info.id);
|
||||
|
||||
let (
|
||||
bank,
|
||||
entry_height,
|
||||
last_entry_id,
|
||||
db_ledger,
|
||||
ledger_signal_sender,
|
||||
ledger_signal_receiver,
|
||||
) = Self::new_bank_from_ledger(ledger_path, Some(&config.leader_scheduler_config));
|
||||
|
||||
info!("node info: {:?}", node.info);
|
||||
info!("node entrypoint_info: {:?}", entrypoint_info_option);
|
||||
info!(
|
||||
|
@ -132,9 +136,9 @@ impl Fullnode {
|
|||
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let bank = Arc::new(bank);
|
||||
let db_ledger = Arc::new(db_ledger);
|
||||
|
||||
node.info.wallclock = timestamp();
|
||||
assert_eq!(id, node.info.id);
|
||||
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new_with_keypair(
|
||||
node.info.clone(),
|
||||
keypair.clone(),
|
||||
|
@ -474,51 +478,37 @@ impl Fullnode {
|
|||
self.join()
|
||||
}
|
||||
|
||||
pub fn new_bank_from_db_ledger(
|
||||
genesis_block: &GenesisBlock,
|
||||
db_ledger: &DbLedger,
|
||||
pub fn new_bank_from_ledger(
|
||||
ledger_path: &str,
|
||||
leader_scheduler_config: Option<&LeaderSchedulerConfig>,
|
||||
) -> (Bank, u64, Hash) {
|
||||
) -> (Bank, u64, Hash, DbLedger, SyncSender<bool>, Receiver<bool>) {
|
||||
let (db_ledger, ledger_signal_sender, ledger_signal_receiver) =
|
||||
DbLedger::open_with_signal(ledger_path)
|
||||
.expect("Expected to successfully open database ledger");
|
||||
let genesis_block =
|
||||
GenesisBlock::load(ledger_path).expect("Expected to successfully open genesis block");
|
||||
let mut bank =
|
||||
Bank::new_with_leader_scheduler_config(genesis_block, leader_scheduler_config);
|
||||
Bank::new_with_leader_scheduler_config(&genesis_block, leader_scheduler_config);
|
||||
|
||||
let now = Instant::now();
|
||||
let entries = db_ledger.read_ledger().expect("opening ledger");
|
||||
info!("processing ledger...");
|
||||
|
||||
let (entry_height, last_entry_id) = bank.process_ledger(entries).expect("process_ledger");
|
||||
// entry_height is the network-wide agreed height of the ledger.
|
||||
// initialize it from the input ledger
|
||||
info!(
|
||||
"processed {} ledger entries in {}ms, tick_height={}...",
|
||||
entry_height,
|
||||
duration_as_ms(&now.elapsed()),
|
||||
bank.tick_height()
|
||||
);
|
||||
(bank, entry_height, last_entry_id)
|
||||
}
|
||||
|
||||
pub fn new_bank_from_ledger(
|
||||
ledger_path: &str,
|
||||
leader_scheduler_config: Option<&LeaderSchedulerConfig>,
|
||||
) -> (Bank, u64, Hash) {
|
||||
let (genesis_block, db_ledger, _, _) = Self::make_db_ledger(ledger_path);
|
||||
Self::new_bank_from_db_ledger(&genesis_block, &db_ledger, leader_scheduler_config)
|
||||
}
|
||||
|
||||
fn make_db_ledger(
|
||||
ledger_path: &str,
|
||||
) -> (
|
||||
GenesisBlock,
|
||||
Arc<DbLedger>,
|
||||
SyncSender<bool>,
|
||||
Receiver<bool>,
|
||||
) {
|
||||
let (db_ledger, l_sender, l_receiver) = DbLedger::open_with_signal(ledger_path)
|
||||
.expect("Expected to successfully open database ledger");
|
||||
let genesis_block =
|
||||
GenesisBlock::load(ledger_path).expect("Expected to successfully open genesis block");
|
||||
(genesis_block, Arc::new(db_ledger), l_sender, l_receiver)
|
||||
(
|
||||
bank,
|
||||
entry_height,
|
||||
last_entry_id,
|
||||
db_ledger,
|
||||
ledger_signal_sender,
|
||||
ledger_signal_receiver,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -838,9 +828,9 @@ mod tests {
|
|||
);
|
||||
|
||||
// Close the validator so that rocksdb has locks available
|
||||
// validator.close().unwrap();
|
||||
validator_exit();
|
||||
let (bank, entry_height, _) = Fullnode::new_bank_from_ledger(&validator_ledger_path, None);
|
||||
let (bank, entry_height, _, _, _, _) =
|
||||
Fullnode::new_bank_from_ledger(&validator_ledger_path, None);
|
||||
|
||||
assert!(
|
||||
bank.tick_height()
|
||||
|
|
|
@ -403,9 +403,7 @@ mod test {
|
|||
);
|
||||
last_id = active_set_entries.last().unwrap().id;
|
||||
{
|
||||
let (db_ledger, l_sender, l_receiver) =
|
||||
DbLedger::open_with_signal(&my_ledger_path).unwrap();
|
||||
let db_ledger = Arc::new(db_ledger);
|
||||
let db_ledger = DbLedger::open(&my_ledger_path).unwrap();
|
||||
db_ledger
|
||||
.write_entries(
|
||||
DEFAULT_SLOT_HEIGHT,
|
||||
|
@ -413,22 +411,19 @@ mod test {
|
|||
&active_set_entries,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let genesis_block = GenesisBlock::load(&my_ledger_path)
|
||||
.expect("Expected to successfully open genesis block");
|
||||
|
||||
{
|
||||
// Set up the bank
|
||||
let (bank, _, last_entry_id) = Fullnode::new_bank_from_db_ledger(
|
||||
&genesis_block,
|
||||
&db_ledger,
|
||||
Some(&leader_scheduler_config),
|
||||
);
|
||||
let (bank, _entry_height, last_entry_id, db_ledger, l_sender, l_receiver) =
|
||||
Fullnode::new_bank_from_ledger(&my_ledger_path, Some(&leader_scheduler_config));
|
||||
|
||||
// Set up the replay stage
|
||||
let (rotation_sender, rotation_receiver) = channel();
|
||||
let meta = db_ledger.meta().unwrap().unwrap();
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let bank = Arc::new(bank);
|
||||
let db_ledger = Arc::new(db_ledger);
|
||||
let (replay_stage, ledger_writer_recv) = ReplayStage::new(
|
||||
my_id,
|
||||
Some(Arc::new(voting_keypair)),
|
||||
|
@ -524,15 +519,11 @@ mod test {
|
|||
let voting_keypair = Arc::new(VotingKeypair::new_local(&my_keypair));
|
||||
let (to_leader_sender, _) = channel();
|
||||
{
|
||||
let (db_ledger, l_sender, l_receiver) =
|
||||
DbLedger::open_with_signal(&my_ledger_path).unwrap();
|
||||
let db_ledger = Arc::new(db_ledger);
|
||||
// Set up the bank
|
||||
let genesis_block = GenesisBlock::load(&my_ledger_path)
|
||||
.expect("Expected to successfully open genesis block");
|
||||
let (bank, entry_height, last_entry_id) =
|
||||
Fullnode::new_bank_from_db_ledger(&genesis_block, &db_ledger, None);
|
||||
let (bank, entry_height, last_entry_id, db_ledger, l_sender, l_receiver) =
|
||||
Fullnode::new_bank_from_ledger(&my_ledger_path, None);
|
||||
|
||||
let bank = Arc::new(bank);
|
||||
let db_ledger = Arc::new(db_ledger);
|
||||
let (replay_stage, ledger_writer_recv) = ReplayStage::new(
|
||||
my_keypair.pubkey(),
|
||||
Some(voting_keypair.clone()),
|
||||
|
@ -606,6 +597,17 @@ mod test {
|
|||
let active_set_entries_len = active_set_entries.len() as u64;
|
||||
let initial_non_tick_height = genesis_entry_height - initial_tick_height;
|
||||
|
||||
{
|
||||
let db_ledger = DbLedger::open(&my_ledger_path).unwrap();
|
||||
db_ledger
|
||||
.write_entries(
|
||||
DEFAULT_SLOT_HEIGHT,
|
||||
genesis_entry_height,
|
||||
&active_set_entries,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// Set up the LeaderScheduler so that this this node becomes the leader at
|
||||
// bootstrap_height = num_bootstrap_slots * leader_rotation_interval
|
||||
// Set up the LeaderScheduler so that this this node becomes the leader at
|
||||
|
@ -626,32 +628,17 @@ mod test {
|
|||
let (rotation_tx, rotation_rx) = channel();
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
{
|
||||
let (db_ledger, l_sender, l_receiver) =
|
||||
DbLedger::open_with_signal(&my_ledger_path).unwrap();
|
||||
let db_ledger = Arc::new(db_ledger);
|
||||
db_ledger
|
||||
.write_entries(
|
||||
DEFAULT_SLOT_HEIGHT,
|
||||
genesis_entry_height,
|
||||
&active_set_entries,
|
||||
)
|
||||
.unwrap();
|
||||
let (bank, _entry_height, last_entry_id, db_ledger, l_sender, l_receiver) =
|
||||
Fullnode::new_bank_from_ledger(&my_ledger_path, Some(&leader_scheduler_config));
|
||||
|
||||
let meta = db_ledger
|
||||
.meta()
|
||||
.unwrap()
|
||||
.expect("First slot metadata must exist");
|
||||
|
||||
// Set up the bank
|
||||
let genesis_block = GenesisBlock::load(&my_ledger_path)
|
||||
.expect("Expected to successfully open genesis block");
|
||||
let (bank, _, last_entry_id) = Fullnode::new_bank_from_db_ledger(
|
||||
&genesis_block,
|
||||
&db_ledger,
|
||||
Some(&leader_scheduler_config),
|
||||
);
|
||||
|
||||
let voting_keypair = Arc::new(voting_keypair);
|
||||
let bank = Arc::new(bank);
|
||||
let db_ledger = Arc::new(db_ledger);
|
||||
let (replay_stage, ledger_writer_recv) = ReplayStage::new(
|
||||
my_keypair.pubkey(),
|
||||
Some(voting_keypair.clone()),
|
||||
|
|
|
@ -1018,7 +1018,7 @@ fn test_leader_to_validator_transition() {
|
|||
leader_exit();
|
||||
|
||||
info!("Check the ledger to make sure it's the right height...");
|
||||
let (bank, _, _) = Fullnode::new_bank_from_ledger(&leader_ledger_path, None);
|
||||
let bank = Fullnode::new_bank_from_ledger(&leader_ledger_path, None).0;
|
||||
|
||||
assert_eq!(
|
||||
bank.tick_height(),
|
||||
|
|
Loading…
Reference in New Issue