Skip to content

Commit

Permalink
Merge pull request #2537 from dusk-network/piecrust_port
Browse files Browse the repository at this point in the history
Port to Piecrust which supports delta-based state persistence model
  • Loading branch information
miloszm authored Oct 1, 2024
2 parents ee5e359 + 8ebfb4d commit 331f047
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jubjub-schnorr = { version = "=0.5.0", default-features = false }
kadcast = "=0.7.0-rc.5"
phoenix-circuits = { version = "=0.4.0", default-features = false }
phoenix-core = { version = "=0.32.0", default-features = false }
piecrust = "=0.24.0"
piecrust = "=0.25.0"
piecrust-uplink = "=0.17.1"
poseidon-merkle = "=0.7.0"
zk-citadel = "=0.14.0"
Expand Down
2 changes: 2 additions & 0 deletions rusk-recovery/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Ported to Piecrust 0.25.0 [#2536]
- Removed 'phoenix-core' dependency [#1139]
- Added closure argument to the 'deploy' method [#1630]
- Update Plonk to 0.20
Expand All @@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.6.0] - 2023-12-14

[#2536]: https://github.com/dusk-network/rusk/issues/2536
[#1675]: https://github.com/dusk-network/rusk/issues/1675
[#1630]: https://github.com/dusk-network/rusk/issues/1630
[#1139]: https://github.com/dusk-network/rusk/issues/1139
2 changes: 2 additions & 0 deletions rusk-recovery/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,10 @@ where
fs::write(state_id_path, commit_id)?;

if old_commit_id != commit_id {
vm.finalize_commit(old_commit_id)?;
vm.delete_commit(old_commit_id)?;
}
vm.finalize_commit(commit_id)?;

info!("{} {}", theme.action("Init Root"), hex::encode(commit_id));

Expand Down
2 changes: 2 additions & 0 deletions rusk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Ported to Piecrust 0.25.0 [#2536]
- Allow state transitions to be executed in parallel with queries [#970]
- Change dependencies declarations enforce bytecheck [#1371]
- Fixed tests passing incorrect arguments [#1371]
Expand Down Expand Up @@ -213,6 +214,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add linking between Rusk and Protobuff structs
- Add build system that generates keys for circuits and caches them.

[#2536]: https://github.com/dusk-network/rusk/issues/2536
[#2207]: https://github.com/dusk-network/rusk/issues/2207
[#1884]: https://github.com/dusk-network/rusk/issues/1884
[#1882]: https://github.com/dusk-network/rusk/issues/1882
Expand Down
9 changes: 0 additions & 9 deletions rusk/src/bin/args/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use super::*;

use std::{env, fs, io};

use rusk::DELETING_VM_FNAME;
use rusk_recovery_tools::state::{deploy, restore_state, tar};
use rusk_recovery_tools::Theme;
use tracing::info;
Expand Down Expand Up @@ -44,14 +43,6 @@ pub fn recovery_state(

let state_dir = rusk_profile::get_rusk_state_dir()?;

let paths = fs::read_dir(&state_dir)?;
for dir in paths.flatten() {
if dir.path().join(DELETING_VM_FNAME).exists() {
info!("{} dirty state {:?}", theme.info("Deleting"), dir.path());
fs::remove_dir_all(dir.path())?
}
}

let state_id_path = rusk_profile::to_rusk_state_id_path(&state_dir);

let _ = rusk_abi::new_vm(&state_dir)?;
Expand Down
25 changes: 9 additions & 16 deletions rusk/src/lib/node/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use std::fs::File;
use std::path::Path;
use std::sync::{mpsc, Arc, LazyLock};
use std::time::{Duration, Instant};
Expand All @@ -14,7 +13,7 @@ use execution_core::stake::StakeKeys;
use execution_core::transfer::PANIC_NONCE_NOT_READY;
use parking_lot::RwLock;
use tokio::task;
use tracing::{debug, info, warn};
use tracing::{debug, info};

use dusk_bytes::{DeserializableSlice, Serializable};
use dusk_consensus::config::{
Expand Down Expand Up @@ -46,7 +45,7 @@ use crate::gen_id::gen_contract_id;
use crate::http::RuesEvent;
use crate::node::{coinbase_value, Rusk, RuskTip};
use crate::Error::InvalidCreditsCount;
use crate::{Error, Result, DELETING_VM_FNAME};
use crate::{Error, Result};

pub static DUSK_KEY: LazyLock<BlsPublicKey> = LazyLock::new(|| {
let dusk_cpk_bytes = include_bytes!("../../assets/dusk.cpk");
Expand Down Expand Up @@ -351,10 +350,10 @@ impl Rusk {
commit: [u8; 32],
to_delete: Vec<[u8; 32]>,
) -> Result<()> {
self.set_base_and_delete(commit, to_delete)?;

let commit_id_path = to_rusk_state_id_path(&self.dir);
fs::write(commit_id_path, commit)?;

self.set_base_and_delete(commit, to_delete);
Ok(())
}

Expand Down Expand Up @@ -485,23 +484,17 @@ impl Rusk {
&self,
base: [u8; 32],
to_delete: Vec<[u8; 32]>,
) {
) -> Result<()> {
self.vm.finalize_commit(base)?;
self.tip.write().base = base;

for c in &to_delete {
if let Err(e) = File::create(
self.dir.join(hex::encode(c)).join(DELETING_VM_FNAME),
) {
warn!("cannot mark state as in deletion: {e}");
}
}

// Deleting commits is blocking, meaning it will wait until any process
// using the commit is done. This includes any queries that are
// currently executing.
// Since we do want commits to be deleted, but don't want block
// finalization to wait, we spawn a new task to delete the commits.
task::spawn(delete_commits(self.vm.clone(), to_delete));
Ok(())
}

pub(crate) fn block_gas_limit(&self) -> u64 {
Expand Down Expand Up @@ -665,8 +658,8 @@ fn contract_deploy(
Ok(_) => receipt.gas_spent += deploy_charge,
Err(err) => {
info!("Tx caused deployment error {err:?}");
receipt.data =
Err(ContractError::Panic("failed deployment".into()))
let msg = format!("failed deployment: {err:?}");
receipt.data = Err(ContractError::Panic(msg))
}
}
}
Expand Down

0 comments on commit 331f047

Please sign in to comment.