Gateway conditional expiration (#3946)

* wormchain: conditionally enable new guardian set expiration logic

The new code path costs more gas, so it changes the app hash.
By guarding the new code path behind a block height, consensus does not
break (as every validator that upgrades by that block will switch at the
same block height).

* wormchain: update mainnet cutover block height

* wormchain: update cutover to 24 hours later

---------

Co-authored-by: Csongor Kiss <kiss.csongor.kiss@gmail.com>
This commit is contained in:
Nikhil Suri 2024-05-21 12:04:17 -07:00 committed by GitHub
parent 1fe680dfb8
commit af8bbc208c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 24 additions and 3 deletions

View File

@ -33,10 +33,31 @@ func (k Keeper) CalculateQuorum(ctx sdk.Context, guardianSetIndex uint32) (int,
return 0, nil, types.ErrGuardianSetNotFound
}
latestGuardianSetIndex := k.GetLatestGuardianSetIndex(ctx)
isMainnet := ctx.ChainID() == "wormchain"
isTestnet := ctx.ChainID() == "wormchain-testnet-0"
if guardianSet.Index != latestGuardianSetIndex && guardianSet.ExpirationTime < uint64(ctx.BlockTime().Unix()) {
return 0, nil, types.ErrGuardianSetExpired
// We enable the new conditional approximately a week after block 6,961,447, which is
// calculated by dividing the number of seconds in a week by the average block time (~6s).
// The average block time may change in the future, so future calculations should be based
// on the actual block times at the time of the change.
// On testnet, the block height is different (and so is the block time
// slightly). There, we switch over at 2pm UTC 07/02/2024.
// On mainnet, the average block time is 5.77 seconds.
// We are targeting the cutover to happen on 5/29/2024 ~8am UTC.
// At 5.77 blocks/second, this is ~127,279 blocks from 5/20/2024 at 8pm UTC, which had a block height of 8,503,027.
// Therefore, 8,503,027 + 127,279 = 8,630,306
if (isMainnet && ctx.BlockHeight() < 8630306) || (isTestnet && ctx.BlockHeight() < 7468418) {
// old
if 0 < guardianSet.ExpirationTime && guardianSet.ExpirationTime < uint64(ctx.BlockTime().Unix()) {
return 0, nil, types.ErrGuardianSetExpired
}
} else {
// new
latestGuardianSetIndex := k.GetLatestGuardianSetIndex(ctx)
if guardianSet.Index != latestGuardianSetIndex && guardianSet.ExpirationTime < uint64(ctx.BlockTime().Unix()) {
return 0, nil, types.ErrGuardianSetExpired
}
}
return CalculateQuorum(len(guardianSet.Keys)), &guardianSet, nil