Avoid overflow in the initial 'nextExchangeTransitionConfTime' calculation (#3809)

This commit is contained in:
zah 2022-06-28 23:50:40 +03:00 committed by Zahary Karadjov
parent 725b120bc3
commit fa7d7fcc42
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 12 additions and 4 deletions

View File

@ -712,11 +712,19 @@ proc init*(T: type BeaconNode,
else:
nil
bellatrixEpochTime =
genesisTime + cfg.BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH * SECONDS_PER_SLOT
maxSecondsInMomentType = Moment.high.epochSeconds
# If the Bellatrix epoch is above this value, the calculation
# below will overflow. This happens in practice for networks
# where the `BELLATRIX_FORK_EPOCH` is not yet specified.
maxSupportedBellatrixEpoch = (maxSecondsInMomentType.uint64 - genesisTime) div
(SLOTS_PER_EPOCH * SECONDS_PER_SLOT)
bellatrixEpochTime = if cfg.BELLATRIX_FORK_EPOCH < maxSupportedBellatrixEpoch:
int64(genesisTime + cfg.BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH * SECONDS_PER_SLOT)
else:
maxSecondsInMomentType
nextExchangeTransitionConfTime =
max(Moment.init(int64 bellatrixEpochTime, Second),
max(Moment.init(bellatrixEpochTime, Second),
Moment.now)
let node = BeaconNode(

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit 2a5095505f771610f9559d2e774b2a9561f01101
Subproject commit a5bc5ca996ab72c1c5dda7d5b922b536f39f603e