Skip to content

Commit

Permalink
doppelganger: guard against reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Mar 3, 2023
1 parent ea060de commit 283b8b5
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions beacon_chain/validators/validator_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,18 @@ proc doppelgangerChecked*(validator: AttachedValidator, epoch: Epoch) =
if validator.doppelCheck.isNone():
debug "Doppelganger first check",
validator = shortLog(validator), epoch
elif validator.doppelCheck.get() + 1 notin [epoch, epoch + 1]:
debug "Doppelganger stale check",
validator = shortLog(validator),
checked = validator.doppelCheck.get(), epoch
else:
let check = validator.doppelCheck.get()
if check > epoch:
# Shouldn't happen but due to `await`, it may - consider turning into
# assert
debug "Doppelganger reordered check",
validator = shortLog(validator), check, epoch
return

if check - epoch > 1:
debug "Doppelganger stale check",
validator = shortLog(validator), check, epoch

validator.doppelCheck = Opt.some epoch

Expand All @@ -290,10 +298,19 @@ proc doppelgangerActivity*(validator: AttachedValidator, epoch: Epoch) =
if validator.doppelActivity.isNone():
debug "Doppelganger first activity",
validator = shortLog(validator), epoch
elif validator.doppelActivity.get() + 1 notin [epoch, epoch + 1]:
debug "Doppelganger stale activity",
validator = shortLog(validator),
checked = validator.doppelActivity.get(), epoch
else:
let activity = validator.doppelActivity.get()
if activity > epoch:
# Shouldn't happen but due to `await`, it may - consider turning into
# assert
debug "Doppelganger reordered activity",
validator = shortLog(validator), activity, epoch
return

if activity - epoch > 1:
# We missed work in some epoch
debug "Doppelganger stale activity",
validator = shortLog(validator), activity, epoch

validator.doppelActivity = Opt.some epoch

Expand Down

0 comments on commit 283b8b5

Please sign in to comment.