Skip to content

Commit

Permalink
Fix amino registry for custom modules (#1889)
Browse files Browse the repository at this point in the history
* Fix amino registry for custom modules

* remove some debug prints

* updated codec

* fix test codec
  • Loading branch information
udpatil authored Oct 4, 2024
1 parent 976cbaa commit 4a64247
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 27 deletions.
2 changes: 1 addition & 1 deletion testutil/keeper/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func EpochKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
cdc := codec.NewProtoCodec(registry)

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
codec.NewLegacyAmino(),
storeKey,
memStoreKey,
"EpochParams",
Expand Down
9 changes: 7 additions & 2 deletions x/epoch/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
}

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterCodec(amino)
amino.Seal()
}
2 changes: 0 additions & 2 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func (server msgServer) EVMTransaction(goCtx context.Context, msg *types.MsgEVMT
originalGasMeter.ConsumeGas(adjustedGasUsed.TruncateInt().Uint64(), "evm transaction")
}()

fmt.Println("JEREMYDEBUG: calling apply evm message from EVMTransaction")
res, applyErr := server.applyEVMMessage(ctx, emsg, stateDB, gp)
serverRes = &types.MsgEVMTransactionResponse{
Hash: tx.Hash().Hex(),
Expand Down Expand Up @@ -230,7 +229,6 @@ func (k *Keeper) GetEVMMessage(ctx sdk.Context, tx *ethtypes.Transaction, sender
}

func (k Keeper) applyEVMMessage(ctx sdk.Context, msg *core.Message, stateDB *state.DBImpl, gp core.GasPool) (*core.ExecutionResult, error) {
// fmt.Printf("JEREMYDEBUG: In applyEVMMessage, msg = %+v\n", msg)
blockCtx, err := k.GetVMBlockContext(ctx, gp)
if err != nil {
return nil, err
Expand Down
7 changes: 3 additions & 4 deletions x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func (AppModuleBasic) Name() string {
return types.ModuleName
}

func (AppModuleBasic) RegisterCodec(*codec.LegacyAmino) {}

func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {}
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterCodec(cdc)
}

// RegisterInterfaces registers the module's interface types
func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
Expand Down Expand Up @@ -286,7 +286,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
// EndBlock executes all ABCI EndBlock logic respective to the evm module. It
// returns no validator updates.
func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate {
fmt.Println("JEREMYDEBUG: block gas used", req.BlockGasUsed, ", block height", ctx.BlockHeight())
newBaseFee := am.keeper.AdjustDynamicBaseFeePerGas(ctx, uint64(req.BlockGasUsed))
if newBaseFee != nil {
metrics.GaugeEvmBlockBaseFee(newBaseFee.TruncateInt().BigInt(), req.Height)
Expand Down
3 changes: 2 additions & 1 deletion x/evm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func TestQuerierRoute(t *testing.T) {
func TestModuleExportGenesis(t *testing.T) {
k, ctx := testkeeper.MockEVMKeeper()
module := evm.NewAppModule(nil, k)
jsonMsg := module.ExportGenesis(ctx, types.ModuleCdc)
cdc := app.MakeEncodingConfig().Marshaler
jsonMsg := module.ExportGenesis(ctx, cdc)
jsonStr := string(jsonMsg)
assert.Equal(t, "{\"params\":{\"priority_normalizer\":\"1.000000000000000000\",\"base_fee_per_gas\":\"0.000000000000000000\",\"minimum_fee_per_gas\":\"100000000000.000000000000000000\",\"whitelisted_cw_code_hashes_for_delegate_call\":[],\"deliver_tx_hook_wasm_gas_limit\":\"300000\",\"max_dynamic_base_fee_upward_adjustment\":\"0.000000000000000000\",\"max_dynamic_base_fee_downward_adjustment\":\"0.000000000000000000\",\"target_gas_used_per_block\":\"100000\"},\"address_associations\":[{\"sei_address\":\"sei17xpfvakm2amg962yls6f84z3kell8c5la4jkdu\",\"eth_address\":\"0x27F7B8B8B5A4e71E8E9aA671f4e4031E3773303F\"}],\"codes\":[],\"states\":[],\"nonces\":[],\"serialized\":[{\"prefix\":\"Fg==\",\"key\":\"AwAC\",\"value\":\"AAAAAAAAAAM=\"},{\"prefix\":\"Fg==\",\"key\":\"BAAG\",\"value\":\"AAAAAAAAAAQ=\"}]}", jsonStr)
}
Expand Down
12 changes: 10 additions & 2 deletions x/evm/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (

var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
AminoCdc = codec.NewAminoCodec(amino)
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterCodec(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}
Expand All @@ -31,6 +31,14 @@ func GetAmino() *codec.LegacyAmino {
return amino
}

func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgAssociate{}, "evm/MsgAssociate", nil)
cdc.RegisterConcrete(&MsgEVMTransaction{}, "evm/MsgEVMTransaction", nil)
cdc.RegisterConcrete(&MsgSend{}, "evm/MsgSend", nil)
cdc.RegisterConcrete(&MsgRegisterPointer{}, "evm/MsgRegisterPointer", nil)
cdc.RegisterConcrete(&MsgAssociateContractAddress{}, "evm/MsgAssociateContractAddress", nil)
}

func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations((*govtypes.Content)(nil),
&AddERCNativePointerProposal{},
Expand Down
8 changes: 5 additions & 3 deletions x/mint/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

var amino = codec.NewLegacyAmino()
var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterCodec(amino)
cryptocodec.RegisterCrypto(amino)
amino.Seal()
}
Expand All @@ -23,5 +27,3 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
&UpdateMinterProposal{},
)
}

var ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
2 changes: 1 addition & 1 deletion x/oracle/keeper/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func MakeEncodingConfig(_ *testing.T) simparams.EncodingConfig {

ModuleBasics.RegisterLegacyAminoCodec(amino)
ModuleBasics.RegisterInterfaces(interfaceRegistry)
types.RegisterLegacyAminoCodec(amino)
types.RegisterCodec(amino)
types.RegisterInterfaces(interfaceRegistry)
return simparams.EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (AppModuleBasic) Name() string {

// RegisterLegacyAminoCodec registers the module's types on the given LegacyAmino codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
types.RegisterCodec(cdc)
}

// RegisterInterfaces registers the module's interface types
Expand Down
12 changes: 9 additions & 3 deletions x/oracle/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgAggregateExchangeRateVote{}, "oracle/MsgAggregateExchangeRateVote", nil)
cdc.RegisterConcrete(&MsgDelegateFeedConsent{}, "oracle/MsgDelegateFeedConsent", nil)
}
Expand All @@ -24,6 +24,12 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
}

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterCodec(amino)
sdk.RegisterLegacyAminoCodec(amino)
amino.Seal()
}
2 changes: 1 addition & 1 deletion x/tokenfactory/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestMigrate2to3(t *testing.T) {
cdc := codec.NewProtoCodec(registry)

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
codec.NewLegacyAmino(),
storeKey,
memStoreKey,
"TokenfactoryParams",
Expand Down
27 changes: 21 additions & 6 deletions x/tokenfactory/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import (
)

func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgCreateDenom{}, "tokenfactory/create-denom", nil)
cdc.RegisterConcrete(&MsgMint{}, "tokenfactory/mint", nil)
cdc.RegisterConcrete(&MsgBurn{}, "tokenfactory/burn", nil)
cdc.RegisterConcrete(&MsgChangeAdmin{}, "tokenfactory/change-admin", nil)
cdc.RegisterConcrete(&MsgCreateDenom{}, "tokenfactory/MsgCreateDenom", nil)
cdc.RegisterConcrete(&MsgUpdateDenom{}, "tokenfactory/MsgUpdateDenom", nil)
cdc.RegisterConcrete(&MsgMint{}, "tokenfactory/MsgMint", nil)
cdc.RegisterConcrete(&MsgBurn{}, "tokenfactory/MsgBurn", nil)
cdc.RegisterConcrete(&MsgChangeAdmin{}, "tokenfactory/MsgChangeAdmin", nil)
cdc.RegisterConcrete(&MsgSetDenomMetadata{}, "tokenfactory/MsgSetDenomMetadata", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgCreateDenom{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateDenom{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgMint{},
)
Expand All @@ -29,11 +34,21 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgChangeAdmin{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSetDenomMetadata{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(amino)
)

func init() {
RegisterCodec(amino)
sdk.RegisterLegacyAminoCodec(amino)

amino.Seal()
}

0 comments on commit 4a64247

Please sign in to comment.