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