Skip to content
Merged
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
2 changes: 1 addition & 1 deletion consensus/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct CallParams {
pub round: u64,
pub generator_pubkey: node_data::bls::PublicKey,
pub to_slash: Vec<Slash>,
pub voters_pubkey: Option<Vec<Voter>>,
pub voters_pubkey: Vec<Voter>,
pub max_txs_bytes: usize,
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/src/proposal/block_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<T: Operations> Generator<T> {
round: ru.round,
generator_pubkey: ru.pubkey_bls.clone(),
to_slash,
voters_pubkey: Some(voters.to_owned()),
voters_pubkey: voters.to_owned(),
max_txs_bytes,
};

Expand Down
2 changes: 1 addition & 1 deletion node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {

let (txs, rolling_result) = self.db.read().await.update(|db| {
let (txs, verification_output) =
vm.accept(blk, Some(&prev_block_voters[..]))?;
vm.accept(blk, &prev_block_voters[..])?;
for spent_tx in txs.iter() {
events.push(TransactionEvent::Executed(spent_tx).into());
}
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl<DB: database::DB, VM: vm::VMExecution> Operations for Executor<DB, VM> {

let vm = self.vm.read().await;

vm.verify_state_transition(blk, Some(voters))
vm.verify_state_transition(blk, voters)
.map_err(OperationError::InvalidVST)
}

Expand Down
4 changes: 2 additions & 2 deletions node/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ pub trait VMExecution: Send + Sync + 'static {
fn verify_state_transition(
&self,
blk: &Block,
voters: Option<&[Voter]>,
voters: &[Voter],
) -> anyhow::Result<VerificationOutput>;

fn accept(
&self,
blk: &Block,
voters: Option<&[Voter]>,
voters: &[Voter],
) -> anyhow::Result<(Vec<SpentTransaction>, VerificationOutput)>;

fn finalize_state(
Expand Down
2 changes: 1 addition & 1 deletion rusk/benches/block_ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn bench_accept(
txs,
None,
vec![],
None,
&[],
)
.expect("Accepting transactions should succeed");

Expand Down
19 changes: 8 additions & 11 deletions rusk/src/lib/node/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl Rusk {
let generator = params.generator_pubkey.inner();
let to_slash = params.to_slash.clone();

let voters = params.voters_pubkey.as_ref().map(|voters| &voters[..]);
let voters = &params.voters_pubkey[..];

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

Expand Down Expand Up @@ -280,7 +280,7 @@ impl Rusk {
generator: &BlsPublicKey,
txs: &[Transaction],
slashing: Vec<Slash>,
voters: Option<&[Voter]>,
voters: &[Voter],
) -> Result<(Vec<SpentTransaction>, VerificationOutput)> {
let session = self.session(block_height, None)?;

Expand Down Expand Up @@ -312,7 +312,7 @@ impl Rusk {
txs: Vec<Transaction>,
consistency_check: Option<VerificationOutput>,
slashing: Vec<Slash>,
voters: Option<&[Voter]>,
voters: &[Voter],
) -> Result<(Vec<SpentTransaction>, VerificationOutput)> {
let session = self.session(block_height, None)?;

Expand Down Expand Up @@ -524,7 +524,7 @@ fn accept(
generator: &BlsPublicKey,
txs: &[Transaction],
slashing: Vec<Slash>,
voters: Option<&[Voter]>,
voters: &[Voter],
gas_per_deploy_byte: Option<u64>,
min_deployment_gas_price: Option<u64>,
) -> Result<(
Expand Down Expand Up @@ -793,18 +793,17 @@ fn reward_slash_and_update_root(
dusk_spent: Dusk,
generator: &BlsPublicKey,
slashing: Vec<Slash>,
voters: Option<&[Voter]>,
voters: &[Voter],
) -> Result<Vec<Event>> {
let (dusk_value, generator_reward, generator_extra_reward, voters_reward) =
coinbase_value(block_height, dusk_spent);

let credits = voters
.unwrap_or_default()
.iter()
.map(|(_, credits)| *credits as u64)
.sum::<u64>();

if voters.is_some() && credits == 0 && block_height > 1 {
if !voters.is_empty() && credits == 0 && block_height > 1 {
return Err(InvalidCreditsCount(block_height, 0));
}

Expand All @@ -820,9 +819,7 @@ fn reward_slash_and_update_root(
}

// Additionally we also reward the voters.
if let Some(voters) = &voters {
num_rewards += voters.len();
}
num_rewards += voters.len();

let mut rewards = Vec::with_capacity(num_rewards);

Expand Down Expand Up @@ -850,7 +847,7 @@ fn reward_slash_and_update_root(
/ (VALIDATION_COMMITTEE_CREDITS + RATIFICATION_COMMITTEE_CREDITS)
as u64;

for (to_voter, credits) in voters.unwrap_or_default() {
for (to_voter, credits) in voters {
let voter = to_voter.inner();
let voter_reward = *credits as u64 * credit_reward;
rewards.push(Reward {
Expand Down
4 changes: 2 additions & 2 deletions rusk/src/lib/node/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl VMExecution for Rusk {
fn verify_state_transition(
&self,
blk: &Block,
voters: Option<&[Voter]>,
voters: &[Voter],
) -> anyhow::Result<VerificationOutput> {
info!("Received verify_state_transition request");
let generator = blk.header().generator_bls_pubkey;
Expand All @@ -77,7 +77,7 @@ impl VMExecution for Rusk {
fn accept(
&self,
blk: &Block,
voters: Option<&[Voter]>,
voters: &[Voter],
) -> anyhow::Result<(Vec<SpentTransaction>, VerificationOutput)> {
info!("Received accept request");
let generator = blk.header().generator_bls_pubkey;
Expand Down
6 changes: 3 additions & 3 deletions rusk/tests/common/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn generator_procedure(
round,
generator_pubkey,
to_slash,
voters_pubkey: Some(voters.clone()),
voters_pubkey: voters.clone(),
max_txs_bytes: usize::MAX,
};

Expand Down Expand Up @@ -162,10 +162,10 @@ pub fn generator_procedure(
)
.expect("valid block");

let verify_output = rusk.verify_state_transition(&block, Some(&voters))?;
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, Some(&voters))?;
let (accept_txs, accept_output) = rusk.accept(&block, &voters)?;

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

Expand Down
Loading