failed broadcast is not a routing error (#3843)

a notice in the log is enough - we don't want the REST API to return an
error in this case because that makes the validator client think
something is seriously wrong (like the BN or message being broken)
This commit is contained in:
Jacek Sieka 2022-07-07 14:57:56 +02:00 committed by GitHub
parent 35712e0dd0
commit 9de2c6171f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 82 additions and 102 deletions

View File

@ -133,20 +133,26 @@ proc routeSignedBeaconBlock*(
let let
sendTime = router[].getCurrentBeaconTime() sendTime = router[].getCurrentBeaconTime()
delay = sendTime - blck.message.slot.block_deadline() delay = sendTime - blck.message.slot.block_deadline()
# The block passed basic gossip validation - we can "safely" broadcast it
# now. In fact, per the spec, we should broadcast it even if it later fails
# to apply to our state.
res = await router[].network.broadcastBeaconBlock(blck)
# The block passed basic gossip validation - we can "safely" broadcast it now. if res.isOk():
# In fact, per the spec, we should broadcast it even if it later fails to beacon_blocks_sent.inc()
# apply to our state. beacon_blocks_sent_delay.observe(delay.toFloatSeconds())
block:
let res = await router[].network.broadcastBeaconBlock(blck)
if res.isErr:
notice "Block not sent",
blockRoot = shortLog(blck.root), blck = shortLog(blck.message),
signature = shortLog(blck.signature), error = res.error()
return err(res.error())
let newBlockRef = await router[].blockProcessor.storeBlock( notice "Block sent",
MsgSource.api, sendTime, blck, true) blockRoot = shortLog(blck.root), blck = shortLog(blck.message),
signature = shortLog(blck.signature), delay
else: # "no broadcast" is not a fatal error
notice "Block not sent",
blockRoot = shortLog(blck.root), blck = shortLog(blck.message),
signature = shortLog(blck.signature), error = res.error()
let
newBlockRef = await router[].blockProcessor.storeBlock(
MsgSource.api, sendTime, blck, true)
# The boolean we return tells the caller whether the block was integrated # The boolean we return tells the caller whether the block was integrated
# into the chain # into the chain
@ -156,13 +162,6 @@ proc routeSignedBeaconBlock*(
signature = shortLog(blck.signature), err = newBlockRef.error() signature = shortLog(blck.signature), err = newBlockRef.error()
return ok(Opt.none(BlockRef)) return ok(Opt.none(BlockRef))
beacon_blocks_sent.inc()
beacon_blocks_sent_delay.observe(delay.toFloatSeconds())
notice "Block sent",
blockRoot = shortLog(blck.root), blck = shortLog(blck.message),
signature = shortLog(blck.signature), delay
return ok(Opt.some(newBlockRef.get())) return ok(Opt.some(newBlockRef.get()))
proc routeAttestation*( proc routeAttestation*(
@ -182,20 +181,17 @@ proc routeAttestation*(
let let
sendTime = router[].processor.getCurrentBeaconTime() sendTime = router[].processor.getCurrentBeaconTime()
delay = sendTime - attestation.data.slot.attestation_deadline() delay = sendTime - attestation.data.slot.attestation_deadline()
res = await router[].network.broadcastAttestation(subnet_id, attestation)
block: if res.isOk():
let res = await router[].network.broadcastAttestation( beacon_attestations_sent.inc()
subnet_id, attestation) beacon_attestation_sent_delay.observe(delay.toFloatSeconds())
if not res.isOk:
notice "Attestation not sent",
attestation = shortLog(attestation), error = res.error()
return err(res.error())
beacon_attestations_sent.inc() notice "Attestation sent",
beacon_attestation_sent_delay.observe(delay.toFloatSeconds()) attestation = shortLog(attestation), delay, subnet_id
else: # "no broadcast" is not a fatal error
notice "Attestation sent", notice "Attestation not sent",
attestation = shortLog(attestation), delay, subnet_id attestation = shortLog(attestation), error = res.error()
return ok() return ok()
@ -250,23 +246,21 @@ proc routeSignedAggregateAndProof*(
let let
sendTime = router[].processor.getCurrentBeaconTime() sendTime = router[].processor.getCurrentBeaconTime()
delay = sendTime - proof.message.aggregate.data.slot.aggregate_deadline() delay = sendTime - proof.message.aggregate.data.slot.aggregate_deadline()
res = await router[].network.broadcastAggregateAndProof(proof)
block: if res.isOk():
let res = await router[].network.broadcastAggregateAndProof(proof) beacon_aggregates_sent.inc()
if not res.isOk():
notice "Aggregated attestation not sent",
attestation = shortLog(proof.message.aggregate),
aggregator_index = proof.message.aggregator_index,
signature = shortLog(proof.signature), error = res.error()
return err(res.error())
beacon_aggregates_sent.inc() notice "Aggregated attestation sent",
attestation = shortLog(proof.message.aggregate),
notice "Aggregated attestation sent", aggregator_index = proof.message.aggregator_index,
attestation = shortLog(proof.message.aggregate), selection_proof = shortLog(proof.message.selection_proof),
aggregator_index = proof.message.aggregator_index, signature = shortLog(proof.signature), delay
selection_proof = shortLog(proof.message.selection_proof), else: # "no broadcast" is not a fatal error
signature = shortLog(proof.signature), delay notice "Aggregated attestation not sent",
attestation = shortLog(proof.message.aggregate),
aggregator_index = proof.message.aggregator_index,
signature = shortLog(proof.signature), error = res.error()
return ok() return ok()
@ -287,18 +281,17 @@ proc routeSyncCommitteeMessage*(
sendTime = router[].processor.getCurrentBeaconTime() sendTime = router[].processor.getCurrentBeaconTime()
delay = sendTime - msg.slot.sync_committee_message_deadline() delay = sendTime - msg.slot.sync_committee_message_deadline()
block: res = await router[].network.broadcastSyncCommitteeMessage(
let res = await router[].network.broadcastSyncCommitteeMessage(
msg, subcommitteeIdx) msg, subcommitteeIdx)
if not res.isOk():
notice "Sync committee message not sent",
message = shortLog(msg), error = res.error()
return err(res.error())
beacon_sync_committee_messages_sent.inc() if res.isOk():
beacon_sync_committee_message_sent_delay.observe(delay.toFloatSeconds()) beacon_sync_committee_messages_sent.inc()
beacon_sync_committee_message_sent_delay.observe(delay.toFloatSeconds())
notice "Sync committee message sent", message = shortLog(msg), delay notice "Sync committee message sent", message = shortLog(msg), delay
else: # "no broadcast" is not a fatal error
notice "Sync committee message not sent",
message = shortLog(msg), error = res.error()
if router[].onSyncCommitteeMessage != nil: if router[].onSyncCommitteeMessage != nil:
router[].onSyncCommitteeMessage(msg.slot) router[].onSyncCommitteeMessage(msg.slot)
@ -407,23 +400,20 @@ proc routeSignedContributionAndProof*(
sendTime = router[].processor.getCurrentBeaconTime() sendTime = router[].processor.getCurrentBeaconTime()
delay = sendTime - msg.message.contribution.slot.sync_contribution_deadline() delay = sendTime - msg.message.contribution.slot.sync_contribution_deadline()
block: let res = await router[].network.broadcastSignedContributionAndProof(msg)
let res = await router[].network.broadcastSignedContributionAndProof(msg) if res.isOk():
if not res.isOk(): beacon_sync_committee_contributions_sent.inc()
notice "Contribution not sent", notice "Contribution sent",
contribution = shortLog(msg.message.contribution), contribution = shortLog(msg.message.contribution),
aggregator_index = msg.message.aggregator_index, aggregator_index = msg.message.aggregator_index,
selection_proof = shortLog(msg.message.selection_proof), selection_proof = shortLog(msg.message.selection_proof),
signature = shortLog(msg.signature), error = res.error() signature = shortLog(msg.signature), delay
return err(res.error()) else: # "no broadcast" is not a fatal error
notice "Contribution not sent",
beacon_sync_committee_contributions_sent.inc() contribution = shortLog(msg.message.contribution),
aggregator_index = msg.message.aggregator_index,
notice "Contribution sent", selection_proof = shortLog(msg.message.selection_proof),
contribution = shortLog(msg.message.contribution), signature = shortLog(msg.signature), error = res.error()
aggregator_index = msg.message.aggregator_index,
selection_proof = shortLog(msg.message.selection_proof),
signature = shortLog(msg.signature), delay
return ok() return ok()
@ -438,16 +428,12 @@ proc routeSignedVoluntaryExit*(
exit = shortLog(exit), error = res.error() exit = shortLog(exit), error = res.error()
return err(res.error()[1]) return err(res.error()[1])
block: let res = await router[].network.broadcastVoluntaryExit(exit)
let res = await router[].network.broadcastVoluntaryExit(exit) if res.isOk():
if not res.isOk(): beacon_voluntary_exits_sent.inc()
notice "Voluntary exit not sent", notice "Voluntary exit sent", exit = shortLog(exit)
exit = shortLog(exit), error = res.error() else: # "no broadcast" is not a fatal error
return err(res.error()) notice "Voluntary exit not sent", exit = shortLog(exit), error = res.error()
beacon_voluntary_exits_sent.inc()
notice "Voluntary exit sent", exit = shortLog(exit)
return ok() return ok()
@ -462,16 +448,13 @@ proc routeAttesterSlashing*(
slashing = shortLog(slashing), error = res.error() slashing = shortLog(slashing), error = res.error()
return err(res.error()[1]) return err(res.error()[1])
block: let res = await router[].network.broadcastAttesterSlashing(slashing)
let res = await router[].network.broadcastAttesterSlashing(slashing) if res.isOk():
if not res.isOk(): beacon_attester_slashings_sent.inc()
notice "Attester slashing not sent", notice "Attester slashing sent", slashing = shortLog(slashing)
slashing = shortLog(slashing), error = res.error() else: # "no broadcast" is not a fatal error
return err(res.error()) notice "Attester slashing not sent",
slashing = shortLog(slashing), error = res.error()
beacon_attester_slashings_sent.inc()
notice "Attester slashing sent", slashing = shortLog(slashing)
return ok() return ok()
@ -486,15 +469,12 @@ proc routeProposerSlashing*(
slashing = shortLog(slashing), error = res.error() slashing = shortLog(slashing), error = res.error()
return err(res.error()[1]) return err(res.error()[1])
block: let res = await router[].network.broadcastProposerSlashing(slashing)
let res = await router[].network.broadcastProposerSlashing(slashing) if res.isOk():
if not res.isOk(): beacon_proposer_slashings_sent.inc()
notice "Proposer slashing not sent", notice "Proposer slashing sent", slashing = shortLog(slashing)
slashing = shortLog(slashing), error = res.error() else: # "no broadcast" is not a fatal error
return err(res.error()) notice "Proposer slashing not sent",
slashing = shortLog(slashing), error = res.error()
beacon_proposer_slashings_sent.inc()
notice "Proposer slashing sent", slashing = shortLog(slashing)
return ok() return ok()