From c587a3218f40bc95b3de9b8f7d39d471eb774530 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 2d69fa016..c727946e1 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; @@ -150,17 +161,6 @@ impl Rusk { missed_generators, )?; - 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(); @@ -396,7 +396,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, @@ -405,6 +405,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()); @@ -443,17 +454,6 @@ fn accept( missed_generators, )?; - 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 187a455ad..0736915a0 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),