Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rusk: refactor accept to not break clippy::too_many_arguments #3449

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rusk-wallet/src/wallet/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {
}

/// Executes a generic contract call, paying gas from a public account.
#[allow(clippy::too_many_arguments)]
pub async fn moonlight_execute(
&self,
sender_idx: u8,
Expand Down
18 changes: 11 additions & 7 deletions rusk/benches/block_ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use criterion::{
};
use dusk_core::transfer::Transaction as ProtocolTransaction;
use node_data::bls::PublicKey;
use node_data::ledger::Transaction;
use node_data::ledger::{Header, Transaction};
use rand::prelude::StdRng;
use rand::seq::SliceRandom;
use rand::SeedableRng;
Expand Down Expand Up @@ -116,14 +116,21 @@ fn bench_accept(
const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000;
const BLOCK_HASH: [u8; 32] = [0u8; 32];

let generator = PublicKey::new(*DUSK_CONSENSUS_KEY).into_inner();
let generator = *PublicKey::new(*DUSK_CONSENSUS_KEY).bytes();

let txs = Arc::new(txs);
let prev_root = rusk.state_root();

for n_txs in N_TXS {
let rusk = rusk.clone();
let txs = txs.clone();
let header = Header {
height: BLOCK_HEIGHT,
gas_limit: BLOCK_GAS_LIMIT,
hash: BLOCK_HASH,
generator_bls_pubkey: generator,
..Default::default()
};

group.bench_with_input(
BenchmarkId::new(name, format!("{} TXs", n_txs)),
Expand All @@ -134,11 +141,8 @@ fn bench_accept(

rusk.accept_transactions(
prev_root,
BLOCK_HEIGHT,
BLOCK_GAS_LIMIT,
BLOCK_HASH,
generator,
txs,
&header,
&txs,
None,
vec![],
&[],
Expand Down
51 changes: 21 additions & 30 deletions rusk/src/lib/node/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::{mpsc, Arc};
use std::time::Instant;
use std::{fs, io};

use dusk_bytes::Serializable;
use dusk_bytes::{DeserializableSlice, Serializable};
use dusk_consensus::config::{
ratification_extra, ratification_quorum, validation_extra,
validation_quorum, MAX_NUMBER_OF_TRANSACTIONS,
Expand All @@ -31,7 +31,7 @@ use dusk_vm::{
#[cfg(feature = "archive")]
use node::archive::Archive;
use node_data::events::contract::ContractTxEvent;
use node_data::ledger::{Hash, Slash, SpentTransaction, Transaction};
use node_data::ledger::{Header, Slash, SpentTransaction, Transaction};
use parking_lot::RwLock;
use rusk_profile::to_rusk_state_id_path;
use tokio::sync::broadcast;
Expand Down Expand Up @@ -238,26 +238,22 @@ impl Rusk {
}

/// Verify the given transactions are ok.
#[allow(clippy::too_many_arguments)]
pub fn verify_transactions(
&self,
prev_commit: [u8; 32],
block_height: u64,
block_hash: Hash,
block_gas_limit: u64,
header: &Header,
generator: &BlsPublicKey,
txs: &[Transaction],
slashing: Vec<Slash>,
voters: &[Voter],
) -> Result<(Vec<SpentTransaction>, VerificationOutput)> {
let block_height = header.height;
let session = self.new_block_session(block_height, prev_commit)?;
let execution_config = self.vm_config.to_execution_config(block_height);

accept(
session,
block_height,
block_hash,
block_gas_limit,
header,
generator,
txs,
slashing,
Expand All @@ -278,15 +274,11 @@ impl Rusk {
/// - VerificationOutput - The verification output.
/// - Vec<ContractTxEvent> - All contract events that were emitted from the
/// given transactions.
#[allow(clippy::too_many_arguments)]
pub fn accept_transactions(
&self,
prev_commit: [u8; 32],
block_height: u64,
block_gas_limit: u64,
block_hash: Hash,
generator: BlsPublicKey,
txs: Vec<Transaction>,
header: &Header,
txs: &[Transaction],
consistency_check: Option<VerificationOutput>,
slashing: Vec<Slash>,
voters: &[Voter],
Expand All @@ -295,17 +287,20 @@ impl Rusk {
VerificationOutput,
Vec<ContractTxEvent>,
)> {
let generator = header.generator_bls_pubkey.inner();
let generator = BlsPublicKey::from_slice(generator).map_err(|e| {
Error::Other(anyhow::anyhow!("Error in from_slice {e:?}").into())
})?;
let block_height = header.height;
let session = self.new_block_session(block_height, prev_commit)?;

let execution_config = self.vm_config.to_execution_config(block_height);

let (spent_txs, verification_output, session, events) = accept(
session,
block_height,
block_hash,
block_gas_limit,
header,
&generator,
&txs[..],
txs,
slashing,
voters,
&execution_config,
Expand Down Expand Up @@ -534,12 +529,9 @@ impl Rusk {
}
}

#[allow(clippy::too_many_arguments)]
fn accept(
session: Session,
block_height: u64,
block_hash: Hash,
block_gas_limit: u64,
header: &Header,
generator: &BlsPublicKey,
txs: &[Transaction],
slashing: Vec<Slash>,
Expand All @@ -553,7 +545,8 @@ fn accept(
)> {
let mut session = session;

let mut block_gas_left = block_gas_limit;
let mut block_gas_left = header.gas_limit;
let block_height = header.height;

let mut spent_txs = Vec::with_capacity(txs.len());
let mut dusk_spent = 0;
Expand Down Expand Up @@ -606,13 +599,11 @@ fn accept(

event_bloom.add_events(&coinbase_events);

let coinbase_events: Vec<_> = coinbase_events
.into_iter()
.map(|event| ContractTxEvent {
let coinbase_events =
coinbase_events.into_iter().map(|event| ContractTxEvent {
event: event.into(),
origin: block_hash,
})
.collect();
origin: header.hash,
});
events.extend(coinbase_events);

let state_root = session.root();
Expand Down
27 changes: 10 additions & 17 deletions rusk/src/lib/node/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl VMExecution for Rusk {
voters: &[Voter],
) -> Result<VerificationOutput, VstError> {
info!("Received verify_state_transition request");
let generator = blk.header().generator_bls_pubkey;
let generator = BlsPublicKey::from_slice(&generator.0)
let generator = blk.header().generator_bls_pubkey.inner();
let generator = BlsPublicKey::from_slice(generator)
.map_err(VstError::InvalidGenerator)?;

let slashing =
Expand All @@ -63,9 +63,7 @@ impl VMExecution for Rusk {
let (_, verification_output) = self
.verify_transactions(
prev_commit,
blk.header().height,
blk.header().hash,
blk.header().gas_limit,
blk.header(),
&generator,
blk.txs(),
slashing,
Expand Down Expand Up @@ -93,24 +91,19 @@ impl VMExecution for Rusk {
Vec<ContractTxEvent>,
)> {
debug!("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 expected = VerificationOutput {
event_bloom: blk.header().event_bloom,
state_root: blk.header().state_hash,
};

let (txs, verification_output, contract_events) = self
.accept_transactions(
prev_root,
blk.header().height,
blk.header().gas_limit,
blk.header().hash,
generator,
blk.txs().clone(),
Some(VerificationOutput {
state_root: blk.header().state_hash,
event_bloom: blk.header().event_bloom,
}),
blk.header(),
blk.txs(),
Some(expected),
slashing,
voters,
)
Expand Down
5 changes: 0 additions & 5 deletions rusk/tests/common/wallet/test_wallet/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ where
}

/// Executes a generic contract call, paying gas from a public account.
#[allow(clippy::too_many_arguments)]
pub fn moonlight_execute(
&self,
sender_idx: u8,
Expand Down Expand Up @@ -382,7 +381,6 @@ where

/// Execute a generic contract call or deployment, using Phoenix notes to
/// pay for gas.
#[allow(clippy::too_many_arguments)]
pub fn phoenix_execute<Rng: RngCore + CryptoRng>(
&self,
rng: &mut Rng,
Expand Down Expand Up @@ -432,7 +430,6 @@ where
}

/// Transfer Dusk in the form of Phoenix notes from one key to another.
#[allow(clippy::too_many_arguments)]
pub fn phoenix_transfer<Rng: RngCore + CryptoRng>(
&self,
rng: &mut Rng,
Expand Down Expand Up @@ -483,7 +480,6 @@ where
}

/// Stakes an amount of Dusk using Phoenix notes.
#[allow(clippy::too_many_arguments)]
pub fn phoenix_stake<Rng: RngCore + CryptoRng>(
&self,
rng: &mut Rng,
Expand Down Expand Up @@ -796,7 +792,6 @@ where
}

/// Stakes an amount of Dusk using a Moonlight account.
#[allow(clippy::too_many_arguments)]
pub fn moonlight_stake(
&self,
sender_index: u8,
Expand Down
Loading