Skip to content

Commit

Permalink
rusk: change migration to be performed before any tx execution
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Mar 12, 2024
1 parent d2a7157 commit 109dcc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
50 changes: 25 additions & 25 deletions rusk/src/lib/chain/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,7 +85,18 @@ impl Rusk {
provisioners: &Provisioners,
) -> Result<(Vec<SpentTransaction>, Vec<Transaction>, 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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -395,7 +395,7 @@ async fn delete_commits(vm: Arc<VM>, 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,
Expand All @@ -404,6 +404,17 @@ fn accept(
provisioners: &Provisioners,
migration_height: Option<u64>,
) -> Result<(Vec<SpentTransaction>, 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());
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion rusk/src/lib/chain/vm/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Migration {
session: Session,
block_height: u64,
provisioners: &Provisioners,
) -> anyhow::Result<Session> {
) -> crate::Result<Session> {
match migration_height {
Some(h) if h == block_height => (),
_ => return Ok(session),
Expand Down

0 comments on commit 109dcc5

Please sign in to comment.