Pass errors back from block ops processing

This commit is contained in:
Paul Hauner 2019-03-29 18:54:01 +11:00
parent 8b1a91e9ee
commit 2b53851062
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 53 additions and 32 deletions

View File

@ -7,10 +7,15 @@ use db::{
}; };
use fork_choice::{ForkChoice, ForkChoiceError}; use fork_choice::{ForkChoice, ForkChoiceError};
use log::{debug, trace, warn}; use log::{debug, trace, warn};
use operation_pool::DepositInsertStatus;
use operation_pool::OperationPool; use operation_pool::OperationPool;
use parking_lot::{RwLock, RwLockReadGuard}; use parking_lot::{RwLock, RwLockReadGuard};
use slot_clock::SlotClock; use slot_clock::SlotClock;
use ssz::ssz_encode; use ssz::ssz_encode;
pub use state_processing::per_block_processing::errors::{
AttestationValidationError, AttesterSlashingValidationError, DepositValidationError,
ExitValidationError, ProposerSlashingValidationError, TransferValidationError,
};
use state_processing::{ use state_processing::{
per_block_processing, per_block_processing_without_verifying_block_signature, per_block_processing, per_block_processing_without_verifying_block_signature,
per_slot_processing, BlockProcessingError, SlotProcessingError, per_slot_processing, BlockProcessingError, SlotProcessingError,
@ -545,57 +550,67 @@ where
/// ///
/// If valid, the attestation is added to the `op_pool` and aggregated with another attestation /// If valid, the attestation is added to the `op_pool` and aggregated with another attestation
/// if possible. /// if possible.
pub fn process_attestation(&self, attestation: Attestation) { pub fn process_attestation(
let _ = &self,
self.op_pool attestation: Attestation,
.write() ) -> Result<(), AttestationValidationError> {
.insert_attestation(attestation, &*self.state.read(), &self.spec); self.op_pool
.write()
.insert_attestation(attestation, &*self.state.read(), &self.spec)
} }
/// Accept some deposit and queue it for inclusion in an appropriate block. /// Accept some deposit and queue it for inclusion in an appropriate block.
pub fn receive_deposit_for_inclusion(&self, deposit: Deposit) { pub fn receive_deposit_for_inclusion(
// Bad deposits are ignored. &self,
let _ = self deposit: Deposit,
.op_pool ) -> Result<DepositInsertStatus, DepositValidationError> {
self.op_pool
.write() .write()
.insert_deposit(deposit, &*self.state.read(), &self.spec); .insert_deposit(deposit, &*self.state.read(), &self.spec)
} }
/// Accept some exit and queue it for inclusion in an appropriate block. /// Accept some exit and queue it for inclusion in an appropriate block.
pub fn receive_exit_for_inclusion(&self, exit: VoluntaryExit) { pub fn receive_exit_for_inclusion(
// Bad exits are ignored &self,
let _ = self exit: VoluntaryExit,
.op_pool ) -> Result<(), ExitValidationError> {
self.op_pool
.write() .write()
.insert_voluntary_exit(exit, &*self.state.read(), &self.spec); .insert_voluntary_exit(exit, &*self.state.read(), &self.spec)
} }
/// Accept some transfer and queue it for inclusion in an appropriate block. /// Accept some transfer and queue it for inclusion in an appropriate block.
pub fn receive_transfer_for_inclusion(&self, transfer: Transfer) { pub fn receive_transfer_for_inclusion(
// Bad transfers are ignored. &self,
let _ = self transfer: Transfer,
.op_pool ) -> Result<(), TransferValidationError> {
self.op_pool
.write() .write()
.insert_transfer(transfer, &*self.state.read(), &self.spec); .insert_transfer(transfer, &*self.state.read(), &self.spec)
} }
/// Accept some proposer slashing and queue it for inclusion in an appropriate block. /// Accept some proposer slashing and queue it for inclusion in an appropriate block.
pub fn receive_proposer_slashing_for_inclusion(&self, proposer_slashing: ProposerSlashing) { pub fn receive_proposer_slashing_for_inclusion(
// Bad proposer slashings are ignored. &self,
let _ = self.op_pool.write().insert_proposer_slashing( proposer_slashing: ProposerSlashing,
) -> Result<(), ProposerSlashingValidationError> {
self.op_pool.write().insert_proposer_slashing(
proposer_slashing, proposer_slashing,
&*self.state.read(), &*self.state.read(),
&self.spec, &self.spec,
); )
} }
/// Accept some attester slashing and queue it for inclusion in an appropriate block. /// Accept some attester slashing and queue it for inclusion in an appropriate block.
pub fn receive_attester_slashing_for_inclusion(&self, attester_slashing: AttesterSlashing) { pub fn receive_attester_slashing_for_inclusion(
let _ = self.op_pool.write().insert_attester_slashing( &self,
attester_slashing: AttesterSlashing,
) -> Result<(), AttesterSlashingValidationError> {
self.op_pool.write().insert_attester_slashing(
attester_slashing, attester_slashing,
&*self.state.read(), &*self.state.read(),
&self.spec, &self.spec,
); )
} }
/// Returns `true` if the given block root has not been processed. /// Returns `true` if the given block root has not been processed.

View File

@ -285,7 +285,9 @@ impl BeaconChainHarness {
/// If a new `ValidatorHarness` was created, the validator should become fully operational as /// If a new `ValidatorHarness` was created, the validator should become fully operational as
/// if the validator were created during `BeaconChainHarness` instantiation. /// if the validator were created during `BeaconChainHarness` instantiation.
pub fn add_deposit(&mut self, deposit: Deposit, keypair: Option<Keypair>) { pub fn add_deposit(&mut self, deposit: Deposit, keypair: Option<Keypair>) {
self.beacon_chain.receive_deposit_for_inclusion(deposit); self.beacon_chain
.receive_deposit_for_inclusion(deposit)
.unwrap();
// If a keypair is present, add a new `ValidatorHarness` to the rig. // If a keypair is present, add a new `ValidatorHarness` to the rig.
if let Some(keypair) = keypair { if let Some(keypair) = keypair {
@ -301,24 +303,28 @@ impl BeaconChainHarness {
/// will stop receiving duties from the beacon chain and just do nothing when prompted to /// will stop receiving duties from the beacon chain and just do nothing when prompted to
/// produce/attest. /// produce/attest.
pub fn add_exit(&mut self, exit: VoluntaryExit) { pub fn add_exit(&mut self, exit: VoluntaryExit) {
self.beacon_chain.receive_exit_for_inclusion(exit); self.beacon_chain.receive_exit_for_inclusion(exit).unwrap();
} }
/// Submit an transfer to the `BeaconChain` for inclusion in some block. /// Submit an transfer to the `BeaconChain` for inclusion in some block.
pub fn add_transfer(&mut self, transfer: Transfer) { pub fn add_transfer(&mut self, transfer: Transfer) {
self.beacon_chain.receive_transfer_for_inclusion(transfer); self.beacon_chain
.receive_transfer_for_inclusion(transfer)
.unwrap();
} }
/// Submit a proposer slashing to the `BeaconChain` for inclusion in some block. /// Submit a proposer slashing to the `BeaconChain` for inclusion in some block.
pub fn add_proposer_slashing(&mut self, proposer_slashing: ProposerSlashing) { pub fn add_proposer_slashing(&mut self, proposer_slashing: ProposerSlashing) {
self.beacon_chain self.beacon_chain
.receive_proposer_slashing_for_inclusion(proposer_slashing); .receive_proposer_slashing_for_inclusion(proposer_slashing)
.unwrap();
} }
/// Submit an attester slashing to the `BeaconChain` for inclusion in some block. /// Submit an attester slashing to the `BeaconChain` for inclusion in some block.
pub fn add_attester_slashing(&mut self, attester_slashing: AttesterSlashing) { pub fn add_attester_slashing(&mut self, attester_slashing: AttesterSlashing) {
self.beacon_chain self.beacon_chain
.receive_attester_slashing_for_inclusion(attester_slashing); .receive_attester_slashing_for_inclusion(attester_slashing)
.unwrap();
} }
/// Executes the fork choice rule on the `BeaconChain`, selecting a new canonical head. /// Executes the fork choice rule on the `BeaconChain`, selecting a new canonical head.