Pārlūkot izejas kodu

serial: Bring it back home

x 7 mēneši atpakaļ
vecāks
revīzija
ed9be657ab
47 mainītis faili ar 430 papildinājumiem un 170 dzēšanām
  1. 4 25
      Cargo.lock
  2. 11 32
      Cargo.toml
  3. 2 2
      bin/app/Cargo.toml
  4. 2 2
      bin/darkfid/Cargo.toml
  5. 2 2
      bin/darkirc/Cargo.toml
  6. 2 2
      bin/drk/Cargo.toml
  7. 2 2
      bin/explorer/explorerd/Cargo.toml
  8. 2 2
      bin/fud/fud/Cargo.toml
  9. 1 1
      bin/genev/genev-cli/Cargo.toml
  10. 2 2
      bin/genev/genevd/Cargo.toml
  11. 2 2
      bin/tau/taud/Cargo.toml
  12. 1 1
      example/dchat/dchatd/Cargo.toml
  13. 1 1
      example/wasm-hello-world/Cargo.toml
  14. 1 1
      example/wasm-hello-world/client/Cargo.toml
  15. 2 2
      script/evgrd/Cargo.toml
  16. 1 1
      script/ping/Cargo.toml
  17. 0 1
      script/research/.gitignore
  18. 1 1
      script/research/blockchain-storage-metrics/Cargo.toml
  19. 1 1
      script/research/dam/dam-cli/Cargo.toml
  20. 1 1
      script/research/dam/damd/Cargo.toml
  21. 1 1
      script/research/generic-node/Cargo.toml
  22. 1 1
      script/research/gg/Cargo.toml
  23. 1 1
      script/research/rlnd/rlnd-cli/Cargo.toml
  24. 2 2
      script/research/rlnd/rlnd/Cargo.toml
  25. 3 3
      script/research/zkvm-metering/generator/Cargo.toml
  26. 3 3
      script/research/zkvm-metering/verifier/Cargo.toml
  27. 2 5
      src/blockchain/block_store.rs
  28. 2 2
      src/blockchain/contract_store.rs
  29. 2 5
      src/blockchain/header_store.rs
  30. 73 1
      src/blockchain/mod.rs
  31. 2 5
      src/blockchain/tx_store.rs
  32. 1 1
      src/contract/dao/Cargo.toml
  33. 1 1
      src/contract/deployooor/Cargo.toml
  34. 1 1
      src/contract/money/Cargo.toml
  35. 2 2
      src/contract/test-harness/Cargo.toml
  36. 2 2
      src/sdk/Cargo.toml
  37. 1 1
      src/sdk/python/Cargo.toml
  38. 2 9
      src/serial/Cargo.toml
  39. 1 1
      src/serial/derive/Cargo.toml
  40. 6 6
      src/serial/src/async_lib.rs
  41. 7 7
      src/serial/src/lib.rs
  42. 3 0
      src/serial/src/types.rs
  43. 5 5
      src/serial/src/types/bridgetree.rs
  44. 9 9
      src/serial/src/types/pasta.rs
  45. 5 9
      src/serial/src/types/semver.rs
  46. 248 0
      src/serial/src/types/sled_overlay.rs
  47. 3 3
      src/serial/src/types/url.rs

+ 4 - 25
Cargo.lock

@@ -483,17 +483,6 @@ dependencies = [
  "rustix",
 ]
 
-[[package]]
-name = "async-recursion"
-version = "1.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.111",
-]
-
 [[package]]
 name = "async-signal"
 version = "0.2.13"
@@ -1800,15 +1789,12 @@ name = "darkfi"
 version = "0.5.0"
 dependencies = [
  "arti-client",
- "async-recursion",
  "async-trait",
  "blake3",
  "bs58",
- "chrono",
  "clap 4.5.53",
  "criterion 0.8.1",
  "crypto_api_chachapoly",
- "darkfi-derive",
  "darkfi-sdk",
  "darkfi-serial",
  "easy-parallel",
@@ -1831,7 +1817,6 @@ dependencies = [
  "rand 0.8.5",
  "randomx",
  "rcgen",
- "regex",
  "semver",
  "serde",
  "sha2",
@@ -1881,8 +1866,6 @@ dependencies = [
 [[package]]
 name = "darkfi-derive"
 version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b8ae0dcfc7efc650d952d13559a549c93108a912a32e9242c1fe9527bb865429"
 dependencies = [
  "darkfi-derive-internal",
  "proc-macro-crate",
@@ -1894,8 +1877,6 @@ dependencies = [
 [[package]]
 name = "darkfi-derive-internal"
 version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "024e68bb1f1a0363368ed824bd9dd8a67176d00b47ea5aafe1185a1fe4986110"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -1948,8 +1929,6 @@ dependencies = [
 [[package]]
 name = "darkfi-serial"
 version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf58eb094bebe226ea473d6d35d8af074a97f7a7eeb9e485b124638448a0ad05"
 dependencies = [
  "async-trait",
  "blake3",
@@ -1959,6 +1938,7 @@ dependencies = [
  "num-bigint",
  "pasta_curves",
  "semver",
+ "sled-overlay",
  "url",
 ]
 
@@ -5691,7 +5671,7 @@ dependencies = [
 [[package]]
 name = "randomx"
 version = "1.2.1"
-source = "git+https://codeberg.org/darkrenaissance/RandomX#0e31d5a23983164a171276dea7bea94dc58ca8ed"
+source = "git+https://codeberg.org/darkrenaissance/RandomX?rev=0e31d5a#0e31d5a23983164a171276dea7bea94dc58ca8ed"
 dependencies = [
  "bindgen 0.72.1",
  "bitflags 2.10.0",
@@ -6555,11 +6535,10 @@ dependencies = [
 
 [[package]]
 name = "sled-overlay"
-version = "0.1.14"
+version = "0.1.15"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cd5d8153cababba322b8d9a3815c25b9f1e5cd78e72c81e8004a1ad78a69122c"
+checksum = "f84cfae62f52cad8adbf36565bd86225f8e432b2cb1be2db7cb21567b2063e01"
 dependencies = [
- "darkfi-serial",
  "sled",
 ]
 

+ 11 - 32
Cargo.toml

@@ -13,11 +13,6 @@ name = "darkfi"
 doctest = false
 bench = false
 
-#[profile.release]
-#debug = true
-#lto = "fat"
-#codegen-units = 1
-
 [workspace]
 members = [
     "bin/zkas",
@@ -29,7 +24,6 @@ members = [
     "bin/genev/genevd",
     "bin/genev/genev-cli",
     "bin/darkirc",
-    #"bin/darkwallet",
     "bin/tau/taud",
     "bin/vanityaddr",
     "bin/lilith",
@@ -37,9 +31,9 @@ members = [
     "src/sdk",
     "src/sdk/python",
 
-    #"src/serial",
-    #"src/serial/derive",
-    #"src/serial/derive-internal",
+    "src/serial",
+    "src/serial/derive",
+    "src/serial/derive-internal",
 
     "src/contract/test-harness",
     "src/contract/money",
@@ -56,7 +50,6 @@ thiserror = "2.0.17"
 tracing = "0.1.44"
 
 # async-runtime
-async-recursion = {version = "1.1.1", optional = true}
 async-trait = {version = "0.1.89", optional = true}
 futures = {version = "0.3.31", optional = true}
 smol = {version = "2.0.2", optional = true}
@@ -93,24 +86,17 @@ structopt-toml = {version= "0.5.1", optional = true}
 toml = {version = "0.9.8", optional = true}
 
 # Utilities
-#darkfi-serial = {path = "src/serial", optional = true}
-#darkfi-derive = {path = "src/serial/derive", optional = true}
-darkfi-serial = {version = "0.5.1", optional = true}
-darkfi-derive = {version = "0.5.1", optional = true}
+darkfi-serial = {path = "src/serial", optional = true}
 
-# TODO: check chrono usage and impl our own
-chrono = {version = "0.4.42", optional = true}
 lazy_static = {version = "1.5.0", optional = true}
 num-bigint = {version = "0.4.6", optional = true}
 url = {version = "2.5.7", features = ["serde"], optional = true}
 
 # Misc
-regex = {version = "1.12.2", optional = true}
 tracing-subscriber = { version = "0.3.22", default-features = false, features = ["fmt"], optional = true }
 tracing-appender = {version = "0.2.4", optional = true }
 nu-ansi-term = {version = "0.50.3", optional = true}
 
-
 # Crypto
 rand = {version = "0.8.5", optional = true}
 blake3 = {version = "1.8.2", features = ["rayon"], optional = true}
@@ -126,10 +112,10 @@ wasmer-compiler-singlepass = {version = "6.1.0", optional = true}
 wasmer-middlewares = {version = "6.1.0", optional = true}
 
 # Blockchain store
-sled-overlay = {version = "0.1.14", optional = true}
+sled-overlay = {version = "0.1.15", optional = true}
 
 # Miner
-randomx = {git = "https://codeberg.org/darkrenaissance/RandomX", optional = true}
+randomx = {git = "https://codeberg.org/darkrenaissance/RandomX", rev = "0e31d5a", optional = true}
 monero = {version = "0.21.0", optional = true}
 tiny-keccak = { version = "2.0.2", features = ["keccak"], optional = true }
 
@@ -141,7 +127,7 @@ plotters = "0.3.7"
 easy-parallel = "3.3.1"
 prettytable-rs = "0.10.0"
 # Used for benchmarks
-criterion = { version = "0.8.1", features = ["html_reports"] }
+criterion = {version = "0.8.1", features = ["html_reports"]}
 
 # -----BEGIN LIBRARY FEATURES-----
 [features]
@@ -156,7 +142,7 @@ async-sdk = [
 ]
 
 blockchain = [
-    "sled-overlay/serial",
+    "sled-overlay",
     "monero",
     "num-bigint",
     "primitive-types",
@@ -164,6 +150,7 @@ blockchain = [
     "tiny-keccak",
 
     "darkfi-serial/num-bigint",
+    "darkfi-serial/sled-overlay",
 
     "tx",
     "util",
@@ -222,7 +209,6 @@ net-defaults = [
     "futures",
     "futures-rustls",
     "rcgen",
-    "regex",
     "semver",
     "serde",
     "socket2",
@@ -240,6 +226,8 @@ net-defaults = [
     "p2p-tor",
     #"p2p-nym",
     "p2p-i2p",
+    "p2p-socks5",
+    "p2p-unix",
 ]
 
 p2p-unix = []
@@ -268,7 +256,6 @@ system = [
 
 tx = [
     "blake3",
-    "rand",
 
     "async-sdk",
     "async-serial",
@@ -322,14 +309,6 @@ dht = [
     "darkfi-serial",
     "net",
 ]
-
-# Could not get this to work. Complains manifest-key is ignored.
-#[target.'cfg(target_family = "unix")'.features]
-#net = ["net-defaults", "p2p-unix"]
-#
-#[target.'cfg(target_family = "windows")'.features]
-#net = ["net-defaults"]
-
 # -----END LIBRARY FEATURES-----
 
 [patch.crates-io]

+ 2 - 2
bin/app/Cargo.toml

@@ -28,7 +28,7 @@ glam = "0.30.9"
 zeromq = { version = "0.4.1", default-features = false, features = ["async-std-runtime", "all-transport"] }
 darkfi = {path = "../../", features = ["async-daemonize", "event-graph", "net", "util", "system", "zk"]}
 #darkfi-sdk = {path = "../../src/sdk", features = ["async"]}
-darkfi-serial = {version = "0.5.0", features = ["async"]}
+darkfi-serial = {path = "../../src/serial", features = ["async"]}
 fud = { path = "../fud/fud/" }
 bs58 = "0.5.1"
 thiserror = "2.0.17"
@@ -43,7 +43,7 @@ futures = "0.3.31"
 async-recursion = "1.1.1"
 colored = "3.0.0"
 #rustpython-vm = "0.3.1"
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 url = "2.5.7"
 semver = "1.0.27"
 chrono = "0.4.42"

+ 2 - 2
bin/darkfid/Cargo.toml

@@ -14,7 +14,7 @@ darkfi = {path = "../../", features = ["async-daemonize", "bs58"]}
 darkfi_money_contract = {path = "../../src/contract/money"}
 darkfi-contract-test-harness = {path = "../../src/contract/test-harness"}
 darkfi-sdk = {path = "../../src/sdk"}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../src/serial"}
 
 # Misc
 blake3 = "1.8.2"
@@ -22,7 +22,7 @@ bs58 = "0.5.1"
 tracing = "0.1.44"
 num-bigint = "0.4.6"
 rand = "0.8.5"
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 toml = "0.9.8"
 
 # JSON-RPC

+ 2 - 2
bin/darkirc/Cargo.toml

@@ -20,11 +20,11 @@ path = "src/main.rs"
 [dependencies]
 darkfi = {path = "../../", features = ["async-daemonize", "event-graph", "rpc", "zk"]}
 darkfi-sdk = {path = "../../src/sdk", features = ["async"]}
-darkfi-serial = {version = "0.5.0", features = ["async"]}
+darkfi-serial = {path = "../../src/serial", features = ["async"]}
 libc = "0.2.178"
 
 # Event Graph DB
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 
 # TLS
 async-trait = "0.1.89"

+ 2 - 2
bin/drk/Cargo.toml

@@ -15,7 +15,7 @@ darkfi_money_contract = {path = "../../src/contract/money", features = ["no-entr
 darkfi_dao_contract = {path = "../../src/contract/dao", features = ["no-entrypoint", "client"]}
 darkfi_deployooor_contract = {path = "../../src/contract/deployooor", features = ["no-entrypoint", "client"]}
 darkfi-sdk = {path = "../../src/sdk", features = ["async"]}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../src/serial"}
 
 # Misc
 blake3 = "1.8.2"
@@ -29,7 +29,7 @@ prettytable-rs = "0.10.0"
 rand = "0.8.5"
 rodio = {version = "0.21.1", default-features = false, features = ["playback", "mp3"]}
 rusqlite = {version = "0.37.0", features = ["sqlcipher"]}
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 toml = "0.9.8"
 tracing = "0.1.44"
 url = "2.5.7"

+ 2 - 2
bin/explorer/explorerd/Cargo.toml

@@ -11,7 +11,7 @@ edition = "2021"
 # Darkfi
 darkfi = {path = "../../../", features = ["async-daemonize", "validator", "rpc"]}
 darkfi-sdk = {path = "../../../src/sdk"}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../src/serial"}
 
 # JSON-RPC
 async-trait = "0.1.89"
@@ -32,7 +32,7 @@ structopt = "0.3.26"
 structopt-toml = "0.5.1"
 
 # Database
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 
 # Misc
 blake3 = "1.8.2"

+ 2 - 2
bin/fud/fud/Cargo.toml

@@ -19,7 +19,7 @@ path = "src/main.rs"
 [dependencies]
 darkfi = {path = "../../../", features = ["async-daemonize", "geode", "rpc", "dht", "sled-overlay"]}
 darkfi-sdk = {path = "../../../src/sdk"}
-darkfi-serial = {version = "0.5.0", features = ["hash"]}
+darkfi-serial = {path = "../../../src/serial", features = ["hash"]}
 
 # Encoding
 bs58 = "0.5.1"
@@ -48,7 +48,7 @@ blake2 = "0.10.6"
 equix = "0.5.1"
 
 # Database
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 
 # Argument parsing
 serde = {version = "1.0.228", features = ["derive"]}

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

@@ -12,7 +12,7 @@ repository = "https://codeberg.org/darkrenaissance/darkfi"
 genevd = {path = "../genevd"}
 
 darkfi = {path = "../../../", features = ["event-graph", "rpc", "bs58"]}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../src/serial"}
 
 smol = "2.0.2"
 clap = {version = "4.4.11", features = ["derive"]}

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

@@ -22,13 +22,13 @@ darkfi = { path = "../../../", features = [
     "event-graph",
     "rpc",
 ] }
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../src/serial"}
 
 # Crypto
 blake3 = "1.8.2"
 
 # Event Graph DB
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 
 # Misc
 async-trait = "0.1.89"

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

@@ -25,10 +25,10 @@ darkfi = { path = "../../../", features = [
 ] }
 
 darkfi-sdk = {path = "../../../src/sdk", features = ["async"]}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../src/serial"}
 
 # Event Graph DB
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 
 # Crypto
 blake3 = "1.8.2"

+ 1 - 1
example/dchat/dchatd/Cargo.toml

@@ -12,7 +12,7 @@ edition = "2021"
 [dependencies]
 # ANCHOR: darkfi
 darkfi = {path = "../../../", features = ["toml", "async-daemonize", "rpc"]}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../src/serial"}
 # ANCHOR_END: darkfi
 
 # daemon

+ 1 - 1
example/wasm-hello-world/Cargo.toml

@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
 
 [dependencies]
 darkfi-sdk = { path = "../../src/sdk", features = ["wasm"] }
-darkfi-serial = { version = "0.5.0", features = ["derive", "crypto"] }
+darkfi-serial = { path = "../../src/serial", features = ["derive", "crypto"] }
 
 # We need to disable random using "custom" which makes the crate a noop
 # so the wasm32-unknown-unknown target is enabled.

+ 1 - 1
example/wasm-hello-world/client/Cargo.toml

@@ -16,7 +16,7 @@ wasm_hello_world = {path = "../", features = [ "client" ]}
 # Darkfi
 darkfi = {path = "../../../", features = ["tx", "rpc"]}
 darkfi-sdk = {path = "../../../src/sdk"}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../src/serial"}
 
 # Misc
 clap = {version = "4.4.11", features = ["derive"]}

+ 2 - 2
script/evgrd/Cargo.toml

@@ -23,10 +23,10 @@ path = "example/send.rs"
 
 [dependencies]
 darkfi = {path = "../../", features = ["event-graph"]}
-darkfi-serial = {version = "0.5.0", features = ["async"]}
+darkfi-serial = {path = "../../src/serial", features = ["async"]}
 
 # Event Graph DB
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 
 # Crypto
 blake3 = "1.8.2"

+ 1 - 1
script/ping/Cargo.toml

@@ -10,7 +10,7 @@ edition = "2021"
 
 [dependencies]
 darkfi = {path = "../../", features = ["net"]}
-darkfi-serial = {version = "0.5.0"}
+darkfi-serial = {path = "../../src/serial"}
 url = {version = "2.5.7", features = ["serde"]}
 smol = "2.0.2"
 

+ 0 - 1
script/research/.gitignore

@@ -1 +0,0 @@
-keys

+ 1 - 1
script/research/blockchain-storage-metrics/Cargo.toml

@@ -12,7 +12,7 @@ edition = "2021"
 [dependencies]
 # Darkfi
 darkfi = {path = "../../../", features = ["async-daemonize", "validator", "rpc"]}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../src/serial"}
 
 # Misc
 tracing = "0.1.44"

+ 1 - 1
script/research/dam/dam-cli/Cargo.toml

@@ -12,7 +12,7 @@ edition = "2021"
 [dependencies]
 # Darkfi
 darkfi = {path = "../../../../", features = ["async-sdk", "rpc"]}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../../src/serial"}
 
 # Misc
 clap = {version = "4.4.11", features = ["derive"]}

+ 1 - 1
script/research/dam/damd/Cargo.toml

@@ -12,7 +12,7 @@ edition = "2021"
 [dependencies]
 # Darkfi
 darkfi = {path = "../../../../", features = ["async-daemonize", "rpc"]}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../../src/serial"}
 
 # Misc
 tracing = "0.1.44"

+ 1 - 1
script/research/generic-node/Cargo.toml

@@ -11,7 +11,7 @@ edition = "2021"
 
 [dependencies]
 darkfi = {path = "../../../", features = ["async-daemonize", "net"]}
-darkfi-serial = {version = "0.5.0", features = ["async"]}
+darkfi-serial = {path = "../../../src/serial", features = ["async"]}
 rand = "0.8.5"
 
 # Daemon

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

@@ -18,7 +18,7 @@ darkfi = {path = "../../../", features = ["bs58", "validator"]}
 darkfi_money_contract = {path = "../../../src/contract/money", features = ["no-entrypoint", "client"]}
 darkfi-contract-test-harness = {path = "../../../src/contract/test-harness"}
 darkfi-sdk = {path = "../../../src/sdk"}
-darkfi-serial = "0.5.1"
+darkfi-serial = {path = "../../../src/serial"}
 
 # Misc
 bs58 = "0.5.1"

+ 1 - 1
script/research/rlnd/rlnd-cli/Cargo.toml

@@ -13,7 +13,7 @@ edition = "2021"
 # Darkfi
 darkfi = {path = "../../../../", features = ["async-sdk", "rpc"]}
 darkfi-sdk = {path = "../../../../src/sdk"}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../../src/serial"}
 rlnd = {path = "../rlnd"}
 
 # Misc

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

@@ -13,11 +13,11 @@ edition = "2021"
 # Darkfi
 darkfi = {path = "../../../../", features = ["async-daemonize", "async-sdk", "rpc", "sled-overlay"]}
 darkfi-sdk = {path = "../../../../src/sdk"}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../../src/serial"}
 
 # Misc
 bs58 = "0.5.1"
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 tracing = "0.1.44"
 
 # JSON-RPC

+ 3 - 3
script/research/zkvm-metering/generator/Cargo.toml

@@ -15,12 +15,12 @@ darkfi = {path = "../../../../", features = ["zk"]}
 halo2_proofs = {version = "0.3.2", features = ["circuit-params"]}
 halo2_gadgets = {version = "0.4.0", features = ["circuit-params"]}
 rand = "0.8.5"
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../../src/serial"}
 
 [dev-dependencies]
 halo2_proofs = {version = "0.3.1", features = ["dev-graph", "sanity-checks"]}
 halo2_gadgets = "0.3.1"
 
 [patch.crates-io]
-halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v031"}
-halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v031"}
+halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v032"}
+halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v032"}

+ 3 - 3
script/research/zkvm-metering/verifier/Cargo.toml

@@ -12,11 +12,11 @@ edition = "2024"
 [dependencies]
 darkfi-sdk = {path = "../../../../src/sdk"}
 darkfi = {path = "../../../../", features = ["zk"]}
-darkfi-serial = "0.5.0"
+darkfi-serial = {path = "../../../../src/serial"}
 
 [patch.crates-io]
-halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v031"}
-halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v031"}
+halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v032"}
+halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v032"}
 
 [profile.release]
 debug = true

+ 2 - 5
src/blockchain/block_store.rs

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

+ 2 - 2
src/blockchain/contract_store.rs

@@ -26,7 +26,7 @@ use darkfi_sdk::{
     monotree::{MemoryDb, Monotree, SledOverlayDb, SledTreeDb, EMPTY_HASH},
 };
 use darkfi_serial::{deserialize, serialize};
-use sled_overlay::{serial::parse_record, sled, SledDbOverlayStateDiff};
+use sled_overlay::{sled, SledDbOverlayStateDiff};
 use tracing::{debug, error};
 
 use crate::{
@@ -35,7 +35,7 @@ use crate::{
     Error, Result,
 };
 
-use super::SledDbOverlayPtr;
+use super::{parse_record, SledDbOverlayPtr};
 
 pub const SLED_CONTRACTS_TREE: &[u8] = b"_contracts";
 pub const SLED_CONTRACTS_TREES_TREE: &[u8] = b"_contracts_trees";

+ 2 - 5
src/blockchain/header_store.rs

@@ -26,16 +26,13 @@ use darkfi_sdk::{
 #[cfg(feature = "async-serial")]
 use darkfi_serial::{async_trait, FutAsyncWriteExt};
 use darkfi_serial::{deserialize, serialize, Encodable, SerialDecodable, SerialEncodable};
-use sled_overlay::{
-    serial::{parse_record, parse_u32_key_record},
-    sled,
-};
+use sled_overlay::sled;
 
 use crate::{util::time::Timestamp, Error, Result};
 
 use super::{
     monero::{extract_aux_merkle_root, MoneroPowData},
-    SledDbOverlayPtr,
+    parse_record, parse_u32_key_record, SledDbOverlayPtr,
 };
 
 /// Struct representing the Proof of Work used in a block.

+ 73 - 1
src/blockchain/mod.rs

@@ -25,9 +25,16 @@ use darkfi_sdk::{
     monotree::{self, Monotree},
     tx::TransactionHash,
 };
-use sled_overlay::{sled, sled::Transactional};
+use darkfi_serial::{deserialize, Decodable};
+use sled_overlay::{
+    sled,
+    sled::{IVec, Transactional},
+};
 use tracing::debug;
 
+#[cfg(feature = "async-serial")]
+use darkfi_serial::{deserialize_async, AsyncDecodable};
+
 use crate::{tx::Transaction, util::time::Timestamp, Error, Result};
 
 /// Block related definitions and storage implementations
@@ -704,6 +711,71 @@ impl BlockchainOverlay {
     }
 }
 
+/// Parse a sled record in the form of a tuple (`key`, `value`).
+pub fn parse_record<T1: Decodable, T2: Decodable>(record: (IVec, IVec)) -> Result<(T1, T2)> {
+    let key = deserialize(&record.0)?;
+    let value = deserialize(&record.1)?;
+
+    Ok((key, value))
+}
+
+/// Parse a sled record with a u32 key, encoded in Big Endian bytes,
+/// in the form of a tuple (`key`, `value`).
+pub fn parse_u32_key_record<T: Decodable>(record: (IVec, 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, encoded in Big Endian bytes,
+/// in the form of a tuple (`key`, `value`).
+pub fn parse_u64_key_record<T: Decodable>(record: (IVec, 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))
+}
+
+#[cfg(feature = "async-serial")]
+/// Parse a sled record in the form of a tuple (`key`, `value`).
+pub async fn parse_record_async<T1: AsyncDecodable, T2: AsyncDecodable>(
+    record: (IVec, IVec),
+) -> Result<(T1, T2)> {
+    let key = deserialize_async(&record.0).await?;
+    let value = deserialize_async(&record.1).await?;
+
+    Ok((key, value))
+}
+
+#[cfg(feature = "async-serial")]
+/// Parse a sled record with a u32 key, encoded in Big Endian bytes,
+/// in the form of a tuple (`key`, `value`).
+pub async fn parse_u32_key_record_async<T: AsyncDecodable>(
+    record: (IVec, 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_async(&record.1).await?;
+
+    Ok((key, value))
+}
+
+#[cfg(feature = "async-serial")]
+/// Parse a sled record with a u64 key, encoded in Big Endian bytes,
+/// in the form of a tuple (`key`, `value`).
+pub async fn parse_u64_key_record_async<T: AsyncDecodable>(
+    record: (IVec, 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_async(&record.1).await?;
+
+    Ok((key, value))
+}
+
 #[cfg(test)]
 mod tests {
     use crate::validator::pow::{RANDOMX_KEY_CHANGE_DELAY, RANDOMX_KEY_CHANGING_HEIGHT};

+ 2 - 5
src/blockchain/tx_store.rs

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

+ 1 - 1
src/contract/dao/Cargo.toml

@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
 blake2b_simd = "1.0.3"
 bs58 = "0.5.1"
 darkfi-sdk = { path = "../../sdk", features = ["wasm"] }
-darkfi-serial = { version = "0.5.0", features = ["derive", "crypto"] }
+darkfi-serial = { path = "../../serial", features = ["derive", "crypto"] }
 darkfi_money_contract = { path = "../money", features = ["no-entrypoint"] }
 thiserror = "2.0.17"
 

+ 1 - 1
src/contract/deployooor/Cargo.toml

@@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]
 
 [dependencies]
 darkfi-sdk = { path = "../../sdk", features = ["wasm"] }
-darkfi-serial = { version = "0.5.0", features = ["derive", "crypto"] }
+darkfi-serial = { path = "../../serial", features = ["derive", "crypto"] }
 thiserror = "2.0.17"
 wasmparser = "0.243.0"
 

+ 1 - 1
src/contract/money/Cargo.toml

@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
 blake3 = "1.8.2"
 bs58 = "0.5.1"
 darkfi-sdk = { path = "../../sdk", features = ["wasm"] }
-darkfi-serial = { version = "0.5.0", features = ["derive", "crypto"] }
+darkfi-serial = { path = "../../serial", features = ["derive", "crypto"] }
 thiserror = "2.0.17"
 
 # The following dependencies are used for the client API and

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

@@ -7,8 +7,8 @@ edition = "2021"
 
 [dependencies]
 darkfi = {path = "../../../", features = ["validator"]}
-darkfi-sdk = {path = "../../../src/sdk"}
-darkfi-serial = {version = "0.5.0", features = ["crypto"]}
+darkfi-sdk = {path = "../../sdk"}
+darkfi-serial = {path = "../../serial", features = ["crypto"]}
 
 darkfi_dao_contract = {path = "../dao", features = ["client", "no-entrypoint"]}
 darkfi_money_contract = {path = "../money", features = ["client", "no-entrypoint"]}

+ 2 - 2
src/sdk/Cargo.toml

@@ -21,7 +21,7 @@ wasm = []
 thiserror = "2.0.17"
 
 # Serialization
-darkfi-serial = {version = "0.5.1", features = ["crypto"]}
+darkfi-serial = {path = "../serial", features = ["crypto"]}
 
 # Encoding
 bs58 = {version = "0.5.1", features = ["check"]}
@@ -46,7 +46,7 @@ subtle = "2.6.1"
 hashbrown = "0.16.1"
 
 # Storage
-sled-overlay = "0.1.14"
+sled-overlay = "0.1.15"
 
 [dev-dependencies]
 halo2_proofs = {version = "0.3.2", features = ["circuit-params", "dev-graph", "sanity-checks"]}

+ 1 - 1
src/sdk/python/Cargo.toml

@@ -19,7 +19,7 @@ darkfi_money_contract = {path = "../../contract/money", features=["no-entrypoint
 darkfi_dao_contract = {path = "../../contract/dao", features=["no-entrypoint", "client"]}
 darkfi_deployooor_contract = {path = "../../contract/deployooor", features=["no-entrypoint", "client"]}
 darkfi-sdk = {path = "../"}
-darkfi-serial = {version = "0.5.1", features = ["crypto"]}
+darkfi-serial = {path = "../../serial", features = ["crypto"]}
 halo2_proofs = {version = "0.3.2", features = ["circuit-params", "dev-graph", "sanity-checks"]}
 halo2_gadgets = {version = "0.4.0", features = ["circuit-params"]}
 plotters = "0.3.7"

+ 2 - 9
src/serial/Cargo.toml

@@ -8,16 +8,8 @@ repository = "https://codeberg.org/darkrenaissance/darkfi"
 license = "AGPL-3.0-only"
 edition = "2021"
 
-# Uncomment this when publishing crate
-#[workspace]
-#members = [
-#    "./derive-internal",
-#    "./derive",
-#    "./",
-#]
-
 [dependencies]
-darkfi-derive = {version = "0.5.1", optional = true}
+darkfi-derive = {path = "./derive", optional = true}
 
 futures-lite = {version = "2", optional = true}
 async-trait = {version = "0", optional = true}
@@ -29,6 +21,7 @@ pasta_curves = {version = "0.5", optional = true}
 semver = {version = "1", optional = true}
 url = {version = "2", optional = true}
 num-bigint = {version = "0.4", optional = true}
+sled-overlay = {version = "0.1.15", optional = true}
 
 [features]
 default = ["derive", "semver"]

+ 1 - 1
src/serial/derive/Cargo.toml

@@ -17,7 +17,7 @@ proc-macro2 = "1"
 quote = "1"
 syn = {version = "2", features = ["full", "fold"]}
 
-darkfi-derive-internal = "0.5.1"
+darkfi-derive-internal = {path = "../derive-internal"}
 
 [features]
 default = []

+ 6 - 6
src/serial/src/async_lib.rs

@@ -18,7 +18,7 @@
 
 use std::{
     collections::VecDeque,
-    io::{Error, ErrorKind, Result},
+    io::{Error, Result},
 };
 
 pub use async_trait::async_trait;
@@ -69,7 +69,7 @@ pub async fn deserialize_async<T: AsyncDecodable>(data: &[u8]) -> Result<T> {
 
     // Fail if data is not consumed entirely.
     if consumed != data.len() {
-        return Err(Error::new(ErrorKind::Other, "Data not consumed fully on deserialization"))
+        return Err(Error::other("Data not consumed fully on deserialization"))
     }
 
     Ok(rv)
@@ -431,7 +431,7 @@ impl AsyncDecodable for VarInt {
             0xFF => {
                 let x = AsyncReadExt::read_u64_async(d).await?;
                 if x < 0x100000000 {
-                    return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt"))
+                    return Err(Error::other("Non-minimal VarInt"))
                 }
                 Ok(VarInt(x))
             }
@@ -439,7 +439,7 @@ impl AsyncDecodable for VarInt {
             0xFE => {
                 let x = AsyncReadExt::read_u32_async(d).await?;
                 if x < 0x10000 {
-                    return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt"))
+                    return Err(Error::other("Non-minimal VarInt"))
                 }
                 Ok(VarInt(x as u64))
             }
@@ -447,7 +447,7 @@ impl AsyncDecodable for VarInt {
             0xFD => {
                 let x = AsyncReadExt::read_u16_async(d).await?;
                 if x < 0xFD {
-                    return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt"))
+                    return Err(Error::other("Non-minimal VarInt"))
                 }
                 Ok(VarInt(x as u64))
             }
@@ -665,7 +665,7 @@ impl AsyncDecodable for String {
     async fn decode_async<D: AsyncRead + Unpin + Send>(d: &mut D) -> Result<String> {
         match String::from_utf8(AsyncDecodable::decode_async(d).await?) {
             Ok(v) => Ok(v),
-            Err(_) => Err(Error::new(ErrorKind::Other, "Invalid UTF-8 for string")),
+            Err(_) => Err(Error::other("Invalid UTF-8 for string")),
         }
     }
 }

+ 7 - 7
src/serial/src/lib.rs

@@ -18,7 +18,7 @@
 
 use std::{
     collections::VecDeque,
-    io::{Cursor, Error, ErrorKind, Read, Write},
+    io::{Cursor, Error, Read, Write},
 };
 
 #[cfg(feature = "derive")]
@@ -74,7 +74,7 @@ pub fn deserialize<T: Decodable>(data: &[u8]) -> Result<T, Error> {
 
     // Fail if data is not consumed entirely.
     if consumed != data.len() {
-        return Err(Error::new(ErrorKind::Other, "Data not consumed fully on deserialization"))
+        return Err(Error::other("Data not consumed fully on deserialization"))
     }
 
     Ok(rv)
@@ -341,7 +341,7 @@ impl Decodable for VarInt {
             0xFF => {
                 let x = ReadExt::read_u64(d)?;
                 if x < 0x100000000 {
-                    return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt"))
+                    return Err(Error::other("Non-minimal VarInt"))
                 }
                 Ok(VarInt(x))
             }
@@ -349,7 +349,7 @@ impl Decodable for VarInt {
             0xFE => {
                 let x = ReadExt::read_u32(d)?;
                 if x < 0x10000 {
-                    return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt"))
+                    return Err(Error::other("Non-minimal VarInt"))
                 }
                 Ok(VarInt(x as u64))
             }
@@ -357,7 +357,7 @@ impl Decodable for VarInt {
             0xFD => {
                 let x = ReadExt::read_u16(d)?;
                 if x < 0xFD {
-                    return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt"))
+                    return Err(Error::other("Non-minimal VarInt"))
                 }
                 Ok(VarInt(x as u64))
             }
@@ -592,7 +592,7 @@ impl Decodable for String {
     fn decode<D: Read>(d: &mut D) -> Result<String, Error> {
         match String::from_utf8(Decodable::decode(d)?) {
             Ok(v) => Ok(v),
-            Err(_) => Err(Error::new(ErrorKind::Other, "Invalid UTF-8 for string")),
+            Err(_) => Err(Error::other("Invalid UTF-8 for string")),
         }
     }
 }
@@ -614,7 +614,7 @@ impl Decodable for Cow<'static, str> {
     fn decode<D: Read>(d: D) -> Result<Cow<'static, str>, Error> {
         match String::from_utf8(Decodable::decode(d)?) {
             Ok(v) => v.map(Cow::Owned),
-            Err(_) => Err(Error::new(ErrorKind::Other, "Invalid UTF-8 for string")),
+            Err(_) => Err(Error::other("Invalid UTF-8 for string")),
         }
     }
 }

+ 3 - 0
src/serial/src/types.rs

@@ -38,3 +38,6 @@ mod semver;
 
 #[cfg(feature = "num-bigint")]
 mod bigint;
+
+#[cfg(feature = "sled-overlay")]
+mod sled_overlay;

+ 5 - 5
src/serial/src/types/bridgetree.rs

@@ -17,7 +17,7 @@
  */
 
 use core::fmt::Debug;
-use std::io::{Error, ErrorKind, Read, Result, Write};
+use std::io::{Error, Read, Result, Write};
 
 #[cfg(feature = "async")]
 use crate::{AsyncDecodable, AsyncEncodable};
@@ -128,7 +128,7 @@ impl<H: Decodable + Ord + Clone> Decodable for bridgetree::NonEmptyFrontier<H> {
 
         match Self::from_parts(position, leaf, ommers) {
             Ok(v) => Ok(v),
-            Err(_) => Err(Error::new(ErrorKind::Other, "FrontierError")),
+            Err(_) => Err(Error::other("FrontierError")),
         }
     }
 }
@@ -143,7 +143,7 @@ impl<H: AsyncDecodable + Send + Ord + Clone> AsyncDecodable for bridgetree::NonE
 
         match Self::from_parts(position, leaf, ommers) {
             Ok(v) => Ok(v),
-            Err(_) => Err(Error::new(ErrorKind::Other, "FrontierError")),
+            Err(_) => Err(Error::other("FrontierError")),
         }
     }
 }
@@ -287,7 +287,7 @@ impl<
         let max_checkpoints = Decodable::decode(d)?;
         match Self::from_parts(prior_bridges, current_bridge, saved, checkpoints, max_checkpoints) {
             Ok(v) => Ok(v),
-            Err(_) => Err(Error::new(ErrorKind::Other, "BridgeTreeError")),
+            Err(_) => Err(Error::other("BridgeTreeError")),
         }
     }
 }
@@ -308,7 +308,7 @@ impl<
         let max_checkpoints = AsyncDecodable::decode_async(d).await?;
         match Self::from_parts(prior_bridges, current_bridge, saved, checkpoints, max_checkpoints) {
             Ok(v) => Ok(v),
-            Err(_) => Err(Error::new(ErrorKind::Other, "BridgeTreeError")),
+            Err(_) => Err(Error::other("BridgeTreeError")),
         }
     }
 }

+ 9 - 9
src/serial/src/types/pasta.rs

@@ -17,7 +17,7 @@
  */
 
 //! Implementations for pasta curves
-use std::io::{Error, ErrorKind, Read, Result, Write};
+use std::io::{Error, Read, Result, Write};
 
 #[cfg(feature = "async")]
 use crate::{
@@ -58,7 +58,7 @@ impl Decodable for Fp {
         d.read_slice(&mut bytes)?;
         match Self::from_repr(bytes).into() {
             Some(v) => Ok(v),
-            None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Base")),
+            None => Err(Error::other("Noncanonical bytes for pallas::Base")),
         }
     }
 }
@@ -70,7 +70,7 @@ impl AsyncDecodable for Fp {
         d.read_slice_async(&mut bytes).await?;
         match Self::from_repr(bytes).into() {
             Some(v) => Ok(v),
-            None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Base")),
+            None => Err(Error::other("Noncanonical bytes for pallas::Base")),
         }
     }
 }
@@ -97,7 +97,7 @@ impl Decodable for Fq {
         d.read_slice(&mut bytes)?;
         match Self::from_repr(bytes).into() {
             Some(v) => Ok(v),
-            None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Scalar")),
+            None => Err(Error::other("Noncanonical bytes for pallas::Scalar")),
         }
     }
 }
@@ -110,7 +110,7 @@ impl AsyncDecodable for Fq {
         d.read_slice_async(&mut bytes).await?;
         match Self::from_repr(bytes).into() {
             Some(v) => Ok(v),
-            None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Scalar")),
+            None => Err(Error::other("Noncanonical bytes for pallas::Scalar")),
         }
     }
 }
@@ -137,7 +137,7 @@ impl Decodable for Ep {
         d.read_slice(&mut bytes)?;
         match Self::from_bytes(&bytes).into() {
             Some(v) => Ok(v),
-            None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Point")),
+            None => Err(Error::other("Noncanonical bytes for pallas::Point")),
         }
     }
 }
@@ -150,7 +150,7 @@ impl AsyncDecodable for Ep {
         d.read_slice_async(&mut bytes).await?;
         match Self::from_bytes(&bytes).into() {
             Some(v) => Ok(v),
-            None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Point")),
+            None => Err(Error::other("Noncanonical bytes for pallas::Point")),
         }
     }
 }
@@ -177,7 +177,7 @@ impl Decodable for Eq {
         d.read_slice(&mut bytes)?;
         match Self::from_bytes(&bytes).into() {
             Some(v) => Ok(v),
-            None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for vesta::Point")),
+            None => Err(Error::other("Noncanonical bytes for vesta::Point")),
         }
     }
 }
@@ -190,7 +190,7 @@ impl AsyncDecodable for Eq {
         d.read_slice_async(&mut bytes).await?;
         match Self::from_bytes(&bytes).into() {
             Some(v) => Ok(v),
-            None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for vesta::Point")),
+            None => Err(Error::other("Noncanonical bytes for vesta::Point")),
         }
     }
 }

+ 5 - 9
src/serial/src/types/semver.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::io::{Error, ErrorKind, Read, Result, Write};
+use std::io::{Error, Read, Result, Write};
 
 #[cfg(feature = "async")]
 use crate::{AsyncDecodable, AsyncEncodable};
@@ -47,7 +47,7 @@ impl Decodable for semver::Prerelease {
 
         match Self::new(&s) {
             Ok(v) => Ok(v),
-            Err(_) => Err(Error::new(ErrorKind::Other, "Failed deserializing semver::Prerelase")),
+            Err(_) => Err(Error::other("Failed deserializing semver::Prerelase")),
         }
     }
 }
@@ -60,7 +60,7 @@ impl AsyncDecodable for semver::Prerelease {
 
         match Self::new(&s) {
             Ok(v) => Ok(v),
-            Err(_) => Err(Error::new(ErrorKind::Other, "Failed deserializing semver::Prerelease")),
+            Err(_) => Err(Error::other("Failed deserializing semver::Prerelease")),
         }
     }
 }
@@ -85,9 +85,7 @@ impl Decodable for semver::BuildMetadata {
 
         match Self::new(&s) {
             Ok(v) => Ok(v),
-            Err(_) => {
-                Err(Error::new(ErrorKind::Other, "Failed deserializing semver::BuildMetadata"))
-            }
+            Err(_) => Err(Error::other("Failed deserializing semver::BuildMetadata")),
         }
     }
 }
@@ -100,9 +98,7 @@ impl AsyncDecodable for semver::BuildMetadata {
 
         match Self::new(&s) {
             Ok(v) => Ok(v),
-            Err(_) => {
-                Err(Error::new(ErrorKind::Other, "Failed deserializing semver::BuildMetadata"))
-            }
+            Err(_) => Err(Error::other("Failed deserializing semver::BuildMetadata")),
         }
     }
 }

+ 248 - 0
src/serial/src/types/sled_overlay.rs

@@ -0,0 +1,248 @@
+/* This file is part of DarkFi (https://dark.fi)
+ *
+ * Copyright (C) 2020-2026 Dyne.org foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+use std::{
+    collections::BTreeMap,
+    io::{Read, Result, Write},
+};
+
+use sled_overlay::{SledDbOverlayStateDiff, SledTreeOverlayStateDiff};
+
+#[cfg(feature = "async")]
+use crate::{AsyncDecodable, AsyncEncodable};
+#[cfg(feature = "async")]
+use async_trait::async_trait;
+#[cfg(feature = "async")]
+use futures_lite::{AsyncRead, AsyncWrite};
+
+use crate::{Decodable, Encodable, VarInt};
+
+impl Encodable for SledTreeOverlayStateDiff {
+    fn encode<S: Write>(&self, s: &mut S) -> Result<usize> {
+        let mut len = 0;
+
+        len += VarInt(self.cache.len() as u64).encode(s)?;
+        for (key, (previous, current)) in self.cache.iter() {
+            len += key.to_vec().encode(s)?;
+            let previous = previous.as_ref().map(|p| p.to_vec());
+            len += previous.encode(s)?;
+            len += current.to_vec().encode(s)?;
+        }
+
+        len += VarInt(self.removed.len() as u64).encode(s)?;
+        for (key, value) in self.removed.iter() {
+            len += key.to_vec().encode(s)?;
+            len += value.to_vec().encode(s)?;
+        }
+
+        Ok(len)
+    }
+}
+
+#[cfg(feature = "async")]
+#[async_trait]
+impl AsyncEncodable for SledTreeOverlayStateDiff {
+    async fn encode_async<S: AsyncWrite + Unpin + Send>(&self, s: &mut S) -> Result<usize> {
+        let mut len = 0;
+
+        len += VarInt(self.cache.len() as u64).encode_async(s).await?;
+        for (key, (previous, current)) in self.cache.iter() {
+            len += key.to_vec().encode_async(s).await?;
+            let previous = previous.as_ref().map(|p| p.to_vec());
+            len += previous.encode_async(s).await?;
+            len += current.to_vec().encode_async(s).await?;
+        }
+
+        len += VarInt(self.removed.len() as u64).encode_async(s).await?;
+        for (key, value) in self.removed.iter() {
+            len += key.to_vec().encode_async(s).await?;
+            len += value.to_vec().encode_async(s).await?;
+        }
+
+        Ok(len)
+    }
+}
+
+impl Decodable for SledTreeOverlayStateDiff {
+    fn decode<D: Read>(d: &mut D) -> Result<Self> {
+        let len = VarInt::decode(d)?.0;
+        let mut cache = BTreeMap::new();
+        for _ in 0..len {
+            let key: Vec<u8> = Decodable::decode(d)?;
+            let (previous, current): (Option<Vec<u8>>, Vec<u8>) = Decodable::decode(d)?;
+            let previous = previous.as_ref().map(|p| p.clone().into());
+            cache.insert(key.into(), (previous, current.into()));
+        }
+
+        let len = VarInt::decode(d)?.0;
+        let mut removed = BTreeMap::new();
+        for _ in 0..len {
+            let key: Vec<u8> = Decodable::decode(d)?;
+            let entry: Vec<u8> = Decodable::decode(d)?;
+            removed.insert(key.into(), entry.into());
+        }
+
+        Ok(Self { cache, removed })
+    }
+}
+
+#[cfg(feature = "async")]
+#[async_trait]
+impl AsyncDecodable for SledTreeOverlayStateDiff {
+    async fn decode_async<D: AsyncRead + Unpin + Send>(d: &mut D) -> Result<Self> {
+        let len = VarInt::decode_async(d).await?.0;
+        let mut cache = BTreeMap::new();
+        for _ in 0..len {
+            let key: Vec<u8> = AsyncDecodable::decode_async(d).await?;
+            let (previous, current): (Option<Vec<u8>>, Vec<u8>) =
+                AsyncDecodable::decode_async(d).await?;
+            let previous = previous.as_ref().map(|p| p.clone().into());
+            cache.insert(key.into(), (previous, current.into()));
+        }
+
+        let len = VarInt::decode_async(d).await?.0;
+        let mut removed = BTreeMap::new();
+        for _ in 0..len {
+            let key: Vec<u8> = AsyncDecodable::decode_async(d).await?;
+            let entry: Vec<u8> = AsyncDecodable::decode_async(d).await?;
+            removed.insert(key.into(), entry.into());
+        }
+
+        Ok(Self { cache, removed })
+    }
+}
+
+impl Encodable for SledDbOverlayStateDiff {
+    fn encode<S: Write>(&self, s: &mut S) -> Result<usize> {
+        let mut len = 0;
+
+        len += VarInt(self.initial_tree_names.len() as u64).encode(s)?;
+        for tree_name in &self.initial_tree_names {
+            len += tree_name.to_vec().encode(s)?;
+        }
+
+        len += VarInt(self.caches.len() as u64).encode(s)?;
+        for (key, (cache, drop)) in self.caches.iter() {
+            len += key.to_vec().encode(s)?;
+            len += cache.encode(s)?;
+            len += drop.encode(s)?;
+        }
+
+        len += VarInt(self.dropped_trees.len() as u64).encode(s)?;
+        for (key, (cache, restore)) in self.dropped_trees.iter() {
+            len += key.to_vec().encode(s)?;
+            len += cache.encode(s)?;
+            len += restore.encode(s)?;
+        }
+
+        Ok(len)
+    }
+}
+
+#[cfg(feature = "async")]
+#[async_trait]
+impl AsyncEncodable for SledDbOverlayStateDiff {
+    async fn encode_async<S: AsyncWrite + Unpin + Send>(&self, s: &mut S) -> Result<usize> {
+        let mut len = 0;
+
+        len += VarInt(self.initial_tree_names.len() as u64).encode_async(s).await?;
+        for tree_name in &self.initial_tree_names {
+            len += tree_name.to_vec().encode_async(s).await?;
+        }
+
+        len += VarInt(self.caches.len() as u64).encode_async(s).await?;
+        for (key, (cache, drop)) in self.caches.iter() {
+            len += key.to_vec().encode_async(s).await?;
+            len += cache.encode_async(s).await?;
+            len += drop.encode_async(s).await?;
+        }
+
+        len += VarInt(self.dropped_trees.len() as u64).encode_async(s).await?;
+        for (key, (cache, restore)) in self.dropped_trees.iter() {
+            len += key.to_vec().encode_async(s).await?;
+            len += cache.encode_async(s).await?;
+            len += restore.encode_async(s).await?;
+        }
+
+        Ok(len)
+    }
+}
+
+impl Decodable for SledDbOverlayStateDiff {
+    fn decode<D: Read>(d: &mut D) -> Result<Self> {
+        let len = VarInt::decode(d)?.0;
+        let mut initial_tree_names = vec![];
+        for _ in 0..len {
+            let initial_tree_name: Vec<u8> = Decodable::decode(d)?;
+            initial_tree_names.push(initial_tree_name.into());
+        }
+
+        let len = VarInt::decode(d)?.0;
+        let mut caches = BTreeMap::new();
+        for _ in 0..len {
+            let key: Vec<u8> = Decodable::decode(d)?;
+            let cache = Decodable::decode(d)?;
+            let drop = Decodable::decode(d)?;
+            caches.insert(key.into(), (cache, drop));
+        }
+
+        let len = VarInt::decode(d)?.0;
+        let mut dropped_trees = BTreeMap::new();
+        for _ in 0..len {
+            let key: Vec<u8> = Decodable::decode(d)?;
+            let cache = Decodable::decode(d)?;
+            let restore = Decodable::decode(d)?;
+            dropped_trees.insert(key.into(), (cache, restore));
+        }
+
+        Ok(Self { initial_tree_names, caches, dropped_trees })
+    }
+}
+
+#[cfg(feature = "async")]
+#[async_trait]
+impl AsyncDecodable for SledDbOverlayStateDiff {
+    async fn decode_async<D: AsyncRead + Unpin + Send>(d: &mut D) -> Result<Self> {
+        let len = VarInt::decode_async(d).await?.0;
+        let mut initial_tree_names = vec![];
+        for _ in 0..len {
+            let initial_tree_name: Vec<u8> = AsyncDecodable::decode_async(d).await?;
+            initial_tree_names.push(initial_tree_name.into());
+        }
+
+        let len = VarInt::decode_async(d).await?.0;
+        let mut caches = BTreeMap::new();
+        for _ in 0..len {
+            let key: Vec<u8> = AsyncDecodable::decode_async(d).await?;
+            let cache = AsyncDecodable::decode_async(d).await?;
+            let drop = AsyncDecodable::decode_async(d).await?;
+            caches.insert(key.into(), (cache, drop));
+        }
+
+        let len = VarInt::decode_async(d).await?.0;
+        let mut dropped_trees = BTreeMap::new();
+        for _ in 0..len {
+            let key: Vec<u8> = AsyncDecodable::decode_async(d).await?;
+            let cache = AsyncDecodable::decode_async(d).await?;
+            let restore = AsyncDecodable::decode_async(d).await?;
+            dropped_trees.insert(key.into(), (cache, restore));
+        }
+
+        Ok(Self { initial_tree_names, caches, dropped_trees })
+    }
+}

+ 3 - 3
src/serial/src/types/url.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::io::{Error, ErrorKind, Read, Result, Write};
+use std::io::{Error, Read, Result, Write};
 use url::Url;
 
 #[cfg(feature = "async")]
@@ -47,7 +47,7 @@ impl Decodable for Url {
         let s: String = Decodable::decode(d)?;
         match Url::parse(&s) {
             Ok(v) => Ok(v),
-            Err(e) => Err(Error::new(ErrorKind::Other, e)),
+            Err(e) => Err(Error::other(e)),
         }
     }
 }
@@ -59,7 +59,7 @@ impl AsyncDecodable for Url {
         let s: String = AsyncDecodable::decode_async(d).await?;
         match Url::parse(&s) {
             Ok(v) => Ok(v),
-            Err(e) => Err(Error::new(ErrorKind::Other, e)),
+            Err(e) => Err(Error::other(e)),
         }
     }
 }