Ver código fonte

validatord/protocol_sync.rs: handle_receive_block to be executed based on node mode flag

aggstam 4 anos atrás
pai
commit
66baa52e91

+ 2 - 1
script/research/validatord/src/main.rs

@@ -315,10 +315,11 @@ async fn start(executor: Arc<Executor<'_>>, opts: &Opt) -> Result<()> {
 
 
     // Adding ProtocolSync to the registry
     // Adding ProtocolSync to the registry
     let state2 = state.clone();
     let state2 = state.clone();
+    let consensus_mode = false; // This flag should be based on staking
     registry
     registry
         .register(net::SESSION_ALL, move |channel, main_p2p| {
         .register(net::SESSION_ALL, move |channel, main_p2p| {
             let state = state2.clone();
             let state = state2.clone();
-            async move { ProtocolSync::init(channel, state, main_p2p).await }
+            async move { ProtocolSync::init(channel, state, main_p2p, consensus_mode).await }
         })
         })
         .await;
         .await;
 
 

+ 15 - 13
script/research/validatord/src/protocols/protocol_sync.rs

@@ -24,14 +24,16 @@ pub struct ProtocolSync {
     block_sub: MessageSubscription<BlockInfo>,
     block_sub: MessageSubscription<BlockInfo>,
     jobsman: ProtocolJobsManagerPtr,
     jobsman: ProtocolJobsManagerPtr,
     state: ValidatorStatePtr,
     state: ValidatorStatePtr,
-    _p2p: P2pPtr,
+    p2p: P2pPtr,
+    consensus_mode: bool,
 }
 }
 
 
 impl ProtocolSync {
 impl ProtocolSync {
     pub async fn init(
     pub async fn init(
         channel: ChannelPtr,
         channel: ChannelPtr,
         state: ValidatorStatePtr,
         state: ValidatorStatePtr,
-        _p2p: P2pPtr,
+        p2p: P2pPtr,
+        consensus_mode: bool,
     ) -> ProtocolBasePtr {
     ) -> ProtocolBasePtr {
         let message_subsytem = channel.get_message_subsystem();
         let message_subsytem = channel.get_message_subsystem();
         message_subsytem.add_dispatch::<BlockOrder>().await;
         message_subsytem.add_dispatch::<BlockOrder>().await;
@@ -48,7 +50,8 @@ impl ProtocolSync {
             block_sub,
             block_sub,
             jobsman: ProtocolJobsManager::new("SyncProtocol", channel),
             jobsman: ProtocolJobsManager::new("SyncProtocol", channel),
             state,
             state,
-            _p2p,
+            p2p,
+            consensus_mode,
         })
         })
     }
     }
 
 
@@ -82,20 +85,19 @@ impl ProtocolSync {
                 info
                 info
             );
             );
 
 
-            // TODO: Following code should be executed only by replicators, not consensus nodes.
-            // Commented for now, as to not mess consensus testing.
-            // (Don't forget to remove _ from _p2p)
-            /*
             // Node stores finalized block, if it doesn't exists (checking by slot),
             // Node stores finalized block, if it doesn't exists (checking by slot),
             // and removes its transactions from the unconfirmed_txs vector.
             // and removes its transactions from the unconfirmed_txs vector.
+            // Consensus mode enabled nodes have already performed this steps,
+            // during proposal finalization.
             // Extra validations can be added here.
             // Extra validations can be added here.
-            let info_copy = (*info).clone();
-            if !self.state.read().unwrap().blockchain.has_block(&info_copy)? {
-                self.state.write().unwrap().blockchain.add_by_info(info_copy.clone())?;
-                self.state.write().unwrap().remove_txs(info_copy.txs.clone())?;
-                self.p2p.broadcast(info_copy).await?;
+            if self.consensus_mode {
+                let info_copy = (*info).clone();
+                if !self.state.read().unwrap().blockchain.has_block(&info_copy)? {
+                    self.state.write().unwrap().blockchain.add_by_info(info_copy.clone())?;
+                    self.state.write().unwrap().remove_txs(info_copy.txs.clone())?;
+                    self.p2p.broadcast(info_copy).await?;
+                }
             }
             }
-            */
         }
         }
     }
     }
 }
 }