Skip to content

Commit

Permalink
Merge pull request #2392 from dusk-network/fix-commit-deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia authored Sep 13, 2024
2 parents e95d7bf + 0e38eef commit 34b6c7e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 10 additions & 0 deletions rusk/src/bin/args/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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 @@ -42,6 +43,15 @@ 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
2 changes: 2 additions & 0 deletions rusk/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ pub type Result<T, E = Error> = core::result::Result<T, E>;
#[cfg(feature = "node")]
pub use node::Rusk;

pub const DELETING_VM_FNAME: &str = ".delete";

#[cfg(feature = "testwallet")]
mod test_utils;
13 changes: 11 additions & 2 deletions rusk/src/lib/node/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// 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 +15,7 @@ use execution_core::transfer::PANIC_NONCE_NOT_READY;
use parking_lot::RwLock;
use sha3::{Digest, Sha3_256};
use tokio::task;
use tracing::{debug, info};
use tracing::{debug, info, warn};

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

pub static DUSK_KEY: LazyLock<BlsPublicKey> = LazyLock::new(|| {
let dusk_cpk_bytes = include_bytes!("../../assets/dusk.cpk");
Expand Down Expand Up @@ -484,6 +485,14 @@ impl Rusk {
) {
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.
Expand Down

0 comments on commit 34b6c7e

Please sign in to comment.