From 95ed40222827c5aba0259ce4a128ab51af54631b Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 20 Mar 2019 16:13:06 +1100 Subject: [PATCH] op-pool: rename to verify_*_time_independent_only --- eth2/operation_pool/src/lib.rs | 4 +-- .../src/per_block_processing.rs | 8 ++--- .../per_block_processing/verify_transfer.rs | 30 +++++++++++-------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/eth2/operation_pool/src/lib.rs b/eth2/operation_pool/src/lib.rs index ecf4e41e7..ff5a7416b 100644 --- a/eth2/operation_pool/src/lib.rs +++ b/eth2/operation_pool/src/lib.rs @@ -4,7 +4,7 @@ use ssz::ssz_encode; use state_processing::per_block_processing::errors::ProposerSlashingValidationError; use state_processing::per_block_processing::{ validate_attestation, verify_deposit, verify_exit, verify_exit_time_independent_only, - verify_proposer_slashing, verify_transfer, verify_transfer_partial, + verify_proposer_slashing, verify_transfer, verify_transfer_time_independent_only, }; use std::collections::{btree_map::Entry, hash_map, BTreeMap, HashMap, HashSet}; use types::chain_spec::Domain; @@ -322,7 +322,7 @@ impl OperationPool { // The signature of the transfer isn't hashed, but because we check // it before we insert into the HashSet, we can't end up with duplicate // transactions. - verify_transfer_partial(state, &transfer, spec, true).map_err(|_| ())?; + verify_transfer_time_independent_only(state, &transfer, spec).map_err(|_| ())?; self.transfers.insert(transfer); Ok(()) } diff --git a/eth2/state_processing/src/per_block_processing.rs b/eth2/state_processing/src/per_block_processing.rs index 617da00d4..55e2c29d0 100644 --- a/eth2/state_processing/src/per_block_processing.rs +++ b/eth2/state_processing/src/per_block_processing.rs @@ -9,12 +9,12 @@ pub use self::verify_attester_slashing::{ }; pub use self::verify_proposer_slashing::verify_proposer_slashing; pub use validate_attestation::{validate_attestation, validate_attestation_without_signature}; -pub use verify_deposit::{ - get_existing_validator_index, verify_deposit, verify_deposit_index, -}; +pub use verify_deposit::{get_existing_validator_index, verify_deposit, verify_deposit_index}; pub use verify_exit::{verify_exit, verify_exit_time_independent_only}; pub use verify_slashable_attestation::verify_slashable_attestation; -pub use verify_transfer::{execute_transfer, verify_transfer, verify_transfer_partial}; +pub use verify_transfer::{ + execute_transfer, verify_transfer, verify_transfer_time_independent_only, +}; pub mod errors; mod validate_attestation; diff --git a/eth2/state_processing/src/per_block_processing/verify_transfer.rs b/eth2/state_processing/src/per_block_processing/verify_transfer.rs index 4f3815797..ac9e9aa09 100644 --- a/eth2/state_processing/src/per_block_processing/verify_transfer.rs +++ b/eth2/state_processing/src/per_block_processing/verify_transfer.rs @@ -16,18 +16,24 @@ pub fn verify_transfer( transfer: &Transfer, spec: &ChainSpec, ) -> Result<(), Error> { - verify_transfer_partial(state, transfer, spec, false) + verify_transfer_parametric(state, transfer, spec, false) } -/// Parametric version of `verify_transfer` that allows some checks to be skipped. -/// -/// In everywhere except the operation pool, `verify_transfer` should be preferred over this -/// function. -pub fn verify_transfer_partial( +/// Like `verify_transfer` but doesn't run checks which may become true in future states. +pub fn verify_transfer_time_independent_only( state: &BeaconState, transfer: &Transfer, spec: &ChainSpec, - for_op_pool: bool, +) -> Result<(), Error> { + verify_transfer_parametric(state, transfer, spec, true) +} + +/// Parametric version of `verify_transfer` that allows some checks to be skipped. +fn verify_transfer_parametric( + state: &BeaconState, + transfer: &Transfer, + spec: &ChainSpec, + time_independent_only: bool, ) -> Result<(), Error> { let sender_balance = *state .validator_balances @@ -40,17 +46,17 @@ pub fn verify_transfer_partial( .ok_or_else(|| Error::Invalid(Invalid::FeeOverflow(transfer.amount, transfer.fee)))?; verify!( - for_op_pool || sender_balance >= transfer.amount, + time_independent_only || sender_balance >= transfer.amount, Invalid::FromBalanceInsufficient(transfer.amount, sender_balance) ); verify!( - for_op_pool || sender_balance >= transfer.fee, + time_independent_only || sender_balance >= transfer.fee, Invalid::FromBalanceInsufficient(transfer.fee, sender_balance) ); verify!( - for_op_pool + time_independent_only || (sender_balance == total_amount) || (sender_balance >= (total_amount + spec.min_deposit_amount)), Invalid::InvalidResultingFromBalance( @@ -59,7 +65,7 @@ pub fn verify_transfer_partial( ) ); - if for_op_pool { + if time_independent_only { verify!( state.slot <= transfer.slot, Invalid::TransferSlotInPast(state.slot, transfer.slot) @@ -78,7 +84,7 @@ pub fn verify_transfer_partial( let epoch = state.slot.epoch(spec.slots_per_epoch); verify!( - for_op_pool + time_independent_only || sender_validator.is_withdrawable_at(epoch) || sender_validator.activation_epoch == spec.far_future_epoch, Invalid::FromValidatorIneligableForTransfer(transfer.sender)