Skip to content

Commit

Permalink
added full registration details to stored validator nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ksrichard committed Nov 7, 2024
1 parent 7b69524 commit 31cc467
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 21 deletions.
1 change: 1 addition & 0 deletions applications/minotari_app_grpc/proto/base_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ message ValidatorNodeChange {
bytes public_key = 1;
ValidatorNodeChangeState state = 2;
uint64 start_height = 3;
ValidatorNodeRegistration registration = 4;
}

message GetValidatorNodeChangesResponse {
Expand Down
1 change: 1 addition & 0 deletions applications/minotari_app_grpc/src/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub mod transaction_input;
pub mod transaction_kernel;
pub mod transaction_output;
pub mod unblinded_output;
pub mod validator_node_change;

use prost_types::Timestamp;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tari_core::base_node::comms_interface::{ValidatorNodeChange, ValidatorNodeChangeState};
use tari_utilities::ByteArray;

impl From<&ValidatorNodeChange> for crate::tari_rpc::ValidatorNodeChange {
fn from(node_change: &ValidatorNodeChange) -> Self {
crate::tari_rpc::ValidatorNodeChange {
public_key: node_change.public_key.to_vec(),
state: match node_change.state {
ValidatorNodeChangeState::ADD => crate::tari_rpc::ValidatorNodeChangeState::Add.into(),
ValidatorNodeChangeState::REMOVE => crate::tari_rpc::ValidatorNodeChangeState::Remove.into(),
},
start_height: node_change.height,
registration: match &node_change.registration {
Some(value) => Some(crate::tari_rpc::ValidatorNodeRegistration {
public_key: value.public_key().to_vec(),
signature: Some(crate::tari_rpc::Signature {
public_nonce: value.signature().get_public_nonce().to_vec(),
signature: value.signature().get_signature().to_vec(),
}),
claim_public_key: value.claim_public_key().to_vec(),
sidechain_id: match value.sidechain_id() {
None => vec![],
Some(id) => id.to_vec(),
},
sidechain_id_knowledge_proof: value.sidechain_id_knowledge_proof().map(|signature| {
crate::tari_rpc::Signature {
public_nonce: signature.get_public_nonce().to_vec(),
signature: signature.get_signature().to_vec(),
}
}),
}),
None => None,
},
}
}
}
20 changes: 2 additions & 18 deletions applications/minotari_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ use futures::{channel::mpsc, SinkExt};
use log::*;
use minotari_app_grpc::{
tari_rpc,
tari_rpc::{
CalcType,
GetValidatorNodeChangesRequest,
GetValidatorNodeChangesResponse,
Sorting,
ValidatorNodeChange,
},
tari_rpc::{CalcType, GetValidatorNodeChangesRequest, GetValidatorNodeChangesResponse, Sorting},
};
use tari_common_types::{
key_branches::TransactionKeyManagerBranch,
Expand All @@ -48,7 +42,6 @@ use tari_common_types::{
use tari_comms::{Bytes, CommsNode};
use tari_core::{
base_node::{
comms_interface,
comms_interface::CommsInterfaceError,
state_machine_service::states::StateInfo,
LocalNodeCommsInterface,
Expand Down Expand Up @@ -2587,16 +2580,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
Status::internal("Internal error!")
})?
.iter()
.map(|node_change| ValidatorNodeChange {
public_key: node_change.public_key.to_vec(),
state: match node_change.state {
comms_interface::ValidatorNodeChangeState::ADD => tari_rpc::ValidatorNodeChangeState::Add.into(),
comms_interface::ValidatorNodeChangeState::REMOVE => {
tari_rpc::ValidatorNodeChangeState::Remove.into()
},
},
start_height: node_change.height,
})
.map(|node_change| node_change.into())
.collect();

Ok(Response::new(GetValidatorNodeChangesResponse { changes }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ use crate::{
blocks::{Block, ChainHeader, HistoricalBlock, NewBlockTemplate},
chain_storage::{TemplateRegistrationEntry, ValidatorNodeRegistrationInfo},
proof_of_work::Difficulty,
transactions::transaction_components::{Transaction, TransactionKernel, TransactionOutput},
transactions::transaction_components::{
Transaction,
TransactionKernel,
TransactionOutput,
ValidatorNodeRegistration,
},
};

/// API Response enum
Expand Down Expand Up @@ -123,5 +128,6 @@ pub enum ValidatorNodeChangeState {
pub struct ValidatorNodeChange {
pub public_key: PublicKey,
pub state: ValidatorNodeChangeState,
pub registration: Option<ValidatorNodeRegistration>,
pub height: u64,
}
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ where B: BlockchainBackend + 'static
node_changes.insert(prev_node.public_key.clone(), ValidatorNodeChange {
public_key: prev_node.public_key.clone(),
state: ValidatorNodeChangeState::REMOVE,
registration: None,
height: constants.epoch_to_block_height(prev_node.start_epoch),
});
}
Expand All @@ -488,6 +489,7 @@ where B: BlockchainBackend + 'static
node_changes.insert(current_node.public_key.clone(), ValidatorNodeChange {
public_key: current_node.public_key.clone(),
state: ValidatorNodeChangeState::ADD,
registration: Some(current_node.original_registration.clone()),
height: constants.epoch_to_block_height(current_node.start_epoch),
});
}
Expand All @@ -502,6 +504,7 @@ where B: BlockchainBackend + 'static
.map(|(pub_key, change)| ValidatorNodeChange {
public_key: pub_key.clone(),
state: change.state.clone(),
registration: change.registration.clone(),
height: change.height,
})
.collect(),
Expand Down
3 changes: 3 additions & 0 deletions base_layer/core/src/chain_storage/active_validator_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ use tari_common_types::{
types::{Commitment, PublicKey},
};

use crate::transactions::transaction_components::ValidatorNodeRegistration;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
pub struct ValidatorNodeEntry {
pub shard_key: [u8; 32],
pub start_epoch: VnEpoch,
pub public_key: PublicKey,
pub commitment: Commitment,
pub sidechain_id: Option<PublicKey>,
pub registration: ValidatorNodeRegistration,
}
1 change: 1 addition & 0 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,7 @@ impl LMDBDatabase {
public_key: vn_reg.public_key().clone(),
commitment: commitment.clone(),
sidechain_id: vn_reg.sidechain_id().cloned(),
registration: vn_reg.clone(),
};

store.insert(header.height, &validator_node)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl<'a, Txn: Deref<Target = ConstTransaction<'a>>> ValidatorNodeStore<'a, Txn>
sidechain_id: vn.sidechain_id,
shard_key: vn.shard_key,
start_epoch: vn.start_epoch,
original_registration: vn.registration.clone(),
}));
},
None => return Ok(Vec::new()),
Expand All @@ -238,6 +239,7 @@ impl<'a, Txn: Deref<Target = ConstTransaction<'a>>> ValidatorNodeStore<'a, Txn>
sidechain_id: vn.sidechain_id,
shard_key: vn.shard_key,
start_epoch: vn.start_epoch,
original_registration: vn.registration,
}));
i += 1;
}
Expand Down
3 changes: 3 additions & 0 deletions base_layer/core/src/chain_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ use tari_common_types::{
mod template_registation;
pub use template_registation::TemplateRegistrationEntry;

use crate::transactions::transaction_components::ValidatorNodeRegistration;

#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq)]
pub struct ChainTipData {
pub hash: HashOutput,
Expand All @@ -103,4 +105,5 @@ pub struct ValidatorNodeRegistrationInfo {
pub sidechain_id: Option<PublicKey>,
pub shard_key: [u8; 32],
pub start_epoch: VnEpoch,
pub original_registration: ValidatorNodeRegistration,
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use tari_utilities::ByteArray;

use crate::{consensus::DomainSeparatedConsensusHasher, transactions::transaction_components::ValidatorNodeSignature};

#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize, BorshSerialize, BorshDeserialize)]
#[derive(Default, Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize, BorshSerialize, BorshDeserialize)]
pub struct ValidatorNodeRegistration {
signature: ValidatorNodeSignature,
claim_public_key: PublicKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ hash_domain!(
0
);

#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize, BorshSerialize, BorshDeserialize)]
#[derive(Default, Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize, BorshSerialize, BorshDeserialize)]
pub struct ValidatorNodeSignature {
public_key: PublicKey,
signature: Signature,
Expand Down

0 comments on commit 31cc467

Please sign in to comment.