op-pool: rename to verify_*_time_independent_only

This commit is contained in:
Michael Sproul 2019-03-20 16:13:06 +11:00
parent b2fe14e12c
commit 95ed402228
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
3 changed files with 24 additions and 18 deletions

View File

@ -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(())
}

View File

@ -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;

View File

@ -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)