Skip to content

Commit

Permalink
VID share required target epoch as well
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszrzasik committed Dec 19, 2024
1 parent 1908d61 commit 3110ee5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
9 changes: 5 additions & 4 deletions crates/task-impls/src/quorum_vote/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> QuorumVoteTaskS

// Validate the VID share.
let payload_commitment = &disperse.data.payload_commitment;
let disperse_epoch = disperse.data.epoch;
let vid_epoch = disperse.data.epoch;
let target_epoch = disperse.data.target_node_epoch;

// Check that the signature is valid
ensure!(
Expand All @@ -557,15 +558,15 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> QuorumVoteTaskS
// ensure that the VID share was sent by a DA member OR the view leader
ensure!(
self.membership
.da_committee_members(view, disperse_epoch)
.da_committee_members(view, vid_epoch)
.contains(sender)
|| *sender == self.membership.leader(view, disperse_epoch)?,
|| *sender == self.membership.leader(view, vid_epoch)?,
"VID share was not sent by a DA member or the view leader."
);

// NOTE: `verify_share` returns a nested `Result`, so we must check both the inner
// and outer results
match vid_scheme(self.membership.total_nodes(disperse_epoch)).verify_share(
match vid_scheme(self.membership.total_nodes(target_epoch)).verify_share(
&disperse.data.share,
&disperse.data.common,
payload_commitment,
Expand Down
4 changes: 2 additions & 2 deletions crates/task-impls/src/vid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> VidTaskState<TYPES, I> {
&Arc::clone(&self.membership),
*view_number,
epoch,
None,
epoch,
vid_precompute.clone(),
)
.await;
Expand Down Expand Up @@ -200,7 +200,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> VidTaskState<TYPES, I> {
&Arc::clone(&self.membership),
proposal_view_number,
target_epoch,
Some(sender_epoch),
sender_epoch,
None,
)
.await;
Expand Down
2 changes: 1 addition & 1 deletion crates/testing/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub fn build_vid_proposal<TYPES: NodeType>(
vid.disperse(&encoded_transactions).unwrap(),
quorum_membership,
epoch_number,
None,
epoch_number,
);

let signature =
Expand Down
3 changes: 1 addition & 2 deletions crates/testing/tests/tests_1/test_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// You should have received a copy of the MIT License
// along with the HotShot repository. If not, see <https://mit-license.org/>.

use std::{sync::Arc, time::Duration};
use std::time::Duration;

use hotshot_example_types::{
node_types::{
Expand All @@ -18,7 +18,6 @@ use hotshot_macros::cross_tests;
use hotshot_testing::{
block_builder::SimpleBuilderImplementation,
completion_task::{CompletionTaskDescription, TimeBasedCompletionTaskDescription},
overall_safety_task::OverallSafetyPropertiesDescription,
spinning_task::{ChangeNode, NodeAction, SpinningTaskDescription},
test_builder::TestDescription,
view_sync_task::ViewSyncTaskDescription,
Expand Down
2 changes: 1 addition & 1 deletion crates/testing/tests/tests_1/vid_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async fn test_vid_task() {
vid_disperse,
&membership,
EpochNumber::new(0),
None,
EpochNumber::new(0),
);

let vid_proposal = Proposal {
Expand Down
2 changes: 1 addition & 1 deletion crates/types/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ impl<TYPES: NodeType> Consensus<TYPES> {
.view_inner
.epoch()?;
let vid =
VidDisperse::calculate_vid_disperse(txns, &membership, view, epoch, None, None).await;
VidDisperse::calculate_vid_disperse(txns, &membership, view, epoch, epoch, None).await;
let shares = VidDisperseShare2::from_vid_disperse(vid);
let mut consensus_writer = consensus.write().await;
for share in shares {
Expand Down
24 changes: 19 additions & 5 deletions crates/types/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ where
pub struct VidDisperse<TYPES: NodeType> {
/// The view number for which this VID data is intended
pub view_number: TYPES::View,
/// Epoch this proposal applies to
/// Epoch the data of this proposal belongs to
pub epoch: TYPES::Epoch,
/// Epoch to which the recipients of this VID belong to
pub target_epoch: TYPES::Epoch,
/// Block payload commitment
pub payload_commitment: VidCommitment,
/// A storage node's key and its corresponding VID share
Expand All @@ -229,7 +231,7 @@ impl<TYPES: NodeType> VidDisperse<TYPES> {
mut vid_disperse: JfVidDisperse<VidSchemeType>,
membership: &TYPES::Membership,
target_epoch: TYPES::Epoch,
sender_epoch: Option<TYPES::Epoch>,
sender_epoch: TYPES::Epoch,
) -> Self {
let shares = membership
.committee_members(view_number, target_epoch)
Expand All @@ -242,7 +244,8 @@ impl<TYPES: NodeType> VidDisperse<TYPES> {
shares,
common: vid_disperse.common,
payload_commitment: vid_disperse.commit,
epoch: sender_epoch.unwrap_or(target_epoch),
epoch: sender_epoch,
target_epoch,
}
}

Expand All @@ -258,7 +261,7 @@ impl<TYPES: NodeType> VidDisperse<TYPES> {
membership: &Arc<TYPES::Membership>,
view: TYPES::View,
target_epoch: TYPES::Epoch,
sender_epoch: Option<TYPES::Epoch>,
sender_epoch: TYPES::Epoch,
precompute_data: Option<VidPrecomputeData>,
) -> Self {
let num_nodes = membership.total_nodes(target_epoch);
Expand Down Expand Up @@ -368,6 +371,7 @@ impl<TYPES: NodeType> VidDisperseShare<TYPES> {
let mut vid_disperse = VidDisperse {
view_number: first_vid_disperse_share.view_number,
epoch: TYPES::Epoch::new(0),
target_epoch: TYPES::Epoch::new(0),
payload_commitment: first_vid_disperse_share.payload_commitment,
common: first_vid_disperse_share.common,
shares: share_map,
Expand Down Expand Up @@ -409,8 +413,10 @@ impl<TYPES: NodeType> VidDisperseShare<TYPES> {
pub struct VidDisperseShare2<TYPES: NodeType> {
/// The view number for which this VID data is intended
pub view_number: TYPES::View,
/// The epoch number for which this VID data is intended
/// The epoch number for which this VID data belongs to
pub epoch: TYPES::Epoch,
/// The epoch number to which the recipient of this VID belongs to
pub target_node_epoch: TYPES::Epoch,
/// Block payload commitment
pub payload_commitment: VidCommitment,
/// A storage node's key and its corresponding VID share
Expand All @@ -426,6 +432,7 @@ impl<TYPES: NodeType> From<VidDisperseShare2<TYPES>> for VidDisperseShare<TYPES>
let VidDisperseShare2 {
view_number,
epoch: _,
target_node_epoch: _,
payload_commitment,
share,
common,
Expand Down Expand Up @@ -455,6 +462,7 @@ impl<TYPES: NodeType> From<VidDisperseShare<TYPES>> for VidDisperseShare2<TYPES>
Self {
view_number,
epoch: TYPES::Epoch::new(0),
target_node_epoch: TYPES::Epoch::new(0),
payload_commitment,
share,
common,
Expand All @@ -467,6 +475,7 @@ impl<TYPES: NodeType> VidDisperseShare2<TYPES> {
/// Create a vector of `VidDisperseShare` from `VidDisperse`
pub fn from_vid_disperse(vid_disperse: VidDisperse<TYPES>) -> Vec<Self> {
let epoch = vid_disperse.epoch;
let target_epoch = vid_disperse.target_epoch;
vid_disperse
.shares
.into_iter()
Expand All @@ -477,6 +486,7 @@ impl<TYPES: NodeType> VidDisperseShare2<TYPES> {
common: vid_disperse.common.clone(),
payload_commitment: vid_disperse.payload_commitment,
epoch,
target_node_epoch: target_epoch,
})
.collect()
}
Expand Down Expand Up @@ -506,6 +516,7 @@ impl<TYPES: NodeType> VidDisperseShare2<TYPES> {
{
let first_vid_disperse_share = it.next()?.clone();
let epoch = first_vid_disperse_share.epoch;
let target_epoch = first_vid_disperse_share.target_node_epoch;
let mut share_map = BTreeMap::new();
share_map.insert(
first_vid_disperse_share.recipient_key,
Expand All @@ -514,6 +525,7 @@ impl<TYPES: NodeType> VidDisperseShare2<TYPES> {
let mut vid_disperse = VidDisperse {
view_number: first_vid_disperse_share.view_number,
epoch,
target_epoch,
payload_commitment: first_vid_disperse_share.payload_commitment,
common: first_vid_disperse_share.common,
shares: share_map,
Expand All @@ -532,6 +544,7 @@ impl<TYPES: NodeType> VidDisperseShare2<TYPES> {
vid_disperse_proposal: Proposal<TYPES, VidDisperse<TYPES>>,
) -> Vec<Proposal<TYPES, Self>> {
let epoch = vid_disperse_proposal.data.epoch;
let target_epoch = vid_disperse_proposal.data.target_epoch;
vid_disperse_proposal
.data
.shares
Expand All @@ -544,6 +557,7 @@ impl<TYPES: NodeType> VidDisperseShare2<TYPES> {
common: vid_disperse_proposal.data.common.clone(),
payload_commitment: vid_disperse_proposal.data.payload_commitment,
epoch,
target_node_epoch: target_epoch,
},
signature: vid_disperse_proposal.signature.clone(),
_pd: vid_disperse_proposal._pd,
Expand Down

0 comments on commit 3110ee5

Please sign in to comment.