Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAG] Adding randomness field in dag node #9687

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions consensus/src/consensusdb/consensusdb_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

use super::*;
use crate::dag::{CertifiedNode, Node, Vote};
use crate::dag::{CertifiedNode, Extensions, Node, Vote};
use aptos_consensus_types::{
block::block_test_utils::certificate_for_genesis,
common::{Author, Payload},
Expand Down Expand Up @@ -93,7 +93,15 @@ fn test_dag() {
let tmp_dir = TempPath::new();
let db = ConsensusDB::new(&tmp_dir);

let node = Node::new(1, 1, Author::random(), 123, Payload::empty(false), vec![]);
let node = Node::new(
1,
1,
Author::random(),
123,
Payload::empty(false),
vec![],
Extensions::empty(),
);
test_dag_type::<NodeSchema, <NodeSchema as Schema>::Key>(node.digest(), node.clone(), &db);

let certified_node = CertifiedNode::new(node.clone(), AggregateSignature::empty());
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/dag/dag_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
dag_fetcher::FetchRequester,
order_rule::OrderRule,
storage::DAGStorage,
types::{CertifiedAck, DAGMessage},
types::{CertifiedAck, DAGMessage, Extensions},
RpcHandler,
};
use crate::{
Expand Down Expand Up @@ -124,6 +124,7 @@ impl DagDriver {
timestamp.as_micros() as u64,
payload,
strong_links,
Extensions::empty(),
);
self.storage
.save_node(&new_node)
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/dag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ mod tests;
mod types;

pub use dag_network::{RpcHandler, RpcWithFallback, TDAGNetworkSender};
pub use types::{CertifiedNode, DAGMessage, DAGNetworkMessage, Node, NodeId, Vote};
pub use types::{CertifiedNode, DAGMessage, DAGNetworkMessage, Extensions, Node, NodeId, Vote};
22 changes: 19 additions & 3 deletions consensus/src/dag/tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright © Aptos Foundation

use crate::dag::types::{CertifiedNode, Node, NodeCertificate};
use crate::dag::types::{CertifiedNode, Extensions, Node, NodeCertificate};
use aptos_consensus_types::common::{Author, Payload, Round};
use aptos_types::aggregate_signature::AggregateSignature;

Expand All @@ -9,7 +9,15 @@ pub(crate) fn new_certified_node(
author: Author,
parents: Vec<NodeCertificate>,
) -> CertifiedNode {
let node = Node::new(1, round, author, 0, Payload::empty(false), parents);
let node = Node::new(
1,
round,
author,
0,
Payload::empty(false),
parents,
Extensions::empty(),
);
CertifiedNode::new(node, AggregateSignature::empty())
}

Expand All @@ -19,5 +27,13 @@ pub(crate) fn new_node(
author: Author,
parents: Vec<NodeCertificate>,
) -> Node {
Node::new(0, round, author, timestamp, Payload::empty(false), parents)
Node::new(
0,
round,
author,
timestamp,
Payload::empty(false),
parents,
Extensions::empty(),
)
}
6 changes: 4 additions & 2 deletions consensus/src/dag/tests/types_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use super::helpers::new_node;
use crate::dag::{
tests::helpers::new_certified_node,
types::{
CertifiedNode, DagSnapshotBitmask, Node, NodeCertificate, NodeMetadata, RemoteFetchRequest,
TDAGMessage,
CertifiedNode, DagSnapshotBitmask, Extensions, Node, NodeCertificate, NodeMetadata,
RemoteFetchRequest, TDAGMessage,
},
};
use aptos_consensus_types::common::Payload;
Expand All @@ -24,6 +24,7 @@ fn test_node_verify() {
NodeMetadata::new_for_test(0, 0, signers[0].author(), 0, HashValue::random()),
Payload::empty(false),
vec![],
Extensions::empty(),
);
assert_eq!(
invalid_node
Expand Down Expand Up @@ -64,6 +65,7 @@ fn test_certified_node_verify() {
NodeMetadata::new_for_test(0, 0, signers[0].author(), 0, HashValue::random()),
Payload::empty(false),
vec![],
Extensions::empty(),
);
let invalid_certified_node = CertifiedNode::new(invalid_node, AggregateSignature::empty());
assert_eq!(
Expand Down
33 changes: 31 additions & 2 deletions consensus/src/dag/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ impl TDAGMessage for CertifiedAck {
}
}

#[derive(Clone, Serialize, Deserialize, CryptoHasher, Debug, PartialEq)]
pub enum Extensions {
Empty,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: None is probably more appropriate.

Suggested change
Empty,
None,

// Reserved for future extensions such as randomness shares
}

impl Extensions {
pub fn empty() -> Self {
Self::Empty
}
}

#[derive(Serialize)]
struct NodeWithoutDigest<'a> {
epoch: u64,
Expand All @@ -46,6 +58,7 @@ struct NodeWithoutDigest<'a> {
timestamp: u64,
payload: &'a Payload,
parents: &'a Vec<NodeCertificate>,
extensions: &'a Extensions,
}

impl<'a> CryptoHash for NodeWithoutDigest<'a> {
Expand All @@ -68,6 +81,7 @@ impl<'a> From<&'a Node> for NodeWithoutDigest<'a> {
timestamp: node.metadata.timestamp,
payload: &node.payload,
parents: &node.parents,
extensions: &node.extensions,
}
}
}
Expand Down Expand Up @@ -131,6 +145,7 @@ pub struct Node {
metadata: NodeMetadata,
payload: Payload,
parents: Vec<NodeCertificate>,
extensions: Extensions,
}

impl Node {
Expand All @@ -141,9 +156,17 @@ impl Node {
timestamp: u64,
payload: Payload,
parents: Vec<NodeCertificate>,
extensions: Extensions,
) -> Self {
let digest =
Self::calculate_digest_internal(epoch, round, author, timestamp, &payload, &parents);
let digest = Self::calculate_digest_internal(
epoch,
round,
author,
timestamp,
&payload,
&parents,
&extensions,
);

Self {
metadata: NodeMetadata {
Expand All @@ -157,6 +180,7 @@ impl Node {
},
payload,
parents,
extensions,
}
}

Expand All @@ -165,11 +189,13 @@ impl Node {
metadata: NodeMetadata,
payload: Payload,
parents: Vec<NodeCertificate>,
extensions: Extensions,
) -> Self {
Self {
metadata,
payload,
parents,
extensions,
}
}

Expand All @@ -181,6 +207,7 @@ impl Node {
timestamp: u64,
payload: &Payload,
parents: &Vec<NodeCertificate>,
extensions: &Extensions,
) -> HashValue {
let node_with_out_digest = NodeWithoutDigest {
epoch,
Expand All @@ -189,6 +216,7 @@ impl Node {
timestamp,
payload,
parents,
extensions,
};
node_with_out_digest.hash()
}
Expand All @@ -201,6 +229,7 @@ impl Node {
self.metadata.timestamp,
&self.payload,
&self.parents,
&self.extensions,
)
}

Expand Down
Loading