-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Description --- When VN receives foreign proposal that was not expected, it requests all the missing proposals. They are send in order. So the node can process them as they come. Motivation and Context --- How Has This Been Tested? --- Not tested. What process can a PR reviewer use to test or verify this change? --- You can change the code to VN to not receive foreign proposal and then request it again later when another foreign proposal comes in. Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify
- Loading branch information
Showing
15 changed files
with
257 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
dan_layer/consensus/src/hotstuff/on_receive_request_missing_foreign_blocks.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2023 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use log::*; | ||
use tari_dan_storage::{StateStore, StateStoreReadTransaction}; | ||
use tari_epoch_manager::EpochManagerReader; | ||
use tokio::sync::mpsc; | ||
|
||
use crate::{ | ||
hotstuff::error::HotStuffError, | ||
messages::{HotstuffMessage, ProposalMessage, RequestMissingForeignBlocksMessage}, | ||
traits::ConsensusSpec, | ||
}; | ||
|
||
const LOG_TARGET: &str = "tari::dan::consensus::hotstuff::on_receive_request_missing_transactions"; | ||
|
||
pub struct OnReceiveRequestMissingForeignBlocksHandler<TConsensusSpec: ConsensusSpec> { | ||
store: TConsensusSpec::StateStore, | ||
epoch_manager: TConsensusSpec::EpochManager, | ||
tx_request_missing_foreign_blocks: mpsc::Sender<(TConsensusSpec::Addr, HotstuffMessage<TConsensusSpec::Addr>)>, | ||
} | ||
|
||
impl<TConsensusSpec> OnReceiveRequestMissingForeignBlocksHandler<TConsensusSpec> | ||
where TConsensusSpec: ConsensusSpec | ||
{ | ||
pub fn new( | ||
store: TConsensusSpec::StateStore, | ||
epoch_manager: TConsensusSpec::EpochManager, | ||
tx_request_missing_foreign_blocks: mpsc::Sender<(TConsensusSpec::Addr, HotstuffMessage<TConsensusSpec::Addr>)>, | ||
) -> Self { | ||
Self { | ||
store, | ||
epoch_manager, | ||
tx_request_missing_foreign_blocks, | ||
} | ||
} | ||
|
||
pub async fn handle( | ||
&mut self, | ||
from: TConsensusSpec::Addr, | ||
msg: RequestMissingForeignBlocksMessage, | ||
) -> Result<(), HotStuffError> { | ||
debug!(target: LOG_TARGET, "{} is requesting {}..{} missing blocks from epoch {}", from, msg.from, msg.to, msg.epoch); | ||
let foreign_shard = self | ||
.epoch_manager | ||
.get_committee_shard_by_validator_address(msg.epoch, &from) | ||
.await?; | ||
let missing_blocks = self | ||
.store | ||
.with_read_tx(|tx| tx.blocks_get_foreign_ids(foreign_shard.bucket(), msg.from, msg.to))?; | ||
for block in missing_blocks { | ||
// We send the proposal back to the requester via hotstuff, so they follow the normal path including | ||
// validation. | ||
self.tx_request_missing_foreign_blocks | ||
.send(( | ||
from.clone(), | ||
HotstuffMessage::ForeignProposal(ProposalMessage { block: block.clone() }), | ||
)) | ||
.await | ||
.map_err(|_| HotStuffError::InternalChannelClosed { | ||
context: "tx_leader in OnReceiveRequestMissingForeignBlocksHandler::handle", | ||
})?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
dan_layer/consensus/src/messages/request_missing_foreign_blocks.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2023 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use serde::Serialize; | ||
use tari_dan_common_types::Epoch; | ||
|
||
#[derive(Debug, Clone, Serialize)] | ||
pub struct RequestMissingForeignBlocksMessage { | ||
pub epoch: Epoch, | ||
pub from: u64, | ||
pub to: u64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.