wormchain: only latest guardian set is exempt from expiry (#3714)

This commit is contained in:
Csongor Kiss 2024-01-17 17:01:05 +00:00 committed by GitHub
parent a858d76ef5
commit 521cff4ae2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 6 deletions

View File

@ -33,7 +33,9 @@ func (k Keeper) CalculateQuorum(ctx sdk.Context, guardianSetIndex uint32) (int,
return 0, nil, types.ErrGuardianSetNotFound
}
if 0 < guardianSet.ExpirationTime && guardianSet.ExpirationTime < uint64(ctx.BlockTime().Unix()) {
latestGuardianSetIndex := k.GetLatestGuardianSetIndex(ctx)
if guardianSet.Index != latestGuardianSetIndex && guardianSet.ExpirationTime < uint64(ctx.BlockTime().Unix()) {
return 0, nil, types.ErrGuardianSetExpired
}

View File

@ -56,7 +56,7 @@ func TestKeeperCalculateQuorum(t *testing.T) {
tests := []struct {
label string
guardianSet types.GuardianSet
guardianSets []types.GuardianSet
guardianSetIndex uint32
quorum int
willError bool
@ -64,17 +64,20 @@ func TestKeeperCalculateQuorum(t *testing.T) {
}{
{label: "HappyPath",
guardianSet: types.GuardianSet{Index: 0, Keys: addrsBytes, ExpirationTime: 0},
guardianSets: []types.GuardianSet{{Index: 0, Keys: addrsBytes, ExpirationTime: 0}},
guardianSetIndex: 0,
quorum: 1,
willError: false},
{label: "GuardianSetNotFound",
guardianSet: types.GuardianSet{Index: 0, Keys: addrsBytes, ExpirationTime: 0},
guardianSets: []types.GuardianSet{{Index: 0, Keys: addrsBytes, ExpirationTime: 0}},
guardianSetIndex: 1,
willError: true,
err: types.ErrGuardianSetNotFound},
{label: "GuardianSetExpired",
guardianSet: types.GuardianSet{Index: 0, Keys: addrsBytes, ExpirationTime: 100},
guardianSets: []types.GuardianSet{
{Index: 0, Keys: addrsBytes, ExpirationTime: 0},
{Index: 1, Keys: addrsBytes, ExpirationTime: 0},
},
guardianSetIndex: 0,
willError: true,
err: types.ErrGuardianSetExpired},
@ -83,7 +86,9 @@ func TestKeeperCalculateQuorum(t *testing.T) {
for _, tc := range tests {
t.Run(tc.label, func(t *testing.T) {
keeper, ctx := keepertest.WormholeKeeper(t)
keeper.AppendGuardianSet(ctx, tc.guardianSet)
for _, gs := range tc.guardianSets {
keeper.AppendGuardianSet(ctx, gs)
}
quorum, _, err := keeper.CalculateQuorum(ctx, tc.guardianSetIndex)
if tc.willError == true {