Refactor attest and sync duties loops.
This commit is contained in:
parent
4656b427c4
commit
2d135abc56
|
@ -338,17 +338,18 @@ proc pollForAttesterDuties*(service: DutiesServiceRef,
|
|||
var alreadyWarned = false
|
||||
var res: seq[tuple[epoch: Epoch, duty: RestAttesterDuty]]
|
||||
for duty in relevantDuties:
|
||||
let map = vc.attesters.getOrDefault(duty.pubkey)
|
||||
let epochDuty = map.duties.getOrDefault(epoch, DefaultDutyAndProof)
|
||||
if not(epochDuty.isDefault()):
|
||||
if epochDuty.dependentRoot != currentRoot.get():
|
||||
var dutyFound = false
|
||||
vc.attesters.withValue(duty.pubkey, map):
|
||||
map[].duties.withValue(epoch, epochDuty):
|
||||
dutyFound = true
|
||||
if epochDuty[].dependentRoot != currentRoot.get():
|
||||
res.add((epoch, duty))
|
||||
if not(alreadyWarned):
|
||||
warn "Attester duties re-organization",
|
||||
info "Attester duties re-organization",
|
||||
prior_dependent_root = epochDuty.dependentRoot,
|
||||
dependent_root = currentRoot.get()
|
||||
alreadyWarned = true
|
||||
else:
|
||||
if not(dutyFound):
|
||||
info "Received new attester duty", duty, epoch = epoch,
|
||||
dependent_root = currentRoot.get()
|
||||
res.add((epoch, duty))
|
||||
|
@ -593,12 +594,15 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef,
|
|||
for sdap in relevantSdaps:
|
||||
var dutyFound = false
|
||||
vc.syncCommitteeDuties.withValue(sdap.data.pubkey, map):
|
||||
map.duties.withValue(epoch, epochDuty):
|
||||
if epochDuty[] != sdap:
|
||||
map[].duties.withValue(epoch, epochDuty):
|
||||
dutyFound = true
|
||||
if dutyFound and not(alreadyWarned):
|
||||
if epochDuty[] != sdap:
|
||||
res.add((epoch, sdap))
|
||||
if not(alreadyWarned):
|
||||
info "Sync committee duties re-organization", sdap, epoch
|
||||
alreadyWarned = true
|
||||
if not(dutyFound):
|
||||
info "Received new sync committee duty", sdap, epoch
|
||||
res.add((epoch, sdap))
|
||||
res
|
||||
|
||||
|
|
Loading…
Reference in New Issue