Skip to content

Commit

Permalink
fix: fix validator node registration logic (#4718)
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler authored Sep 27, 2022
1 parent e3a4af2 commit 72018f4
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 145 deletions.
11 changes: 5 additions & 6 deletions applications/tari_app_grpc/proto/base_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ service BaseNode {
// Get mempool stats
rpc GetMempoolStats(Empty) returns (MempoolStatsResponse);
// Get VNs
rpc GetActiveValidatorNodes(GetActiveValidatorNodesRequest) returns (stream ActiveValidatorNode);
rpc GetActiveValidatorNodes(GetActiveValidatorNodesRequest) returns (stream GetActiveValidatorNodesResponse);
rpc GetCommittee(GetCommitteeRequest) returns (GetCommitteeResponse);
rpc GetShardKey(GetShardKeyRequest) returns (GetShardKeyResponse);
}
Expand Down Expand Up @@ -442,13 +442,12 @@ message GetActiveValidatorNodesRequest {
uint64 height = 1;
}

message ActiveValidatorNode {
message GetActiveValidatorNodesResponse {
bytes shard_key = 1;
uint64 from_height = 2;
uint64 to_height = 3;
bytes public_key = 4;
bytes public_key = 2;
}


message GetCommitteeRequest {
uint64 height = 1;
bytes shard_key = 2;
Expand All @@ -465,4 +464,4 @@ message GetShardKeyRequest {

message GetShardKeyResponse {
bytes shard_key = 1;
}
}

This file was deleted.

1 change: 0 additions & 1 deletion applications/tari_app_grpc/src/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

mod active_validator_node;
mod aggregate_body;
mod base_node_state;
mod block;
Expand Down
29 changes: 6 additions & 23 deletions applications/tari_base_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl BaseNodeGrpcServer {}
#[tonic::async_trait]
impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
type FetchMatchingUtxosStream = mpsc::Receiver<Result<tari_rpc::FetchMatchingUtxosResponse, Status>>;
type GetActiveValidatorNodesStream = mpsc::Receiver<Result<tari_rpc::ActiveValidatorNode, Status>>;
type GetActiveValidatorNodesStream = mpsc::Receiver<Result<tari_rpc::GetActiveValidatorNodesResponse, Status>>;
type GetBlocksStream = mpsc::Receiver<Result<tari_rpc::HistoricalBlock, Status>>;
type GetMempoolTransactionsStream = mpsc::Receiver<Result<tari_rpc::GetMempoolTransactionsResponse, Status>>;
type GetNetworkDifficultyStream = mpsc::Receiver<Result<tari_rpc::NetworkDifficultyResponse, Status>>;
Expand Down Expand Up @@ -1488,28 +1488,11 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
},
Ok(data) => data,
};
for active_validator_node in active_validator_nodes {
let active_validator_node = match tari_rpc::ActiveValidatorNode::try_from(active_validator_node) {
Ok(t) => t,
Err(e) => {
warn!(
target: LOG_TARGET,
"Error sending converting active validator node for GRPC: {}", e
);
match tx
.send(Err(obscure_error_if_true(
report_error_flag,
Status::internal("Error converting active validator node"),
)))
.await
{
Ok(_) => (),
Err(send_err) => {
warn!(target: LOG_TARGET, "Error sending error to GRPC client: {}", send_err)
},
}
return;
},
dbg!(&active_validator_nodes);
for (public_key, shard_key) in active_validator_nodes {
let active_validator_node = tari_rpc::GetActiveValidatorNodesResponse {
public_key: public_key.to_vec(),
shard_key: shard_key.to_vec(),
};

match tx.send(Ok(active_validator_node)).await {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::{

use tari_common_types::{
chain_metadata::ChainMetadata,
types::{HashOutput, PrivateKey},
types::{HashOutput, PrivateKey, PublicKey},
};

use crate::{
Expand Down Expand Up @@ -71,7 +71,7 @@ pub enum NodeCommsResponse {
FetchOutputsByContractIdResponse {
outputs: Vec<UtxoMinedInfo>,
},
FetchValidatorNodesKeysResponse(Vec<ActiveValidatorNode>),
FetchValidatorNodesKeysResponse(Vec<(PublicKey, [u8; 32])>),
FetchCommitteeResponse(Vec<ActiveValidatorNode>),
GetShardKeyResponse([u8; 32]),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl LocalNodeCommsInterface {
pub async fn get_active_validator_nodes(
&mut self,
height: u64,
) -> Result<Vec<ActiveValidatorNode>, CommsInterfaceError> {
) -> Result<Vec<(PublicKey, [u8; 32])>, CommsInterfaceError> {
match self
.request_sender
.call(NodeCommsRequest::FetchValidatorNodesKeys { height })
Expand Down
3 changes: 2 additions & 1 deletion base_layer/core/src/chain_storage/active_validator_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use serde::{Deserialize, Serialize};
use tari_common_types::types::PublicKey;
use tari_common_types::types::{HashOutput, PublicKey};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ActiveValidatorNode {
pub shard_key: [u8; 32],
pub from_height: u64,
pub to_height: u64,
pub public_key: PublicKey,
pub output_hash: HashOutput,
}
3 changes: 1 addition & 2 deletions base_layer/core/src/chain_storage/async_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ use crate::{
proof_of_work::{PowAlgorithm, TargetDifficultyWindow},
transactions::transaction_components::{TransactionKernel, TransactionOutput},
};

const LOG_TARGET: &str = "c::bn::async_db";

fn trace_log<F, R>(name: &str, f: F) -> R
Expand Down Expand Up @@ -266,7 +265,7 @@ impl<B: BlockchainBackend + 'static> AsyncBlockchainDb<B> {

make_async_fn!(fetch_total_size_stats() -> DbTotalSizeStats, "fetch_total_size_stats");

make_async_fn!(fetch_active_validator_nodes(height: u64) -> Vec<ActiveValidatorNode>, "fetch_active_validator_nodes");
make_async_fn!(fetch_active_validator_nodes(height: u64) -> Vec<(PublicKey, [u8;32])>, "fetch_active_validator_nodes");

make_async_fn!(fetch_committee(height: u64, shard: [u8;32]) -> Vec<ActiveValidatorNode>, "fetch_committee");

Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/chain_storage/blockchain_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub trait BlockchainBackend: Send + Sync {
/// Fetches all tracked reorgs
fn fetch_all_reorgs(&self) -> Result<Vec<Reorg>, ChainStorageError>;

fn fetch_active_validator_nodes(&self, height: u64) -> Result<Vec<ActiveValidatorNode>, ChainStorageError>;
fn fetch_active_validator_nodes(&self, height: u64) -> Result<Vec<(PublicKey, [u8; 32])>, ChainStorageError>;
fn fetch_committee(&self, height: u64, shard: [u8; 32]) -> Result<Vec<ActiveValidatorNode>, ChainStorageError>;
fn get_shard_key(&self, height: u64, public_key: PublicKey) -> Result<[u8; 32], ChainStorageError>;
}
4 changes: 2 additions & 2 deletions base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ where B: BlockchainBackend
db.write(txn)
}

pub fn fetch_active_validator_nodes(&self, height: u64) -> Result<Vec<ActiveValidatorNode>, ChainStorageError> {
pub fn fetch_active_validator_nodes(&self, height: u64) -> Result<Vec<(PublicKey, [u8; 32])>, ChainStorageError> {
let db = self.db_read_access()?;
db.fetch_active_validator_nodes(height)
}
Expand Down Expand Up @@ -1322,7 +1322,7 @@ pub fn calculate_mmr_roots<T: BlockchainBackend>(db: &T, block: &Block) -> Resul
output_mmr.compress();

let validator_nodes = db.fetch_active_validator_nodes(metadata.height_of_longest_chain() + 1)?;
let vn_mmr = ValidatorNodeMmr::new(validator_nodes.iter().map(|vn| vn.shard_key.to_vec()).collect());
let vn_mmr = ValidatorNodeMmr::new(validator_nodes.iter().map(|vn| vn.1.to_vec()).collect());

let mmr_roots = MmrRoots {
kernel_mr: FixedHash::try_from(kernel_mmr.get_merkle_root()?)?,
Expand Down
6 changes: 1 addition & 5 deletions base_layer/core/src/chain_storage/db_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::{
};

use croaring::Bitmap;
use tari_common_types::types::{BlockHash, Commitment, HashOutput, PublicKey};
use tari_common_types::types::{BlockHash, Commitment, HashOutput};
use tari_utilities::hex::Hex;

use super::ActiveValidatorNode;
Expand Down Expand Up @@ -362,9 +362,6 @@ pub enum WriteOperation {
InsertValidatorNode {
validator_node: ActiveValidatorNode,
},
DeleteValidatorNode {
public_key: PublicKey,
},
}

impl fmt::Display for WriteOperation {
Expand Down Expand Up @@ -464,7 +461,6 @@ impl fmt::Display for WriteOperation {
InsertValidatorNode { validator_node } => {
write!(f, "Inserting VN {:?}", validator_node)
},
DeleteValidatorNode { public_key } => write!(f, "Delete VN key {}", public_key),
}
}
}
Expand Down
Loading

0 comments on commit 72018f4

Please sign in to comment.