Fix failing unit-tests after maxEnqueuedTime change

This commit is contained in:
claudijd 2022-09-12 18:19:52 -04:00 committed by Jonathan Claudius
parent 780d004bbd
commit 570feb79f4
5 changed files with 26 additions and 49 deletions

View File

@ -7,13 +7,15 @@ import (
"time"
"github.com/certusone/wormhole/node/pkg/common"
"github.com/certusone/wormhole/node/pkg/governor"
"github.com/certusone/wormhole/node/pkg/vaa"
"github.com/dgraph-io/badger/v3"
"go.uber.org/zap"
)
// WARNING: Change me in ./node/governor as well
const maxEnqueuedTime = time.Duration(time.Hour * 24)
type GovernorDB interface {
StoreTransfer(t *Transfer) error
StorePendingMsg(k *PendingTransfer) error
@ -225,8 +227,8 @@ func (d *Database) GetChainGovernorDataForTime(logger *zap.Logger, now time.Time
return err
}
if (p.ReleaseTime.Sub(time.Now()) > governor.MaxEnqueuedTime) {
p.ReleaseTime = now.Add(governor.MaxEnqueuedTime)
if p.ReleaseTime.Sub(time.Now()) > maxEnqueuedTime {
p.ReleaseTime = now.Add(maxEnqueuedTime)
err := d.StorePendingMsg(p)
if err != nil {
return fmt.Errorf("failed to write new pending msg for key [%v]: %w", p.Msg.MessageIDString(), err)
@ -247,7 +249,7 @@ func (d *Database) GetChainGovernorDataForTime(logger *zap.Logger, now time.Time
return err
}
p := &PendingTransfer{ReleaseTime: now.Add(governor.MaxEnqueuedTime), Msg: *msg}
p := &PendingTransfer{ReleaseTime: now.Add(maxEnqueuedTime), Msg: *msg}
pending = append(pending, p)
oldPendingToUpdate = append(oldPendingToUpdate, p)
}

View File

@ -471,8 +471,8 @@ func TestLoadingOldPendingTransfers(t *testing.T) {
assert.Equal(t, xfer1, xfers[0])
assert.Equal(t, xfer2, xfers[1])
assert.Equal(t, pending1, pendings[0])
assert.Equal(t, pending2, pendings[1])
assert.Equal(t, pending1.Msg, pendings[0].Msg)
assert.Equal(t, pending2.Msg, pendings[1].Msg)
// Make sure we can reload the updated pendings.
@ -484,6 +484,6 @@ func TestLoadingOldPendingTransfers(t *testing.T) {
assert.Equal(t, xfer1, xfers2[0])
assert.Equal(t, xfer2, xfers2[1])
assert.Equal(t, pending1, pendings2[0])
assert.Equal(t, pending2, pendings2[1])
assert.Equal(t, pending1.Msg, pendings2[0].Msg)
assert.Equal(t, pending2.Msg, pendings2[1].Msg)
}

View File

@ -47,7 +47,8 @@ const (
GoTestMode = 4
)
const MaxEnqueuedTime = time.Duration(time.Hour * 24)
// WARNING: Change me in ./node/db as well
const maxEnqueuedTime = time.Duration(time.Hour * 24)
type (
// Layout of the config data for each token
@ -341,7 +342,7 @@ func (gov *ChainGovernor) ProcessMsgForTime(msg *common.MessagePublication, now
var releaseTime time.Time
if ce.isBigTransfer(value) {
enqueueIt = true
releaseTime = now.Add(MaxEnqueuedTime)
releaseTime = now.Add(maxEnqueuedTime)
gov.logger.Error("cgov: enqueuing vaa because it is a big transaction",
zap.Uint64("value", value),
zap.Uint64("prevTotalValue", prevTotalValue),
@ -352,7 +353,7 @@ func (gov *ChainGovernor) ProcessMsgForTime(msg *common.MessagePublication, now
)
} else if newTotalValue > ce.dailyLimit {
enqueueIt = true
releaseTime = now.Add(MaxEnqueuedTime)
releaseTime = now.Add(maxEnqueuedTime)
gov.logger.Error("cgov: enqueuing vaa because it would exceed the daily limit",
zap.Uint64("value", value),
zap.Uint64("prevTotalValue", prevTotalValue),

View File

@ -205,7 +205,7 @@ func (gov *ChainGovernor) resetReleaseTimerForTime(vaaId string, now time.Time)
for _, pe := range ce.pending {
msgId := pe.dbData.Msg.MessageIDString()
if msgId == vaaId {
pe.dbData.ReleaseTime = now.Add(MaxEnqueuedTime)
pe.dbData.ReleaseTime = now.Add(maxEnqueuedTime)
gov.logger.Info("cgov: updating the release time due to admin command",
zap.String("msgId", msgId),
zap.Stringer("timeStamp", pe.dbData.Msg.Timestamp),

View File

@ -1113,8 +1113,8 @@ func TestLargeTransactionGetsEnqueuedAndReleasedWhenTheTimerExpires(t *testing.T
assert.Equal(t, 1, numPending)
assert.Equal(t, uint64(177461), valuePending)
// 24 hours after the big transaction is enqueued, it should still be there.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 3, 2022 at 2:01am (CST)")
// 23 hours after the big transaction is enqueued, it should still be there.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 3, 2022 at 1:01am (CST)")
toBePublished, err = gov.CheckPendingForTime(now)
require.NoError(t, err)
assert.Equal(t, 0, len(toBePublished))
@ -1126,25 +1126,12 @@ func TestLargeTransactionGetsEnqueuedAndReleasedWhenTheTimerExpires(t *testing.T
assert.Equal(t, 1, numPending)
assert.Equal(t, uint64(177461), valuePending)
// 48 hours after the big transaction is enqueued, it should still be there.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 4, 2022 at 2:01am (CST)")
toBePublished, err = gov.CheckPendingForTime(now)
require.NoError(t, err)
assert.Equal(t, 0, len(toBePublished))
numTrans, valueTrans, numPending, valuePending = gov.getStatsForAllChains()
require.NoError(t, err)
assert.Equal(t, 0, numTrans)
assert.Equal(t, uint64(0), valueTrans)
assert.Equal(t, 1, numPending)
assert.Equal(t, uint64(177461), valuePending)
// But then the operator resets the release time.
// // But then the operator resets the release time.
_, err = gov.resetReleaseTimerForTime(msg3.MessageIDString(), now)
require.NoError(t, err)
// So now, 72 hours after the big transaction is enqueued, it still won't get released.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 5, 2022 at 2:01am (CST)")
// So now, 12 hours later the big transaction is enqueued, it still won't get released.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 3, 2022 at 1:00pm (CST)")
toBePublished, err = gov.CheckPendingForTime(now)
require.NoError(t, err)
assert.Equal(t, 0, len(toBePublished))
@ -1156,21 +1143,8 @@ func TestLargeTransactionGetsEnqueuedAndReleasedWhenTheTimerExpires(t *testing.T
assert.Equal(t, 1, numPending)
assert.Equal(t, uint64(177461), valuePending)
// And 24 hours later, it still won't get released.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 6, 2022 at 2:01am (CST)")
toBePublished, err = gov.CheckPendingForTime(now)
require.NoError(t, err)
assert.Equal(t, 0, len(toBePublished))
numTrans, valueTrans, numPending, valuePending = gov.getStatsForAllChains()
require.NoError(t, err)
assert.Equal(t, 0, numTrans)
assert.Equal(t, uint64(0), valueTrans)
assert.Equal(t, 1, numPending)
assert.Equal(t, uint64(177461), valuePending)
// But finally, one more day later, it should get released.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 7, 2022 at 2:01am (CST)")
// But finally, a full 24hrs, it should get released.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 4, 2022 at 1:01am (CST)")
toBePublished, err = gov.CheckPendingForTime(now)
require.NoError(t, err)
assert.Equal(t, 1, len(toBePublished))
@ -1243,8 +1217,8 @@ func TestSmallTransactionsGetReleasedWhenTheTimerExpires(t *testing.T) {
assert.Equal(t, 1, numPending)
assert.Equal(t, uint64(88730), valuePending)
// If we check a day later, nothing should happen.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 2, 2022 at 12:01pm (CST)")
// If we check 23hrs later, nothing should happen.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 2, 2022 at 11:00am (CST)")
toBePublished, err := gov.CheckPendingForTime(now)
require.NoError(t, err)
assert.Equal(t, 0, len(toBePublished))
@ -1256,8 +1230,8 @@ func TestSmallTransactionsGetReleasedWhenTheTimerExpires(t *testing.T) {
assert.Equal(t, 1, numPending)
assert.Equal(t, uint64(88730), valuePending)
// But after three days, it should get released.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 4, 2022 at 12:01pm (CST)")
// But after 24hrs, it should get released.
now, _ = time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jun 2, 2022 at 12:01pm (CST)")
toBePublished, err = gov.CheckPendingForTime(now)
require.NoError(t, err)
assert.Equal(t, 1, len(toBePublished))