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 3a4a528841e..647ea9ac067 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 @@ -129,7 +129,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { target: LOG_TARGET, "Preparing database for horizon sync to height #{}", self.horizon_sync_height ); - let header = self.db().fetch_header(self.horizon_sync_height).await?.ok_or_else(|| { + let to_header = self.db().fetch_header(self.horizon_sync_height).await?.ok_or_else(|| { ChainStorageError::ValueNotFound { entity: "Header", field: "height", @@ -139,7 +139,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { let mut latency_increases_counter = 0; loop { - match self.sync(&header).await { + match self.sync(&to_header).await { Ok(()) => return Ok(()), Err(err @ HorizonSyncError::AllSyncPeersExceedLatency) => { // If we don't have many sync peers to select from, return the listening state and see if we can get @@ -167,7 +167,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { } } - async fn sync(&mut self, header: &BlockHeader) -> Result<(), HorizonSyncError> { + async fn sync(&mut self, to_header: &BlockHeader) -> Result<(), HorizonSyncError> { let sync_peer_node_ids = self.sync_peers.iter().map(|p| p.node_id()).cloned().collect::>(); info!( target: LOG_TARGET, @@ -176,7 +176,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { ); let mut latency_counter = 0usize; for node_id in sync_peer_node_ids { - match self.connect_and_attempt_sync(&node_id, header).await { + match self.connect_and_attempt_sync(&node_id, to_header).await { Ok(_) => return Ok(()), // Try another peer Err(err) => { @@ -213,7 +213,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { async fn connect_and_attempt_sync( &mut self, node_id: &NodeId, - header: &BlockHeader, + to_header: &BlockHeader, ) -> Result<(), HorizonSyncError> { let peer_index = self .get_sync_peer_index(node_id) @@ -250,7 +250,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { debug!(target: LOG_TARGET, "Sync peer latency is {:.2?}", latency); let sync_peer = self.sync_peers[peer_index].clone(); - self.begin_sync(sync_peer.clone(), &mut client, header).await?; + self.begin_sync(sync_peer.clone(), &mut client, to_header).await?; self.finalize_horizon_sync(&sync_peer).await?; Ok(()) @@ -328,7 +328,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { "Requesting kernels from {} to {} ({} remaining)", local_num_kernels, remote_num_kernels, - remote_num_kernels - local_num_kernels, + remote_num_kernels.saturating_sub(local_num_kernels), ); let latency = client.get_last_request_latency(); @@ -374,7 +374,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { } txn.insert_kernel_via_horizon_sync(kernel, *current_header.hash(), mmr_position); - if mmr_position == current_header.header().kernel_mmr_size - 1 { + if mmr_position == current_header.header().kernel_mmr_size.saturating_sub(1) { let num_kernels = kernel_hashes.len(); debug!( target: LOG_TARGET, @@ -425,9 +425,9 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { num_kernels, mmr_position + 1, end, - end - (mmr_position + 1) + end.saturating_sub(mmr_position + 1) ); - if mmr_position < end - 1 { + if mmr_position < end.saturating_sub(1) { current_header = db.fetch_chain_header(current_header.height() + 1).await?; } } @@ -483,42 +483,46 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { let remote_num_outputs = to_header.output_smt_size; self.num_outputs = remote_num_outputs; + let db = self.db().clone(); + + let tip_header = db.fetch_tip_header().await?; + let local_num_outputs = tip_header.header().output_smt_size; let info = HorizonSyncInfo::new(vec![sync_peer.node_id().clone()], HorizonSyncStatus::Outputs { - current: 0, + current: local_num_outputs, total: self.num_outputs, sync_peer: sync_peer.clone(), }); self.hooks.call_on_progress_horizon_hooks(info); - debug!( - target: LOG_TARGET, - "Requesting outputs from {}", - remote_num_outputs, - ); - let db = self.db().clone(); - - let end = remote_num_outputs; - let end_hash = to_header.hash(); - let start_hash = db.fetch_chain_header(1).await?; - let gen_block = db.fetch_chain_header(0).await?; - let latency = client.get_last_request_latency(); debug!( target: LOG_TARGET, - "Initiating output sync with peer `{}` (latency = {}ms)", + "Initiating output sync with peer `{}`, requesting {} outputs (latency = {}ms)", sync_peer.node_id(), + remote_num_outputs.saturating_sub(local_num_outputs), latency.unwrap_or_default().as_millis() ); + // let start_chain_header = db.fetch_chain_header(1).await?; + debug!( + target: LOG_TARGET, + "synchronize_outputs: tip_header height {}", + tip_header.height(), + ); + debug!( + target: LOG_TARGET, + "synchronize_outputs: last_chain_header height {}", + db.fetch_last_chain_header().await?.height(), + ); + let start_chain_header = db.fetch_chain_header(tip_header.height() + 1).await?; let req = SyncUtxosRequest { - start_header_hash: start_hash.hash().to_vec(), - end_header_hash: end_hash.to_vec(), + start_header_hash: start_chain_header.hash().to_vec(), + end_header_hash: to_header.hash().to_vec(), }; - let mut output_stream = client.sync_utxos(req).await?; let mut txn = db.write_transaction(); - let mut utxo_counter = gen_block.header().output_smt_size; + let mut utxo_counter = local_num_outputs; let timer = Instant::now(); let mut output_smt = db.fetch_tip_smt().await?; let mut last_sync_timer = Instant::now(); @@ -530,7 +534,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { let res: SyncUtxosResponse = response?; utxo_counter += 1; - if utxo_counter > end { + if utxo_counter > remote_num_outputs { return Err(HorizonSyncError::IncorrectResponse( "Peer sent too many outputs".to_string(), )); @@ -551,9 +555,11 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { let constants = self.rules.consensus_constants(current_header.height).clone(); let output = TransactionOutput::try_from(output).map_err(HorizonSyncError::ConversionError)?; trace!( - target: LOG_TARGET, - "UTXO {} received from sync peer", - output.hash(), + target: LOG_TARGET, + "UTXO {} received from sync peer ({} of {})", + output.hash(), + utxo_counter.saturating_sub(local_num_outputs), + remote_num_outputs.saturating_sub(local_num_outputs), ); helpers::check_tari_script_byte_size(&output.script, constants.max_script_byte_size())?; @@ -583,7 +589,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { sync_peer.add_sample(last_sync_timer.elapsed()); last_sync_timer = Instant::now(); } - if utxo_counter != end { + if utxo_counter != remote_num_outputs { return Err(HorizonSyncError::IncorrectResponse( "Peer did not send enough outputs".to_string(), )); @@ -591,7 +597,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { debug!( target: LOG_TARGET, "finished syncing UTXOs: {} downloaded in {:.2?}", - end, + remote_num_outputs.saturating_sub(local_num_outputs), timer.elapsed() ); let root = FixedHash::try_from(output_smt.hash().as_slice())?; @@ -693,7 +699,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> { curr_header.height(), curr_header.header().kernel_mmr_size, prev_kernel_mmr, - curr_header.header().kernel_mmr_size - 1 + curr_header.header().kernel_mmr_size.saturating_sub(1) ); trace!(target: LOG_TARGET, "Number of utxos returned: {}", utxos.len()); diff --git a/base_layer/core/tests/helpers/block_builders.rs b/base_layer/core/tests/helpers/block_builders.rs index b4f11bc64b8..772d6d41b4d 100644 --- a/base_layer/core/tests/helpers/block_builders.rs +++ b/base_layer/core/tests/helpers/block_builders.rs @@ -191,6 +191,7 @@ fn update_genesis_block_mmr_roots(template: NewBlockTemplate) -> Result (NodeInterfaces, ConsensusManager) { + pub async fn start( + self, + data_path: &str, + blockchain_db_config: BlockchainDatabaseConfig, + ) -> (NodeInterfaces, ConsensusManager) { let validators = self.validators.unwrap_or_else(|| { Validators::new( MockValidator::new(true), @@ -198,7 +202,11 @@ impl BaseNodeBuilder { let consensus_manager = self .consensus_manager .unwrap_or_else(|| ConsensusManagerBuilder::new(network).build().unwrap()); - let blockchain_db = create_store_with_consensus_and_validators(consensus_manager.clone(), validators); + let blockchain_db = create_store_with_consensus_and_validators_and_config( + consensus_manager.clone(), + validators, + blockchain_db_config, + ); let mempool_validator = TransactionChainLinkedValidator::new(blockchain_db.clone(), consensus_manager.clone()); let mempool = Mempool::new( self.mempool_config.unwrap_or_default(), @@ -244,13 +252,13 @@ pub async fn create_network_with_2_base_nodes(data_path: &str) -> (NodeInterface let (alice_node, consensus_manager) = BaseNodeBuilder::new(network.into()) .with_node_identity(alice_node_identity.clone()) .with_peers(vec![bob_node_identity.clone()]) - .start(data_path) + .start(data_path, BlockchainDatabaseConfig::default()) .await; let (bob_node, consensus_manager) = BaseNodeBuilder::new(network.into()) .with_node_identity(bob_node_identity) .with_peers(vec![alice_node_identity]) .with_consensus_manager(consensus_manager) - .start(data_path) + .start(data_path, BlockchainDatabaseConfig::default()) .await; wait_until_online(&[&alice_node, &bob_node]).await; @@ -263,6 +271,8 @@ pub async fn create_network_with_2_base_nodes(data_path: &str) -> (NodeInterface pub async fn create_network_with_2_base_nodes_with_config>( mempool_service_config: MempoolServiceConfig, liveness_service_config: LivenessConfig, + local_blockchain_db_config: BlockchainDatabaseConfig, + peer_blockchain_db_config: BlockchainDatabaseConfig, p2p_config: P2pConfig, consensus_manager: ConsensusManager, data_path: P, @@ -270,27 +280,33 @@ pub async fn create_network_with_2_base_nodes_with_config>( let alice_node_identity = random_node_identity(); let bob_node_identity = random_node_identity(); let network = Network::LocalNet; - let (alice_node, consensus_manager) = BaseNodeBuilder::new(network.into()) + let (local_node, consensus_manager) = BaseNodeBuilder::new(network.into()) .with_node_identity(alice_node_identity.clone()) .with_mempool_service_config(mempool_service_config.clone()) .with_liveness_service_config(liveness_service_config.clone()) .with_p2p_config(p2p_config.clone()) .with_consensus_manager(consensus_manager) - .start(data_path.as_ref().join("alice").as_os_str().to_str().unwrap()) + .start( + data_path.as_ref().join("alice").as_os_str().to_str().unwrap(), + local_blockchain_db_config, + ) .await; - let (bob_node, consensus_manager) = BaseNodeBuilder::new(network.into()) + let (peer_node, consensus_manager) = BaseNodeBuilder::new(network.into()) .with_node_identity(bob_node_identity) .with_peers(vec![alice_node_identity]) .with_mempool_service_config(mempool_service_config) .with_liveness_service_config(liveness_service_config) .with_p2p_config(p2p_config.clone()) .with_consensus_manager(consensus_manager) - .start(data_path.as_ref().join("bob").as_os_str().to_str().unwrap()) + .start( + data_path.as_ref().join("bob").as_os_str().to_str().unwrap(), + peer_blockchain_db_config, + ) .await; - wait_until_online(&[&alice_node, &bob_node]).await; + wait_until_online(&[&local_node, &peer_node]).await; - (alice_node, bob_node, consensus_manager) + (local_node, peer_node, consensus_manager) } // Creates a network with three Base Nodes where each node in the network knows the other nodes in the network. @@ -303,6 +319,10 @@ pub async fn create_network_with_3_base_nodes( create_network_with_3_base_nodes_with_config( MempoolServiceConfig::default(), LivenessConfig::default(), + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + P2pConfig::default(), consensus_manager, data_path, ) @@ -314,6 +334,10 @@ pub async fn create_network_with_3_base_nodes( pub async fn create_network_with_3_base_nodes_with_config>( mempool_service_config: MempoolServiceConfig, liveness_service_config: LivenessConfig, + alice_blockchain_db_config: BlockchainDatabaseConfig, + bob_blockchain_db_config: BlockchainDatabaseConfig, + carol_blockchain_db_config: BlockchainDatabaseConfig, + p2p_config: P2pConfig, consensus_manager: ConsensusManager, data_path: P, ) -> (NodeInterfaces, NodeInterfaces, NodeInterfaces, ConsensusManager) { @@ -332,24 +356,36 @@ pub async fn create_network_with_3_base_nodes_with_config>( .with_node_identity(carol_node_identity.clone()) .with_mempool_service_config(mempool_service_config.clone()) .with_liveness_service_config(liveness_service_config.clone()) + .with_p2p_config(p2p_config.clone()) .with_consensus_manager(consensus_manager) - .start(data_path.as_ref().join("carol").as_os_str().to_str().unwrap()) + .start( + data_path.as_ref().join("carol").as_os_str().to_str().unwrap(), + alice_blockchain_db_config, + ) .await; let (bob_node, consensus_manager) = BaseNodeBuilder::new(network.into()) .with_node_identity(bob_node_identity.clone()) .with_peers(vec![carol_node_identity.clone()]) .with_mempool_service_config(mempool_service_config.clone()) .with_liveness_service_config(liveness_service_config.clone()) + .with_p2p_config(p2p_config.clone()) .with_consensus_manager(consensus_manager) - .start(data_path.as_ref().join("bob").as_os_str().to_str().unwrap()) + .start( + data_path.as_ref().join("bob").as_os_str().to_str().unwrap(), + bob_blockchain_db_config, + ) .await; let (alice_node, consensus_manager) = BaseNodeBuilder::new(network.into()) .with_node_identity(alice_node_identity) .with_peers(vec![bob_node_identity, carol_node_identity]) .with_mempool_service_config(mempool_service_config) .with_liveness_service_config(liveness_service_config) + .with_p2p_config(p2p_config.clone()) .with_consensus_manager(consensus_manager) - .start(data_path.as_ref().join("alice").as_os_str().to_str().unwrap()) + .start( + data_path.as_ref().join("alice").as_os_str().to_str().unwrap(), + carol_blockchain_db_config, + ) .await; wait_until_online(&[&alice_node, &bob_node, &carol_node]).await; diff --git a/base_layer/core/tests/helpers/sync.rs b/base_layer/core/tests/helpers/sync.rs index c3af8050318..4e7fa8929c4 100644 --- a/base_layer/core/tests/helpers/sync.rs +++ b/base_layer/core/tests/helpers/sync.rs @@ -28,14 +28,14 @@ use tari_comms::peer_manager::NodeId; use tari_core::{ base_node::{ chain_metadata_service::PeerChainMetadata, - state_machine_service::states::{BlockSync, HeaderSyncState, StateEvent, StatusInfo}, + state_machine_service::states::{BlockSync, HeaderSyncState, HorizonStateSync, StateEvent, StatusInfo}, sync::SyncPeer, BaseNodeStateMachine, BaseNodeStateMachineConfig, SyncValidators, }, blocks::ChainBlock, - chain_storage::DbTransaction, + chain_storage::{BlockchainDatabaseConfig, DbTransaction}, consensus::{ConsensusConstantsBuilder, ConsensusManager, ConsensusManagerBuilder}, mempool::MempoolServiceConfig, proof_of_work::{randomx_factory::RandomXFactory, Difficulty}, @@ -91,7 +91,25 @@ pub async fn sync_blocks_execute( block_sync.next_event(state_machine).await } -pub async fn create_network_with_local_and_peer_nodes() -> ( +pub fn initialize_horizon_sync(peer_node_interfaces: &NodeInterfaces) -> HorizonStateSync { + HorizonStateSync::from(vec![SyncPeer::from(PeerChainMetadata::new( + peer_node_interfaces.node_identity.node_id().clone(), + peer_node_interfaces.blockchain_db.get_chain_metadata().unwrap(), + None, + ))]) +} + +pub async fn horizon_sync_execute( + state_machine: &mut BaseNodeStateMachine, + horizon_sync: &mut HorizonStateSync, +) -> StateEvent { + horizon_sync.next_event(state_machine).await +} + +pub async fn create_network_with_local_and_peer_nodes( + local_blockchain_db_config: BlockchainDatabaseConfig, + peer_blockchain_db_config: BlockchainDatabaseConfig, +) -> ( BaseNodeStateMachine, NodeInterfaces, NodeInterfaces, @@ -117,6 +135,8 @@ pub async fn create_network_with_local_and_peer_nodes() -> ( auto_ping_interval: Some(Duration::from_millis(100)), ..Default::default() }, + local_blockchain_db_config, + peer_blockchain_db_config, P2pConfig::default(), consensus_manager, temp_dir.path().to_str().unwrap(), diff --git a/base_layer/core/tests/tests/base_node_rpc.rs b/base_layer/core/tests/tests/base_node_rpc.rs index ec11eff7c3d..3d0f25bc4df 100644 --- a/base_layer/core/tests/tests/base_node_rpc.rs +++ b/base_layer/core/tests/tests/base_node_rpc.rs @@ -41,6 +41,7 @@ use tari_core::{ sync::rpc::BaseNodeSyncRpcService, }, blocks::ChainBlock, + chain_storage::BlockchainDatabaseConfig, consensus::{ConsensusConstantsBuilder, ConsensusManager, ConsensusManagerBuilder, NetworkConsensus}, proto::{ base_node::{FetchMatchingUtxos, Signatures as SignaturesProto, SyncUtxosByBlockRequest}, @@ -94,7 +95,7 @@ async fn setup() -> ( .unwrap(); let (mut base_node, _consensus_manager) = BaseNodeBuilder::new(network) .with_consensus_manager(consensus_manager.clone()) - .start(temp_dir.path().to_str().unwrap()) + .start(temp_dir.path().to_str().unwrap(), BlockchainDatabaseConfig::default()) .await; base_node.mock_base_node_state_machine.publish_status(StatusInfo { bootstrapped: true, diff --git a/base_layer/core/tests/tests/block_sync.rs b/base_layer/core/tests/tests/block_sync.rs index 9011a4b2765..38aaf1dbc14 100644 --- a/base_layer/core/tests/tests/block_sync.rs +++ b/base_layer/core/tests/tests/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 tari_core::base_node::state_machine_service::states::StateEvent; +use tari_core::{base_node::state_machine_service::states::StateEvent, chain_storage::BlockchainDatabaseConfig}; use crate::helpers::{sync, sync::WhatToDelete}; @@ -30,10 +30,14 @@ async fn test_block_sync_happy_path() { // Create the network with Alice node and Bob node let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = - sync::create_network_with_local_and_peer_nodes().await; + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + ) + .await; // Add some block to Bob's chain - let _bob_blocks = + let _blocks = sync::create_and_add_some_blocks(&bob_node, &initial_block, 5, &consensus_manager, &key_manager, &[3; 5]).await; assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 5); @@ -79,7 +83,11 @@ async fn test_block_sync_peer_supplies_no_blocks_with_ban() { // Create the network with Alice node and Bob node let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = - sync::create_network_with_local_and_peer_nodes().await; + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + ) + .await; // Add some block to Bob's chain let blocks = sync::create_and_add_some_blocks( @@ -130,7 +138,11 @@ async fn test_block_sync_peer_supplies_not_all_blocks_with_ban() { // Create the network with Alice node and Bob node let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = - sync::create_network_with_local_and_peer_nodes().await; + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + ) + .await; // Add some block to Bob's chain let blocks = sync::create_and_add_some_blocks( diff --git a/base_layer/core/tests/tests/header_sync.rs b/base_layer/core/tests/tests/header_sync.rs index 5745f241259..906357e794b 100644 --- a/base_layer/core/tests/tests/header_sync.rs +++ b/base_layer/core/tests/tests/header_sync.rs @@ -20,7 +20,10 @@ // 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 tari_core::base_node::{state_machine_service::states::StateEvent, sync::HeaderSyncStatus}; +use tari_core::{ + base_node::{state_machine_service::states::StateEvent, sync::HeaderSyncStatus}, + chain_storage::BlockchainDatabaseConfig, +}; use crate::helpers::{sync, sync::WhatToDelete}; @@ -31,7 +34,11 @@ async fn test_header_sync_happy_path() { // Create the network with Alice node and Bob node let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = - sync::create_network_with_local_and_peer_nodes().await; + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + ) + .await; // Add 1 block to Bob's chain let bob_blocks = @@ -74,7 +81,7 @@ async fn test_header_sync_happy_path() { } // Bob adds another block - let _bob_blocks = + let _blocks = sync::create_and_add_some_blocks(&bob_node, &bob_blocks[1], 1, &consensus_manager, &key_manager, &[3]).await; assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 2); @@ -103,7 +110,11 @@ async fn test_header_sync_with_fork_happy_path() { // Create the network with Alice node and Bob node let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = - sync::create_network_with_local_and_peer_nodes().await; + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + ) + .await; // Add 1 block to Bob's chain let bob_blocks = @@ -148,7 +159,7 @@ async fn test_header_sync_with_fork_happy_path() { assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); // Bob adds more blocks and draws ahead of Alice - let _bob_blocks = + let _blocks = sync::create_and_add_some_blocks(&bob_node, &bob_blocks[1], 2, &consensus_manager, &key_manager, &[3; 2]).await; assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 4); @@ -177,7 +188,11 @@ async fn test_header_sync_uneven_headers_and_blocks_happy_path() { // Create the network with Alice node and Bob node let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = - sync::create_network_with_local_and_peer_nodes().await; + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + ) + .await; // Add blocks and headers to Bob's chain, with more headers than blocks let blocks = sync::create_and_add_some_blocks( @@ -225,7 +240,11 @@ async fn test_header_sync_uneven_headers_and_blocks_peer_lies_about_pow_no_ban() // Create the network with Alice node and Bob node let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = - sync::create_network_with_local_and_peer_nodes().await; + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + ) + .await; // Add blocks and headers to Bob's chain, with more headers than blocks let blocks = sync::create_and_add_some_blocks( @@ -288,7 +307,11 @@ async fn test_header_sync_even_headers_and_blocks_peer_lies_about_pow_with_ban() // Create the network with Alice node and Bob node let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = - sync::create_network_with_local_and_peer_nodes().await; + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + ) + .await; // Add blocks and headers to Bob's chain let blocks = @@ -334,7 +357,11 @@ async fn test_header_sync_even_headers_and_blocks_peer_metadata_improve_with_reo // Create the network with Alice node and Bob node let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = - sync::create_network_with_local_and_peer_nodes().await; + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + ) + .await; // Add blocks and headers to Bob's chain let blocks = diff --git a/base_layer/core/tests/tests/horizon_sync.rs b/base_layer/core/tests/tests/horizon_sync.rs new file mode 100644 index 00000000000..a40e77ab222 --- /dev/null +++ b/base_layer/core/tests/tests/horizon_sync.rs @@ -0,0 +1,216 @@ +// Copyright 2022. The Tari Project +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +// following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following +// disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the +// following disclaimer in the documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote +// products derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// 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 tari_core::{base_node::state_machine_service::states::StateEvent, chain_storage::BlockchainDatabaseConfig}; + +use crate::helpers::{sync, sync::WhatToDelete}; + +#[allow(clippy::too_many_lines)] +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +async fn test_horizon_sync_to_archival_node_happy_path() { + //` cargo test --release --test core_integration_tests + //` tests::horizon_sync::test_horizon_sync_to_archival_node_happy_path > .\target\output.txt 2>&1 + env_logger::init(); // Set `$env:RUST_LOG = "trace"` + + // Create the network with Alice node and Bob node + let pruning_horizon = 5; + let (mut alice_state_machine, alice_node, bob_node, initial_block, consensus_manager, key_manager) = + sync::create_network_with_local_and_peer_nodes( + BlockchainDatabaseConfig { + orphan_storage_capacity: 5, + pruning_horizon, + pruning_interval: 5, + track_reorgs: false, + cleanup_orphans_at_startup: false, + }, + BlockchainDatabaseConfig::default(), + ) + .await; + println!( + "Genesis block - outputs: {}, output SMT size: {}", + initial_block.block().body.outputs().len(), + initial_block.header().output_smt_size + ); + + // Create a blockchain with many blocks + let blocks = sync::create_and_add_some_blocks( + &bob_node, + &initial_block, + 40, + &consensus_manager, + &key_manager, + &[3; 40], + ) + .await; + assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 40); + assert_eq!(bob_node.blockchain_db.fetch_last_header().unwrap().height, 40); + // Now rewind Bob's chain to height 10 + sync::delete_some_blocks_and_headers(&blocks[10..=40], WhatToDelete::BlocksAndHeaders, &bob_node); + assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 10); + assert_eq!(bob_node.blockchain_db.fetch_last_header().unwrap().height, 10); + + // 1. Alice attempts horizon sync without having done header sync + println!("\n1. Alice attempts horizon sync without having done header sync\n"); + let mut horizon_sync = sync::initialize_horizon_sync(&bob_node); + let event = sync::horizon_sync_execute(&mut alice_state_machine, &mut horizon_sync).await; + println!("Event: {:?}", event); + assert_eq!(event, StateEvent::HorizonStateSynchronized); + assert_eq!(alice_node.blockchain_db.get_height().unwrap(), 0); + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); + + // 2. Alice does header sync (to height 10) + println!("\n2. Alice does header sync (to height 10)\n"); + let mut header_sync = sync::initialize_sync_headers_with_ping_pong_data(&alice_node, &bob_node); + let event = sync::sync_headers_execute(&mut alice_state_machine, &mut header_sync).await; + match event.clone() { + StateEvent::HeadersSynchronized(..) => { + // Good, headers are synced + assert_eq!(alice_node.blockchain_db.fetch_last_header().unwrap().height, 10); + }, + _ => panic!("Expected HeadersSynchronized event"), + } + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); + + // 3. Alice attempts horizon sync after header sync (to height 5) + println!("\n3. Alice attempts horizon sync after header sync (to height 5)\n"); + let mut horizon_sync = sync::initialize_horizon_sync(&bob_node); + let event = sync::horizon_sync_execute(&mut alice_state_machine, &mut horizon_sync).await; + println!("Event: {:?}", event); + assert_eq!(event, StateEvent::HorizonStateSynchronized); + assert_eq!( + alice_node.blockchain_db.get_height().unwrap(), + alice_node.blockchain_db.fetch_last_header().unwrap().height - pruning_horizon + ); + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); + + // 4. Alice attempts horizon sync again without any change in the blockchain + println!("\n4. Alice attempts horizon sync again without any change in the blockchain\n"); + let mut horizon_sync = sync::initialize_horizon_sync(&bob_node); + let event = sync::horizon_sync_execute(&mut alice_state_machine, &mut horizon_sync).await; + println!("Event: {:?}", event); + assert_eq!(event, StateEvent::HorizonStateSynchronized); + assert_eq!( + alice_node.blockchain_db.get_height().unwrap(), + alice_node.blockchain_db.fetch_last_header().unwrap().height - pruning_horizon + ); + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); + + // Give Bob some more blocks + sync::add_some_existing_blocks(&blocks[11..=20], &bob_node); + assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 20); + assert_eq!(bob_node.blockchain_db.fetch_last_header().unwrap().height, 20); + + // 5. Alice does header sync to the new height (to height 20) + println!("\n5. Alice does header sync to the new height (to height 20)\n"); + let mut header_sync = sync::initialize_sync_headers_with_ping_pong_data(&alice_node, &bob_node); + let event = sync::sync_headers_execute(&mut alice_state_machine, &mut header_sync).await; + match event.clone() { + StateEvent::HeadersSynchronized(..) => { + // Good, headers are synced + assert_eq!(alice_node.blockchain_db.fetch_last_header().unwrap().height, 20); + }, + _ => panic!("Expected HeadersSynchronized event"), + } + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); + + // 6. Alice attempts horizon sync to the new pruning height (to height 15) + println!("\n6. Alice attempts horizon sync to the new pruning height (to height 15)\n"); + let mut horizon_sync = sync::initialize_horizon_sync(&bob_node); + let event = sync::horizon_sync_execute(&mut alice_state_machine, &mut horizon_sync).await; + println!("Event: {:?}", event); + assert_eq!( + alice_node.blockchain_db.get_height().unwrap(), + alice_node.blockchain_db.fetch_last_header().unwrap().height - pruning_horizon + ); + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); + + // 7. Alice attempts block sync to the tip (to height 20) + println!("\n7. Alice attempts block sync to the tip (to height 20)\n"); + let mut block_sync = sync::initialize_sync_blocks(&bob_node); + let event = sync::sync_blocks_execute(&mut alice_state_machine, &mut block_sync).await; + match event { + StateEvent::BlocksSynchronized => { + // Good, blocks are synced + }, + _ => panic!("Expected BlocksSynchronized event"), + } + assert_eq!( + alice_node.blockchain_db.get_height().unwrap(), + alice_node.blockchain_db.fetch_last_header().unwrap().height + ); + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); + + // Give Bob some more blocks + sync::add_some_existing_blocks(&blocks[21..=40], &bob_node); + assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 40); + assert_eq!(bob_node.blockchain_db.fetch_last_header().unwrap().height, 40); + + // 8. Alice does header sync to the new height (to height 40) + println!("\n8. Alice does header sync to the new height (to height 40)\n"); + let mut header_sync = sync::initialize_sync_headers_with_ping_pong_data(&alice_node, &bob_node); + let event = sync::sync_headers_execute(&mut alice_state_machine, &mut header_sync).await; + match event.clone() { + StateEvent::HeadersSynchronized(..) => { + // Good, headers are synced + assert_eq!(alice_node.blockchain_db.fetch_last_header().unwrap().height, 40); + }, + _ => panic!("Expected HeadersSynchronized event"), + } + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); + + // 9. Alice attempts horizon sync to the new pruning height (to height 35) + println!("\n9. Alice attempts horizon sync to the new pruning height (to height 35)\n"); + let mut horizon_sync = sync::initialize_horizon_sync(&bob_node); + let event = sync::horizon_sync_execute(&mut alice_state_machine, &mut horizon_sync).await; + println!("Event: {:?}", event); + assert_eq!( + alice_node.blockchain_db.get_height().unwrap(), + alice_node.blockchain_db.fetch_last_header().unwrap().height - pruning_horizon + ); + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); + + // 10. Alice attempts block sync to the tip (to height 40) + println!("\n10. Alice attempts block sync to the tip (to height 40)\n"); + let mut block_sync = sync::initialize_sync_blocks(&bob_node); + let event = sync::sync_blocks_execute(&mut alice_state_machine, &mut block_sync).await; + match event { + StateEvent::BlocksSynchronized => { + // Good, blocks are synced + }, + _ => panic!("Expected BlocksSynchronized event"), + } + assert_eq!( + alice_node.blockchain_db.get_height().unwrap(), + alice_node.blockchain_db.fetch_last_header().unwrap().height + ); + // Bob will not be banned + assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await); +} diff --git a/base_layer/core/tests/tests/mempool.rs b/base_layer/core/tests/tests/mempool.rs index 0bb1d7a6d37..ab07ebad9ce 100644 --- a/base_layer/core/tests/tests/mempool.rs +++ b/base_layer/core/tests/tests/mempool.rs @@ -28,6 +28,7 @@ use tari_common_types::types::{Commitment, PrivateKey, PublicKey, Signature}; use tari_comms_dht::domain_message::OutboundDomainMessage; use tari_core::{ base_node::state_machine_service::states::{ListeningInfo, StateInfo, StatusInfo}, + chain_storage::BlockchainDatabaseConfig, consensus::{ConsensusConstantsBuilder, ConsensusManager}, mempool::{Mempool, MempoolConfig, MempoolServiceConfig, TxStorageResponse}, proof_of_work::Difficulty, @@ -1057,6 +1058,10 @@ async fn receive_and_propagate_transaction() { create_network_with_3_base_nodes_with_config( MempoolServiceConfig::default(), LivenessConfig::default(), + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + P2pConfig::default(), consensus_manager, temp_dir.path().to_str().unwrap(), ) @@ -1725,6 +1730,8 @@ async fn block_event_and_reorg_event_handling() { let (mut alice, mut bob, consensus_manager) = create_network_with_2_base_nodes_with_config( MempoolServiceConfig::default(), LivenessConfig::default(), + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), P2pConfig::default(), consensus_manager, temp_dir.path().to_str().unwrap(), diff --git a/base_layer/core/tests/tests/mod.rs b/base_layer/core/tests/tests/mod.rs index e36b646680d..5e3ade249b6 100644 --- a/base_layer/core/tests/tests/mod.rs +++ b/base_layer/core/tests/tests/mod.rs @@ -27,6 +27,7 @@ mod base_node_rpc; mod block_sync; mod block_validation; mod header_sync; +mod horizon_sync; mod mempool; mod node_comms_interface; mod node_service; diff --git a/base_layer/core/tests/tests/node_service.rs b/base_layer/core/tests/tests/node_service.rs index 9877d99b445..76e3d7c384a 100644 --- a/base_layer/core/tests/tests/node_service.rs +++ b/base_layer/core/tests/tests/node_service.rs @@ -31,6 +31,7 @@ use tari_core::{ state_machine_service::states::{ListeningInfo, StateInfo, StatusInfo}, }, blocks::{ChainBlock, NewBlock}, + chain_storage::BlockchainDatabaseConfig, consensus::{ConsensusConstantsBuilder, ConsensusManager, ConsensusManagerBuilder, NetworkConsensus}, mempool::TxStorageResponse, proof_of_work::{randomx_factory::RandomXFactory, Difficulty, PowAlgorithm}, @@ -104,25 +105,37 @@ async fn propagate_and_forward_many_valid_blocks() { let (mut alice_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(alice_node_identity.clone()) .with_consensus_manager(rules) - .start(temp_dir.path().join("alice").to_str().unwrap()) + .start( + temp_dir.path().join("alice").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; let (mut bob_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(bob_node_identity.clone()) .with_peers(vec![alice_node_identity]) .with_consensus_manager(rules) - .start(temp_dir.path().join("bob").to_str().unwrap()) + .start( + temp_dir.path().join("bob").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; let (mut carol_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(carol_node_identity.clone()) .with_peers(vec![bob_node_identity.clone()]) .with_consensus_manager(rules) - .start(temp_dir.path().join("carol").to_str().unwrap()) + .start( + temp_dir.path().join("carol").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; let (mut dan_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(dan_node_identity) .with_peers(vec![carol_node_identity, bob_node_identity]) .with_consensus_manager(rules) - .start(temp_dir.path().join("dan").to_str().unwrap()) + .start( + temp_dir.path().join("dan").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; wait_until_online(&[&alice_node, &bob_node, &carol_node, &dan_node]).await; @@ -210,6 +223,7 @@ async fn propagate_and_forward_many_valid_blocks() { static EMISSION: [u64; 2] = [10, 10]; #[tokio::test(flavor = "multi_thread", worker_threads = 1)] +#[allow(clippy::too_many_lines)] async fn propagate_and_forward_invalid_block_hash() { // Alice will propagate a "made up" block hash to Bob, Bob will request the block from Alice. Alice will not be able // to provide the block and so Bob will not propagate the hash further to Carol. @@ -234,19 +248,28 @@ async fn propagate_and_forward_invalid_block_hash() { let (mut alice_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(alice_node_identity.clone()) .with_consensus_manager(rules) - .start(temp_dir.path().join("alice").to_str().unwrap()) + .start( + temp_dir.path().join("alice").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; let (mut bob_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(bob_node_identity.clone()) .with_peers(vec![alice_node_identity]) .with_consensus_manager(rules) - .start(temp_dir.path().join("bob").to_str().unwrap()) + .start( + temp_dir.path().join("bob").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; let (mut carol_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(carol_node_identity) .with_peers(vec![bob_node_identity]) .with_consensus_manager(rules) - .start(temp_dir.path().join("carol").to_str().unwrap()) + .start( + temp_dir.path().join("carol").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; wait_until_online(&[&alice_node, &bob_node, &carol_node]).await; @@ -361,7 +384,10 @@ async fn propagate_and_forward_invalid_block() { let (mut dan_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(dan_node_identity.clone()) .with_consensus_manager(rules) - .start(temp_dir.path().join("dan").to_str().unwrap()) + .start( + temp_dir.path().join("dan").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; let (mut carol_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(carol_node_identity.clone()) @@ -372,20 +398,29 @@ async fn propagate_and_forward_invalid_block() { mock_validator.clone(), stateless_block_validator.clone(), ) - .start(temp_dir.path().join("carol").to_str().unwrap()) + .start( + temp_dir.path().join("carol").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; let (mut bob_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(bob_node_identity.clone()) .with_peers(vec![dan_node_identity]) .with_consensus_manager(rules) .with_validators(mock_validator.clone(), mock_validator, stateless_block_validator) - .start(temp_dir.path().join("bob").to_str().unwrap()) + .start( + temp_dir.path().join("bob").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; let (mut alice_node, rules) = BaseNodeBuilder::new(network.into()) .with_node_identity(alice_node_identity) .with_peers(vec![bob_node_identity, carol_node_identity]) .with_consensus_manager(rules) - .start(temp_dir.path().join("alice").to_str().unwrap()) + .start( + temp_dir.path().join("alice").to_str().unwrap(), + BlockchainDatabaseConfig::default(), + ) .await; alice_node @@ -485,7 +520,7 @@ async fn local_get_metadata() { let network = Network::LocalNet; let key_manager = create_memory_db_key_manager(); let (mut node, consensus_manager) = BaseNodeBuilder::new(network.into()) - .start(temp_dir.path().to_str().unwrap()) + .start(temp_dir.path().to_str().unwrap(), BlockchainDatabaseConfig::default()) .await; let db = &node.blockchain_db; let block0 = db.fetch_block(0, true).unwrap().try_into_chain_block().unwrap(); @@ -517,7 +552,7 @@ async fn local_get_new_block_template_and_get_new_block() { .unwrap(); let (mut node, _rules) = BaseNodeBuilder::new(network.into()) .with_consensus_manager(rules) - .start(temp_dir.path().to_str().unwrap()) + .start(temp_dir.path().to_str().unwrap(), BlockchainDatabaseConfig::default()) .await; let schema = [ @@ -566,7 +601,7 @@ async fn local_get_new_block_with_zero_conf() { HeaderFullValidator::new(rules.clone(), difficulty_calculator), BlockBodyInternalConsistencyValidator::new(rules, true, factories.clone()), ) - .start(temp_dir.path().to_str().unwrap()) + .start(temp_dir.path().to_str().unwrap(), BlockchainDatabaseConfig::default()) .await; let (tx01, tx01_out) = spend_utxos( @@ -652,7 +687,7 @@ async fn local_get_new_block_with_combined_transaction() { HeaderFullValidator::new(rules.clone(), difficulty_calculator), BlockBodyInternalConsistencyValidator::new(rules, true, factories.clone()), ) - .start(temp_dir.path().to_str().unwrap()) + .start(temp_dir.path().to_str().unwrap(), BlockchainDatabaseConfig::default()) .await; let (tx01, tx01_out) = spend_utxos( @@ -718,7 +753,7 @@ async fn local_submit_block() { let network = Network::LocalNet; let key_manager = create_memory_db_key_manager(); let (mut node, consensus_manager) = BaseNodeBuilder::new(network.into()) - .start(temp_dir.path().to_str().unwrap()) + .start(temp_dir.path().to_str().unwrap(), BlockchainDatabaseConfig::default()) .await; let db = &node.blockchain_db; diff --git a/base_layer/core/tests/tests/node_state_machine.rs b/base_layer/core/tests/tests/node_state_machine.rs index 55e68c79de8..5c80f2a0dc5 100644 --- a/base_layer/core/tests/tests/node_state_machine.rs +++ b/base_layer/core/tests/tests/node_state_machine.rs @@ -36,6 +36,7 @@ use tari_core::{ }, SyncValidators, }, + chain_storage::BlockchainDatabaseConfig, consensus::{ConsensusConstantsBuilder, ConsensusManagerBuilder}, mempool::MempoolServiceConfig, proof_of_work::{randomx_factory::RandomXFactory, Difficulty}, @@ -87,6 +88,8 @@ async fn test_listening_lagging() { auto_ping_interval: Some(Duration::from_millis(100)), ..Default::default() }, + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), P2pConfig::default(), consensus_manager, temp_dir.path().to_str().unwrap(), @@ -163,6 +166,10 @@ async fn test_listening_initial_fallen_behind() { auto_ping_interval: Some(Duration::from_millis(100)), ..Default::default() }, + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + BlockchainDatabaseConfig::default(), + P2pConfig::default(), consensus_manager, temp_dir.path().to_str().unwrap(), ) @@ -256,7 +263,7 @@ async fn test_listening_initial_fallen_behind() { async fn test_event_channel() { let temp_dir = tempdir().unwrap(); let (node, consensus_manager) = BaseNodeBuilder::new(Network::Esmeralda.into()) - .start(temp_dir.path().to_str().unwrap()) + .start(temp_dir.path().to_str().unwrap(), BlockchainDatabaseConfig::default()) .await; // let shutdown = Shutdown::new(); let db = create_test_blockchain_db();