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

feat: app v2 poc #28

Draft
wants to merge 1 commit into
base: basechain/develop
Choose a base branch
from
Draft
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
716 changes: 716 additions & 0 deletions api/ethermint/evm/module/v1/module.pulsar.go

Large diffs are not rendered by default.

582 changes: 582 additions & 0 deletions api/ethermint/feemarket/module/v1/module.pulsar.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
cosmossdk.io/client/v2 v2.0.0-beta.5
cosmossdk.io/collections v0.4.0
cosmossdk.io/core v0.11.1
cosmossdk.io/depinject v1.0.0
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.4.1
cosmossdk.io/math v1.3.0
Expand Down Expand Up @@ -51,6 +52,7 @@ require (
github.com/tidwall/gjson v1.14.4
github.com/tidwall/sjson v1.2.5
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
golang.org/x/net v0.29.0
golang.org/x/sync v0.8.0
golang.org/x/text v0.18.0
Expand All @@ -67,7 +69,6 @@ require (
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.9 // indirect
cloud.google.com/go/storage v1.41.0 // indirect
cosmossdk.io/depinject v1.0.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand Down Expand Up @@ -225,7 +226,6 @@ require (
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.25.0 // indirect
Expand Down
20 changes: 20 additions & 0 deletions proto/buf.gen.pulsar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: v1
managed:
enabled: true
go_package_prefix:
default: cosmossdk.io/api
except:
- buf.build/googleapis/googleapis
- buf.build/cosmos/gogo-proto
- buf.build/cosmos/cosmos-proto
override:
plugins:
- name: go-pulsar
out: ../api
opt: paths=source_relative
- name: go-grpc
out: ../api
opt: paths=source_relative
- name: go-cosmos-orm
out: ../api
opt: paths=source_relative
21 changes: 21 additions & 0 deletions proto/ethermint/evm/module/v1/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

package ethermint.evm.module.v1;

import "cosmos/app/v1alpha1/module.proto";

// Module is the config object of the params module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/evmos/ethermint/x/evm"
};

// authority defines the custom module authority. If not set, defaults to the
// governance module.
string authority = 1;

// hooks_order specifies the order of epoch hooks and should be a list
// of module names which provide a epoch hooks instance. If no order is
// provided, then hooks will be applied in alphabetical order of module names.
repeated string hooks_order = 2;
}
16 changes: 16 additions & 0 deletions proto/ethermint/feemarket/module/v1/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package ethermint.feemarket.module.v1;

import "cosmos/app/v1alpha1/module.proto";

// Module is the config object of the params module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/evmos/ethermint/x/feemarket"
};

// authority defines the custom module authority. If not set, defaults to the
// governance module.
string authority = 1;
}
8 changes: 8 additions & 0 deletions scripts/protocgen-pulsar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# this script is for generating protobuf files for the new google.golang.org/protobuf API
set -eo pipefail

echo "Cleaning API directory"
(cd api; find ./ -type f \( -iname \*.pulsar.go -o -iname \*.pb.go -o -iname \*.cosmos_orm.go -o -iname \*.pb.gw.go \) -delete; find . -empty -type d -delete; cd ..)

echo "Generating API module"
(cd proto; buf generate --template buf.gen.pulsar.yaml)
4 changes: 3 additions & 1 deletion scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ rm -rf github.com
mv x/evm/types/params_v0.pb.go x/evm/migrations/v0/types/params_v0.pb.go
mv x/evm/types/chain_config_v0.pb.go x/evm/migrations/v0/types/chain_config_v0.pb.go
mv x/evm/types/params_v4.pb.go x/evm/migrations/v4/types/params_v4.pb.go
mv x/evm/types/trace_config_v0.pb.go x/evm/migrations/v0/types/trace_config_v0.pb.go
mv x/evm/types/trace_config_v0.pb.go x/evm/migrations/v0/types/trace_config_v0.pb.go

./scripts/protocgen-pulsar.sh
107 changes: 107 additions & 0 deletions x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,33 @@
import (
"context"
"encoding/json"
"fmt"

Check failure on line 21 in x/evm/module.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)

"cosmossdk.io/core/appmodule"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
"golang.org/x/exp/maps"
"sort"

Check failure on line 28 in x/evm/module.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)

abci "github.com/cometbft/cometbft/abci/types"

"cosmossdk.io/depinject"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
srvflags "github.com/evmos/ethermint/server/flags"
"github.com/spf13/cast"

modulev1 "github.com/evmos/ethermint/api/ethermint/evm/module/v1"
"github.com/evmos/ethermint/x/evm/client/cli"
"github.com/evmos/ethermint/x/evm/keeper"
"github.com/evmos/ethermint/x/evm/simulation"
Expand Down Expand Up @@ -208,3 +219,99 @@

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}

//
// App Wiring Setup
//

func init() {
appmodule.Register(&modulev1.Module{},
appmodule.Provide(ProvideModule),
appmodule.Invoke(InvokeSetEvmHooks),
)
}

type ModuleInputs struct {
depinject.In

Config *modulev1.Module
KvStoreKey *storetypes.KVStoreKey
ObjectStoreKey *storetypes.ObjectStoreKey
Cdc codec.Codec
AppOpts servertypes.AppOptions `optional:"true"`

AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
StakingKeeper types.StakingKeeper
ParamsKeeper paramskeeper.Keeper
FeeMarketKeeper types.FeeMarketKeeper

CustomContractFns []keeper.CustomContractFn
}

type ModuleOutputs struct {
depinject.Out

Keeper *keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in ModuleInputs) ModuleOutputs {
// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

tracer := ""
if in.AppOpts != nil {
tracer = cast.ToString(in.AppOpts.Get(srvflags.EVMTracer))
}

ss := in.ParamsKeeper.Subspace(types.ModuleName)

k := keeper.NewKeeper(in.Cdc, in.KvStoreKey, in.ObjectStoreKey, authority, in.AccountKeeper, in.BankKeeper, in.StakingKeeper, in.FeeMarketKeeper, tracer, ss, in.CustomContractFns)

Check failure on line 273 in x/evm/module.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

the line is 180 characters long, which exceeds the maximum of 150 characters. (lll)

m := NewAppModule(k, in.AccountKeeper, ss)

return ModuleOutputs{Keeper: k, Module: m}
}

func InvokeSetEvmHooks(
config *modulev1.Module,
evmKeeper *keeper.Keeper,
evmHooks map[string]types.EvmHooksWrapper,
) error {
// all arguments to invokers are optional
if evmKeeper == nil || config == nil {
return nil
}

modNames := maps.Keys(evmHooks)
order := config.HooksOrder
if len(order) == 0 {
order = modNames
sort.Strings(order)
}

if len(order) != len(modNames) {
return fmt.Errorf("len(hooks_order: %v) != len(hooks modules: %v)", order, modNames)
}

if len(modNames) == 0 {
return nil
}

var multiHooks keeper.MultiEvmHooks
for _, modName := range order {
hook, ok := evmHooks[modName]
if !ok {
return fmt.Errorf("can't find evm hooks for module %s", modName)
}

multiHooks = append(multiHooks, hook)
}

evmKeeper.SetHooks(multiHooks)
return nil
}
6 changes: 6 additions & 0 deletions x/evm/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ type (
GetParamSetIfExists(ctx sdk.Context, ps LegacyParams)
}
)

// EvmHooksWrapper is a wrapper for modules to inject EvmHooks using depinject.
type EvmHooksWrapper struct{ EvmHooks }

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (EvmHooksWrapper) IsOnePerModuleType() {}
50 changes: 50 additions & 0 deletions x/feemarket/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ import (
abci "github.com/cometbft/cometbft/abci/types"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"

modulev1 "github.com/evmos/ethermint/api/ethermint/feemarket/module/v1"
"github.com/evmos/ethermint/x/feemarket/client/cli"
"github.com/evmos/ethermint/x/feemarket/keeper"
"github.com/evmos/ethermint/x/feemarket/simulation"
Expand Down Expand Up @@ -194,3 +200,47 @@ func (am AppModule) IsAppModule() {}

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}

//
// App Wiring Setup
//

func init() {
appmodule.Register(&modulev1.Module{},
appmodule.Provide(
ProvideModule,
))
}

type ModuleInputs struct {
depinject.In

Config *modulev1.Module
KvStoreKey *storetypes.KVStoreKey
Cdc codec.Codec

ParamsKeeper paramskeeper.Keeper
}

type ModuleOutputs struct {
depinject.Out

ParamsKeeper keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in ModuleInputs) ModuleOutputs {
// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

ss := in.ParamsKeeper.Subspace(types.ModuleName)

k := keeper.NewKeeper(in.Cdc, authority, in.KvStoreKey, ss)

m := NewAppModule(k, ss)

return ModuleOutputs{ParamsKeeper: k, Module: m}
}
Loading