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