Explorar o código

blockchain: Trivial cleanup, add FIXME for certain functions/deps.

parazyd %!s(int64=2) %!d(string=hai) anos
pai
achega
35462e00b2

+ 5 - 2
src/blockchain/block_store.rs

@@ -21,7 +21,10 @@ use darkfi_sdk::{
     crypto::schnorr::Signature,
     pasta::{group::ff::Field, pallas},
 };
-use darkfi_serial::{async_trait, deserialize, serialize, SerialDecodable, SerialEncodable};
+#[cfg(feature = "async-serial")]
+use darkfi_serial::async_trait;
+
+use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
 
 use crate::{tx::Transaction, Error, Result};
 
@@ -188,7 +191,7 @@ impl From<BlockInfo> for Block {
         let slots = block_info.slots.iter().map(|x| x.id).collect();
         Self {
             magic: block_info.magic,
-            header: block_info.header.headerhash(),
+            header: block_info.header.headerhash().unwrap(),
             txs,
             producer: block_info.producer,
             slots,

+ 3 - 1
src/blockchain/contract_store.rs

@@ -23,7 +23,6 @@ use darkfi_serial::{deserialize, serialize};
 use log::{debug, error};
 
 use crate::{
-    runtime::vm_runtime::SMART_CONTRACT_ZKAS_DB_NAME,
     zk::{empty_witnesses, VerifyingKey, ZkCircuit},
     zkas::ZkBinary,
     Error, Result,
@@ -34,6 +33,9 @@ use super::SledDbOverlayPtr;
 const SLED_CONTRACTS_TREE: &[u8] = b"_contracts";
 const SLED_BINCODE_TREE: &[u8] = b"_wasm_bincode";
 
+/// The hardcoded db name for the zkas circuits database tree
+pub const SMART_CONTRACT_ZKAS_DB_NAME: &str = "_zkas";
+
 /// The `WasmStore` is a `sled` tree that stores the wasm bincode for deployed
 /// contracts.
 #[derive(Clone)]

+ 8 - 3
src/blockchain/header_store.rs

@@ -17,7 +17,10 @@
  */
 
 use darkfi_sdk::crypto::{MerkleNode, MerkleTree};
-use darkfi_serial::{async_trait, deserialize, serialize, SerialDecodable, SerialEncodable};
+
+#[cfg(feature = "async-serial")]
+use darkfi_serial::async_trait;
+use darkfi_serial::{deserialize, serialize, Encodable, SerialDecodable, SerialEncodable};
 
 use crate::{util::time::Timestamp, Error, Result};
 
@@ -53,8 +56,10 @@ impl Header {
     }
 
     /// Calculate the header hash
-    pub fn headerhash(&self) -> blake3::Hash {
-        blake3::hash(&serialize(self))
+    pub fn headerhash(&self) -> Result<blake3::Hash> {
+        let mut hasher = blake3::Hasher::new();
+        self.encode(&mut hasher)?;
+        Ok(hasher.finalize())
     }
 }
 

+ 3 - 1
src/blockchain/mod.rs

@@ -24,7 +24,7 @@ use sled::Transactional;
 use darkfi_sdk::blockchain::Slot;
 use darkfi_serial::{deserialize, serialize, Decodable};
 
-use crate::{tx::Transaction, validator::consensus::next_block_reward, Error, Result};
+use crate::{tx::Transaction, Error, Result};
 
 /// Block related definitions and storage implementations
 pub mod block_store;
@@ -103,6 +103,7 @@ impl Blockchain {
         })
     }
 
+    /* TODO: FIXME: This should not be part of `Blockchain`
     /// A blockchain is considered valid, when every block is valid,
     /// based on validate_block checks.
     /// Be careful as this will try to load everything in memory.
@@ -117,6 +118,7 @@ impl Blockchain {
 
         Ok(())
     }
+    */
 
     /// Insert a given [`BlockInfo`] into the blockchain database.
     /// This functions wraps all the logic of separating the block into specific

+ 3 - 1
src/blockchain/slot_store.rs

@@ -20,7 +20,7 @@
 use darkfi_sdk::{blockchain::Slot, pasta::pallas};
 use darkfi_serial::{deserialize, serialize};
 
-use crate::{validator::consensus::pid::slot_pid_output, Error, Result};
+use crate::{Error, Result};
 
 use super::{parse_u64_key_record, SledDbOverlayPtr};
 
@@ -70,12 +70,14 @@ pub fn validate_slot(
         return error
     }
 
+    /* TODO: FIXME: blockchain should not depend on validator
     // Check PID output for this slot (6)
     if (slot.pid.f, slot.pid.error, slot.pid.sigma1, slot.pid.sigma2) !=
         slot_pid_output(previous, slot.previous.producers)
     {
         return error
     }
+    */
 
     // Check reward is the expected one (7)
     if &slot.last_eta != last_eta {

+ 2 - 0
tests/blockchain.rs

@@ -44,8 +44,10 @@ impl Harness {
     }
 
     fn validate_chains(&self) -> Result<()> {
+        /* FIXME: see blockchain fixme
         self.alice.validate()?;
         self.bob.validate()?;
+        */
 
         assert_eq!(self.alice.len(), self.bob.len());