Skip to content

Commit

Permalink
rusk: print several values during TX processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Leegwater Simões committed Nov 14, 2023
1 parent 33b2710 commit f301edc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ overflow-checks = true

[profile.release.package.transfer-contract]
overflow-checks = true

[patch.crates-io]
#piecrust = { path = "../piecrust-0.10.1-rc.0" }
#piecrust-uplink = { path = "../piecrust-uplink-0.8.0-rc.0" }
24 changes: 24 additions & 0 deletions rusk/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use poseidon_merkle::Opening as PoseidonOpening;
use rkyv::validation::validators::DefaultValidator;
use rkyv::{Archive, Deserialize, Infallible, Serialize};
use rusk_abi::dusk::{dusk, Dusk};
use rusk_abi::hash::Hasher;
use rusk_abi::{
CallReceipt, ContractError, ContractId, Error as PiecrustError, Event,
RawResult, Session, StandardBufSerializer, STAKE_CONTRACT,
Expand Down Expand Up @@ -131,9 +132,21 @@ impl Rusk {
let mut event_hasher = Sha3_256::new();

for unspent_tx in txs {
let tx_hash = hex::encode(
Hasher::digest(unspent_tx.inner.to_hash_input_bytes())
.to_bytes(),
);
let root = hex::encode(session.root());
println!(
"=========================================================="
);
println!("Processing transaction: {tx_hash}");

let tx = unspent_tx.inner.clone();
match execute(&mut session, &tx) {
Ok(receipt) => {
println!("SPENT ; Resulting root: {root}");

let gas_spent = receipt.points_spent;

// If the transaction went over the block gas limit we
Expand Down Expand Up @@ -173,6 +186,8 @@ impl Rusk {
});
}
Err(_) => {
println!("UNSPENDABLE ; Resulting root: {root}");

// An unspendable transaction should be discarded
discarded_txs.push(unspent_tx);
continue;
Expand Down Expand Up @@ -625,9 +640,18 @@ fn accept(
let mut event_hasher = Sha3_256::new();

for unspent_tx in txs {
let tx_hash = hex::encode(
Hasher::digest(unspent_tx.inner.to_hash_input_bytes()).to_bytes(),
);
let root = hex::encode(session.root());
println!("==========================================================");
println!("Processing transaction: {tx_hash}");

let tx = &unspent_tx.inner;
let receipt = execute(session, tx)?;

println!("SPENT ; Resulting root: {root}");

for event in receipt.events {
update_hasher(&mut event_hasher, event);
}
Expand Down
2 changes: 1 addition & 1 deletion rusk/tests/services/unspendable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const BLOCK_HEIGHT: u64 = 1;
const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000;
const INITIAL_BALANCE: u64 = 10_000_000_000;

const GAS_LIMIT_0: u64 = 1_000_000; // Enough to spend, but OOG during ICC
const GAS_LIMIT_0: u64 = 7_000_000; // Enough to spend, but OOG during ICC
const GAS_LIMIT_1: u64 = 1_000; // Not enough to spend
const GAS_LIMIT_2: u64 = 200_000_000; // All ok

Expand Down

0 comments on commit f301edc

Please sign in to comment.