From 109dcc5c0a81ac78f3e1c1f35fbe8b8664f068fd Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Tue, 12 Mar 2024 11:01:00 +0100 Subject: [PATCH] rusk: change migration to be performed before any tx execution --- rusk/src/lib/chain/rusk.rs | 50 +++++++++++++++--------------- rusk/src/lib/chain/vm/migration.rs | 2 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/rusk/src/lib/chain/rusk.rs b/rusk/src/lib/chain/rusk.rs index 38db269d2c..c14077e9d5 100644 --- a/rusk/src/lib/chain/rusk.rs +++ b/rusk/src/lib/chain/rusk.rs @@ -11,7 +11,7 @@ use std::{fs, io}; use parking_lot::RwLock; use sha3::{Digest, Sha3_256}; use tokio::task; -use tracing::{debug, info}; +use tracing::{debug, error}; use crate::chain::vm::migration::Migration; use dusk_bls12_381::BlsScalar; @@ -85,7 +85,18 @@ impl Rusk { provisioners: &Provisioners, ) -> Result<(Vec, Vec, VerificationOutput)> { - let mut session = self.session(block_height, None)?; + let session = self.session(block_height, None)?; + + let mut session = Migration::migrate( + self.migration_height, + session, + block_height, + provisioners, + ) + .map_err(|e| { + error!("Error while migrating: {e}"); + e + })?; let mut block_gas_left = block_gas_limit; @@ -149,17 +160,6 @@ impl Rusk { &mut event_hasher, )?; - let r = Migration::migrate( - self.migration_height, - session, - block_height, - provisioners, - ); - if r.is_err() { - info!("MIGRATION RESULT={:?}", r); - } - let session = r.expect("migration should succeed"); - let state_root = session.root(); let event_hash = event_hasher.finalize().into(); @@ -395,7 +395,7 @@ async fn delete_commits(vm: Arc, commits: Vec<[u8; 32]>) { #[allow(clippy::too_many_arguments)] fn accept( - mut session: Session, + session: Session, block_height: u64, block_gas_limit: u64, generator: &BlsPublicKey, @@ -404,6 +404,17 @@ fn accept( provisioners: &Provisioners, migration_height: Option, ) -> Result<(Vec, VerificationOutput, Session)> { + let mut session = Migration::migrate( + migration_height, + session, + block_height, + provisioners, + ) + .map_err(|e| { + error!("Error while migrating: {e}"); + e + })?; + let mut block_gas_left = block_gas_limit; let mut spent_txs = Vec::with_capacity(txs.len()); @@ -441,17 +452,6 @@ fn accept( &mut event_hasher, )?; - let r = Migration::migrate( - migration_height, - session, - block_height, - provisioners, - ); - if r.is_err() { - info!("MIGRATION RESULT={:?}", r); - } - let session = r.expect("migration should succeed"); - let state_root = session.root(); let event_hash = event_hasher.finalize().into(); diff --git a/rusk/src/lib/chain/vm/migration.rs b/rusk/src/lib/chain/vm/migration.rs index 187a455ad0..0736915a0d 100644 --- a/rusk/src/lib/chain/vm/migration.rs +++ b/rusk/src/lib/chain/vm/migration.rs @@ -24,7 +24,7 @@ impl Migration { session: Session, block_height: u64, provisioners: &Provisioners, - ) -> anyhow::Result { + ) -> crate::Result { match migration_height { Some(h) if h == block_height => (), _ => return Ok(session),