Browse Source

lib: Clean up library features.

parazyd 2 years ago
parent
commit
8f46f7b777

+ 0 - 1
Cargo.lock

@@ -1418,7 +1418,6 @@ dependencies = [
  "halo2_proofs",
  "lazy_static",
  "libc",
- "libsqlite3-sys",
  "log",
  "pin-project-lite",
  "plotters",

+ 63 - 58
Cargo.toml

@@ -96,7 +96,6 @@ lazy_static = {version = "1.4.0", optional = true}
 url = {version = "2.4.0", features = ["serde"], optional = true}
 
 # Misc
-# TODO: Implement something simple and kill these deps
 simplelog = {version = "0.12.1", optional = true}
 
 # Crypto
@@ -113,8 +112,7 @@ wasmer-compiler-singlepass = {version = "4.1.2", optional = true}
 wasmer-middlewares = {version = "4.1.2", optional = true}
 
 # Wallet management
-rusqlite = {version = "0.29.0", features = ["bundled-sqlcipher-vendored-openssl"], optional = true}
-libsqlite3-sys = {version = "0.26.0", features = ["bundled-sqlcipher-vendored-openssl"], optional = true}
+rusqlite = {version = "0.29.0", features = ["sqlcipher"], optional = true}
 
 # Blockchain store
 sled = {version = "0.34.7", optional = true}
@@ -130,63 +128,84 @@ prettytable-rs = "0.10.0"
 
 # -----BEGIN LIBRARY FEATURES-----
 [features]
-p2p-transport-unix = []
-p2p-transport-tcp = []
-p2p-transport-tor = ["arti-client", "tor-hscrypto"]
-p2p-transport-nym = []
-
 async-serial = [
-    "darkfi-serial/async"
+    "darkfi-serial/async",
 ]
 
-async-runtime = [
-    "async-trait",
-    "futures",
-    "smol",
+async-sdk = [
+    "darkfi-sdk/async",
+    "darkfi-serial/async",
 ]
 
 blockchain = [
+    "blake3",
+    "sled",
+    "sled-overlay",
+
+    "darkfi-sdk",
+    "darkfi-serial",
+
+    "tx",
+    "util",
+    "zk",
+    "zkas",
+]
+
+validator = [
     "async-trait",
     "blake3",
     "crypto_api_chachapoly",
     "dashu",
-    #"halo2_proofs",
+    "halo2_proofs",
     "lazy_static",
-    #"rand",
-    "sled",
-    "sled-overlay",
+    "rand",
     "smol",
-    #"url",
+    "sled",
+    "url",
 
-    #"async-runtime",
     "darkfi-sdk/async",
-    "darkfi-serial/crypto",
+    "darkfi-serial",
+
+    "async-serial",
+    "blockchain",
     "net",
     "rpc",
+    "system",
     "tx",
-    #"util",
+    "util",
     "wallet",
     "wasm-runtime",
+    "zk",
+    "zkas",
 ]
 
 geode = [
     "blake3",
-
-    "async-runtime",
+    "futures",
+    "smol",
 ]
 
 event-graph = [
+    "async-trait",
     "blake3",
     "rand",
+    "smol",
     "tinyjson",
 
-    "async-runtime",
-    "darkfi-serial/async",
+    "darkfi-serial",
     "darkfi-serial/collections",
     "darkfi-serial/hash",
+
     "net",
+    "system",
+    "util",
 ]
 
+p2p-unix = []
+p2p-tcp = ["socket2"]
+p2p-tor = ["arti-client", "tor-hscrypto"]
+p2p-nym = []
+
 net = [
     "async-rustls",
     "async-trait",
@@ -197,32 +216,36 @@ net = [
     "rustls-pemfile",
     "semver",
     "smol",
-    "socket2",
+    "serde",
     "structopt",
     "structopt-toml",
     "url",
     "x509-parser",
 
     "darkfi-serial",
-    "darkfi-serial/async",
     "darkfi-serial/url",
+
     "async-serial",
     "system",
     "util",
 
-    "p2p-transport-tcp",
-    "p2p-transport-tor",
-    "p2p-transport-nym",
-    "p2p-transport-unix",
+    "p2p-tcp",
+    "p2p-tor",
+    #"p2p-nym",
+    "p2p-unix",
 ]
 
 rpc = [
+    "async-trait",
+    "futures",
     "rand",
+    "smol",
     "tinyjson",
     "url",
 
-    "async-runtime",
     "net",
+    "system",
+    "util",
 ]
 
 system = [
@@ -235,17 +258,15 @@ tx = [
     "blake3",
     "rand",
     
-    "darkfi-sdk/async",
+    "darkfi-sdk",
     "darkfi-serial",
+
     "zk",
 ]
 
 util = [
-    "rand",
-    "serde",
     "simplelog",
     "tinyjson",
-    "toml",
 
     "darkfi-serial",
 ]
@@ -253,9 +274,6 @@ util = [
 wallet = [
     "rusqlite",
     "smol",
-
-    "darkfi-serial",
-    "util",
 ]
 
 wasm-runtime = [
@@ -263,9 +281,10 @@ wasm-runtime = [
     "wasmer-compiler-singlepass",
     "wasmer-middlewares",
 
-    "blockchain",
-    "darkfi-sdk/async",
+    "darkfi-sdk",
     "darkfi-serial",
+
+    "blockchain",
     "util",
     "zk",
     "zkas",
@@ -276,8 +295,9 @@ zk = [
     "halo2_gadgets",
     "rand",
 
-    "darkfi-sdk/async",
-    "darkfi-serial/async",
+    "darkfi-sdk",
+    "darkfi-serial",
+
     "zkas",
 ]
 
@@ -286,21 +306,6 @@ zkas = [
 ]
 # -----END LIBRARY FEATURES-----
 
-[[example]]
-name = "net"
-path = "example/net.rs"
-required-features = ["async-runtime", "net"]
-
-[[example]]
-name = "zk"
-path = "example/zk.rs"
-required-features = ["zk"]
-
-[[example]]
-name = "zk-inclusion-proof"
-path = "example/zk-inclusion-proof.rs"
-required-features = ["zk"]
-
 [patch.crates-io]
 halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v4"}
 halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v4"}

+ 1 - 1
src/error.rs

@@ -415,7 +415,7 @@ pub enum Error {
     #[error("Contract execution failed")]
     ContractError(darkfi_sdk::error::ContractError),
 
-    #[cfg(feature = "wasm-runtime")]
+    #[cfg(feature = "blockchain")]
     #[error("contract wasm bincode not found")]
     WasmBincodeNotFound,
 

+ 3 - 1
src/event_graph/model.rs

@@ -18,8 +18,10 @@
 
 use std::{cmp::Ordering, collections::HashMap, fmt::Debug, path::Path, sync::Arc};
 
+#[cfg(feature = "async-serial")]
+use darkfi_serial::async_trait;
 use darkfi_serial::{
-    async_trait, deserialize, serialize, Decodable, Encodable, SerialDecodable, SerialEncodable,
+    deserialize, serialize, Decodable, Encodable, SerialDecodable, SerialEncodable,
 };
 use log::{error, info};
 use smol::lock::Mutex;

+ 2 - 2
src/lib.rs

@@ -24,10 +24,10 @@ pub use error::{ClientFailed, ClientResult, Error, Result};
 #[cfg(feature = "blockchain")]
 pub mod blockchain;
 
-#[cfg(feature = "blockchain")]
+#[cfg(feature = "validator")]
 pub mod consensus;
 
-#[cfg(feature = "blockchain")]
+#[cfg(feature = "validator")]
 pub mod validator;
 
 #[cfg(feature = "geode")]

+ 3 - 3
src/net/hosts.rs

@@ -158,7 +158,7 @@ impl Hosts {
 
             match addr_.scheme() {
                 // Validate that the address is an actual onion.
-                #[cfg(feature = "p2p-transport-tor")]
+                #[cfg(feature = "p2p-tor")]
                 "tor" | "tor+tls" => {
                     use std::str::FromStr;
                     if tor_hscrypto::pk::HsId::from_str(host_str).is_err() {
@@ -167,10 +167,10 @@ impl Hosts {
                     debug!(target: "net::hosts::filter_addresses()", "[Tor] Valid: {}", host_str);
                 }
 
-                #[cfg(feature = "p2p-transport-nym")]
+                #[cfg(feature = "p2p-nym")]
                 "nym" | "nym+tls" => continue, // <-- Temp skip
 
-                #[cfg(feature = "p2p-transport-tcp")]
+                #[cfg(feature = "p2p-tcp")]
                 "tcp" | "tcp+tls" => {
                     debug!(target: "net::hosts::filter_addresses()", "[TCP] Valid: {}", host_str);
                 }

+ 50 - 39
src/net/transport.rs

@@ -27,50 +27,50 @@ use crate::{Error, Result};
 /// TLS Upgrade Mechanism
 pub(crate) mod tls;
 
-#[cfg(feature = "p2p-transport-tcp")]
+#[cfg(feature = "p2p-tcp")]
 /// TCP Transport
 pub(crate) mod tcp;
 
-#[cfg(feature = "p2p-transport-tor")]
+#[cfg(feature = "p2p-tor")]
 /// Tor transport
 pub(crate) mod tor;
 
-#[cfg(feature = "p2p-transport-nym")]
+#[cfg(feature = "p2p-nym")]
 /// Nym transport
 pub(crate) mod nym;
 
-#[cfg(feature = "p2p-transport-unix")]
+#[cfg(feature = "p2p-unix")]
 /// Unix socket transport
 pub(crate) mod unix;
 
 /// Dialer variants
 #[derive(Debug, Clone)]
 pub enum DialerVariant {
-    #[cfg(feature = "p2p-transport-tcp")]
+    #[cfg(feature = "p2p-tcp")]
     /// Plain TCP
     Tcp(tcp::TcpDialer),
 
-    #[cfg(feature = "p2p-transport-tcp")]
+    #[cfg(feature = "p2p-tcp")]
     /// TCP with TLS
     TcpTls(tcp::TcpDialer),
 
-    #[cfg(feature = "p2p-transport-tor")]
+    #[cfg(feature = "p2p-tor")]
     /// Tor
     Tor(tor::TorDialer),
 
-    #[cfg(feature = "p2p-transport-tor")]
+    #[cfg(feature = "p2p-tor")]
     /// Tor with TLS
     TorTls(tor::TorDialer),
 
-    #[cfg(feature = "p2p-transport-nym")]
+    #[cfg(feature = "p2p-nym")]
     /// Nym
     Nym(nym::NymDialer),
 
-    #[cfg(feature = "p2p-transport-nym")]
+    #[cfg(feature = "p2p-nym")]
     /// Nym with TLS
     NymTls(nym::NymDialer),
 
-    #[cfg(feature = "p2p-transport-unix")]
+    #[cfg(feature = "p2p-unix")]
     /// Unix socket
     Unix(unix::UnixDialer),
 }
@@ -78,15 +78,15 @@ pub enum DialerVariant {
 /// Listener variants
 #[derive(Debug, Clone)]
 pub enum ListenerVariant {
-    #[cfg(feature = "p2p-transport-tcp")]
+    #[cfg(feature = "p2p-tcp")]
     /// Plain TCP
     Tcp(tcp::TcpListener),
 
-    #[cfg(feature = "p2p-transport-tcp")]
+    #[cfg(feature = "p2p-tcp")]
     /// TCP with TLS
     TcpTls(tcp::TcpListener),
 
-    #[cfg(feature = "p2p-transport-unix")]
+    #[cfg(feature = "p2p-unix")]
     /// Unix socket
     Unix(unix::UnixListener),
 }
@@ -123,7 +123,7 @@ impl Dialer {
     /// Instantiate a new [`Dialer`] with the given [`Url`].
     pub async fn new(endpoint: Url) -> Result<Self> {
         match endpoint.scheme().to_lowercase().as_str() {
-            #[cfg(feature = "p2p-transport-tcp")]
+            #[cfg(feature = "p2p-tcp")]
             "tcp" => {
                 // Build a TCP dialer
                 enforce_hostport!(endpoint);
@@ -132,7 +132,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
-            #[cfg(feature = "p2p-transport-tcp")]
+            #[cfg(feature = "p2p-tcp")]
             "tcp+tls" => {
                 // Build a TCP dialer wrapped with TLS
                 enforce_hostport!(endpoint);
@@ -141,7 +141,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
-            #[cfg(feature = "p2p-transport-tor")]
+            #[cfg(feature = "p2p-tor")]
             "tor" => {
                 // Build a Tor dialer
                 enforce_hostport!(endpoint);
@@ -150,7 +150,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
-            #[cfg(feature = "p2p-transport-tor")]
+            #[cfg(feature = "p2p-tor")]
             "tor+tls" => {
                 // Build a Tor dialer wrapped with TLS
                 enforce_hostport!(endpoint);
@@ -159,7 +159,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
-            #[cfg(feature = "p2p-transport-nym")]
+            #[cfg(feature = "p2p-nym")]
             "nym" => {
                 // Build a Nym dialer
                 enforce_hostport!(endpoint);
@@ -168,7 +168,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
-            #[cfg(feature = "p2p-transport-nym")]
+            #[cfg(feature = "p2p-nym")]
             "nym+tls" => {
                 // Build a Nym dialer wrapped with TLS
                 enforce_hostport!(endpoint);
@@ -177,7 +177,7 @@ impl Dialer {
                 Ok(Self { endpoint, variant })
             }
 
-            #[cfg(feature = "p2p-transport-unix")]
+            #[cfg(feature = "p2p-unix")]
             "unix" => {
                 enforce_abspath!(endpoint);
                 // Build a Unix socket dialer
@@ -193,7 +193,7 @@ impl Dialer {
     /// Dial an instantiated [`Dialer`]. This creates a connection and returns a stream.
     pub async fn dial(&self, timeout: Option<Duration>) -> Result<Box<dyn PtStream>> {
         match &self.variant {
-            #[cfg(feature = "p2p-transport-tcp")]
+            #[cfg(feature = "p2p-tcp")]
             DialerVariant::Tcp(dialer) => {
                 // NOTE: sockaddr here is an array, can contain both ipv4 and ipv6
                 let sockaddr = self.endpoint.socket_addrs(|| None)?;
@@ -201,7 +201,7 @@ impl Dialer {
                 Ok(Box::new(stream))
             }
 
-            #[cfg(feature = "p2p-transport-tcp")]
+            #[cfg(feature = "p2p-tcp")]
             DialerVariant::TcpTls(dialer) => {
                 let sockaddr = self.endpoint.socket_addrs(|| None)?;
                 let stream = dialer.do_dial(sockaddr[0], timeout).await?;
@@ -210,7 +210,7 @@ impl Dialer {
                 Ok(Box::new(stream))
             }
 
-            #[cfg(feature = "p2p-transport-tor")]
+            #[cfg(feature = "p2p-tor")]
             DialerVariant::Tor(dialer) => {
                 let host = self.endpoint.host_str().unwrap();
                 let port = self.endpoint.port().unwrap();
@@ -218,7 +218,7 @@ impl Dialer {
                 Ok(Box::new(stream))
             }
 
-            #[cfg(feature = "p2p-transport-tor")]
+            #[cfg(feature = "p2p-tor")]
             DialerVariant::TorTls(dialer) => {
                 let host = self.endpoint.host_str().unwrap();
                 let port = self.endpoint.port().unwrap();
@@ -228,22 +228,30 @@ impl Dialer {
                 Ok(Box::new(stream))
             }
 
-            #[cfg(feature = "p2p-transport-nym")]
+            #[cfg(feature = "p2p-nym")]
             DialerVariant::Nym(_dialer) => {
                 todo!();
             }
 
-            #[cfg(feature = "p2p-transport-nym")]
+            #[cfg(feature = "p2p-nym")]
             DialerVariant::NymTls(_dialer) => {
                 todo!();
             }
 
-            #[cfg(feature = "p2p-transport-unix")]
+            #[cfg(feature = "p2p-unix")]
             DialerVariant::Unix(dialer) => {
                 let path = self.endpoint.to_file_path()?;
                 let stream = dialer.do_dial(path).await?;
                 Ok(Box::new(stream))
             }
+
+            #[cfg(not(any(
+                feature = "p2p-tcp",
+                feature = "p2p-tor",
+                feature = "p2p-nym",
+                feature = "p2p-unix"
+            )))]
+            _ => panic!("No compiled p2p transports!"),
         }
     }
 
@@ -266,7 +274,7 @@ impl Listener {
     /// Must contain a scheme, host string, and a port.
     pub async fn new(endpoint: Url) -> Result<Self> {
         match endpoint.scheme().to_lowercase().as_str() {
-            #[cfg(feature = "p2p-transport-tcp")]
+            #[cfg(feature = "p2p-tcp")]
             "tcp" => {
                 // Build a TCP listener
                 enforce_hostport!(endpoint);
@@ -275,7 +283,7 @@ impl Listener {
                 Ok(Self { endpoint, variant })
             }
 
-            #[cfg(feature = "p2p-transport-tcp")]
+            #[cfg(feature = "p2p-tcp")]
             "tcp+tls" => {
                 // Build a TCP listener wrapped with TLS
                 enforce_hostport!(endpoint);
@@ -284,7 +292,7 @@ impl Listener {
                 Ok(Self { endpoint, variant })
             }
 
-            #[cfg(feature = "p2p-transport-unix")]
+            #[cfg(feature = "p2p-unix")]
             "unix" => {
                 enforce_abspath!(endpoint);
                 let variant = unix::UnixListener::new().await?;
@@ -300,14 +308,14 @@ impl Listener {
     /// This will open a socket and return the listener.
     pub async fn listen(&self) -> Result<Box<dyn PtListener>> {
         match &self.variant {
-            #[cfg(feature = "p2p-transport-tcp")]
+            #[cfg(feature = "p2p-tcp")]
             ListenerVariant::Tcp(listener) => {
                 let sockaddr = self.endpoint.socket_addrs(|| None)?;
                 let l = listener.do_listen(sockaddr[0]).await?;
                 Ok(Box::new(l))
             }
 
-            #[cfg(feature = "p2p-transport-tcp")]
+            #[cfg(feature = "p2p-tcp")]
             ListenerVariant::TcpTls(listener) => {
                 let sockaddr = self.endpoint.socket_addrs(|| None)?;
                 let l = listener.do_listen(sockaddr[0]).await?;
@@ -316,12 +324,15 @@ impl Listener {
                 Ok(Box::new(l))
             }
 
-            #[cfg(feature = "p2p-transport-unix")]
+            #[cfg(feature = "p2p-unix")]
             ListenerVariant::Unix(listener) => {
                 let path = self.endpoint.to_file_path()?;
                 let l = listener.do_listen(&path).await?;
                 Ok(Box::new(l))
             }
+
+            #[cfg(not(any(feature = "p2p-tcp", feature = "p2p-unix")))]
+            _ => panic!("No compiled p2p transports!"),
         }
     }
 
@@ -333,19 +344,19 @@ impl Listener {
 /// Wrapper trait for async streams
 pub trait PtStream: AsyncRead + AsyncWrite + Unpin + Send {}
 
-#[cfg(feature = "p2p-transport-tcp")]
+#[cfg(feature = "p2p-tcp")]
 impl PtStream for smol::net::TcpStream {}
 
-#[cfg(feature = "p2p-transport-tcp")]
+#[cfg(feature = "p2p-tcp")]
 impl PtStream for async_rustls::TlsStream<smol::net::TcpStream> {}
 
-#[cfg(feature = "p2p-transport-tor")]
+#[cfg(feature = "p2p-tor")]
 impl PtStream for arti_client::DataStream {}
 
-#[cfg(feature = "p2p-transport-tor")]
+#[cfg(feature = "p2p-tor")]
 impl PtStream for async_rustls::TlsStream<arti_client::DataStream> {}
 
-#[cfg(feature = "p2p-transport-unix")]
+#[cfg(feature = "p2p-unix")]
 impl PtStream for smol::net::unix::UnixStream {}
 
 /// Wrapper trait for async listeners

+ 1 - 1
src/net/transport/tls.rs

@@ -251,7 +251,7 @@ impl TlsUpgrade {
     }
 
     // FIXME: Try to find a transparent way for this instead of implementing separately for all
-    #[cfg(feature = "p2p-transport-tcp")]
+    #[cfg(feature = "p2p-tcp")]
     pub async fn upgrade_listener_tcp_tls(
         self,
         listener: smol::net::TcpListener,

+ 2 - 1
src/runtime/import/db.rs

@@ -30,7 +30,8 @@ use log::{debug, error, info};
 use wasmer::{FunctionEnvMut, WasmPtr};
 
 use crate::{
-    runtime::vm_runtime::{ContractSection, Env, SMART_CONTRACT_ZKAS_DB_NAME},
+    blockchain::contract_store::SMART_CONTRACT_ZKAS_DB_NAME,
+    runtime::vm_runtime::{ContractSection, Env},
     zk::{empty_witnesses, VerifyingKey, ZkCircuit},
     zkas::ZkBinary,
 };

+ 5 - 4
src/runtime/vm_runtime.rs

@@ -35,7 +35,11 @@ use wasmer_middlewares::{
 };
 
 use super::{import, import::db::DbHandle, memory::MemoryManipulation};
-use crate::{blockchain::BlockchainOverlayPtr, util::time::TimeKeeper, Error, Result};
+use crate::{
+    blockchain::{contract_store::SMART_CONTRACT_ZKAS_DB_NAME, BlockchainOverlayPtr},
+    util::time::TimeKeeper,
+    Error, Result,
+};
 
 /// Name of the wasm linear memory in our guest module
 const MEMORY: &str = "memory";
@@ -43,9 +47,6 @@ const MEMORY: &str = "memory";
 /// Gas limit for a contract
 const GAS_LIMIT: u64 = 400_000_000;
 
-/// The hardcoded db name for the zkas circuits database tree
-pub const SMART_CONTRACT_ZKAS_DB_NAME: &str = "_zkas";
-
 #[derive(Clone, Copy, PartialEq)]
 pub enum ContractSection {
     /// Setup function of a contract

+ 16 - 16
src/tx/mod.rs

@@ -26,7 +26,11 @@ use darkfi_sdk::{
     pasta::pallas,
     tx::ContractCall,
 };
-use darkfi_serial::{async_trait, serialize, Encodable, SerialDecodable, SerialEncodable};
+
+#[cfg(feature = "async-serial")]
+use darkfi_serial::async_trait;
+
+use darkfi_serial::{Encodable, SerialDecodable, SerialEncodable};
 use log::{debug, error};
 use rand::{CryptoRng, RngCore};
 
@@ -103,10 +107,12 @@ impl Transaction {
 
     /// Verify Schnorr signatures for the entire transaction.
     pub fn verify_sigs(&self, pub_table: Vec<Vec<PublicKey>>) -> Result<()> {
-        let tx_data = self.encode_without_sigs()?;
+        // Hash the transaction without the signatures
         let mut hasher = blake3::Hasher::new();
-        hasher.update_rayon(&tx_data);
+        self.calls.encode(&mut hasher)?;
+        self.proofs.encode(&mut hasher)?;
         let data_hash = hasher.finalize();
+
         debug!("tx.verify_sigs: data_hash: {:?}", data_hash.as_bytes());
 
         assert!(pub_table.len() == self.signatures.len());
@@ -131,10 +137,12 @@ impl Transaction {
         rng: &mut (impl CryptoRng + RngCore),
         secret_keys: &[SecretKey],
     ) -> Result<Vec<Signature>> {
-        let tx_data = self.encode_without_sigs()?;
+        // Hash the transaction without the signatures
         let mut hasher = blake3::Hasher::new();
-        hasher.update_rayon(&tx_data);
+        self.calls.encode(&mut hasher)?;
+        self.proofs.encode(&mut hasher)?;
         let data_hash = hasher.finalize();
+
         debug!("tx.create_sigs: data_hash: {:?}", data_hash.as_bytes());
 
         let mut sigs = vec![];
@@ -147,18 +155,10 @@ impl Transaction {
         Ok(sigs)
     }
 
-    /// Encode the object into a byte vector for signing
-    pub fn encode_without_sigs(&self) -> Result<Vec<u8>> {
-        let mut buf = vec![];
-        self.calls.encode(&mut buf)?;
-        self.proofs.encode(&mut buf)?;
-        Ok(buf)
-    }
-
     /// Get the transaction hash
-    pub fn hash(&self) -> blake3::Hash {
+    pub fn hash(&self) -> Result<blake3::Hash> {
         let mut hasher = blake3::Hasher::new();
-        hasher.update_rayon(&serialize(self));
-        hasher.finalize()
+        self.encode(&mut hasher)?;
+        Ok(hasher.finalize())
     }
 }

+ 4 - 4
src/util/cli.rs

@@ -19,18 +19,17 @@
 use std::{
     env, fs,
     io::Write,
-    marker::PhantomData,
-    path::{Path, PathBuf},
+    path::Path,
     str,
     sync::{Arc, Mutex},
     time::Instant,
 };
 
-use serde::{de::DeserializeOwned, Serialize};
 use simplelog::ConfigBuilder;
 
-use crate::{Error, Result};
+use crate::Result;
 
+/*
 #[derive(Clone, Default)]
 pub struct Config<T> {
     config: PhantomData<T>,
@@ -55,6 +54,7 @@ impl<T: Serialize + DeserializeOwned> Config<T> {
         }
     }
 }
+*/
 
 pub fn spawn_config(path: &Path, contents: &[u8]) -> Result<()> {
     if !path.exists() {

+ 1 - 0
src/util/mod.rs

@@ -39,4 +39,5 @@ pub mod ringbuffer;
 
 /// Permuted Congruential Generator (PCG)
 /// This is an insecure PRNG used for simulations and tests.
+#[cfg(feature = "rand")]
 pub mod pcg;

+ 1 - 1
src/validator/consensus/mod.rs

@@ -163,7 +163,7 @@ impl Consensus {
 
         // TODO: sign more stuff?
         // Sign block header using provided secret key
-        let signature = secret_key.sign(&mut OsRng, &header.headerhash().as_bytes()[..]);
+        let signature = secret_key.sign(&mut OsRng, &header.headerhash()?.as_bytes()[..]);
 
         // Generate block producer info
         let block_producer = BlockProducer::new(signature, proposal_tx, slot.last_eta);

+ 2 - 2
src/validator/verification.rs

@@ -158,7 +158,7 @@ pub async fn verify_proposal_transaction(
     time_keeper: &TimeKeeper,
     tx: &Transaction,
 ) -> Result<()> {
-    let tx_hash = tx.hash();
+    let tx_hash = tx.hash()?;
     debug!(target: "validator::verification::verify_proposal_transaction", "Validating proposal transaction {}", tx_hash);
 
     // Transaction must contain a single Consensus::Proposal (0x02) call
@@ -192,7 +192,7 @@ pub async fn verify_transaction(
     tx: &Transaction,
     verifying_keys: &mut HashMap<[u8; 32], HashMap<String, VerifyingKey>>,
 ) -> Result<()> {
-    let tx_hash = tx.hash();
+    let tx_hash = tx.hash()?;
     debug!(target: "validator::verification::verify_transaction", "Validating transaction {}", tx_hash);
 
     // Table of public inputs used for ZK proof verification

+ 4 - 1
src/zk/proof.rs

@@ -17,8 +17,11 @@
  */
 use std::{io, io::Cursor};
 
+#[cfg(feature = "async-serial")]
+use darkfi_serial::async_trait;
+
 use darkfi_sdk::pasta::{pallas, vesta};
-use darkfi_serial::{async_trait, SerialDecodable, SerialEncodable};
+use darkfi_serial::{SerialDecodable, SerialEncodable};
 use halo2_proofs::{
     helpers::SerdeFormat,
     plonk,