Skip to content

Commit

Permalink
Gateway conditional expiration (#3946)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
nik-suri and kcsongor authored May 21, 2024
1 parent 1fe680d commit af8bbc2
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions wormchain/x/wormhole/keeper/vaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af8bbc2

Please sign in to comment.