Skip to content

Commit

Permalink
fix(sequencers): get by cons addr in all scenarios on EVM (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt authored Aug 29, 2024
1 parent 646dfab commit 0c9f532
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,9 @@ func NewRollapp(

app.EvmKeeper = evmkeeper.NewKeeper(
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper, app.BankKeeper, app.SequencersKeeper, app.FeeMarketKeeper,
app.AccountKeeper, app.BankKeeper,
EVMWrappedSeqKeeper{app.SequencersKeeper},
app.FeeMarketKeeper,
tracer, app.GetSubspace(evmtypes.ModuleName),
)

Expand Down
31 changes: 31 additions & 0 deletions app/evm_sequencers_keeper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
seqkeeper "github.com/dymensionxyz/dymension-rdk/x/sequencers/keeper"
evmtypes "github.com/evmos/evmos/v12/x/evm/types"
)

// EVMWrappedSeqKeeper adapts values returned by sequencer keeper. It makes sure a valid validator object is always returned.
// The operator addr of the object will be used in as the EVM 'coinbase' param.
type EVMWrappedSeqKeeper struct {
seqkeeper.Keeper
}

var _ evmtypes.StakingKeeper = &EVMWrappedSeqKeeper{}

func (w EVMWrappedSeqKeeper) GetValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) (validator stakingtypes.Validator, found bool) {
ret, ok := w.Keeper.GetValidatorByConsAddr(ctx, consAddr)
if !ok {
ret = w.generateValidator()
}
return ret, true
}

func (w EVMWrappedSeqKeeper) generateValidator() stakingtypes.Validator {
pref := sdk.GetConfig().GetBech32ValidatorAddrPrefix()
operator, _ := bech32.ConvertAndEncode(pref, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
return stakingtypes.Validator{OperatorAddress: operator}
}
15 changes: 15 additions & 0 deletions app/evm_sequencers_keeper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestEVMWrappedSeqKeeper_generateValidator(t *testing.T) {
k := EVMWrappedSeqKeeper{}
v := k.generateValidator()
require.NotPanics(t, func() {
_ = v.GetOperator()
})
}

0 comments on commit 0c9f532

Please sign in to comment.