Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix amino registry for custom modules #1889

Merged
merged 5 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing MsgInternalEVMDelegateCall and MsgInternalEVMCall

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal calls can only come from smart contract calls like cosmwasm right? If so they can't be called this way, right? adding them here anyways but not sure if itll make a difference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, yeah I dont think we should include this since its not intended to be user facing


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 @@

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

Check warning on line 47 in x/oracle/module.go

View check run for this annotation

Codecov / codecov/patch

x/oracle/module.go#L47

Added line #L47 was not covered by tests
}

// 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 @@
)

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are missing tokenfactory/MsgUpdateDenom it seems

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

cdc.RegisterConcrete(&MsgSetDenomMetadata{}, "tokenfactory/MsgSetDenomMetadata", nil)
}

func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgCreateDenom{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUpdateDenom{},
)

Check warning on line 27 in x/tokenfactory/types/codec.go

View check run for this annotation

Codecov / codecov/patch

x/tokenfactory/types/codec.go#L25-L27

Added lines #L25 - L27 were not covered by tests
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgMint{},
)
Expand All @@ -29,11 +34,21 @@
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgChangeAdmin{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSetDenomMetadata{},
)

Check warning on line 39 in x/tokenfactory/types/codec.go

View check run for this annotation

Codecov / codecov/patch

x/tokenfactory/types/codec.go#L37-L39

Added lines #L37 - L39 were not covered by tests

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()
}
Loading