Skip to content

Commit

Permalink
rusk: change accept to return stake events
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Oct 22, 2024
1 parent 5137e22 commit fe9983b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
14 changes: 11 additions & 3 deletions rusk/src/lib/node/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use execution_core::{
BlsScalar, ContractError, Dusk, Event,
};
use node::vm::bytecode_charge;
use node_data::events::contract::ContractTxEvent;
use node_data::events::contract::{ContractEvent, ContractTxEvent};
use node_data::ledger::{Hash, Slash, SpentTransaction, Transaction};
use rusk_abi::{CallReceipt, PiecrustError, Session};
use rusk_profile::to_rusk_state_id_path;
Expand Down Expand Up @@ -297,7 +297,11 @@ impl Rusk {
consistency_check: Option<VerificationOutput>,
slashing: Vec<Slash>,
voters: &[Voter],
) -> Result<(Vec<SpentTransaction>, VerificationOutput)> {
) -> Result<(
Vec<SpentTransaction>,
VerificationOutput,
Vec<ContractEvent>,
)> {
let session = self.session(block_height, None)?;

let (spent_txs, verification_output, session, events) = accept(
Expand Down Expand Up @@ -334,13 +338,17 @@ impl Rusk {
));
}

let mut stake_events = vec![];
for event in events {
if event.event.target.0 == STAKE_CONTRACT {
stake_events.push(event.event.clone());
}
// Send VN event to RUES
let event = RuesEvent::from(event);
let _ = self.event_sender.send(event);
}

Ok((spent_txs, verification_output))
Ok((spent_txs, verification_output, stake_events))
}

pub fn finalize_state(
Expand Down
14 changes: 9 additions & 5 deletions rusk/src/lib/node/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

mod query;

use node_data::events::contract::ContractEvent;
use tracing::info;

use dusk_bytes::DeserializableSlice;
Expand Down Expand Up @@ -72,15 +73,19 @@ impl VMExecution for Rusk {
&self,
blk: &Block,
voters: &[Voter],
) -> anyhow::Result<(Vec<SpentTransaction>, VerificationOutput)> {
) -> anyhow::Result<(
Vec<SpentTransaction>,
VerificationOutput,
Vec<ContractEvent>,
)> {
info!("Received accept request");
let generator = blk.header().generator_bls_pubkey;
let generator = BlsPublicKey::from_slice(&generator.0)
.map_err(|e| anyhow::anyhow!("Error in from_slice {e:?}"))?;

let slashing = Slash::from_block(blk)?;

let (txs, verification_output) = self
let (txs, verification_output, stake_events) = self
.accept_transactions(
blk.header().height,
blk.header().gas_limit,
Expand All @@ -96,7 +101,7 @@ impl VMExecution for Rusk {
)
.map_err(|inner| anyhow::anyhow!("Cannot accept txs: {inner}!!"))?;

Ok((txs, verification_output))
Ok((txs, verification_output, stake_events))
}

fn move_to_commit(&self, commit: [u8; 32]) -> anyhow::Result<()> {
Expand Down Expand Up @@ -306,8 +311,7 @@ impl Rusk {
let stake_amount = stake.amount.unwrap_or_default();

let value = stake_amount.value;
let eligibility = stake_amount.eligibility;

Stake::new(value, stake.reward, eligibility, stake.nonce)
Stake::new(value, stake_amount.eligibility)
}
}
4 changes: 2 additions & 2 deletions rusk/tests/common/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn generator_procedure(
let verify_output = rusk.verify_state_transition(&block, &voters)?;
info!("verify_state_transition new verification: {verify_output}",);

let (accept_txs, accept_output) = rusk.accept(&block, &voters)?;
let (accept_txs, accept_output, _) = rusk.accept(&block, &voters)?;

assert_eq!(accept_txs.len(), expected.executed, "all txs accepted");

Expand Down Expand Up @@ -285,7 +285,7 @@ pub fn generator_procedure2(
let verify_output = rusk.verify_state_transition(&block, &voters)?;
info!("verify_state_transition new verification: {verify_output}",);

let (accept_txs, accept_output) = rusk.accept(&block, &voters)?;
let (accept_txs, accept_output, _) = rusk.accept(&block, &voters)?;

assert_eq!(accept_txs.len(), expected.executed, "all txs accepted");

Expand Down

0 comments on commit fe9983b

Please sign in to comment.