Skip to content

Commit 51ad833

Browse files
committed
refactor: pass env quarantine into attestatn validation
1 parent 12d29e1 commit 51ad833

5 files changed

Lines changed: 23 additions & 20 deletions

File tree

beacon_chain/consensus_object_pools/attestation_pool.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import
1313
chronicles, stew/byteutils,
1414
# Internal
1515
../spec/[eth2_merkleization, forks, validator],
16-
./[spec_cache, blockchain_dag, block_quarantine, envelope_quarantine],
16+
./[spec_cache, blockchain_dag, block_quarantine],
1717
../fork_choice/fork_choice,
1818
../beacon_clock
1919

@@ -82,7 +82,6 @@ type
8282

8383
dag*: ChainDAGRef
8484
quarantine*: ref Quarantine
85-
envelopeQuarantine*: ref EnvelopeQuarantine
8685

8786
forkChoice*: ForkChoice
8887

@@ -122,7 +121,6 @@ func init(T: type AttestationData, entry: AttestationEntry): T =
122121

123122
proc init*(T: type AttestationPool, dag: ChainDAGRef,
124123
quarantine: ref Quarantine,
125-
envelopeQuarantine: ref EnvelopeQuarantine = nil,
126124
wallTime = default(BeaconTime),
127125
onSingleAttestation: OnSingleAttestationCallback = nil): T =
128126
## Initialize an AttestationPool from the dag `headState`
@@ -200,7 +198,6 @@ proc init*(T: type AttestationPool, dag: ChainDAGRef,
200198
T(
201199
dag: dag,
202200
quarantine: quarantine,
203-
envelopeQuarantine: envelopeQuarantine,
204201
forkChoice: forkChoice,
205202
onSingleAttestationAdded: onSingleAttestation
206203
)

beacon_chain/gossip_processing/eth2_processor.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ proc processAttestation*(
575575

576576
let v = (
577577
await self.attestationPool.validateAttestation(
578-
self.batchCrypto, attestation, wallTime, subnet_id, checkSignature
578+
self.batchCrypto, self.envelopeQuarantine, attestation,
579+
wallTime, subnet_id, checkSignature
579580
)
580581
).valueOr:
581582
debug "Dropping attestation", reason = $error
@@ -647,6 +648,7 @@ proc processSignedAggregateAndProof*(
647648
let v = (
648649
await self.attestationPool.validateAggregate(
649650
self.batchCrypto,
651+
self.envelopeQuarantine,
650652
signedAggregateAndProof,
651653
wallTime,
652654
checkSignature = checkSignature,

beacon_chain/gossip_processing/gossip_validation.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ proc validateExecutionPayload*(
11291129
proc validateAttestation*(
11301130
pool: ref AttestationPool,
11311131
batchCrypto: ref BatchCrypto,
1132+
envelopeQuarantine: ref EnvelopeQuarantine,
11321133
attestation: SingleAttestation,
11331134
wallTime: BeaconTime,
11341135
subnet_id: SubnetId,
@@ -1194,7 +1195,8 @@ proc validateAttestation*(
11941195
if attestation.data.index == 1:
11951196
template block_root: untyped = attestation.data.beacon_block_root
11961197
if not pool.dag.db.containsExecutionPayloadEnvelope(block_root) and
1197-
block_root notin pool.envelopeQuarantine[].orphans:
1198+
(envelopeQuarantine.isNil or
1199+
block_root notin envelopeQuarantine[].orphans):
11981200
return errIgnore(
11991201
"SingleAttestation: execution payload not yet seen")
12001202
else:
@@ -1312,6 +1314,7 @@ proc validateAttestation*(
13121314
proc validateAggregate*(
13131315
pool: ref AttestationPool,
13141316
batchCrypto: ref BatchCrypto,
1317+
envelopeQuarantine: ref EnvelopeQuarantine,
13151318
signedAggregateAndProof: electra.SignedAggregateAndProof,
13161319
wallTime: BeaconTime,
13171320
checkSignature = true,
@@ -1405,7 +1408,8 @@ proc validateAggregate*(
14051408
if aggregate.data.index == 1:
14061409
template block_root: untyped = aggregate.data.beacon_block_root
14071410
if not pool.dag.db.containsExecutionPayloadEnvelope(block_root) and
1408-
block_root notin pool.envelopeQuarantine[].orphans:
1411+
(envelopeQuarantine.isNil or
1412+
block_root notin envelopeQuarantine[].orphans):
14091413
return errIgnore(
14101414
"Aggregate: execution payload not yet seen")
14111415
else:

beacon_chain/nimbus_beacon_node.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ proc initFullNode(
557557
Quarantine.init(dag.cfg))
558558
envelopeQuarantine = newClone(EnvelopeQuarantine.init(onEnvelopeAdded))
559559
attestationPool = newClone(AttestationPool.init(
560-
dag, quarantine, envelopeQuarantine,
560+
dag, quarantine,
561561
getBeaconTime(), onSingleAttestationReceived))
562562
syncCommitteeMsgPool = newClone(
563563
SyncCommitteeMsgPool.init(rng, dag.cfg, onSyncContribution))

tests/test_gossip_validation.nim

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,29 @@ suite "Gossip validation " & preset():
113113
beaconTime = att_1_0.data.slot.start_beacon_time(cfg.timeParams)
114114

115115
check:
116-
validateAttestation(pool, batchCrypto, att_1_0, beaconTime, subnet, true).waitFor().isOk
116+
validateAttestation(pool, batchCrypto, nil, att_1_0, beaconTime, subnet, true).waitFor().isOk
117117

118118
# Same validator again
119-
validateAttestation(pool, batchCrypto, att_1_0, beaconTime, subnet, true).waitFor().error()[0] ==
119+
validateAttestation(pool, batchCrypto, nil, att_1_0, beaconTime, subnet, true).waitFor().error()[0] ==
120120
ValidationResult.Ignore
121121

122122
pool[].nextAttestationEpoch.setLen(0) # reset for test
123123
check:
124124
# Wrong subnet
125125
validateAttestation(
126-
pool, batchCrypto, att_1_0, beaconTime, SubnetId(subnet.uint8 + 1), true).waitFor().isErr
126+
pool, batchCrypto, nil, att_1_0, beaconTime, SubnetId(subnet.uint8 + 1), true).waitFor().isErr
127127

128128
pool[].nextAttestationEpoch.setLen(0) # reset for test
129129
check:
130130
# Too far in the future
131131
validateAttestation(
132-
pool, batchCrypto, att_1_0, beaconTime - 1.seconds, subnet, true).waitFor().isErr
132+
pool, batchCrypto, nil, att_1_0, beaconTime - 1.seconds, subnet, true).waitFor().isErr
133133

134134
pool[].nextAttestationEpoch.setLen(0) # reset for test
135135
check:
136136
# Too far in the past
137137
validateAttestation(
138-
pool, batchCrypto, att_1_0, beaconTime -
138+
pool, batchCrypto, nil, att_1_0, beaconTime -
139139
cfg.timeParams.SLOT_DURATION * SLOTS_PER_EPOCH.int64 - 1.seconds,
140140
subnet, true).waitFor().isErr
141141

@@ -146,7 +146,7 @@ suite "Gossip validation " & preset():
146146
check:
147147
# Invalid signature
148148
validateAttestation(
149-
pool, batchCrypto, broken, beaconTime, subnet, true).waitFor().
149+
pool, batchCrypto, nil, broken, beaconTime, subnet, true).waitFor().
150150
error()[0] == ValidationResult.Reject
151151

152152
block:
@@ -156,9 +156,9 @@ suite "Gossip validation " & preset():
156156
# One invalid, one valid (batched)
157157
let
158158
fut_1_0 = validateAttestation(
159-
pool, batchCrypto, broken, beaconTime, subnet, true)
159+
pool, batchCrypto, nil, broken, beaconTime, subnet, true)
160160
fut_1_1 = validateAttestation(
161-
pool, batchCrypto, att_1_1, beaconTime, subnet, true)
161+
pool, batchCrypto, nil,att_1_1, beaconTime, subnet, true)
162162

163163
check:
164164
fut_1_0.waitFor().error()[0] == ValidationResult.Reject
@@ -172,9 +172,9 @@ suite "Gossip validation " & preset():
172172
# One invalid, one valid (batched)
173173
let
174174
fut_1_0 = validateAttestation(
175-
pool, batchCrypto, broken, beaconTime, subnet, true)
175+
pool, batchCrypto, nil, broken, beaconTime, subnet, true)
176176
fut_1_1 = validateAttestation(
177-
pool, batchCrypto, att_1_1, beaconTime, subnet, true)
177+
pool, batchCrypto, nil,att_1_1, beaconTime, subnet, true)
178178

179179
check:
180180
fut_1_0.waitFor().error()[0] == ValidationResult.Reject
@@ -194,9 +194,9 @@ suite "Gossip validation " & preset():
194194
# the individual attestations are invalid but their aggregate validates!
195195
let
196196
fut_1_0 = validateAttestation(
197-
pool, batchCrypto, broken_1_0, beaconTime, subnet, true)
197+
pool, batchCrypto, nil, broken_1_0, beaconTime, subnet, true)
198198
fut_1_1 = validateAttestation(
199-
pool, batchCrypto, broken_1_1, beaconTime, subnet, true)
199+
pool, batchCrypto, nil, broken_1_1, beaconTime, subnet, true)
200200

201201
check:
202202
fut_1_0.waitFor().error()[0] == ValidationResult.Reject

0 commit comments

Comments
 (0)