diff --git a/applications/minotari_app_grpc/proto/base_node.proto b/applications/minotari_app_grpc/proto/base_node.proto index ae39495981..1f5a916d35 100644 --- a/applications/minotari_app_grpc/proto/base_node.proto +++ b/applications/minotari_app_grpc/proto/base_node.proto @@ -502,6 +502,7 @@ message ValidatorNodeChange { bytes public_key = 1; ValidatorNodeChangeState state = 2; uint64 start_height = 3; + ValidatorNodeRegistration registration = 4; } message GetValidatorNodeChangesResponse { diff --git a/applications/minotari_app_grpc/src/conversions/mod.rs b/applications/minotari_app_grpc/src/conversions/mod.rs index 799d2262a6..0ac7b649af 100644 --- a/applications/minotari_app_grpc/src/conversions/mod.rs +++ b/applications/minotari_app_grpc/src/conversions/mod.rs @@ -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; diff --git a/applications/minotari_app_grpc/src/conversions/validator_node_change.rs b/applications/minotari_app_grpc/src/conversions/validator_node_change.rs new file mode 100644 index 0000000000..3084705028 --- /dev/null +++ b/applications/minotari_app_grpc/src/conversions/validator_node_change.rs @@ -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, + }, + } + } +} diff --git a/applications/minotari_node/src/grpc/base_node_grpc_server.rs b/applications/minotari_node/src/grpc/base_node_grpc_server.rs index 693115fb79..b010eadc47 100644 --- a/applications/minotari_node/src/grpc/base_node_grpc_server.rs +++ b/applications/minotari_node/src/grpc/base_node_grpc_server.rs @@ -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, @@ -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, @@ -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 })) diff --git a/base_layer/core/src/base_node/comms_interface/comms_response.rs b/base_layer/core/src/base_node/comms_interface/comms_response.rs index 9d8c7ad622..1f63d0af24 100644 --- a/base_layer/core/src/base_node/comms_interface/comms_response.rs +++ b/base_layer/core/src/base_node/comms_interface/comms_response.rs @@ -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 @@ -123,5 +128,6 @@ pub enum ValidatorNodeChangeState { pub struct ValidatorNodeChange { pub public_key: PublicKey, pub state: ValidatorNodeChangeState, + pub registration: Option, pub height: u64, } diff --git a/base_layer/core/src/base_node/comms_interface/inbound_handlers.rs b/base_layer/core/src/base_node/comms_interface/inbound_handlers.rs index 5adfbae867..9a5c852bbb 100644 --- a/base_layer/core/src/base_node/comms_interface/inbound_handlers.rs +++ b/base_layer/core/src/base_node/comms_interface/inbound_handlers.rs @@ -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), }); } @@ -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), }); } @@ -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(), diff --git a/base_layer/core/src/chain_storage/active_validator_node.rs b/base_layer/core/src/chain_storage/active_validator_node.rs index 688a0719c6..7ee46b6a7b 100644 --- a/base_layer/core/src/chain_storage/active_validator_node.rs +++ b/base_layer/core/src/chain_storage/active_validator_node.rs @@ -26,6 +26,8 @@ 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], @@ -33,4 +35,5 @@ pub struct ValidatorNodeEntry { pub public_key: PublicKey, pub commitment: Commitment, pub sidechain_id: Option, + pub registration: ValidatorNodeRegistration, } diff --git a/base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs b/base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs index b2edbb71f4..78eb70f542 100644 --- a/base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs +++ b/base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs @@ -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)?; diff --git a/base_layer/core/src/chain_storage/lmdb_db/validator_node_store.rs b/base_layer/core/src/chain_storage/lmdb_db/validator_node_store.rs index 6eefaa8cb7..3bcc3052da 100644 --- a/base_layer/core/src/chain_storage/lmdb_db/validator_node_store.rs +++ b/base_layer/core/src/chain_storage/lmdb_db/validator_node_store.rs @@ -214,6 +214,7 @@ impl<'a, Txn: Deref>> 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()), @@ -238,6 +239,7 @@ impl<'a, Txn: Deref>> ValidatorNodeStore<'a, Txn> sidechain_id: vn.sidechain_id, shard_key: vn.shard_key, start_epoch: vn.start_epoch, + original_registration: vn.registration, })); i += 1; } diff --git a/base_layer/core/src/chain_storage/mod.rs b/base_layer/core/src/chain_storage/mod.rs index 96c5b845ce..9d9533129f 100644 --- a/base_layer/core/src/chain_storage/mod.rs +++ b/base_layer/core/src/chain_storage/mod.rs @@ -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, @@ -103,4 +105,5 @@ pub struct ValidatorNodeRegistrationInfo { pub sidechain_id: Option, pub shard_key: [u8; 32], pub start_epoch: VnEpoch, + pub original_registration: ValidatorNodeRegistration, } diff --git a/base_layer/core/src/transactions/transaction_components/side_chain/validator_node_registration.rs b/base_layer/core/src/transactions/transaction_components/side_chain/validator_node_registration.rs index 540b294f4b..d6eb49722f 100644 --- a/base_layer/core/src/transactions/transaction_components/side_chain/validator_node_registration.rs +++ b/base_layer/core/src/transactions/transaction_components/side_chain/validator_node_registration.rs @@ -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, diff --git a/base_layer/core/src/transactions/transaction_components/side_chain/validator_node_signature.rs b/base_layer/core/src/transactions/transaction_components/side_chain/validator_node_signature.rs index 49e28fe755..a9ba9cd48c 100644 --- a/base_layer/core/src/transactions/transaction_components/side_chain/validator_node_signature.rs +++ b/base_layer/core/src/transactions/transaction_components/side_chain/validator_node_signature.rs @@ -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,