Jelajahi Sumber

consensus: added node public key to Participant struct

aggstam 4 tahun lalu
induk
melakukan
0f36ed8e9e
3 mengubah file dengan 8 tambahan dan 5 penghapusan
  1. 5 3
      src/consensus/participant.rs
  2. 1 1
      src/consensus/state.rs
  3. 2 1
      src/consensus/task/proposal.rs

+ 5 - 3
src/consensus/participant.rs

@@ -1,7 +1,7 @@
 use std::{collections::BTreeMap, io};
 use std::{collections::BTreeMap, io};
 
 
 use crate::{
 use crate::{
-    crypto::address::Address,
+    crypto::{address::Address, keypair::PublicKey},
     impl_vec, net,
     impl_vec, net,
     util::serial::{Decodable, Encodable, SerialDecodable, SerialEncodable, VarInt},
     util::serial::{Decodable, Encodable, SerialDecodable, SerialEncodable, VarInt},
     Result,
     Result,
@@ -11,6 +11,8 @@ use crate::{
 /// (`node_address`, `slot_joined`, `last_slot_voted`, `slot_quarantined`)
 /// (`node_address`, `slot_joined`, `last_slot_voted`, `slot_quarantined`)
 #[derive(Debug, Clone, PartialEq, Eq, SerialEncodable, SerialDecodable)]
 #[derive(Debug, Clone, PartialEq, Eq, SerialEncodable, SerialDecodable)]
 pub struct Participant {
 pub struct Participant {
+    /// Node public key
+    pub public_key: PublicKey,
     /// Node wallet address
     /// Node wallet address
     pub address: Address,
     pub address: Address,
     /// Slot node joined the network
     /// Slot node joined the network
@@ -22,8 +24,8 @@ pub struct Participant {
 }
 }
 
 
 impl Participant {
 impl Participant {
-    pub fn new(address: Address, joined: u64) -> Self {
-        Self { address, joined, voted: None, quarantined: None }
+    pub fn new(public_key: PublicKey, address: Address, joined: u64) -> Self {
+        Self { public_key, address, joined, voted: None, quarantined: None }
     }
     }
 }
 }
 
 

+ 1 - 1
src/consensus/state.rs

@@ -866,7 +866,7 @@ impl ValidatorState {
 
 
         if self.consensus.participants.is_empty() {
         if self.consensus.participants.is_empty() {
             // If no nodes are active, node becomes a single node network.
             // If no nodes are active, node becomes a single node network.
-            let participant = Participant::new(self.address, self.current_slot());
+            let participant = Participant::new(self.public, self.address, self.current_slot());
             self.consensus.participants.insert(participant.address, participant);
             self.consensus.participants.insert(participant.address, participant);
         }
         }
 
 

+ 2 - 1
src/consensus/task/proposal.rs

@@ -39,9 +39,10 @@ pub async fn proposal_task(consensus_p2p: P2pPtr, sync_p2p: P2pPtr, state: Valid
     };
     };
 
 
     // Node signals the network that it will start participating
     // Node signals the network that it will start participating
+    let public = state.read().await.public;
     let address = state.read().await.address;
     let address = state.read().await.address;
     let cur_slot = state.read().await.current_slot();
     let cur_slot = state.read().await.current_slot();
-    let participant = Participant::new(address, cur_slot);
+    let participant = Participant::new(public, address, cur_slot);
     state.write().await.append_participant(participant.clone());
     state.write().await.append_participant(participant.clone());
 
 
     match consensus_p2p.broadcast(participant).await {
     match consensus_p2p.broadcast(participant).await {