Skip to content

Commit

Permalink
add metadata arg to BlockPayload::transaction_commitments (#2399)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggutoski authored Jan 14, 2024
1 parent 821d8a4 commit 22ab2ea
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
8 changes: 7 additions & 1 deletion hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use hotshot_types::{
traits::{
consensus_api::ConsensusApi,
network::{CommunicationChannel, NetworkError},
node_implementation::{ChannelMaps, NodeType, SendToTasks},
node_implementation::{NodeType, SendToTasks},
signature_key::SignatureKey,
state::ConsensusTime,
storage::StoredView,
Expand All @@ -78,6 +78,10 @@ use std::{
};
use tasks::add_vid_task;
use tracing::{debug, error, info, instrument, trace, warn};

#[cfg(feature = "hotshot-testing")]
use hotshot_types::traits::node_implementation::ChannelMaps;

// -- Rexports
// External
/// Reexport rand crate
Expand Down Expand Up @@ -162,6 +166,7 @@ pub struct SystemContextInner<TYPES: NodeType, I: NodeImplementation<TYPES>> {

/// Channels for sending/recv-ing proposals and votes for quorum and committee exchanges, the
/// latter of which is only applicable for sequencing consensus.
#[cfg(feature = "hotshot-testing")]
channel_maps: (ChannelMaps<TYPES>, Option<ChannelMaps<TYPES>>),

// global_registry: GlobalRegistry,
Expand Down Expand Up @@ -256,6 +261,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {

let inner: Arc<SystemContextInner<TYPES, I>> = Arc::new(SystemContextInner {
id: nonce,
#[cfg(feature = "hotshot-testing")]
channel_maps: I::new_channel_maps(start_view),
consensus,
public_key,
Expand Down
14 changes: 9 additions & 5 deletions hotshot/src/types/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ use hotshot_task_impls::events::HotShotEvent;
use hotshot_types::simple_vote::QuorumData;
use hotshot_types::{
consensus::Consensus,
data::Leaf,
error::HotShotError,
event::EventType,
message::{MessageKind, SequencingMessage},
traits::{
election::Membership, node_implementation::NodeType, state::ConsensusTime, storage::Storage,
},
simple_certificate::QuorumCertificate,
traits::{node_implementation::NodeType, state::ConsensusTime, storage::Storage},
};
use hotshot_types::{data::Leaf, simple_certificate::QuorumCertificate};
use std::sync::Arc;
use tracing::error;

#[cfg(feature = "hotshot-testing")]
use hotshot_types::{
message::{MessageKind, SequencingMessage},
traits::election::Membership,
};

/// Event streaming handle for a [`SystemContext`] instance running in the background
///
/// This type provides the means to message and interact with a background [`SystemContext`] instance,
Expand Down
6 changes: 4 additions & 2 deletions task-impls/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,10 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
}

leaf_views.push(leaf.clone());
if let Some(payload) = leaf.block_payload {
for txn in payload.transaction_commitments() {
if let Some(ref payload) = leaf.block_payload {
for txn in payload
.transaction_commitments(leaf.get_block_header().metadata())
{
included_txns.insert(txn);
}
}
Expand Down
7 changes: 5 additions & 2 deletions task-impls/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use hotshot_types::{
consensus::Consensus,
data::Leaf,
traits::{
block_contents::BlockHeader,
consensus_api::ConsensusApi,
election::Membership,
node_implementation::{NodeImplementation, NodeType},
Expand Down Expand Up @@ -121,8 +122,10 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
let mut included_txn_size = 0;
let mut included_txn_count = 0;
for leaf in leaf_chain {
if let Some(payload) = leaf.block_payload {
for txn in payload.transaction_commitments() {
if let Some(ref payload) = leaf.block_payload {
for txn in
payload.transaction_commitments(leaf.get_block_header().metadata())
{
included_txns.insert(txn);
}
}
Expand Down
2 changes: 1 addition & 1 deletion testing/src/block_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl BlockPayload for TestBlockPayload {
Ok(TestTransaction::encode(self.transactions.clone())?.into_iter())
}

fn transaction_commitments(&self) -> Vec<Commitment<Self::Transaction>> {
fn transaction_commitments(&self, _metadata: &Self::Metadata) -> Vec<Commitment<Self::Transaction>> {
self.transactions
.iter()
.map(commit::Committable::commit)
Expand Down
2 changes: 1 addition & 1 deletion types/src/traits/block_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub trait BlockPayload:
fn encode(&self) -> Result<Self::Encode<'_>, Self::Error>;

/// List of transaction commitments.
fn transaction_commitments(&self) -> Vec<Commitment<Self::Transaction>>;
fn transaction_commitments(&self, metadata: &Self::Metadata) -> Vec<Commitment<Self::Transaction>>;
}

/// Compute the VID payload commitment.
Expand Down

0 comments on commit 22ab2ea

Please sign in to comment.