Skip to content

Commit

Permalink
fix(sync): remove mem::take in all syncs (#5721)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnaveira authored Sep 1, 2023
1 parent 3b9890b commit a48e430
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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(),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
//!
//! Horizon state synchronisation module for pruned mode.
use std::mem;

use log::*;

use super::{StateEvent, StateInfo};
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions base_layer/core/src/base_node/sync/block_sync/synchronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ use crate::{

const LOG_TARGET: &str = "c::bn::block_sync";

pub struct BlockSynchronizer<B> {
pub struct BlockSynchronizer<'a, B> {
config: BlockchainSyncConfig,
db: AsyncBlockchainDb<B>,
connectivity: ConnectivityRequester,
sync_peers: Vec<SyncPeer>,
sync_peers: &'a mut Vec<SyncPeer>,
block_validator: Arc<dyn BlockBodyValidator<B>>,
hooks: Hooks,
peer_ban_manager: PeerBanManager,
}

impl<B: BlockchainBackend + 'static> BlockSynchronizer<B> {
impl<'a, B: BlockchainBackend + 'static> BlockSynchronizer<'a, B> {
pub fn new(
config: BlockchainSyncConfig,
db: AsyncBlockchainDb<B>,
connectivity: ConnectivityRequester,
sync_peers: Vec<SyncPeer>,
sync_peers: &'a mut Vec<SyncPeer>,
block_validator: Arc<dyn BlockBodyValidator<B>>,
) -> Self {
let peer_ban_manager = PeerBanManager::new(config.clone(), connectivity.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct HeaderSynchronizer<'a, B> {
db: AsyncBlockchainDb<B>,
header_validator: BlockHeaderSyncValidator<B>,
connectivity: ConnectivityRequester,
sync_peers: Vec<SyncPeer>,
sync_peers: &'a mut Vec<SyncPeer>,
hooks: Hooks,
local_metadata: &'a ChainMetadata,
peer_ban_manager: PeerBanManager,
Expand All @@ -72,7 +72,7 @@ impl<'a, B: BlockchainBackend + 'static> HeaderSynchronizer<'a, B> {
db: AsyncBlockchainDb<B>,
consensus_rules: ConsensusManager,
connectivity: ConnectivityRequester,
sync_peers: Vec<SyncPeer>,
sync_peers: &'a mut Vec<SyncPeer>,
randomx_factory: RandomXFactory,
local_metadata: &'a ChainMetadata,
) -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ use crate::{

const LOG_TARGET: &str = "c::bn::state_machine_service::states::horizon_state_sync";

pub struct HorizonStateSynchronization<B> {
pub struct HorizonStateSynchronization<'a, B> {
config: BlockchainSyncConfig,
db: AsyncBlockchainDb<B>,
rules: ConsensusManager,
sync_peers: Vec<SyncPeer>,
sync_peers: &'a mut Vec<SyncPeer>,
horizon_sync_height: u64,
prover: Arc<RangeProofService>,
num_kernels: u64,
Expand All @@ -95,14 +95,14 @@ pub struct HorizonStateSynchronization<B> {
peer_ban_manager: PeerBanManager,
}

impl<B: BlockchainBackend + 'static> HorizonStateSynchronization<B> {
impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
#[allow(clippy::too_many_arguments)]
pub fn new(
config: BlockchainSyncConfig,
db: AsyncBlockchainDb<B>,
connectivity: ConnectivityRequester,
rules: ConsensusManager,
sync_peers: Vec<SyncPeer>,
sync_peers: &'a mut Vec<SyncPeer>,
horizon_sync_height: u64,
prover: Arc<RangeProofService>,
final_state_validator: Arc<dyn FinalHorizonStateValidation<B>>,
Expand Down

0 comments on commit a48e430

Please sign in to comment.