Skip to content

Commit

Permalink
fix: clarified whitelisted relayer logs
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch committed Nov 13, 2024
1 parent ef99c12 commit 8d0a58a
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 17 deletions.
10 changes: 8 additions & 2 deletions server/ante/bypass_ibc_fee_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

distrkeeper "github.com/dymensionxyz/dymension-rdk/x/dist/keeper"
seqkeeper "github.com/dymensionxyz/dymension-rdk/x/sequencers/keeper"
"github.com/dymensionxyz/dymension-rdk/x/sequencers/types"
)

type anteHandler interface {
Expand Down Expand Up @@ -53,9 +54,14 @@ func (n BypassIBCFeeDecorator) isWhitelistedRelayer(ctx sdk.Context, msgs []sdk.
}

consAddr := n.dk.GetPreviousProposerConsAddr(ctx)
wlRelayers, err := n.sk.GetWhitelistedRelayersByConsAddr(ctx, consAddr)
seq, ok := n.sk.GetSequencerByConsAddr(ctx, consAddr)
if !ok {
return false, fmt.Errorf("get sequencer by consensus addr: %s: %w", consAddr.String(), types.ErrSequencerNotFound)
}
operatorAddr := seq.GetOperator()
wlRelayers, err := n.sk.GetWhitelistedRelayers(ctx, operatorAddr)
if err != nil {
return false, fmt.Errorf("get whitelisted relayers by consensus addr: %w", err)
return false, fmt.Errorf("get whitelisted relayers: sequencer address %s: %w", consAddr.String(), err)
}

wlRelayersMap := make(map[string]struct{}, len(msgs))
Expand Down
23 changes: 18 additions & 5 deletions server/commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,23 @@ func InspectStateCmd() *cobra.Command {
fmt.Println("========================================")
fmt.Println("========================================")

heightInt, _ := strconv.ParseUint(args[0], 10, 64)
var height uint64
switch len(args) {
case 0:
// use latest height
height = state.Height()
fmt.Println("USING LATEST HEIGHT: ", height)
case 1:
// use height from args
height, err = strconv.ParseUint(args[0], 10, 64)
if err != nil {
return fmt.Errorf("failed to parse height: %w", err)
}
fmt.Println("USING PROVIDED HEIGHT: ", height)
}

fmt.Println("LOADING BLOCK AT HEIGHT: ", heightInt)
block, err := s.LoadBlock(heightInt)
fmt.Println("LOADING BLOCK AT HEIGHT: ", height)
block, err := s.LoadBlock(height)
if err != nil {
fmt.Printf("Failed to retrieve block from KVStore: %v\n", err)
return err
Expand All @@ -48,8 +61,8 @@ func InspectStateCmd() *cobra.Command {
fmt.Println("========================================")
fmt.Println("========================================")

fmt.Println("LOADING BLOCK RESPONSES AT HEIGHT: ", heightInt)
resp, err := s.LoadBlockResponses(heightInt)
fmt.Println("LOADING BLOCK RESPONSES AT HEIGHT: ", height)
resp, err := s.LoadBlockResponses(height)
if err != nil {
fmt.Printf("Failed to retrieve block responses from KVStore: %v\n", err)
return err
Expand Down
88 changes: 88 additions & 0 deletions server/consensus/processor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package consensus_test

import (
"testing"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/gogo/protobuf/proto"
prototypes "github.com/gogo/protobuf/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/dymensionxyz/dymension-rdk/server/consensus"
"github.com/dymensionxyz/dymension-rdk/testutil/utils"
seqtypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types"
)

func TestProcessConsensusMessages_ConsensusMsgUpsertSequencer(t *testing.T) {
var (
app = utils.Setup(t, false)
ctx = app.BaseApp.NewContext(false, tmproto.Header{})
consensusMsgHandler = consensus.AllowedMessagesHandler([]string{
proto.MessageName(new(seqtypes.ConsensusMsgUpsertSequencer)),
})
operator = utils.Proposer.GetOperator()
rewardAddr = utils.AccAddress()
relayers = []string{
utils.AccAddress().String(),
utils.AccAddress().String(),
utils.AccAddress().String(),
}
)
anyPubKey, err := codectypes.NewAnyWithValue(utils.ConsPrivKey.PubKey())
require.NoError(t, err)

testCases := []struct {
name string
consensusMsg proto.Message
expectedErr bool
}{
{
name: "Valid message",
consensusMsg: &seqtypes.ConsensusMsgUpsertSequencer{
Signer: authtypes.NewModuleAddress(seqtypes.ModuleName).String(),
Operator: operator.String(),
ConsPubKey: anyPubKey,
RewardAddr: rewardAddr.String(),
Relayers: relayers,
},
expectedErr: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
responses := consensus.ProcessConsensusMessages(
ctx,
app.AppCodec(),
consensusMsgHandler,
app.MsgServiceRouter(),
[]*prototypes.Any{FromProtoMsgToAny(tc.consensusMsg)},
)

if tc.expectedErr {
require.NotEmpty(t, responses)
for _, resp := range responses {
require.IsType(t, &types.ConsensusMessageResponse_Error{}, resp.Response)
}
} else {
require.Len(t, responses, 1)
require.IsType(t, &types.ConsensusMessageResponse_Ok{}, responses[0].Response)
}
})
}
}

func FromProtoMsgToAny(msg proto.Message) *prototypes.Any {
theType, err := proto.Marshal(msg)
if err != nil {
return nil
}

return &prototypes.Any{
TypeUrl: proto.MessageName(msg),
Value: theType,
}
}
14 changes: 6 additions & 8 deletions x/sequencers/keeper/sequencer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"errors"

"cosmossdk.io/collections"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -103,13 +105,9 @@ func (k Keeper) SetWhitelistedRelayers(ctx sdk.Context, sequencer stakingtypes.V

// GetWhitelistedRelayers gets the list of whitelisted relayer addresses
func (k Keeper) GetWhitelistedRelayers(ctx sdk.Context, operator sdk.ValAddress) (types.WhitelistedRelayers, error) {
return k.whitelistedRelayers.Get(ctx, operator)
}

func (k Keeper) GetWhitelistedRelayersByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) (types.WhitelistedRelayers, error) {
seq, ok := k.GetSequencerByConsAddr(ctx, consAddr)
if !ok {
return types.WhitelistedRelayers{}, collections.ErrNotFound
relayers, err := k.whitelistedRelayers.Get(ctx, operator)
if err != nil && errors.Is(err, collections.ErrNotFound) {
return types.WhitelistedRelayers{}, types.ErrWhitelistedRelayersNotFound
}
return k.whitelistedRelayers.Get(ctx, seq.GetOperator())
return relayers, err
}
5 changes: 3 additions & 2 deletions x/sequencers/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

var (
ErrSequencerNotFound = errorsmod.Register(ModuleName, 6, "sequencer address not found")
ErrHistoricalInfoNotFound = errorsmod.Register(ModuleName, 7, "historical info not found")
ErrSequencerNotFound = errorsmod.Register(ModuleName, 6, "sequencer address not found")
ErrHistoricalInfoNotFound = errorsmod.Register(ModuleName, 7, "historical info not found")
ErrWhitelistedRelayersNotFound = errorsmod.Register(ModuleName, 8, "whitelisted relayers not found")
)

0 comments on commit 8d0a58a

Please sign in to comment.