Add checks for eth1 chain connection before inserting to op pool (#868)

This commit is contained in:
realbigsean 2020-03-01 22:04:49 -05:00 committed by GitHub
parent fbb630793e
commit 6368be148d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 25 deletions

View File

@ -977,8 +977,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// Provide the valid attestation to op pool, which may choose to retain the // Provide the valid attestation to op pool, which may choose to retain the
// attestation for inclusion in a future block. // attestation for inclusion in a future block.
if self.eth1_chain.is_some() {
self.op_pool self.op_pool
.insert_attestation(attestation, state, &self.spec)?; .insert_attestation(attestation, state, &self.spec)?;
};
// Update the metrics. // Update the metrics.
metrics::inc_counter(&metrics::ATTESTATION_PROCESSING_SUCCESSES); metrics::inc_counter(&metrics::ATTESTATION_PROCESSING_SUCCESSES);
@ -993,7 +995,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
exit: SignedVoluntaryExit, exit: SignedVoluntaryExit,
) -> Result<(), ExitValidationError> { ) -> Result<(), ExitValidationError> {
match self.wall_clock_state() { match self.wall_clock_state() {
Ok(state) => self.op_pool.insert_voluntary_exit(exit, &state, &self.spec), Ok(state) => {
if self.eth1_chain.is_some() {
self.op_pool.insert_voluntary_exit(exit, &state, &self.spec)
} else {
Ok(())
}
}
Err(e) => { Err(e) => {
error!( error!(
&self.log, &self.log,
@ -1013,8 +1021,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
) -> Result<(), ProposerSlashingValidationError> { ) -> Result<(), ProposerSlashingValidationError> {
match self.wall_clock_state() { match self.wall_clock_state() {
Ok(state) => { Ok(state) => {
if self.eth1_chain.is_some() {
self.op_pool self.op_pool
.insert_proposer_slashing(proposer_slashing, &state, &self.spec) .insert_proposer_slashing(proposer_slashing, &state, &self.spec)
} else {
Ok(())
}
} }
Err(e) => { Err(e) => {
error!( error!(
@ -1035,8 +1047,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
) -> Result<(), AttesterSlashingValidationError> { ) -> Result<(), AttesterSlashingValidationError> {
match self.wall_clock_state() { match self.wall_clock_state() {
Ok(state) => { Ok(state) => {
if self.eth1_chain.is_some() {
self.op_pool self.op_pool
.insert_attester_slashing(attester_slashing, &state, &self.spec) .insert_attester_slashing(attester_slashing, &state, &self.spec)
} else {
Ok(())
}
} }
Err(e) => { Err(e) => {
error!( error!(

View File

@ -518,6 +518,7 @@ pub fn proposer_slashing<T: BeaconChainTypes>(
.and_then(move |proposer_slashing| { .and_then(move |proposer_slashing| {
let spec = &beacon_chain.spec; let spec = &beacon_chain.spec;
let state = &beacon_chain.head().unwrap().beacon_state; let state = &beacon_chain.head().unwrap().beacon_state;
if beacon_chain.eth1_chain.is_some() {
beacon_chain beacon_chain
.op_pool .op_pool
.insert_proposer_slashing(proposer_slashing, state, spec) .insert_proposer_slashing(proposer_slashing, state, spec)
@ -527,6 +528,11 @@ pub fn proposer_slashing<T: BeaconChainTypes>(
e e
)) ))
}) })
} else {
Err(ApiError::BadRequest(
"Cannot insert proposer slashing on node without Eth1 connection.".to_string(),
))
}
}) })
.and_then(|_| response_builder?.body(&true)); .and_then(|_| response_builder?.body(&true));
@ -554,6 +560,7 @@ pub fn attester_slashing<T: BeaconChainTypes>(
.and_then(move |attester_slashing| { .and_then(move |attester_slashing| {
let spec = &beacon_chain.spec; let spec = &beacon_chain.spec;
let state = &beacon_chain.head().unwrap().beacon_state; let state = &beacon_chain.head().unwrap().beacon_state;
if beacon_chain.eth1_chain.is_some() {
beacon_chain beacon_chain
.op_pool .op_pool
.insert_attester_slashing(attester_slashing, state, spec) .insert_attester_slashing(attester_slashing, state, spec)
@ -563,6 +570,11 @@ pub fn attester_slashing<T: BeaconChainTypes>(
e e
)) ))
}) })
} else {
Err(ApiError::BadRequest(
"Cannot insert attester slashing on node without Eth1 connection.".to_string(),
))
}
}) })
.and_then(|_| response_builder?.body(&true)); .and_then(|_| response_builder?.body(&true));