Skip to content

Commit

Permalink
rusk: use prev_state_root for verification
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Dec 16, 2024
1 parent c85b12a commit f072f54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 9 additions & 6 deletions rusk/src/lib/node/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ impl Rusk {
let block_gas_limit = self.block_gas_limit;
let generator = params.generator_pubkey.inner();
let to_slash = params.to_slash.clone();
let prev_state_root = params.prev_state_root;

let voters = &params.voters_pubkey[..];

let mut session = self.new_block_session(block_height, None)?;
let mut session = self.new_block_session(block_height, prev_state_root)?;

let mut block_gas_left = block_gas_limit;

Expand Down Expand Up @@ -179,7 +180,7 @@ impl Rusk {
// transaction, since it is technically valid.
if gas_spent > block_gas_left {
info!("Skipping {tx_id_hex} due gas_spent {gas_spent} greater than left: {block_gas_left}");
session = self.new_block_session(block_height, None)?;
session = self.new_block_session(block_height, prev_state_root)?;

for spent_tx in &spent_txs {
// We know these transactions were correctly
Expand Down Expand Up @@ -259,6 +260,7 @@ impl Rusk {
#[allow(clippy::too_many_arguments)]
pub fn verify_transactions(
&self,
prev_commit: [u8; 32],
block_height: u64,
block_hash: Hash,
block_gas_limit: u64,
Expand All @@ -267,7 +269,7 @@ impl Rusk {
slashing: Vec<Slash>,
voters: &[Voter],
) -> Result<(Vec<SpentTransaction>, VerificationOutput)> {
let session = self.new_block_session(block_height, None)?;
let session = self.new_block_session(block_height, prev_commit)?;

accept(
session,
Expand All @@ -292,6 +294,7 @@ impl Rusk {
#[allow(clippy::too_many_arguments)]
pub fn accept_transactions(
&self,
prev_commit: [u8; 32],
block_height: u64,
block_gas_limit: u64,
block_hash: Hash,
Expand All @@ -305,7 +308,7 @@ impl Rusk {
VerificationOutput,
Vec<ContractEvent>,
)> {
let session = self.new_block_session(block_height, None)?;
let session = self.new_block_session(block_height, prev_commit)?;

let (spent_txs, verification_output, session, events) = accept(
session,
Expand Down Expand Up @@ -472,9 +475,9 @@ impl Rusk {
pub(crate) fn new_block_session(
&self,
block_height: u64,
commit: Option<[u8; 32]>,
commit: [u8; 32],
) -> Result<Session> {
let mut session = self._session(block_height, commit)?;
let mut session = self._session(block_height, Some(commit))?;
let _: CallReceipt<()> = session
.call(STAKE_CONTRACT, "before_state_transition", &(), u64::MAX)
.expect("before_state_transition to success");
Expand Down
4 changes: 4 additions & 0 deletions rusk/src/lib/node/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl VMExecution for Rusk {

fn verify_state_transition(
&self,
prev_commit: [u8; 32],
blk: &Block,
voters: &[Voter],
) -> anyhow::Result<VerificationOutput> {
Expand All @@ -57,6 +58,7 @@ impl VMExecution for Rusk {

let (_, verification_output) = self
.verify_transactions(
prev_commit,
blk.header().height,
blk.header().hash,
blk.header().gas_limit,
Expand All @@ -72,6 +74,7 @@ impl VMExecution for Rusk {

fn accept(
&self,
prev_root: [u8; 32],
blk: &Block,
voters: &[Voter],
) -> anyhow::Result<(
Expand All @@ -88,6 +91,7 @@ impl VMExecution for Rusk {

let (txs, verification_output, stake_events) = self
.accept_transactions(
prev_root,
blk.header().height,
blk.header().gas_limit,
blk.header().hash,
Expand Down

0 comments on commit f072f54

Please sign in to comment.