Pass errors back from block ops processing
This commit is contained in:
parent
8b1a91e9ee
commit
2b53851062
@ -7,10 +7,15 @@ use db::{
|
||||
};
|
||||
use fork_choice::{ForkChoice, ForkChoiceError};
|
||||
use log::{debug, trace, warn};
|
||||
use operation_pool::DepositInsertStatus;
|
||||
use operation_pool::OperationPool;
|
||||
use parking_lot::{RwLock, RwLockReadGuard};
|
||||
use slot_clock::SlotClock;
|
||||
use ssz::ssz_encode;
|
||||
pub use state_processing::per_block_processing::errors::{
|
||||
AttestationValidationError, AttesterSlashingValidationError, DepositValidationError,
|
||||
ExitValidationError, ProposerSlashingValidationError, TransferValidationError,
|
||||
};
|
||||
use state_processing::{
|
||||
per_block_processing, per_block_processing_without_verifying_block_signature,
|
||||
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 possible.
|
||||
pub fn process_attestation(&self, attestation: Attestation) {
|
||||
let _ =
|
||||
self.op_pool
|
||||
.write()
|
||||
.insert_attestation(attestation, &*self.state.read(), &self.spec);
|
||||
pub fn process_attestation(
|
||||
&self,
|
||||
attestation: Attestation,
|
||||
) -> Result<(), AttestationValidationError> {
|
||||
self.op_pool
|
||||
.write()
|
||||
.insert_attestation(attestation, &*self.state.read(), &self.spec)
|
||||
}
|
||||
|
||||
/// Accept some deposit and queue it for inclusion in an appropriate block.
|
||||
pub fn receive_deposit_for_inclusion(&self, deposit: Deposit) {
|
||||
// Bad deposits are ignored.
|
||||
let _ = self
|
||||
.op_pool
|
||||
pub fn receive_deposit_for_inclusion(
|
||||
&self,
|
||||
deposit: Deposit,
|
||||
) -> Result<DepositInsertStatus, DepositValidationError> {
|
||||
self.op_pool
|
||||
.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.
|
||||
pub fn receive_exit_for_inclusion(&self, exit: VoluntaryExit) {
|
||||
// Bad exits are ignored
|
||||
let _ = self
|
||||
.op_pool
|
||||
pub fn receive_exit_for_inclusion(
|
||||
&self,
|
||||
exit: VoluntaryExit,
|
||||
) -> Result<(), ExitValidationError> {
|
||||
self.op_pool
|
||||
.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.
|
||||
pub fn receive_transfer_for_inclusion(&self, transfer: Transfer) {
|
||||
// Bad transfers are ignored.
|
||||
let _ = self
|
||||
.op_pool
|
||||
pub fn receive_transfer_for_inclusion(
|
||||
&self,
|
||||
transfer: Transfer,
|
||||
) -> Result<(), TransferValidationError> {
|
||||
self.op_pool
|
||||
.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.
|
||||
pub fn receive_proposer_slashing_for_inclusion(&self, proposer_slashing: ProposerSlashing) {
|
||||
// Bad proposer slashings are ignored.
|
||||
let _ = self.op_pool.write().insert_proposer_slashing(
|
||||
pub fn receive_proposer_slashing_for_inclusion(
|
||||
&self,
|
||||
proposer_slashing: ProposerSlashing,
|
||||
) -> Result<(), ProposerSlashingValidationError> {
|
||||
self.op_pool.write().insert_proposer_slashing(
|
||||
proposer_slashing,
|
||||
&*self.state.read(),
|
||||
&self.spec,
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
/// Accept some attester slashing and queue it for inclusion in an appropriate block.
|
||||
pub fn receive_attester_slashing_for_inclusion(&self, attester_slashing: AttesterSlashing) {
|
||||
let _ = self.op_pool.write().insert_attester_slashing(
|
||||
pub fn receive_attester_slashing_for_inclusion(
|
||||
&self,
|
||||
attester_slashing: AttesterSlashing,
|
||||
) -> Result<(), AttesterSlashingValidationError> {
|
||||
self.op_pool.write().insert_attester_slashing(
|
||||
attester_slashing,
|
||||
&*self.state.read(),
|
||||
&self.spec,
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns `true` if the given block root has not been processed.
|
||||
|
@ -285,7 +285,9 @@ impl BeaconChainHarness {
|
||||
/// If a new `ValidatorHarness` was created, the validator should become fully operational as
|
||||
/// if the validator were created during `BeaconChainHarness` instantiation.
|
||||
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 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
|
||||
/// produce/attest.
|
||||
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.
|
||||
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.
|
||||
pub fn add_proposer_slashing(&mut self, proposer_slashing: ProposerSlashing) {
|
||||
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.
|
||||
pub fn add_attester_slashing(&mut self, attester_slashing: AttesterSlashing) {
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user