Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AllTests-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ AllTests-mainnet
+ Attestations with disjoint comittee bits and equal data into single on-chain aggregate [Pr OK
+ Can add and retrieve simple electra attestations [Preset: mainnet] OK
+ Working with electra aggregates [Preset: mainnet] OK
+ simple add and get with electra nonzero committee [Preset: mainnet] OK
+ Simple add and get with electra nonzero committee [Preset: mainnet] OK
+ Cache coherence on chain aggregates [Preset: mainnet] OK
```
## Attestation pool processing [Preset: mainnet]
```diff
Expand Down
15 changes: 9 additions & 6 deletions beacon_chain/consensus_object_pools/attestation_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ type
onPhase0AttestationAdded: OnPhase0AttestationCallback
onSingleAttestationAdded: OnSingleAttestationCallback

CandidateKey = tuple
Comment thread
pedromiguelmiranda marked this conversation as resolved.
## Search key for selecting the final candidates for
## electra chain aggregates.
hash: Eth2Digest
slot: Slot

logScope: topics = "attpool"

declareGauge attestation_pool_block_attestation_packing_time,
Expand Down Expand Up @@ -1005,7 +1011,7 @@ proc getElectraAttestationsForBlock*(
# For each round, we'll look for the best attestation and add it to the result
# then re-score the other candidates.
var
candidatesPerBlock: Table[(Eth2Digest, Slot), seq[electra.Attestation]]
candidatesPerBlock: OrderedTable[CandidateKey, seq[electra.Attestation]]

let totalCandidates = candidates.len()
while candidates.len > 0 and candidatesPerBlock.lenu64() <
Expand All @@ -1027,13 +1033,10 @@ proc getElectraAttestationsForBlock*(
var e2 = entry.data
e2.index = 0
e2
key = (hash_tree_root(entry2), entry.data.slot)
key: CandidateKey = (hash_tree_root(entry2), entry.data.slot.Slot)
Comment thread
pedromiguelmiranda marked this conversation as resolved.
Outdated
newAtt = entry[].toElectraAttestation(entry[].aggregates[j])

candidatesPerBlock.withValue(key, candidate):
candidate[].add newAtt
do:
candidatesPerBlock[key] = @[newAtt]
candidatesPerBlock.mGetOrPut(key, @[]).add(newAtt)
Comment thread
tersec marked this conversation as resolved.

# Update cache so that the new votes are taken into account when updating
# the score below
Expand Down
56 changes: 55 additions & 1 deletion tests/test_attestation_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ suite "Attestation pool electra processing" & preset():
pool[].verifyAttestationSignature(state, cache, attestations[0])
pool[].verifyAttestationSignature(state, cache, attestations[1])

test "simple add and get with electra nonzero committee" & preset():
test "Simple add and get with electra nonzero committee" & preset():
let
bc0 = get_beacon_committee(
state[], getStateField(state[], slot), 0.CommitteeIndex, cache)
Expand Down Expand Up @@ -1219,3 +1219,57 @@ suite "Attestation pool electra processing" & preset():
0.CommitteeIndex).isOk
pool[].getElectraAggregatedAttestation(1.Slot, hash_tree_root(attestation_2.data),
1.CommitteeIndex).isOk

test "Cache coherence on chain aggregates" & preset():
# Add attestation from different committee
var maxSlot = 0.Slot

for i in 0 ..< 4:
let
bc = get_beacon_committee(
state[], getStateField(state[], slot), i.CommitteeIndex, cache)
att = makeElectraAttestation(
state[], state[].latest_block_root, bc[0], cache)
var att2 = makeElectraAttestation(
state[], state[].latest_block_root, bc[1], cache)

pool[].addAttestation(
att, @[bc[0]], att.aggregation_bits.len, att.loadSig,
att.data.slot.start_beacon_time)

if att.data.slot < 2:
pool[].addAttestation(
att2, @[bc[1]], att2.aggregation_bits.len, att2.loadSig,
att2.data.slot.start_beacon_time)

if att.data.slot > maxSlot:
maxSlot = att.data.slot

check process_slots(
defaultRuntimeConfig, state[],
maxSlot + MIN_ATTESTATION_INCLUSION_DELAY, cache,
info, {}).isOk()

let attestations = pool[].getElectraAttestationsForBlock(state[], cache)
check:
## Considering that all structures in getElectraAttestationsForBlock
## are sorted, the most relevant should be at sequence head.
## Given the attestations added, the most "scored" is on
## slot 1
attestations.len() == 2

attestations[0].aggregation_bits.countOnes() == 4
attestations[0].committee_bits.countOnes() == 2
attestations[0].data.slot == 1.Slot


attestations[1].aggregation_bits.countOnes() == 2
attestations[1].committee_bits.countOnes() == 2
attestations[1].data.slot == 2.Slot

check_attestation(
state[].electraData.data, attestations[0], {}, cache, true).isOk
check_attestation(
state[].electraData.data, attestations[1], {}, cache, true).isOk
pool[].verifyAttestationSignature(state, cache, attestations[0])
pool[].verifyAttestationSignature(state, cache, attestations[1])