From 377ba53a315d74d802bec5a9d5560e2fd2b1f44a Mon Sep 17 00:00:00 2001 From: steviez Date: Wed, 19 Apr 2023 13:12:34 -0500 Subject: [PATCH] Fix bug where ReplayStage holds an Arc for process lifetime (#31267) * Fix bug where ReplayStage holds an Arc for process lifetime When ReplayStage::new() kicks off, it needs to do some setup with the working bank prior to entering the main processing loop. This setup is done before entering the main processing loop; however, a bug made it such that an Arc remained in scope after the processing loop had been entered. The processing loop is only exited when the process exits, so this means that Bank was being held for the lifetime of the process. This is a waste of resources and prevents background cleanup. * clippy --- core/src/replay_stage.rs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 717ebe4cf1..06b107d728 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -561,7 +561,7 @@ impl ReplayStage { Self::reset_poh_recorder( &my_pubkey, &blockstore, - &working_bank, + working_bank, &poh_recorder, &leader_schedule_cache, ); @@ -931,7 +931,7 @@ impl ReplayStage { Self::reset_poh_recorder( &my_pubkey, &blockstore, - &reset_bank, + reset_bank.clone(), &poh_recorder, &leader_schedule_cache, ); @@ -2358,34 +2358,30 @@ impl ReplayStage { fn reset_poh_recorder( my_pubkey: &Pubkey, blockstore: &Blockstore, - bank: &Arc, + bank: Arc, poh_recorder: &RwLock, leader_schedule_cache: &LeaderScheduleCache, ) { + let slot = bank.slot(); + let tick_height = bank.tick_height(); + let next_leader_slot = leader_schedule_cache.next_leader_slot( my_pubkey, - bank.slot(), - bank, + slot, + &bank, Some(blockstore), GRACE_TICKS_FACTOR * MAX_GRACE_SLOTS, ); - poh_recorder - .write() - .unwrap() - .reset(bank.clone(), next_leader_slot); + + poh_recorder.write().unwrap().reset(bank, next_leader_slot); let next_leader_msg = if let Some(next_leader_slot) = next_leader_slot { format!("My next leader slot is {}", next_leader_slot.0) } else { "I am not in the leader schedule yet".to_owned() }; - info!( - "{} reset PoH to tick {} (within slot {}). {}", - my_pubkey, - bank.tick_height(), - bank.slot(), - next_leader_msg, + "{my_pubkey} reset PoH to tick {tick_height} (within slot {slot}). {next_leader_msg}", ); }