Skip to content

Commit

Permalink
use consensus epoch in checkpoint request
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Sep 24, 2024
1 parent 233b113 commit 3b00480
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
3 changes: 3 additions & 0 deletions applications/tari_validator_node/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -434,6 +435,7 @@ async fn spawn_p2p_rpc(
shard_store_store: SqliteStateStore<PeerAddress>,
mempool: MempoolHandle,
virtual_substate_manager: VirtualSubstateManager<SqliteStateStore<PeerAddress>, EpochManagerHandle<PeerAddress>>,
consensus: ConsensusHandle,
) -> anyhow::Result<()> {
let rpc_server = RpcServer::builder()
.with_maximum_simultaneous_sessions(config.validator_node.rpc.max_simultaneous_sessions)
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions applications/tari_validator_node/src/consensus/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion applications/tari_validator_node/src/p2p/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerAddress>,
shard_store_store: SqliteStateStore<PeerAddress>,
mempool: MempoolHandle,
virtual_substate_manager: VirtualSubstateManager<SqliteStateStore<PeerAddress>, EpochManagerHandle<PeerAddress>>,
consensus: ConsensusHandle,
) -> ValidatorNodeRpcServer<ValidatorNodeRpcServiceImpl> {
ValidatorNodeRpcServer::new(ValidatorNodeRpcServiceImpl::new(
epoch_manager,
shard_store_store,
mempool,
virtual_substate_manager,
consensus,
))
}
10 changes: 5 additions & 5 deletions applications/tari_validator_node/src/p2p/rpc/service_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -80,6 +81,7 @@ pub struct ValidatorNodeRpcServiceImpl {
shard_state_store: SqliteStateStore<PeerAddress>,
mempool: MempoolHandle,
virtual_substate_manager: VirtualSubstateManager<SqliteStateStore<PeerAddress>, EpochManagerHandle<PeerAddress>>,
consensus: ConsensusHandle,
}

impl ValidatorNodeRpcServiceImpl {
Expand All @@ -91,12 +93,14 @@ impl ValidatorNodeRpcServiceImpl {
SqliteStateStore<PeerAddress>,
EpochManagerHandle<PeerAddress>,
>,
consensus: ConsensusHandle,
) -> Self {
Self {
epoch_manager,
shard_state_store,
mempool,
virtual_substate_manager,
consensus,
}
}
}
Expand Down Expand Up @@ -340,11 +344,7 @@ impl ValidatorNodeRpcService for ValidatorNodeRpcServiceImpl {
request: Request<GetCheckpointRequest>,
) -> Result<Response<GetCheckpointResponse>, 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!(
Expand Down
4 changes: 2 additions & 2 deletions dan_layer/rpc_state_sync/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ where TConsensusSpec: ConsensusSpec<Addr = PeerAddress> + 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"
Expand Down
1 change: 1 addition & 0 deletions integration_tests/tests/features/state_sync.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3b00480

Please sign in to comment.