Skip to content

Commit

Permalink
set LastUpdatedTimestamp in SetCrossChainTx to ensure it's always upd…
Browse files Browse the repository at this point in the history
…ated
  • Loading branch information
gartnera committed Aug 12, 2024
1 parent 83e9a28 commit 53a902a
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion x/crosschain/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ func CheckAndUpdateCctxGasPrice(
// set new gas price and last update timestamp
cctx.GetCurrentOutboundParam().GasPrice = newGasPrice.String()
cctx.GetCurrentOutboundParam().GasPriorityFee = newPriorityFee.String()
cctx.CctxStatus.LastUpdateTimestamp = ctx.BlockHeader().Time.Unix()
k.SetCrossChainTx(ctx, cctx)

return gasPriceIncrease, additionalFees, nil
Expand Down
5 changes: 5 additions & 0 deletions x/crosschain/keeper/cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (k Keeper) SetCctxAndNonceToCctxAndInboundHashToCctx(ctx sdk.Context, cctx

// SetCrossChainTx set a specific send in the store from its index
func (k Keeper) SetCrossChainTx(ctx sdk.Context, cctx types.CrossChainTx) {
// only set the update timestamp if the block height is >0 to allow
// for a genesis import
if ctx.BlockHeight() > 0 {
cctx.CctxStatus.LastUpdateTimestamp = ctx.BlockHeader().Time.Unix()
}
p := types.KeyPrefix(fmt.Sprintf("%s", types.CCTXKey))
store := prefix.NewStore(ctx.KVStore(k.storeKey), p)
b := k.cdc.MustMarshal(&cctx)
Expand Down
3 changes: 3 additions & 0 deletions x/crosschain/keeper/grpc_query_cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,8 @@ func TestKeeper_CctxByNonce(t *testing.T) {
})
require.NoError(t, err)
require.Equal(t, cctx, res.CrossChainTx)

// ensure that LastUpdateTimestamp is set to current block time
require.Equal(t, res.CrossChainTx.CctxStatus.LastUpdateTimestamp, ctx.BlockTime().Unix())
})
}
2 changes: 2 additions & 0 deletions x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) {
require.True(t, found)
require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status)
require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage)
// ensure the last update timestamp is updated
require.Equal(t, cctxFound.CctxStatus.LastUpdateTimestamp, ctx.BlockTime().Unix())
})

t.Run("can abort a cctx in pending revert", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/msg_server_refund_aborted_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (k msgServer) RefundAbortedCCTX(
commit()

// set the cctx as refunded
cctx.CctxStatus.AbortRefunded(ctx.BlockTime().Unix())
cctx.CctxStatus.AbortRefunded()

k.SetCrossChainTx(ctx, cctx)

Expand Down
1 change: 0 additions & 1 deletion x/crosschain/types/cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func (m *CrossChainTx) AddOutbound(
m.GetCurrentOutboundParam().EffectiveGasPrice = msg.ObservedOutboundEffectiveGasPrice
m.GetCurrentOutboundParam().EffectiveGasLimit = msg.ObservedOutboundEffectiveGasLimit
m.GetCurrentOutboundParam().ObservedExternalHeight = msg.ObservedOutboundBlockHeight
m.CctxStatus.LastUpdateTimestamp = ctx.BlockHeader().Time.Unix()
return nil
}

Expand Down
2 changes: 0 additions & 2 deletions x/crosschain/types/cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ func TestCrossChainTx_AddOutbound(t *testing.T) {
require.Equal(t, cctx.GetCurrentOutboundParam().EffectiveGasPrice, sdkmath.NewInt(100))
require.Equal(t, cctx.GetCurrentOutboundParam().EffectiveGasLimit, uint64(20))
require.Equal(t, cctx.GetCurrentOutboundParam().ObservedExternalHeight, uint64(10))
require.Equal(t, cctx.CctxStatus.LastUpdateTimestamp, ctx.BlockHeader().Time.Unix())
})

t.Run("successfully get outbound tx for failed ballot without amount check", func(t *testing.T) {
Expand All @@ -220,7 +219,6 @@ func TestCrossChainTx_AddOutbound(t *testing.T) {
require.Equal(t, cctx.GetCurrentOutboundParam().EffectiveGasPrice, sdkmath.NewInt(100))
require.Equal(t, cctx.GetCurrentOutboundParam().EffectiveGasLimit, uint64(20))
require.Equal(t, cctx.GetCurrentOutboundParam().ObservedExternalHeight, uint64(10))
require.Equal(t, cctx.CctxStatus.LastUpdateTimestamp, ctx.BlockHeader().Time.Unix())
})

t.Run("failed to get outbound tx if amount does not match value received", func(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions x/crosschain/types/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"fmt"
)

func (m *Status) AbortRefunded(timeStamp int64) {
func (m *Status) AbortRefunded() {
m.IsAbortRefunded = true
m.StatusMessage = "CCTX aborted and Refunded"
m.LastUpdateTimestamp = timeStamp
}

// ChangeStatus changes the status of the cross chain transaction
Expand Down
5 changes: 1 addition & 4 deletions x/crosschain/types/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types_test
import (
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -19,11 +18,9 @@ func TestStatus_AbortRefunded(t *testing.T) {
LastUpdateTimestamp: 0,
IsAbortRefunded: false,
}
timestamp := time.Now().Unix()
status.AbortRefunded(timestamp)
status.AbortRefunded()
require.Equal(t, status.IsAbortRefunded, true)
require.Equal(t, status.StatusMessage, "CCTX aborted and Refunded")
require.Equal(t, status.LastUpdateTimestamp, timestamp)
})
}

Expand Down

0 comments on commit 53a902a

Please sign in to comment.