disable aggregation when no validators are connected (#908)
* if we don't have validators, don't consider aggregation work * if we do have validators, don't aggregate when we're out of sync * when we do aggregate, use a fresh state, and not one from before sleeping
This commit is contained in:
parent
722c4767fa
commit
edecce1751
|
@ -21,7 +21,7 @@ import
|
||||||
const
|
const
|
||||||
genesisFile = "genesis.ssz"
|
genesisFile = "genesis.ssz"
|
||||||
hasPrompt = not defined(withoutPrompt)
|
hasPrompt = not defined(withoutPrompt)
|
||||||
maxEmptySlotCount = uint64(24*60*60) div SECONDS_PER_SLOT
|
maxEmptySlotCount = uint64(10*60) div SECONDS_PER_SLOT
|
||||||
|
|
||||||
type
|
type
|
||||||
KeyPair = eth2_network.KeyPair
|
KeyPair = eth2_network.KeyPair
|
||||||
|
@ -311,8 +311,7 @@ proc isSynced(node: BeaconNode, head: BlockRef): bool =
|
||||||
# TODO if everyone follows this logic, the network will not recover from a
|
# TODO if everyone follows this logic, the network will not recover from a
|
||||||
# halt: nobody will be producing blocks because everone expects someone
|
# halt: nobody will be producing blocks because everone expects someone
|
||||||
# else to do it
|
# else to do it
|
||||||
if wallSlot.afterGenesis and (wallSlot.slot > head.slot) and
|
if wallSlot.afterGenesis and head.slot + maxEmptySlotCount < wallSlot.slot:
|
||||||
(wallSlot.slot - head.slot) > maxEmptySlotCount:
|
|
||||||
false
|
false
|
||||||
else:
|
else:
|
||||||
true
|
true
|
||||||
|
@ -828,25 +827,24 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.gcsafe, asyn
|
||||||
# block from the expected block proposer for the assigned slot or
|
# block from the expected block proposer for the assigned slot or
|
||||||
# (b) one-third of the slot has transpired (`SECONDS_PER_SLOT / 3` seconds
|
# (b) one-third of the slot has transpired (`SECONDS_PER_SLOT / 3` seconds
|
||||||
# after the start of slot) -- whichever comes first.
|
# after the start of slot) -- whichever comes first.
|
||||||
|
template sleepToSlotOffset(extra: chronos.Duration, msg: static string) =
|
||||||
let
|
let
|
||||||
attestationStart = node.beaconClock.fromNow(slot)
|
fromNow = node.beaconClock.fromNow(slot.toBeaconTime(extra))
|
||||||
thirdSlot = seconds(int64(SECONDS_PER_SLOT)) div 3
|
|
||||||
|
|
||||||
if attestationStart.inFuture or attestationStart.offset <= thirdSlot:
|
if fromNow.inFuture:
|
||||||
let fromNow =
|
trace msg,
|
||||||
if attestationStart.inFuture: attestationStart.offset + thirdSlot
|
|
||||||
else: thirdSlot - attestationStart.offset
|
|
||||||
|
|
||||||
trace "Waiting to send attestations",
|
|
||||||
slot = shortLog(slot),
|
slot = shortLog(slot),
|
||||||
fromNow = shortLog(fromNow),
|
fromNow = shortLog(fromNow.offset),
|
||||||
cat = "scheduling"
|
cat = "scheduling"
|
||||||
|
|
||||||
await sleepAsync(fromNow)
|
await sleepAsync(fromNow.offset)
|
||||||
|
|
||||||
# Time passed - we might need to select a new head in that case
|
# Time passed - we might need to select a new head in that case
|
||||||
head = node.updateHead()
|
head = node.updateHead()
|
||||||
|
|
||||||
|
sleepToSlotOffset(
|
||||||
|
seconds(int64(SECONDS_PER_SLOT)) div 3, "Waiting to send attestations")
|
||||||
|
|
||||||
handleAttestations(node, head, slot)
|
handleAttestations(node, head, slot)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#broadcast-aggregate
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#broadcast-aggregate
|
||||||
|
@ -856,15 +854,16 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.gcsafe, asyn
|
||||||
# through the slot-that is, SECONDS_PER_SLOT * 2 / 3 seconds after the start
|
# through the slot-that is, SECONDS_PER_SLOT * 2 / 3 seconds after the start
|
||||||
# of slot.
|
# of slot.
|
||||||
if slot > 2:
|
if slot > 2:
|
||||||
|
sleepToSlotOffset(
|
||||||
|
seconds(int64(SECONDS_PER_SLOT * 2) div 3),
|
||||||
|
"Waiting to aggregate attestations")
|
||||||
|
|
||||||
const TRAILING_DISTANCE = 1
|
const TRAILING_DISTANCE = 1
|
||||||
let aggregationSlot = slot - TRAILING_DISTANCE
|
let aggregationSlot = slot - TRAILING_DISTANCE
|
||||||
var aggregationHead = getAncestorAt(head, aggregationSlot)
|
var aggregationHead = getAncestorAt(head, aggregationSlot)
|
||||||
|
|
||||||
let bs = BlockSlot(blck: aggregationHead, slot: aggregationSlot)
|
let bs = BlockSlot(blck: aggregationHead, slot: aggregationSlot)
|
||||||
node.blockPool.withState(node.blockPool.tmpState, bs):
|
node.blockPool.withState(node.blockPool.tmpState, bs):
|
||||||
let twoThirdsSlot =
|
|
||||||
toBeaconTime(slot, seconds(2*int64(SECONDS_PER_SLOT)) div 3)
|
|
||||||
addTimer(saturate(node.beaconClock.fromNow(twoThirdsSlot))) do (p: pointer):
|
|
||||||
broadcastAggregatedAttestations(
|
broadcastAggregatedAttestations(
|
||||||
node, state, aggregationHead, aggregationSlot, TRAILING_DISTANCE)
|
node, state, aggregationHead, aggregationSlot, TRAILING_DISTANCE)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue