Skip to content

Commit 68eaa07

Browse files
committed
feat: update gossip handler
1 parent 4c66a97 commit 68eaa07

File tree

2 files changed

+68
-13
lines changed

2 files changed

+68
-13
lines changed

beacon_chain/gossip_processing/eth2_processor.nim

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import
1616
../el/el_manager,
1717
../spec/[helpers, forks],
1818
../consensus_object_pools/[
19-
blob_quarantine, block_clearance, block_quarantine, blockchain_dag,
20-
attestation_pool, light_client_pool,
21-
sync_committee_msg_pool, validator_change_pool],
19+
attestation_pool, blob_quarantine, block_clearance,
20+
block_quarantine, blockchain_dag, envelope_quarantine,
21+
light_client_pool, sync_committee_msg_pool, validator_change_pool],
2222
../validators/validator_pool,
2323
../beacon_clock,
2424
"."/[gossip_validation, block_processor, batch_validation],
@@ -45,6 +45,10 @@ declareCounter beacon_blocks_received,
4545
"Number of valid blocks processed by this node"
4646
declareCounter beacon_blocks_dropped,
4747
"Number of invalid blocks dropped by this node", labels = ["reason"]
48+
declareCounter execution_payload_envelopes_received,
49+
"Number of valid execution payload envelope processed by this node"
50+
declareCounter execution_payload_envelopes_dropped,
51+
"Number of invalid execution payload envelope dropped by this node", labels = ["reason"]
4852
declareCounter blob_sidecars_received,
4953
"Number of valid blobs processed by this node"
5054
declareCounter blob_sidecars_dropped,
@@ -93,6 +97,9 @@ declareHistogram beacon_aggregate_delay,
9397
declareHistogram beacon_block_delay,
9498
"Time(s) between slot start and beacon block reception", buckets = delayBuckets
9599

100+
declareHistogram execution_payload_envelope_delay,
101+
"Time(s) between slot start and execution payload envelope reception", buckets = delayBuckets
102+
96103
declareHistogram blob_sidecar_delay,
97104
"Time(s) between slot start and blob sidecar reception", buckets = delayBuckets
98105

@@ -157,6 +164,8 @@ type
157164

158165
dataColumnQuarantine*: ref ColumnQuarantine
159166

167+
envelopeQuarantine*: ref EnvelopeQuarantine
168+
160169
# Application-provided current time provider (to facilitate testing)
161170
getCurrentBeaconTime*: GetBeaconTimeFn
162171

@@ -291,6 +300,37 @@ proc processSignedBeaconBlock*(
291300

292301
ok()
293302

303+
proc processExecutionPayloadEnvelope*(
304+
self: var Eth2Processor, src: MsgSource,
305+
signedEnvelope: SignedExecutionPayloadEnvelope): ValidationRes =
306+
let
307+
wallTime = self.getCurrentBeaconTime()
308+
(afterGenesis, wallSlot) = wallTime.toSlot(self.dag.timeParams)
309+
310+
logScope:
311+
blockRoot = shortLog(signedEnvelope.message.beacon_block_root)
312+
envelope = shortLog(signedEnvelope.message)
313+
wallSlot
314+
315+
if not afterGenesis:
316+
notice "Execution payload envelope before genesis"
317+
return errIgnore("Execution payload envelope before genesis")
318+
319+
let delay = wallTime -
320+
signedEnvelope.message.slot.start_beacon_time(self.dag.timeParams)
321+
322+
self.dag.validateExecutionPayload(
323+
self.quarantine, self.envelopeQuarantine, signedEnvelope).isOkOr:
324+
execution_payload_envelopes_dropped.inc(1, [$error[0]])
325+
return err(error)
326+
327+
debugGloasComment("process execution payload")
328+
329+
execution_payload_envelopes_received.inc()
330+
execution_payload_envelope_delay.observe(delay.toFloatSeconds())
331+
332+
ok()
333+
294334
proc processBlobSidecar*(
295335
self: var Eth2Processor, src: MsgSource,
296336
blobSidecar: deneb.BlobSidecar, subnet_id: BlobId): ValidationRes =

beacon_chain/gossip_processing/gossip_validation.nim

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import
1818
helpers, network, signatures, peerdas_helpers],
1919
../consensus_object_pools/[
2020
attestation_pool, blockchain_dag, blob_quarantine, block_quarantine,
21-
light_client_pool, spec_cache, sync_committee_msg_pool,
22-
validator_change_pool],
21+
envelope_quarantine, light_client_pool, spec_cache,
22+
sync_committee_msg_pool, validator_change_pool],
2323
".."/[beacon_clock],
2424
./batch_validation
2525

@@ -973,9 +973,10 @@ proc validateBeaconBlock*(
973973

974974
ok()
975975

976-
# https://github.com/ethereum/consensus-specs/blob/v1.6.0-beta.0/specs/gloas/p2p-interface.md#execution_payload
976+
# https://github.com/ethereum/consensus-specs/blob/v1.6.0/specs/gloas/p2p-interface.md#execution_payload
977977
proc validateExecutionPayload*(
978978
dag: ChainDAGRef, quarantine: ref Quarantine,
979+
envelopeQuarantine: ref EnvelopeQuarantine,
979980
signed_execution_payload_envelope: SignedExecutionPayloadEnvelope):
980981
Result[void, ValidationError] =
981982
template envelope: untyped = signed_execution_payload_envelope.message
@@ -996,11 +997,27 @@ proc validateExecutionPayload*(
996997
break
997998
seen
998999
if not blockSeen:
1000+
quarantine[].addMissing(envelope.beacon_block_root)
1001+
envelopeQuarantine[].addOrphan(signed_execution_payload_envelope)
9991002
return errIgnore("ExecutionPayload: block not found")
10001003

10011004
# [IGNORE] The node has not seen another valid SignedExecutionPayloadEnvelope
10021005
# for this block root from this builder.
1003-
debugGloasComment("")
1006+
#
1007+
# Validation of an envelope requires a valid block. There is a check to ensure
1008+
# that the builder index are the same from the envelope and the bid from the
1009+
# block. Meaning that checking builder index here would not be helpful due to
1010+
# the check later.
1011+
var validEnvelope: TrustedSignedExecutionPayloadEnvelope
1012+
if dag.db.getExecutionPayloadEnvelope(
1013+
envelope.beacon_block_root, validEnvelope):
1014+
return errIgnore("ExecutionPayload: already seen")
1015+
1016+
# [IGNORE] The envelope is from a slot greater than or equal to the latest
1017+
# finalized slot -- i.e. validate that `envelope.slot >=
1018+
# compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)`
1019+
if envelope.slot <= dag.finalizedHead.slot:
1020+
return errIgnore("ExecutionPayload: slot already finalized")
10041021

10051022
# [REJECT] block passes validation.
10061023
let blck =
@@ -1012,23 +1029,21 @@ proc validateExecutionPayload*(
10121029
when consensusFork >= ConsensusFork.Gloas:
10131030
forkyBlck.asSigned().message
10141031
else:
1015-
return errReject("ExecutionPayload: invalid fork")
1032+
return dag.checkedReject("ExecutionPayload: invalid fork")
10161033

10171034
# [REJECT] block.slot equals envelope.slot.
10181035
if blck.slot != envelope.slot:
1019-
return errReject("ExecutionPayload: slot mismatch")
1036+
return dag.checkedReject("ExecutionPayload: slot mismatch")
10201037

1021-
# TODO: check if it needs fallback to `state.latest_execution_payload_bid`
10221038
template bid: untyped = blck.body.signed_execution_payload_bid.message
1023-
debug "Validating execution payload", bid = shortLog(bid)
10241039

10251040
# [REJECT] envelope.builder_index == bid.builder_index
10261041
if envelope.builder_index != bid.builder_index:
1027-
return errReject("ExecutionPayload: builder index mismatch")
1042+
return dag.checkedReject("ExecutionPayload: builder index mismatch")
10281043

10291044
# [REJECT] payload.block_hash == bid.block_hash
10301045
if envelope.payload.block_hash != bid.block_hash:
1031-
return errReject("ExecutionPayload: block hash mismatch")
1046+
return dag.checkedReject("ExecutionPayload: block hash mismatch")
10321047

10331048
# [REJECT] signed_execution_payload_envelope.signature is valid with respect
10341049
# to the builder's public key.

0 commit comments

Comments
 (0)