Explorar o código

validator: eat ze bugs

skoupidi %!s(int64=2) %!d(string=hai) anos
pai
achega
8871f0898d
Modificáronse 3 ficheiros con 12 adicións e 12 borrados
  1. 1 3
      bin/darkfid/src/task/miner.rs
  2. 9 3
      src/validator/mod.rs
  3. 2 6
      src/validator/utils.rs

+ 1 - 3
bin/darkfid/src/task/miner.rs

@@ -19,7 +19,7 @@
 use darkfi::{
     blockchain::BlockInfo,
     rpc::{jsonrpc::JsonNotification, util::JsonValue},
-    system::{sleep, Subscription},
+    system::Subscription,
     tx::{ContractCallLeaf, Transaction, TransactionBuilder},
     util::encoding::base64,
     validator::{
@@ -202,8 +202,6 @@ async fn wait_stop_signal(stop_signal: &Receiver<()>) -> Result<()> {
 
     // Wait for listener signal
     stop_signal.recv().await?;
-    // Take a nap to let listener notify minerd
-    sleep(10).await;
 
     Ok(())
 }

+ 9 - 3
src/validator/mod.rs

@@ -312,12 +312,12 @@ impl Validator {
         let append_lock = self.consensus.append_lock.write().await;
 
         // Execute append
-        self.consensus.append_proposal(proposal).await?;
+        let result = self.consensus.append_proposal(proposal).await;
 
         // Release append lock
         drop(append_lock);
 
-        Ok(())
+        result
     }
 
     /// The node checks if best fork can be finalized.
@@ -331,7 +331,13 @@ impl Validator {
         info!(target: "validator::finalization", "Performing finalization check");
 
         // Grab best fork index that can be finalized
-        let finalized_fork = self.consensus.finalization().await?;
+        let finalized_fork = match self.consensus.finalization().await {
+            Ok(f) => f,
+            Err(e) => {
+                drop(append_lock);
+                return Err(e)
+            }
+        };
         if finalized_fork.is_none() {
             info!(target: "validator::finalization", "No proposals can be finalized");
             drop(append_lock);

+ 2 - 6
src/validator/utils.rs

@@ -146,12 +146,12 @@ pub fn median(mut v: Vec<u64>) -> u64 {
     }
 }
 
-/// Given a proposal, find the index of the fork chain it extends, along with the specific
+/// Given a proposal, find the index of a fork chain it extends, along with the specific
 /// extended proposal index. Additionally, check that proposal doesn't already exists in any
 /// fork chain.
 pub fn find_extended_fork_index(forks: &[Fork], proposal: &Proposal) -> Result<(usize, usize)> {
     // Grab provided proposal hash
-    let proposal_hash = proposal.block.hash()?;
+    let proposal_hash = proposal.hash;
 
     // Keep track of fork and proposal indexes
     let (mut fork_index, mut proposal_index) = (None, None);
@@ -167,10 +167,6 @@ pub fn find_extended_fork_index(forks: &[Fork], proposal: &Proposal) -> Result<(
 
             // Check if proposal extends this fork
             if &proposal.block.header.previous == p_hash {
-                // Proposal must only extend a single fork
-                if fork_index.is_some() {
-                    return Err(Error::ProposalAlreadyExists)
-                }
                 (fork_index, proposal_index) = (Some(f_index), Some(p_index));
             }
         }