From af8bbc208cfc1bcfc53d4e5b7afee567816a1279 Mon Sep 17 00:00:00 2001 From: Nikhil Suri Date: Tue, 21 May 2024 12:04:17 -0700 Subject: [PATCH] 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 --- wormchain/x/wormhole/keeper/vaa.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/wormchain/x/wormhole/keeper/vaa.go b/wormchain/x/wormhole/keeper/vaa.go index b1e6f6d5ac..28b3f93f2f 100644 --- a/wormchain/x/wormhole/keeper/vaa.go +++ b/wormchain/x/wormhole/keeper/vaa.go @@ -33,10 +33,31 @@ func (k Keeper) CalculateQuorum(ctx sdk.Context, guardianSetIndex uint32) (int, return 0, nil, types.ErrGuardianSetNotFound } - latestGuardianSetIndex := k.GetLatestGuardianSetIndex(ctx) - - if guardianSet.Index != latestGuardianSetIndex && guardianSet.ExpirationTime < uint64(ctx.BlockTime().Unix()) { - return 0, nil, types.ErrGuardianSetExpired + isMainnet := ctx.ChainID() == "wormchain" + isTestnet := ctx.ChainID() == "wormchain-testnet-0" + + // 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