Skip to content

Commit 1d10dd4

Browse files
committed
review
1 parent d83a949 commit 1d10dd4

6 files changed

Lines changed: 25 additions & 31 deletions

File tree

beacon_chain/consensus_object_pools/attestation_pool.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ func init(T: type AttestationData, entry: AttestationEntry): T =
120120
)
121121

122122
proc init*(T: type AttestationPool, dag: ChainDAGRef,
123-
quarantine: ref Quarantine,
124-
wallTime = default(BeaconTime),
123+
quarantine: ref Quarantine, wallTime = default(BeaconTime),
125124
onSingleAttestation: OnSingleAttestationCallback = nil): T =
126125
## Initialize an AttestationPool from the dag `headState`
127126
## The `finalized_root` works around the finalized_checkpoint of the genesis block

beacon_chain/gossip_processing/gossip_validation.nim

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,7 @@ proc validateAttestation*(
11961196
if attestation.data.index == 1:
11971197
template block_root: untyped = attestation.data.beacon_block_root
11981198
if not pool.dag.db.containsExecutionPayloadEnvelope(block_root) and
1199-
(envelopeQuarantine.isNil or
1200-
block_root notin envelopeQuarantine[].orphans):
1199+
block_root notin envelopeQuarantine[].orphans:
12011200
return errIgnore(
12021201
"SingleAttestation: execution payload not yet seen")
12031202
else:
@@ -1409,8 +1408,7 @@ proc validateAggregate*(
14091408
if aggregate.data.index == 1:
14101409
template block_root: untyped = aggregate.data.beacon_block_root
14111410
if not pool.dag.db.containsExecutionPayloadEnvelope(block_root) and
1412-
(envelopeQuarantine.isNil or
1413-
block_root notin envelopeQuarantine[].orphans):
1411+
block_root notin envelopeQuarantine[].orphans:
14141412
return errIgnore(
14151413
"Aggregate: execution payload not yet seen")
14161414
else:

beacon_chain/nimbus_beacon_node.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,7 @@ proc initFullNode(
557557
Quarantine.init(dag.cfg))
558558
envelopeQuarantine = newClone(EnvelopeQuarantine.init(onEnvelopeAdded))
559559
attestationPool = newClone(AttestationPool.init(
560-
dag, quarantine,
561-
getBeaconTime(), onSingleAttestationReceived))
560+
dag, quarantine, getBeaconTime(), onSingleAttestationReceived))
562561
syncCommitteeMsgPool = newClone(
563562
SyncCommitteeMsgPool.init(rng, dag.cfg, onSyncContribution))
564563
lightClientPool = newClone(

beacon_chain/spec/beaconstate.nim

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,11 +1768,11 @@ func convert_builder_index_to_validator_index(builder_index: BuilderIndex):
17681768
uint64 =
17691769
builder_index or BUILDER_INDEX_FLAG
17701770

1771-
# https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-convert_validator_index_to_builder_index
1771+
# https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.4/specs/gloas/beacon-chain.md#new-convert_validator_index_to_builder_index
17721772
func convert_validator_index_to_builder_index*(validator_index: uint64): BuilderIndex =
17731773
validator_index and not BUILDER_INDEX_FLAG
17741774

1775-
# https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-is_builder_index
1775+
# https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.4/specs/gloas/beacon-chain.md#new-is_builder_index
17761776
func is_builder_index*(validator_index: uint64): bool =
17771777
(validator_index and BUILDER_INDEX_FLAG) != 0
17781778

@@ -2319,7 +2319,7 @@ iterator compute_ptc*(state: gloas.BeaconState, slot: Slot, cache: var StateCach
23192319
# See: https://github.com/nim-lang/Nim/issues/25287
23202320
# https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.4/specs/gloas/beacon-chain.md#new-get_ptc
23212321
iterator get_ptc*(state: gloas.BeaconState, slot: Slot):
2322-
ValidatorIndex {. closure .} =
2322+
ValidatorIndex {.closure.} =
23232323
## Get the payload timeliness committee for the given ``slot``
23242324
let
23252325
epoch = slot.epoch()
@@ -2353,13 +2353,10 @@ proc initialize_ptc_window(
23532353
base_index = (1 + epoch_offset) * SLOTS_PER_EPOCH
23542354
for slot_offset in 0'u64 ..< SLOTS_PER_EPOCH:
23552355
let slot = epoch.start_slot() + slot_offset
2356-
var
2357-
ptcArray: HashArray[Limit PTC_SIZE, uint64]
2358-
i = 0
2356+
var i = 0
23592357
for idx in compute_ptc(state, slot, cache):
2360-
ptcArray[i] = uint64(idx)
2358+
state.ptc_window.mitem(base_index + slot_offset)[i] = uint64(idx)
23612359
inc i
2362-
state.ptc_window.mitem(base_index + slot_offset) = ptcArray
23632360

23642361
# upgrade_to_altair
23652362
func upgrade_to_next*(cfg: RuntimeConfig, pre: phase0.BeaconState, _: var StateCache):

beacon_chain/spec/state_transition_block.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ proc process_attester_slashing*(
312312
from ".."/validator_bucket_sort import
313313
BucketSortedValidators, add, findValidatorIndex, sortValidatorBuckets
314314

315-
# https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.3/specs/gloas/beacon-chain.md#new-is_pending_validator
315+
# https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.4/specs/gloas/beacon-chain.md#new-is_pending_validator
316316
func get_pending_validators*(cfg: RuntimeConfig, state: gloas.BeaconState):
317317
HashSet[ValidatorPubKey] =
318318
## Check if a pending deposit with a valid signature is in the queue for the given pubkey.
@@ -482,7 +482,7 @@ proc check_voluntary_exit*(
482482
signed_voluntary_exit: SomeSignedVoluntaryExit,
483483
flags: UpdateFlags): Result[ValidatorIndex, cstring] =
484484

485-
template voluntary_exit:untyped = signed_voluntary_exit.message
485+
template voluntary_exit: untyped = signed_voluntary_exit.message
486486

487487
if voluntary_exit.validator_index >= state.validators.lenu64:
488488
return err("Exit: invalid validator index")

tests/test_gossip_validation.nim

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import
1919
../beacon_chain/fork_choice/fork_choice,
2020
../beacon_chain/consensus_object_pools/[
2121
block_quarantine, blockchain_dag, block_clearance, attestation_pool,
22-
sync_committee_msg_pool],
22+
envelope_quarantine, sync_committee_msg_pool],
2323
../beacon_chain/spec/datatypes/[phase0, altair],
2424
../beacon_chain/spec/[
2525
beaconstate, state_transition, helpers, network, validator],
@@ -48,6 +48,7 @@ suite "Gossip validation " & preset():
4848
taskpool = Taskpool.new()
4949
verifier {.used.} = BatchVerifier.init(rng, taskpool)
5050
quarantine = newClone(Quarantine.init(dag.cfg))
51+
envQuarantine = newClone(EnvelopeQuarantine.init())
5152
pool {.used.} = newClone(AttestationPool.init(dag, quarantine))
5253
state = newClone(dag.headState)
5354
cache = StateCache()
@@ -113,29 +114,29 @@ suite "Gossip validation " & preset():
113114
beaconTime = att_1_0.data.slot.start_beacon_time(cfg.timeParams)
114115

115116
check:
116-
validateAttestation(pool, batchCrypto, nil, att_1_0, beaconTime, subnet, true).waitFor().isOk
117+
validateAttestation(pool, batchCrypto, envQuarantine, att_1_0, beaconTime, subnet, true).waitFor().isOk
117118

118119
# Same validator again
119-
validateAttestation(pool, batchCrypto, nil, att_1_0, beaconTime, subnet, true).waitFor().error()[0] ==
120+
validateAttestation(pool, batchCrypto, envQuarantine, att_1_0, beaconTime, subnet, true).waitFor().error()[0] ==
120121
ValidationResult.Ignore
121122

122123
pool[].nextAttestationEpoch.setLen(0) # reset for test
123124
check:
124125
# Wrong subnet
125126
validateAttestation(
126-
pool, batchCrypto, nil, att_1_0, beaconTime, SubnetId(subnet.uint8 + 1), true).waitFor().isErr
127+
pool, batchCrypto, envQuarantine, att_1_0, beaconTime, SubnetId(subnet.uint8 + 1), true).waitFor().isErr
127128

128129
pool[].nextAttestationEpoch.setLen(0) # reset for test
129130
check:
130131
# Too far in the future
131132
validateAttestation(
132-
pool, batchCrypto, nil, att_1_0, beaconTime - 1.seconds, subnet, true).waitFor().isErr
133+
pool, batchCrypto, envQuarantine, att_1_0, beaconTime - 1.seconds, subnet, true).waitFor().isErr
133134

134135
pool[].nextAttestationEpoch.setLen(0) # reset for test
135136
check:
136137
# Too far in the past
137138
validateAttestation(
138-
pool, batchCrypto, nil, att_1_0, beaconTime -
139+
pool, batchCrypto, envQuarantine, att_1_0, beaconTime -
139140
cfg.timeParams.SLOT_DURATION * SLOTS_PER_EPOCH.int64 - 1.seconds,
140141
subnet, true).waitFor().isErr
141142

@@ -146,7 +147,7 @@ suite "Gossip validation " & preset():
146147
check:
147148
# Invalid signature
148149
validateAttestation(
149-
pool, batchCrypto, nil, broken, beaconTime, subnet, true).waitFor().
150+
pool, batchCrypto, envQuarantine, broken, beaconTime, subnet, true).waitFor().
150151
error()[0] == ValidationResult.Reject
151152

152153
block:
@@ -156,9 +157,9 @@ suite "Gossip validation " & preset():
156157
# One invalid, one valid (batched)
157158
let
158159
fut_1_0 = validateAttestation(
159-
pool, batchCrypto, nil, broken, beaconTime, subnet, true)
160+
pool, batchCrypto, envQuarantine, broken, beaconTime, subnet, true)
160161
fut_1_1 = validateAttestation(
161-
pool, batchCrypto, nil,att_1_1, beaconTime, subnet, true)
162+
pool, batchCrypto, envQuarantine, att_1_1, beaconTime, subnet, true)
162163

163164
check:
164165
fut_1_0.waitFor().error()[0] == ValidationResult.Reject
@@ -172,9 +173,9 @@ suite "Gossip validation " & preset():
172173
# One invalid, one valid (batched)
173174
let
174175
fut_1_0 = validateAttestation(
175-
pool, batchCrypto, nil, broken, beaconTime, subnet, true)
176+
pool, batchCrypto, envQuarantine, broken, beaconTime, subnet, true)
176177
fut_1_1 = validateAttestation(
177-
pool, batchCrypto, nil,att_1_1, beaconTime, subnet, true)
178+
pool, batchCrypto, envQuarantine, att_1_1, beaconTime, subnet, true)
178179

179180
check:
180181
fut_1_0.waitFor().error()[0] == ValidationResult.Reject
@@ -194,9 +195,9 @@ suite "Gossip validation " & preset():
194195
# the individual attestations are invalid but their aggregate validates!
195196
let
196197
fut_1_0 = validateAttestation(
197-
pool, batchCrypto, nil, broken_1_0, beaconTime, subnet, true)
198+
pool, batchCrypto, envQuarantine, broken_1_0, beaconTime, subnet, true)
198199
fut_1_1 = validateAttestation(
199-
pool, batchCrypto, nil, broken_1_1, beaconTime, subnet, true)
200+
pool, batchCrypto, envQuarantine, broken_1_1, beaconTime, subnet, true)
200201

201202
check:
202203
fut_1_0.waitFor().error()[0] == ValidationResult.Reject

0 commit comments

Comments
 (0)