Skip to content

Commit

Permalink
Merge pull request #285 from dusk-network/update-deps
Browse files Browse the repository at this point in the history
Remove unused dependencies and upgrade to latest versions
  • Loading branch information
Eduardo Leegwater Simões authored Oct 31, 2023
2 parents a3eae78 + e806b66 commit 189d265
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 81 deletions.
3 changes: 3 additions & 0 deletions piecrust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Changed

- Upgrade `dusk-merkle` to version `0.5`
- Change contract tree to be arity 4 and height 17 [#159]
- Maximum contract size is now 4TiB [#159]
- Change `Error::RuntimeError` variant to contain `dusk_wasmtime::Error`,
Expand All @@ -25,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Removed

- Remove `parking_lot` dependency
- Remove `colored` dependency
- Remove 4 page - 256KiB - minimum memory requirement for contracts
- Remove `Clone` derivation for `Error`
- Remove some `Error` variants, along with `From` implementations:
Expand Down
4 changes: 1 addition & 3 deletions piecrust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ dusk-wasmtime = { version = "14", default-features = false, features = ["craneli
bytecheck = "0.6"
rkyv = { version = "0.7", features = ["size_32", "validation"] }
once_cell = "1.18"
parking_lot = "0.12"
blake3 = "1"
colored = "2"
memmap2 = "0.7"
tempfile = "3"
thiserror = "1"
rand = "0.8"
hex = "0.4"
dusk-merkle = { version = "0.1", features = ["rkyv-impl"] }
dusk-merkle = { version = "0.5", features = ["rkyv-impl"] }
const-decoder = "0.3"

[dev-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions piecrust/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use std::io;
use std::ops::{Deref, DerefMut};

use colored::*;
use dusk_wasmtime::{Instance, Module, Mutability, Store, ValType};
use piecrust_uplink::{ContractId, Event, ARGBUF_LEN};

Expand Down Expand Up @@ -325,7 +324,7 @@ impl WrappedInstance {
let buf_end = buf_start + ARGBUF_LEN;

if ofs + i >= buf_start && ofs + i < buf_end {
print!("{}", format!("{byte:02x}").green());
print!("{byte:02x}");
print!(" ");
} else {
print!("{byte:02x} ")
Expand Down
5 changes: 3 additions & 2 deletions piecrust/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ fn read_all_commits<P: AsRef<Path>>(
let entry = entry?;
if entry.path().is_dir() {
let commit = read_commit(entry.path())?;
commits.insert(*commit.index.root(), commit);
let root = *commit.index.root();
commits.insert(root, commit);
}
}

Expand Down Expand Up @@ -430,7 +431,7 @@ fn write_commit_inner<P: AsRef<Path>>(
bytecode_dir,
memory_dir,
base: base.map(|inner| {
let base_root = inner.index.root();
let base_root = *inner.index.root();

let base_hex = hex::encode(base_root);
let base_dir = root_dir.join(base_hex);
Expand Down
6 changes: 4 additions & 2 deletions piecrust/src/store/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ impl ContractSession {
for (contract, entry) in &self.contracts {
commit.index.insert(*contract, &entry.memory);
}
*commit.index.root()
let root = commit.index.root();

*root
}

/// Commits the given session to disk, consuming the session and adding it
Expand Down Expand Up @@ -137,7 +139,7 @@ impl ContractSession {

match base_commit.index.contains_key(&contract) {
true => {
let base_hex = hex::encode(base);
let base_hex = hex::encode(*base);
let base_dir = self.root_dir.join(base_hex);

let contract_hex = hex::encode(contract);
Expand Down
83 changes: 11 additions & 72 deletions piecrust/src/store/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use std::collections::{BTreeMap, BTreeSet};
use std::{
cell::Ref,
collections::{BTreeMap, BTreeSet},
};

use bytecheck::CheckBytes;
use piecrust_uplink::ContractId;
Expand Down Expand Up @@ -74,7 +77,7 @@ impl ContractIndex {
.insert(position_from_contract(&contract), *element.tree.root());
}

pub fn root(&self) -> &Hash {
pub fn root(&self) -> Ref<Hash> {
self.tree.root()
}

Expand Down Expand Up @@ -140,14 +143,10 @@ impl AsRef<[u8]> for Hash {
}
}

impl dusk_merkle::Aggregate<C_HEIGHT, C_ARITY> for Hash {
const EMPTY_SUBTREES: [Hash; C_HEIGHT] = C_EMPTY_SUBTREES;
impl dusk_merkle::Aggregate<C_ARITY> for Hash {
const EMPTY_SUBTREE: Self = Hash([0; blake3::OUT_LEN]);

fn aggregate<'a, I>(items: I) -> Self
where
Self: 'a,
I: Iterator<Item = &'a Self>,
{
fn aggregate(items: [&Self; C_ARITY]) -> Self {
let mut hasher = Hasher::new();
for item in items {
hasher.update(item.as_bytes());
Expand All @@ -156,14 +155,10 @@ impl dusk_merkle::Aggregate<C_HEIGHT, C_ARITY> for Hash {
}
}

impl dusk_merkle::Aggregate<P_HEIGHT, P_ARITY> for Hash {
const EMPTY_SUBTREES: [Hash; P_HEIGHT] = P_EMPTY_SUBTREES;
impl dusk_merkle::Aggregate<P_ARITY> for Hash {
const EMPTY_SUBTREE: Self = Hash([0; blake3::OUT_LEN]);

fn aggregate<'a, I>(items: I) -> Self
where
Self: 'a,
I: Iterator<Item = &'a Self>,
{
fn aggregate(items: [&Self; P_ARITY]) -> Self {
let mut hasher = Hasher::new();
for item in items {
hasher.update(item.as_bytes());
Expand Down Expand Up @@ -218,59 +213,3 @@ pub fn position_from_contract(contract: &ContractId) -> u64 {

pos as u64
}

const P_EMPTY_SUBTREES: [Hash; P_HEIGHT] = subtrees();
const C_EMPTY_SUBTREES: [Hash; C_HEIGHT] = subtrees();

const fn subtrees<const N: usize>() -> [Hash; N] {
let mut subtrees = [Hash([0; blake3::OUT_LEN]); N];

let mut i = 0;
while i < N {
subtrees[i] = EMPTY_SUBTREES[i];
i += 1;
}

subtrees
}

const EMPTY_SUBTREES: [Hash; C_HEIGHT] = [
h2h("452b8b91767b270a61db2159db2dd6d411ce560f4a34230d70928950fdda3a88"),
h2h("f588290692a4d73ba016dee67a00e928f38e381b8eb5ca8c01d8b8c9bee32211"),
h2h("0b69ae637dbf590e15b9e06b4195341087cb3f60e95a43a1a8c459a5d321b1ff"),
h2h("4087415c8d818403a4b52dcb9fc1c100ac72c3b52dba28181924cc394f39d873"),
h2h("d426e95515107709df948c05a45cf9257c03510fe89ed6e81c0f34bd02c67a1f"),
h2h("f71910e10293859199e9ce0a9eb553d9a332b9931b0516842ff4528143493789"),
h2h("19af8e0debcf1f9ed745a87e264e0930ac0163066b4a78bba42660252bf888d0"),
h2h("82b948b894a90ff6b6b5ff728e2f4e4d5442d40e52a8920ef4fb6922469032a1"),
h2h("7a6b33825bf9cb46f03a4db60821f811679b3b2ea0bc62e92b2c70a55b207be7"),
h2h("ba58322ab8cdb81e2d3e5f48c56d016c94fa03d37559e1fe2f6ce5e1947c1b11"),
h2h("2a6f776446db67a81008cc0d39a59c65456dfc0de7119158dcb593fceda81def"),
h2h("fcc45ccc66aef0862029fc21785cbc1de4f15f4a1de5f6ed2458b1061093de18"),
h2h("c20f6e2e047be3bccbfbc9a66352ee30a6b664a03da6df415fa2fde67e174c60"),
h2h("a0abd3f2694a3518379cd1df96701eb10d94f1025732796f28c1f6eb7a197282"),
h2h("ee20a233662e859c2af6a3feff6f1de5cea6d3421074d7a5fd2a472ba8083f51"),
h2h("d47a16c4ebfebe96fe29a5df123992c17f092f990cf4403a3f5b9c3d86219105"),
h2h("71c0c670191c8b1b7389d83b6da3e6a00f467ccc477ef0eabfbee4ab7b4b0087"),
h2h("136ce719e0a7865f0f39715a85e97a44284dc20fc86edff441b52d523f9c8aa5"),
h2h("5149df3556905068c59c3e5a35691b77dc31f411106802c29b4924009b95d953"),
h2h("b5b17224a6b2965cb162319dbc0a9ff87d3eee8f84fcc35e568fcf034e257601"),
h2h("1f23b1ebdb969ed8f77520d17e5c49b09c2becb73f65807ce548fac20705fb99"),
h2h("31bc05ea5dc0009352ddb2af607fddbf7605a314411aa77b18b1e00caef0109a"),
h2h("e895bc877f2c61c066e5e742b5e6e3b054e0e50c2f97cf6b1ff3d70830964765"),
h2h("5002d9b6c51486682cf6d109ebcacad9662bbaca1ce80fcdc38d4b5a3bde4f7f"),
h2h("3fe9023a11950dcbd3be3da7023f006369832ee531fbe25b4068bb9d3fc86878"),
h2h("8505d1e1aaac1592fe422ab50ed6d7e08a8f4ec1935be058f7fba446ffbf6868"),
h2h("513fef2ba48aadea5347054c866e9a1101475a9616badbdca1e8d38e76fa01a7"),
h2h("b1cbaba537ce45006efc736dbaa54d325cd9d5b7c03a796cc50b91ba06216fbf"),
h2h("d5e03be0716d41ef6cb9a2e7a761fba03c7e2df1e3c9c5a73560ed0f82900795"),
h2h("cc84fcaddbb73c6dc3803fb015a27e8aca4cb5783c1da7f0f1af353311b447d0"),
h2h("0ebcb81ff4a62dcd965ea581fffead4dbecf308ac7400eb13dbad6d4c253e3c0"),
h2h("88ade4a900cb56d9dbbef5e4f4e15cb0bbc40f2fcbabd916926b6b1481acfdc4"),
];

const fn h2h(s: &str) -> Hash {
use const_decoder::Decoder;
let bytes = Decoder::Hex.decode(s.as_bytes());
Hash(bytes)
}

0 comments on commit 189d265

Please sign in to comment.