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

fix: fix VN merkle root mismatch #220

Merged
merged 5 commits into from
Nov 25, 2022
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
33 changes: 28 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"dan_layer/transaction_manifest",
"dan_layer/template_test_tooling",
"dan_layer/integration_tests",
"dan_layer/tari_bor",
"applications/tari_validator_node",
"applications/tari_validator_node_cli",
]
Expand Down
8 changes: 5 additions & 3 deletions applications/tari_validator_node/proto/dan/consensus.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ syntax = "proto3";

package tari.dan.consensus;

import "common.proto";
import "transaction.proto";

enum HotStuffMessageType {
Expand Down Expand Up @@ -58,9 +59,10 @@ message HotStuffTreeNode {

message ValidatorMetadata {
bytes public_key = 1;
bytes signature = 2;
bytes merkle_proof = 3;
uint64 merkle_leaf_index = 4;
bytes vn_shard_key = 2;
tari.dan.common.Signature signature = 3;
bytes merkle_proof = 4;
uint64 merkle_leaf_index = 5;
}

message TariDanPayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl BaseNodeClient for GrpcBaseNodeClient {
})
}

async fn get_validator_nodes(&mut self, height: u64) -> Result<Vec<ValidatorNode>, BaseNodeError> {
async fn get_validator_nodes(&mut self, height: u64) -> Result<Vec<ValidatorNode<CommsPublicKey>>, BaseNodeError> {
let inner = self.connection().await?;
let request = grpc::GetActiveValidatorNodesRequest { height };
let mut vns = vec![];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl From<VoteMessage> for proto::consensus::VoteMessage {
shard_id: msg.shard().as_bytes().to_vec(),
decision: i32::from(msg.decision().as_u8()),
all_shard_nodes: msg.all_shard_nodes().iter().map(|n| n.clone().into()).collect(),
validator_metadata: Some(msg.validator_metadata().to_owned().into()),
validator_metadata: Some(msg.validator_metadata().clone().into()),
}
}
}
Expand All @@ -63,6 +63,9 @@ impl TryFrom<proto::consensus::VoteMessage> for VoteMessage {
type Error = anyhow::Error;

fn try_from(value: proto::consensus::VoteMessage) -> Result<Self, Self::Error> {
let metadata = value
.validator_metadata
.ok_or_else(|| anyhow!("Validator metadata is missing"))?;
Ok(VoteMessage::with_validator_metadata(
TreeNodeHash::try_from(value.local_node_hash)?,
ShardId::from_bytes(&value.shard_id)?,
Expand All @@ -72,17 +75,7 @@ impl TryFrom<proto::consensus::VoteMessage> for VoteMessage {
.into_iter()
.map(|n| n.try_into())
.collect::<Result<Vec<_>, _>>()?,
ValidatorMetadata::from_bytes(
&value.validator_metadata.as_ref().unwrap().public_key,
&value.validator_metadata.as_ref().unwrap().signature,
&value.validator_metadata.as_ref().unwrap().merkle_proof,
&value
.validator_metadata
.as_ref()
.unwrap()
.merkle_leaf_index
.to_le_bytes(),
)?,
metadata.try_into()?,
))
}
}
Expand Down Expand Up @@ -308,30 +301,37 @@ impl From<SubstateState> for proto::consensus::SubstateState {

// -------------------------------- ValidatorMetadata -------------------------------- //

impl From<ValidatorMetadata> for proto::consensus::ValidatorMetadata {
fn from(msg: ValidatorMetadata) -> Self {
let merkle_proof = msg.encode_merkle_proof();
Self {
public_key: msg.public_key.to_vec(),
vn_shard_key: msg.vn_shard_key.as_bytes().to_vec(),
signature: Some(msg.signature.into()),
merkle_proof,
merkle_leaf_index: msg.merkle_leaf_index,
}
}
}

impl TryFrom<proto::consensus::ValidatorMetadata> for ValidatorMetadata {
type Error = anyhow::Error;

fn try_from(value: proto::consensus::ValidatorMetadata) -> Result<Self, Self::Error> {
Ok(Self {
public_key: value.public_key,
signature: value.signature,
merkle_proof: value.merkle_proof,
Ok(ValidatorMetadata {
public_key: PublicKey::from_bytes(&value.public_key)?,
vn_shard_key: value.vn_shard_key.try_into()?,
signature: value
.signature
.map(TryFrom::try_from)
.transpose()?
.ok_or_else(|| anyhow!("ValidatorMetadata missing signature"))?,
merkle_proof: ValidatorMetadata::decode_merkle_proof(&value.merkle_proof)?,
merkle_leaf_index: value.merkle_leaf_index,
})
}
}

impl From<ValidatorMetadata> for proto::consensus::ValidatorMetadata {
fn from(value: ValidatorMetadata) -> Self {
Self {
public_key: value.public_key,
signature: value.signature,
merkle_proof: value.merkle_proof,
merkle_leaf_index: value.merkle_leaf_index,
}
}
}

// -------------------------------- TariDanPayload -------------------------------- //

impl TryFrom<proto::consensus::TariDanPayload> for TariDanPayload {
Expand Down
Loading