Parcourir la source

blockchain: use sled-overlay record parsing functions

skoupidi il y a 1 an
Parent
commit
7739d8a40e

+ 2 - 2
Cargo.lock

@@ -6492,9 +6492,9 @@ dependencies = [
 
 
 [[package]]
 [[package]]
 name = "sled-overlay"
 name = "sled-overlay"
-version = "0.1.5"
+version = "0.1.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ad42f44feda8a0f1697d6608bd34999ec40a3894915ca826bb3df66ac9247e75"
+checksum = "4c33dea88a6fcef15045db58735976a75488268751fa4574ca6d95a3f612a0da"
 dependencies = [
 dependencies = [
  "darkfi-serial",
  "darkfi-serial",
  "sled",
  "sled",

+ 1 - 1
Cargo.toml

@@ -122,7 +122,7 @@ wasmer-compiler-singlepass = {version = "4.4.0", optional = true}
 wasmer-middlewares = {version = "4.4.0", optional = true}
 wasmer-middlewares = {version = "4.4.0", optional = true}
 
 
 # Blockchain store
 # Blockchain store
-sled-overlay = {version = "0.1.5", optional = true}
+sled-overlay = {version = "0.1.6", optional = true}
 
 
 # Miner
 # Miner
 randomx = {git = "https://github.com/darkrenaissance/RandomX", optional = true}
 randomx = {git = "https://github.com/darkrenaissance/RandomX", optional = true}

+ 1 - 1
bin/darkfid/Cargo.toml

@@ -22,7 +22,7 @@ bs58 = "0.5.1"
 log = "0.4.22"
 log = "0.4.22"
 num-bigint = "0.4.6"
 num-bigint = "0.4.6"
 rand = "0.8.5"
 rand = "0.8.5"
-sled-overlay = "0.1.5"
+sled-overlay = "0.1.6"
 toml = "0.8.19"
 toml = "0.8.19"
 
 
 # JSON-RPC
 # JSON-RPC

+ 1 - 1
bin/darkirc/Cargo.toml

@@ -24,7 +24,7 @@ darkfi-serial = {version = "0.4.2", features = ["async"]}
 libc = "0.2.159"
 libc = "0.2.159"
 
 
 # Event Graph DB
 # Event Graph DB
-sled-overlay = "0.1.5"
+sled-overlay = "0.1.6"
 
 
 # TLS
 # TLS
 async-trait = "0.1.83"
 async-trait = "0.1.83"

+ 1 - 1
bin/darkwallet/Cargo.toml

@@ -42,7 +42,7 @@ futures = "0.3.31"
 async-recursion = "1.1.1"
 async-recursion = "1.1.1"
 colored = "2.1.0"
 colored = "2.1.0"
 #rustpython-vm = "0.3.1"
 #rustpython-vm = "0.3.1"
-sled-overlay = "0.1.5"
+sled-overlay = "0.1.6"
 url = "2.5.2"
 url = "2.5.2"
 semver = "1.0.23"
 semver = "1.0.23"
 chrono = "0.4.38"
 chrono = "0.4.38"

+ 1 - 1
bin/genev/genevd/Cargo.toml

@@ -28,7 +28,7 @@ darkfi-serial = "0.4.2"
 blake3 = "1.5.4"
 blake3 = "1.5.4"
 
 
 # Event Graph DB
 # Event Graph DB
-sled-overlay = "0.1.5"
+sled-overlay = "0.1.6"
 
 
 # Misc
 # Misc
 async-trait = "0.1.83"
 async-trait = "0.1.83"

+ 1 - 1
bin/tau/taud/Cargo.toml

@@ -27,7 +27,7 @@ darkfi = { path = "../../../", features = [
 darkfi-serial = "0.4.2"
 darkfi-serial = "0.4.2"
 
 
 # Event Graph DB
 # Event Graph DB
-sled-overlay = "0.1.5"
+sled-overlay = "0.1.6"
 
 
 # Crypto
 # Crypto
 blake3 = "1.5.4"
 blake3 = "1.5.4"

+ 1 - 1
script/evgrd/Cargo.toml

@@ -26,7 +26,7 @@ darkfi = {path = "../../", features = ["event-graph"]}
 darkfi-serial = {version = "0.4.2", features = ["async"]}
 darkfi-serial = {version = "0.4.2", features = ["async"]}
 
 
 # Event Graph DB
 # Event Graph DB
-sled-overlay = "0.1.5"
+sled-overlay = "0.1.6"
 
 
 # Crypto
 # Crypto
 blake3 = "1.5.4"
 blake3 = "1.5.4"

+ 1 - 1
script/research/blockchain-explorer/Cargo.toml

@@ -18,7 +18,7 @@ drk = {path = "../../../bin/drk"}
 
 
 # Misc
 # Misc
 log = "0.4.22"
 log = "0.4.22"
-sled-overlay = "0.1.5"
+sled-overlay = "0.1.6"
 
 
 # JSON-RPC
 # JSON-RPC
 async-trait = "0.1.83"
 async-trait = "0.1.83"

+ 2 - 2
script/research/gg/Cargo.toml

@@ -18,13 +18,13 @@ darkfi = {path = "../../../", features = ["bs58", "validator"]}
 darkfi_money_contract = {path = "../../../src/contract/money", features = ["no-entrypoint", "client"]}
 darkfi_money_contract = {path = "../../../src/contract/money", features = ["no-entrypoint", "client"]}
 darkfi-contract-test-harness = {path = "../../../src/contract/test-harness"}
 darkfi-contract-test-harness = {path = "../../../src/contract/test-harness"}
 darkfi-sdk = {path = "../../../src/sdk"}
 darkfi-sdk = {path = "../../../src/sdk"}
-darkfi-serial = {path = "../../../src/serial"}
+darkfi-serial = "0.4.2"
 
 
 # Misc
 # Misc
 async-std = {version = "1.13.0", features = ["attributes"]}
 async-std = {version = "1.13.0", features = ["attributes"]}
 bs58 = "0.5.1"
 bs58 = "0.5.1"
 clap = {version = "4.4.11", features = ["derive"]}
 clap = {version = "4.4.11", features = ["derive"]}
-sled-overlay = "0.1.5"
+sled-overlay = "0.1.6"
 
 
 [patch.crates-io]
 [patch.crates-io]
 halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v4"}
 halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v4"}

+ 5 - 2
src/blockchain/block_store.rs

@@ -28,11 +28,14 @@ use darkfi_sdk::{
 use darkfi_serial::async_trait;
 use darkfi_serial::async_trait;
 use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
 use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
 use num_bigint::BigUint;
 use num_bigint::BigUint;
-use sled_overlay::{sled, SledDbOverlayStateDiff};
+use sled_overlay::{
+    serial::{parse_record, parse_u32_key_record},
+    sled, SledDbOverlayStateDiff,
+};
 
 
 use crate::{tx::Transaction, util::time::Timestamp, Error, Result};
 use crate::{tx::Transaction, util::time::Timestamp, Error, Result};
 
 
-use super::{parse_record, parse_u32_key_record, Header, HeaderHash, SledDbOverlayPtr};
+use super::{Header, HeaderHash, SledDbOverlayPtr};
 
 
 /// This struct represents a tuple of the form (`header`, `txs`, `signature`).
 /// This struct represents a tuple of the form (`header`, `txs`, `signature`).
 ///
 ///

+ 2 - 2
src/blockchain/contract_store.rs

@@ -21,7 +21,7 @@ use std::io::Cursor;
 use darkfi_sdk::crypto::ContractId;
 use darkfi_sdk::crypto::ContractId;
 use darkfi_serial::{deserialize, serialize};
 use darkfi_serial::{deserialize, serialize};
 use log::{debug, error};
 use log::{debug, error};
-use sled_overlay::sled;
+use sled_overlay::{serial::parse_record, sled};
 
 
 use crate::{
 use crate::{
     zk::{empty_witnesses, VerifyingKey, ZkCircuit},
     zk::{empty_witnesses, VerifyingKey, ZkCircuit},
@@ -29,7 +29,7 @@ use crate::{
     Error, Result,
     Error, Result,
 };
 };
 
 
-use super::{parse_record, SledDbOverlayPtr};
+use super::SledDbOverlayPtr;
 
 
 pub const SLED_CONTRACTS_TREE: &[u8] = b"_contracts";
 pub const SLED_CONTRACTS_TREE: &[u8] = b"_contracts";
 pub const SLED_BINCODE_TREE: &[u8] = b"_wasm_bincode";
 pub const SLED_BINCODE_TREE: &[u8] = b"_wasm_bincode";

+ 5 - 2
src/blockchain/header_store.rs

@@ -27,11 +27,14 @@ use darkfi_sdk::{
 #[cfg(feature = "async-serial")]
 #[cfg(feature = "async-serial")]
 use darkfi_serial::async_trait;
 use darkfi_serial::async_trait;
 use darkfi_serial::{deserialize, serialize, Encodable, SerialDecodable, SerialEncodable};
 use darkfi_serial::{deserialize, serialize, Encodable, SerialDecodable, SerialEncodable};
-use sled_overlay::sled;
+use sled_overlay::{
+    serial::{parse_record, parse_u32_key_record},
+    sled,
+};
 
 
 use crate::{util::time::Timestamp, Error, Result};
 use crate::{util::time::Timestamp, Error, Result};
 
 
-use super::{parse_record, parse_u32_key_record, SledDbOverlayPtr};
+use super::SledDbOverlayPtr;
 
 
 #[derive(Copy, Clone, Debug, Eq, PartialEq, SerialEncodable, SerialDecodable)]
 #[derive(Copy, Clone, Debug, Eq, PartialEq, SerialEncodable, SerialDecodable)]
 // We have to introduce a type rather than using an alias so we can restrict API access
 // We have to introduce a type rather than using an alias so we can restrict API access

+ 0 - 29
src/blockchain/mod.rs

@@ -19,7 +19,6 @@
 use std::sync::{Arc, Mutex};
 use std::sync::{Arc, Mutex};
 
 
 use darkfi_sdk::tx::TransactionHash;
 use darkfi_sdk::tx::TransactionHash;
-use darkfi_serial::{deserialize, Decodable};
 use log::debug;
 use log::debug;
 use sled_overlay::{sled, sled::Transactional};
 use sled_overlay::{sled, sled::Transactional};
 
 
@@ -585,31 +584,3 @@ impl BlockchainOverlay {
         Ok(Arc::new(Mutex::new(Self { overlay, headers, blocks, transactions, contracts })))
         Ok(Arc::new(Mutex::new(Self { overlay, headers, blocks, transactions, contracts })))
     }
     }
 }
 }
-
-/// Parse a sled record with a u32 key in the form of a tuple (`key`, `value`).
-pub fn parse_u32_key_record<T: Decodable>(record: (sled::IVec, sled::IVec)) -> Result<(u32, T)> {
-    let key_bytes: [u8; 4] = record.0.as_ref().try_into().unwrap();
-    let key = u32::from_be_bytes(key_bytes);
-    let value = deserialize(&record.1)?;
-
-    Ok((key, value))
-}
-
-/// Parse a sled record with a u64 key in the form of a tuple (`key`, `value`).
-pub fn parse_u64_key_record<T: Decodable>(record: (sled::IVec, sled::IVec)) -> Result<(u64, T)> {
-    let key_bytes: [u8; 8] = record.0.as_ref().try_into().unwrap();
-    let key = u64::from_be_bytes(key_bytes);
-    let value = deserialize(&record.1)?;
-
-    Ok((key, value))
-}
-
-/// Parse a sled record in the form of a tuple (`key`, `value`).
-pub fn parse_record<T1: Decodable, T2: Decodable>(
-    record: (sled::IVec, sled::IVec),
-) -> Result<(T1, T2)> {
-    let key = deserialize(&record.0)?;
-    let value = deserialize(&record.1)?;
-
-    Ok((key, value))
-}

+ 5 - 2
src/blockchain/tx_store.rs

@@ -20,11 +20,14 @@ use std::collections::HashMap;
 
 
 use darkfi_sdk::tx::TransactionHash;
 use darkfi_sdk::tx::TransactionHash;
 use darkfi_serial::{deserialize, serialize};
 use darkfi_serial::{deserialize, serialize};
-use sled_overlay::sled;
+use sled_overlay::{
+    serial::{parse_record, parse_u64_key_record},
+    sled,
+};
 
 
 use crate::{tx::Transaction, Error, Result};
 use crate::{tx::Transaction, Error, Result};
 
 
-use super::{parse_record, parse_u64_key_record, SledDbOverlayPtr};
+use super::SledDbOverlayPtr;
 
 
 pub const SLED_TX_TREE: &[u8] = b"_transactions";
 pub const SLED_TX_TREE: &[u8] = b"_transactions";
 pub const SLED_TX_LOCATION_TREE: &[u8] = b"_transaction_location";
 pub const SLED_TX_LOCATION_TREE: &[u8] = b"_transaction_location";

+ 1 - 1
src/contract/test-harness/Cargo.toml

@@ -19,7 +19,7 @@ blake3 = "1.5.4"
 log = "0.4.22"
 log = "0.4.22"
 rand = "0.8.5"
 rand = "0.8.5"
 simplelog = "0.12.2"
 simplelog = "0.12.2"
-sled-overlay = "0.1.5"
+sled-overlay = "0.1.6"
 
 
 [lints]
 [lints]
 workspace = true
 workspace = true