diff --git a/applications/tari_validator_node/src/bootstrap.rs b/applications/tari_validator_node/src/bootstrap.rs index bf2725a9f..61b833792 100644 --- a/applications/tari_validator_node/src/bootstrap.rs +++ b/applications/tari_validator_node/src/bootstrap.rs @@ -341,6 +341,7 @@ pub async fn spawn_services( state_store.clone(), mempool.clone(), virtual_substate_manager, + consensus_handle.clone(), ) .await?; // Save final node identity after comms has initialized. This is required because the public_address can be @@ -434,6 +435,7 @@ async fn spawn_p2p_rpc( shard_store_store: SqliteStateStore, mempool: MempoolHandle, virtual_substate_manager: VirtualSubstateManager, EpochManagerHandle>, + consensus: ConsensusHandle, ) -> anyhow::Result<()> { let rpc_server = RpcServer::builder() .with_maximum_simultaneous_sessions(config.validator_node.rpc.max_simultaneous_sessions) @@ -444,6 +446,7 @@ async fn spawn_p2p_rpc( shard_store_store, mempool, virtual_substate_manager, + consensus, )); let (notify_tx, notify_rx) = mpsc::unbounded_channel(); diff --git a/applications/tari_validator_node/src/consensus/handle.rs b/applications/tari_validator_node/src/consensus/handle.rs index 1acfc8f85..c46ce0d1f 100644 --- a/applications/tari_validator_node/src/consensus/handle.rs +++ b/applications/tari_validator_node/src/consensus/handle.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause use tari_consensus::hotstuff::{ConsensusCurrentState, CurrentView, HotstuffEvent}; +use tari_dan_common_types::Epoch; use tari_transaction::Transaction; use tokio::sync::{broadcast, mpsc, watch}; @@ -30,6 +31,10 @@ impl ConsensusHandle { } } + pub fn current_epoch(&self) -> Epoch { + self.current_view.get_epoch() + } + pub async fn notify_new_transaction( &self, transaction: Transaction, diff --git a/applications/tari_validator_node/src/p2p/rpc/mod.rs b/applications/tari_validator_node/src/p2p/rpc/mod.rs index 98a283a64..88e9629cf 100644 --- a/applications/tari_validator_node/src/p2p/rpc/mod.rs +++ b/applications/tari_validator_node/src/p2p/rpc/mod.rs @@ -30,18 +30,24 @@ use tari_epoch_manager::base_layer::EpochManagerHandle; use tari_state_store_sqlite::SqliteStateStore; use tari_validator_node_rpc::rpc_service::ValidatorNodeRpcServer; -use crate::{p2p::services::mempool::MempoolHandle, virtual_substate::VirtualSubstateManager}; +use crate::{ + consensus::ConsensusHandle, + p2p::services::mempool::MempoolHandle, + virtual_substate::VirtualSubstateManager, +}; pub fn create_tari_validator_node_rpc_service( epoch_manager: EpochManagerHandle, shard_store_store: SqliteStateStore, mempool: MempoolHandle, virtual_substate_manager: VirtualSubstateManager, EpochManagerHandle>, + consensus: ConsensusHandle, ) -> ValidatorNodeRpcServer { ValidatorNodeRpcServer::new(ValidatorNodeRpcServiceImpl::new( epoch_manager, shard_store_store, mempool, virtual_substate_manager, + consensus, )) } diff --git a/applications/tari_validator_node/src/p2p/rpc/service_impl.rs b/applications/tari_validator_node/src/p2p/rpc/service_impl.rs index 8b190cbbb..9e1af4097 100644 --- a/applications/tari_validator_node/src/p2p/rpc/service_impl.rs +++ b/applications/tari_validator_node/src/p2p/rpc/service_impl.rs @@ -66,6 +66,7 @@ use tari_validator_node_rpc::rpc_service::ValidatorNodeRpcService; use tokio::{sync::mpsc, task}; use crate::{ + consensus::ConsensusHandle, p2p::{ rpc::{block_sync_task::BlockSyncTask, state_sync_task::StateSyncTask}, services::mempool::MempoolHandle, @@ -80,6 +81,7 @@ pub struct ValidatorNodeRpcServiceImpl { shard_state_store: SqliteStateStore, mempool: MempoolHandle, virtual_substate_manager: VirtualSubstateManager, EpochManagerHandle>, + consensus: ConsensusHandle, } impl ValidatorNodeRpcServiceImpl { @@ -91,12 +93,14 @@ impl ValidatorNodeRpcServiceImpl { SqliteStateStore, EpochManagerHandle, >, + consensus: ConsensusHandle, ) -> Self { Self { epoch_manager, shard_state_store, mempool, virtual_substate_manager, + consensus, } } } @@ -340,11 +344,7 @@ impl ValidatorNodeRpcService for ValidatorNodeRpcServiceImpl { request: Request, ) -> Result, RpcStatus> { let msg = request.into_message(); - let current_epoch = self - .epoch_manager - .current_epoch() - .await - .map_err(RpcStatus::log_internal_error(LOG_TARGET))?; + let current_epoch = self.consensus.current_epoch(); if msg.current_epoch != current_epoch { // This may occur if one of the nodes has not fully scanned the base layer return Err(RpcStatus::bad_request(format!( diff --git a/dan_layer/rpc_state_sync/src/manager.rs b/dan_layer/rpc_state_sync/src/manager.rs index c542265e6..e0276724b 100644 --- a/dan_layer/rpc_state_sync/src/manager.rs +++ b/dan_layer/rpc_state_sync/src/manager.rs @@ -415,8 +415,8 @@ where TConsensusSpec: ConsensusSpec + Send + Sync + 'static let checkpoint = match self.fetch_epoch_checkpoint(&mut client, current_epoch).await { Ok(Some(cp)) => cp, Ok(None) => { - // EDGE-CASE: This may occur because the previous epoch had not started consensus, typically - // in testing cases where transactions + // EDGE-CASE: This may occur because the previous epoch had not started at the consensus + // level. warn!( target: LOG_TARGET, "❓No checkpoint for epoch {current_epoch}. This may mean that this is the first epoch in the network" diff --git a/integration_tests/tests/features/state_sync.feature b/integration_tests/tests/features/state_sync.feature index 63a00187e..0deb37d03 100644 --- a/integration_tests/tests/features/state_sync.feature +++ b/integration_tests/tests/features/state_sync.feature @@ -45,6 +45,7 @@ Feature: State Sync Then VN2 has scanned to height 37 Then the validator node VN2 is listed as registered + When I wait for validator VN has leaf block height of at least 1 at epoch 3 When I wait for validator VN2 has leaf block height of at least 1 at epoch 3 When I create an account UNUSED4 via the wallet daemon WALLET_D