From a48e430b6b5bc21c5998009738be1436e479f7ec Mon Sep 17 00:00:00 2001 From: Miguel Naveira <47919901+mrnaveira@users.noreply.github.com> Date: Fri, 1 Sep 2023 16:50:24 +0100 Subject: [PATCH] fix(sync): remove mem::take in all syncs (#5721) --- .../base_node/state_machine_service/states/block_sync.rs | 4 ++-- .../base_node/state_machine_service/states/header_sync.rs | 4 ++-- .../state_machine_service/states/horizon_state_sync.rs | 4 +--- .../core/src/base_node/sync/block_sync/synchronizer.rs | 8 ++++---- .../core/src/base_node/sync/header_sync/synchronizer.rs | 4 ++-- .../src/base_node/sync/horizon_state_sync/synchronizer.rs | 8 ++++---- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/base_layer/core/src/base_node/state_machine_service/states/block_sync.rs b/base_layer/core/src/base_node/state_machine_service/states/block_sync.rs index 856224af8f..f40188ce7e 100644 --- a/base_layer/core/src/base_node/state_machine_service/states/block_sync.rs +++ b/base_layer/core/src/base_node/state_machine_service/states/block_sync.rs @@ -20,7 +20,7 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::{mem, time::Instant}; +use std::time::Instant; use log::*; @@ -54,7 +54,7 @@ impl BlockSync { shared.config.blockchain_sync_config.clone(), shared.db.clone(), shared.connectivity.clone(), - mem::take(&mut self.sync_peers), + &mut self.sync_peers, shared.sync_validators.block_body.clone(), ); diff --git a/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs b/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs index d19195b380..7f85ed90c4 100644 --- a/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs +++ b/base_layer/core/src/base_node/state_machine_service/states/header_sync.rs @@ -20,7 +20,7 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::{cmp::Ordering, mem, time::Instant}; +use std::{cmp::Ordering, time::Instant}; use log::*; use tari_common_types::chain_metadata::ChainMetadata; @@ -81,7 +81,7 @@ impl HeaderSyncState { shared.db.clone(), shared.consensus_rules.clone(), shared.connectivity.clone(), - mem::take(&mut self.sync_peers), + &mut self.sync_peers, shared.randomx_factory.clone(), &self.local_metadata, ); diff --git a/base_layer/core/src/base_node/state_machine_service/states/horizon_state_sync.rs b/base_layer/core/src/base_node/state_machine_service/states/horizon_state_sync.rs index 87cb1a4813..84c81c06fb 100644 --- a/base_layer/core/src/base_node/state_machine_service/states/horizon_state_sync.rs +++ b/base_layer/core/src/base_node/state_machine_service/states/horizon_state_sync.rs @@ -23,8 +23,6 @@ //! //! Horizon state synchronisation module for pruned mode. -use std::mem; - use log::*; use super::{StateEvent, StateInfo}; @@ -78,7 +76,7 @@ impl HorizonStateSync { ); return StateEvent::HorizonStateSynchronized; } - let sync_peers = mem::take(&mut self.sync_peers); + let sync_peers = &mut self.sync_peers; let db = shared.db.clone(); let config = shared.config.blockchain_sync_config.clone(); diff --git a/base_layer/core/src/base_node/sync/block_sync/synchronizer.rs b/base_layer/core/src/base_node/sync/block_sync/synchronizer.rs index 1ebf52cc24..09dd18ecbd 100644 --- a/base_layer/core/src/base_node/sync/block_sync/synchronizer.rs +++ b/base_layer/core/src/base_node/sync/block_sync/synchronizer.rs @@ -50,22 +50,22 @@ use crate::{ const LOG_TARGET: &str = "c::bn::block_sync"; -pub struct BlockSynchronizer { +pub struct BlockSynchronizer<'a, B> { config: BlockchainSyncConfig, db: AsyncBlockchainDb, connectivity: ConnectivityRequester, - sync_peers: Vec, + sync_peers: &'a mut Vec, block_validator: Arc>, hooks: Hooks, peer_ban_manager: PeerBanManager, } -impl BlockSynchronizer { +impl<'a, B: BlockchainBackend + 'static> BlockSynchronizer<'a, B> { pub fn new( config: BlockchainSyncConfig, db: AsyncBlockchainDb, connectivity: ConnectivityRequester, - sync_peers: Vec, + sync_peers: &'a mut Vec, block_validator: Arc>, ) -> Self { let peer_ban_manager = PeerBanManager::new(config.clone(), connectivity.clone()); diff --git a/base_layer/core/src/base_node/sync/header_sync/synchronizer.rs b/base_layer/core/src/base_node/sync/header_sync/synchronizer.rs index 0eef90cb2d..75527d04da 100644 --- a/base_layer/core/src/base_node/sync/header_sync/synchronizer.rs +++ b/base_layer/core/src/base_node/sync/header_sync/synchronizer.rs @@ -60,7 +60,7 @@ pub struct HeaderSynchronizer<'a, B> { db: AsyncBlockchainDb, header_validator: BlockHeaderSyncValidator, connectivity: ConnectivityRequester, - sync_peers: Vec, + sync_peers: &'a mut Vec, hooks: Hooks, local_metadata: &'a ChainMetadata, peer_ban_manager: PeerBanManager, @@ -72,7 +72,7 @@ impl<'a, B: BlockchainBackend + 'static> HeaderSynchronizer<'a, B> { db: AsyncBlockchainDb, consensus_rules: ConsensusManager, connectivity: ConnectivityRequester, - sync_peers: Vec, + sync_peers: &'a mut Vec, randomx_factory: RandomXFactory, local_metadata: &'a ChainMetadata, ) -> Self { diff --git a/base_layer/core/src/base_node/sync/horizon_state_sync/synchronizer.rs b/base_layer/core/src/base_node/sync/horizon_state_sync/synchronizer.rs index 6b4e6bef28..d700178a3c 100644 --- a/base_layer/core/src/base_node/sync/horizon_state_sync/synchronizer.rs +++ b/base_layer/core/src/base_node/sync/horizon_state_sync/synchronizer.rs @@ -78,11 +78,11 @@ use crate::{ const LOG_TARGET: &str = "c::bn::state_machine_service::states::horizon_state_sync"; -pub struct HorizonStateSynchronization { +pub struct HorizonStateSynchronization<'a, B> { config: BlockchainSyncConfig, db: AsyncBlockchainDb, rules: ConsensusManager, - sync_peers: Vec, + sync_peers: &'a mut Vec, horizon_sync_height: u64, prover: Arc, num_kernels: u64, @@ -95,14 +95,14 @@ pub struct HorizonStateSynchronization { peer_ban_manager: PeerBanManager, } -impl HorizonStateSynchronization { +impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { #[allow(clippy::too_many_arguments)] pub fn new( config: BlockchainSyncConfig, db: AsyncBlockchainDb, connectivity: ConnectivityRequester, rules: ConsensusManager, - sync_peers: Vec, + sync_peers: &'a mut Vec, horizon_sync_height: u64, prover: Arc, final_state_validator: Arc>,