Skip to content

Commit

Permalink
fix: jit valset updates in SLCs (#1247)
Browse files Browse the repository at this point in the history
# Related Github tickets

- Closes VolumeFi#1042

# Background

Before issuing a jit valset update, check the queue for existing valset
updates with the same ID.

# Testing completed

- [x] test coverage exists or has been added/updated
- [x] tested in a private testnet

# Breaking changes

- [x] I have checked my code for breaking changes
- [x] If there are breaking changes, there is a supporting migration.
  • Loading branch information
maharifu authored Aug 7, 2024
1 parent 09c7bbc commit eeb25aa
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 2 deletions.
10 changes: 8 additions & 2 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,17 @@ func (m msgSender) SendValsetMsgForChain(ctx context.Context, chainInfo *types.C
}

mmsg := cmsg.(*types.Message)
act := mmsg.GetAction()
if mmsg.GetTurnstoneID() != string(chainInfo.GetSmartContractUniqueID()) {
return nil
}
if _, ok := act.(*types.Message_UpdateValset); ok {

if action, ok := mmsg.GetAction().(*types.Message_UpdateValset); ok {
if action.UpdateValset.Valset.ValsetID == valset.ValsetID {
// We already have an update valset scheduled for the same ID
// so there's nothing we need to do
return nil
}

err := m.ConsensusKeeper.DeleteJob(ctx, queueName, msg.GetId())
if err != nil {
m.Logger(sdkCtx).Error("unable to delete message", "err", err)
Expand Down
96 changes: 96 additions & 0 deletions x/evm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import (
"time"

sdkmath "cosmossdk.io/math"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
consensustypes "github.com/palomachain/paloma/x/consensus/types"
"github.com/palomachain/paloma/x/evm/types"
evmtypes "github.com/palomachain/paloma/x/evm/types"
"github.com/palomachain/paloma/x/evm/types/mocks"
metrixtypes "github.com/palomachain/paloma/x/metrix/types"
schedulertypes "github.com/palomachain/paloma/x/scheduler/types"
Expand Down Expand Up @@ -601,3 +605,95 @@ func TestKeeper_PublishSnapshotToAllChains(t *testing.T) {
})
}
}

func TestKeeper_SendValsetMsgForChain(t *testing.T) {
k, ms, ctx := NewEvmKeeper(t)
mSender := msgSender{
ConsensusKeeper: k.ConsensusKeeper,
cdc: k.cdc,
}
valset := types.Valset{
ValsetID: 2,
Validators: []string{"addr1", "addr2"},
Powers: []uint64{15, 5},
}
chainInfo := &types.ChainInfo{
ChainID: 100,
ChainReferenceID: "test-chain",
ReferenceBlockHeight: 1000,
ReferenceBlockHash: "0x00",
MinOnChainBalance: "100",
SmartContractUniqueID: []byte("abc"),
RelayWeights: &types.RelayWeights{
Fee: "1.0",
Uptime: "1.0",
SuccessRate: "1.0",
ExecutionTime: "1.0",
FeatureSet: "1.0",
},
}

t.Run("Should do nothing if valset update is already scheduled", func(t *testing.T) {
qMsg, _ := codectypes.NewAnyWithValue(&evmtypes.Message{
TurnstoneID: "abc",
ChainReferenceID: "test-chain",
Assignee: "addr4",
Action: &evmtypes.Message_UpdateValset{
UpdateValset: &evmtypes.UpdateValset{
Valset: &evmtypes.Valset{
ValsetID: 2,
},
},
},
})

msgs := []consensustypes.QueuedSignedMessageI{
&consensustypes.QueuedSignedMessage{
Id: 1,
Msg: qMsg,
},
}

ms.ConsensusKeeper.On("GetMessagesFromQueue", mock.Anything, mock.Anything, mock.Anything).
Return(msgs, nil).
Once()

err := mSender.SendValsetMsgForChain(ctx, chainInfo, valset, "addr3")
assert.NoError(t, err)
})

t.Run("Should add valset update to queue", func(t *testing.T) {
qMsg, _ := codectypes.NewAnyWithValue(&evmtypes.Message{
TurnstoneID: "abc",
ChainReferenceID: "test-chain",
Assignee: "addr4",
Action: &evmtypes.Message_UpdateValset{
UpdateValset: &evmtypes.UpdateValset{
Valset: &evmtypes.Valset{
ValsetID: 1,
},
},
},
})

msgs := []consensustypes.QueuedSignedMessageI{
&consensustypes.QueuedSignedMessage{
Id: 1,
Msg: qMsg,
},
}

ms.ConsensusKeeper.On("GetMessagesFromQueue", mock.Anything, mock.Anything, mock.Anything).
Return(msgs, nil).
Once()
ms.ConsensusKeeper.On("DeleteJob", mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Once()
ms.ConsensusKeeper.On("PutMessageInQueue", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(uint64(1), nil).
Once()

err := mSender.SendValsetMsgForChain(ctx, chainInfo, valset, "addr3")
assert.NoError(t, err)
})
}

0 comments on commit eeb25aa

Please sign in to comment.