Skip to content

Commit

Permalink
app: hookup commands and eth rpc server
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbeng committed Aug 16, 2024
1 parent e3b421b commit 04dc5d7
Show file tree
Hide file tree
Showing 7 changed files with 448 additions and 584 deletions.
55 changes: 47 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ import (
ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
"github.com/spf13/cast"

"github.com/artela-network/artela-rollkit/app/post"
srvflags "github.com/artela-network/artela-rollkit/ethereum/server/flags"

"github.com/artela-network/artela-rollkit/app/ante"
"github.com/artela-network/artela-rollkit/app/ante/evm"
"github.com/artela-network/artela-rollkit/app/post"
artela "github.com/artela-network/artela-rollkit/ethereum/types"
evmmodulekeeper "github.com/artela-network/artela-rollkit/x/evm/keeper"
feemodulekeeper "github.com/artela-network/artela-rollkit/x/fee/keeper"
Expand All @@ -88,8 +90,15 @@ import (
)

const (
AccountAddressPrefix = "cosmos"
Name = "artela"
AccountAddressPrefix = "art"
Name = "artelad"
)

const (
// DisplayDenom defines the denomination displayed to users in client applications.
DisplayDenom = "art"
// BaseDenom defines artelad base denonm
BaseDenom = "aart"
)

var (
Expand Down Expand Up @@ -332,6 +341,37 @@ func New(
// voteExtHandler.SetHandlers(bApp)
// }

//kvStores := storetypes.NewKVStoreKeys(
// authtypes.StoreKey, authz.ModuleName, banktypes.StoreKey, stakingmodule.StoreKey,
// crisistypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
// govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey,
// feegrant.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, icahosttypes.StoreKey,
// capabilitytypes.StoreKey, group.StoreKey, icacontrollertypes.StoreKey, consensustypes.StoreKey,
// evmmoduletypes.StoreKey,
// feemoduletypes.StoreKey,
// // this line is used by starport scaffolding # stargate/app/storeKey
//)
//
//for _, key := range kvStores {
// if err := app.RegisterStores(key); err != nil {
// panic(err)
// }
//}
//
//tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey, evmmoduletypes.TransientKey, feemoduletypes.TransientStoreKey)
//for _, key := range tkeys {
// if err := app.RegisterStores(key); err != nil {
// panic(err)
// }
//}
//
//memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
//for _, key := range memKeys {
// if err := app.RegisterStores(key); err != nil {
// panic(err)
// }
//}

app.App = appBuilder.Build(db, traceStore, baseAppOptions...)

// Register legacy modules
Expand All @@ -344,10 +384,6 @@ func New(
return nil, err
}

/**** Module Options ****/

app.ModuleManager.RegisterInvariants(app.CrisisKeeper)

// create the simulation manager and define the order of the modules for deterministic simulations
//
// NOTE: this is not required apps that don't use the simulator for fuzz testing transactions
Expand All @@ -368,6 +404,10 @@ func New(
// return app.App.InitChainer(ctx, req)
// })

maxGasWanted := cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted))
app.setAnteHandler(app.txConfig, maxGasWanted)
app.setPostHandler()

if err := app.Load(loadLatest); err != nil {
return nil, err
}
Expand Down Expand Up @@ -471,7 +511,6 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64) {
MaxTxGasWanted: maxGasWanted,
TxFeeChecker: evm.NewDynamicFeeChecker(app.EvmKeeper),

// TODO StakingKeeper: app.StakingKeeper,
IBCKeeper: app.IBCKeeper,
}

Expand Down
39 changes: 30 additions & 9 deletions app/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ var (
govtypes.ModuleName,
minttypes.ModuleName,
crisistypes.ModuleName,
evmmoduletypes.ModuleName,
feemoduletypes.ModuleName,
ibcexported.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
Expand All @@ -96,9 +98,6 @@ var (
group.ModuleName,
consensustypes.ModuleName,
circuittypes.ModuleName,
// chain modules
evmmoduletypes.ModuleName,
feemoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
}

Expand All @@ -109,22 +108,31 @@ var (
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
beginBlockers = []string{
// cosmos sdk modules
upgradetypes.ModuleName,
feemoduletypes.ModuleName,
evmmoduletypes.ModuleName,
minttypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
authz.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
govtypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
group.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensustypes.ModuleName,
// ibc modules
capabilitytypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// chain modules
evmmoduletypes.ModuleName,
feemoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
}

Expand All @@ -133,6 +141,8 @@ var (
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
evmmoduletypes.ModuleName,
feemoduletypes.ModuleName,
feegrant.ModuleName,
group.ModuleName,
genutiltypes.ModuleName,
Expand All @@ -143,8 +153,19 @@ var (
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// chain modules
evmmoduletypes.ModuleName,
feemoduletypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
minttypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
group.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensustypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/artelad/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
"github.com/spf13/viper"

"github.com/artela-network/artela-rollkit/app"
eth "github.com/artela-network/artela-rollkit/ethereum/server/flags"

rollserv "github.com/rollkit/cosmos-sdk-starter/server"
rollconf "github.com/rollkit/rollkit/config"

rollserv "github.com/artela-network/artela-rollkit/ethereum/server"
)

func initRootCmd(
Expand All @@ -49,6 +51,7 @@ func initRootCmd(
server.StartCmdOptions{
AddFlags: func(cmd *cobra.Command) {
rollconf.AddFlags(cmd)
eth.AddEthereumServerFlags(cmd)
addModuleInitFlags(cmd)
},
StartCommandHandler: rollserv.StartHandler[servertypes.Application],
Expand Down
32 changes: 30 additions & 2 deletions cmd/artelad/cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package cmd

import (
"cosmossdk.io/math"
cmtcfg "github.com/cometbft/cometbft/config"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/artela-network/artela-rollkit/app"
"github.com/artela-network/artela-rollkit/ethereum/server/config"
artelatypes "github.com/artela-network/artela-rollkit/ethereum/types"
)

func initSDKConfig() {
Expand All @@ -21,7 +24,23 @@ func initSDKConfig() {
config.SetBech32PrefixForAccount(app.AccountAddressPrefix, accountPubKeyPrefix)
config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix)
config.SetCoinType(artelatypes.Bip44CoinType)
config.SetPurpose(sdk.Purpose) // Shared
config.SetFullFundraiserPath(artelatypes.BIP44HDPath) //nolint: staticcheck
config.Seal()

registerDenoms()
}

// RegisterDenoms registers the base and display denominations to the SDK.
func registerDenoms() {
if err := sdk.RegisterDenom(app.DisplayDenom, math.LegacyOneDec()); err != nil {
panic(err)
}

if err := sdk.RegisterDenom(app.BaseDenom, math.LegacyNewDecWithPrec(1, artelatypes.BaseDenomUnit)); err != nil {
panic(err)
}
}

// initCometBFTConfig helps to override default CometBFT Config values.
Expand All @@ -42,6 +61,11 @@ func initAppConfig() (string, interface{}) {
// The following code snippet is just for reference.
type CustomAppConfig struct {
serverconfig.Config `mapstructure:",squash"`

EVM config.EVMConfig `mapstructure:"evm"`
JSONRPC config.JSONRPCConfig `mapstructure:"json-rpc"`
TLS config.TLSConfig `mapstructure:"tls"`
Aspect config.AspectConfig `mapstructure:"aspect"`
}

// Optionally allow the chain developer to overwrite the SDK's default
Expand All @@ -63,10 +87,14 @@ func initAppConfig() (string, interface{}) {
// srvCfg.BaseConfig.IAVLDisableFastNode = true // disable fastnode by default

customAppConfig := CustomAppConfig{
Config: *srvCfg,
Config: *srvCfg,
EVM: *config.DefaultEVMConfig(),
JSONRPC: *config.DefaultJSONRPCConfig(),
TLS: *config.DefaultTLSConfig(),
Aspect: *config.DefaultAspectConfig(),
}

customAppTemplate := serverconfig.DefaultConfigTemplate
customAppTemplate := serverconfig.DefaultConfigTemplate + config.DefaultConfigTemplate
// Edit the default template file
//
// customAppTemplate := serverconfig.DefaultConfigTemplate + `
Expand Down
31 changes: 31 additions & 0 deletions ethereum/server/flags/flags.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package flags

import (
aspecttypes "github.com/artela-network/aspect-core/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"

"github.com/artela-network/artela-rollkit/ethereum/server/config"
)

// Tendermint/cosmos-sdk full-node start flags
Expand Down Expand Up @@ -76,6 +79,34 @@ const (
TLSKeyPath = "tls.key-path"
)

func AddEthereumServerFlags(cmd *cobra.Command) {
cmd.Flags().Bool(JSONRPCEnable, config.DefaultJSONRPCEnable, "Define if the JSON-RPC server should be enabled")
cmd.Flags().StringSlice(JSONRPCAPI, config.GetDefaultAPINamespaces(), "Defines a list of JSON-RPC namespaces that should be enabled")
cmd.Flags().String(JSONRPCAddress, config.DefaultJSONRPCAddress, "the JSON-RPC server address to listen on")
cmd.Flags().String(JSONWsAddress, config.DefaultJSONRPCWsAddress, "the JSON-RPC WS server address to listen on")
cmd.Flags().Uint64(JSONRPCGasCap, config.DefaultGasCap, "Sets a cap on gas that can be used in eth_call/estimateGas unit is uart (0=infinite)") //nolint:lll
cmd.Flags().Float64(JSONRPCTxFeeCap, config.DefaultTxFeeCap, "Sets a cap on transaction fee that can be sent via the RPC APIs (1 = default 1 artela)") //nolint:lll
cmd.Flags().Int32(JSONRPCFilterCap, config.DefaultFilterCap, "Sets the global cap for total number of filters that can be created")
cmd.Flags().Duration(JSONRPCEVMTimeout, config.DefaultEVMTimeout, "Sets a timeout used for eth_call (0=infinite)")
cmd.Flags().Duration(JSONRPCHTTPTimeout, config.DefaultHTTPTimeout, "Sets a read/write timeout for json-rpc http server (0=infinite)")
cmd.Flags().Duration(JSONRPCHTTPIdleTimeout, config.DefaultHTTPIdleTimeout, "Sets a idle timeout for json-rpc http server (0=infinite)")
cmd.Flags().Bool(JSONRPCAllowUnprotectedTxs, config.DefaultAllowUnprotectedTxs, "Allow for unprotected (non EIP155 signed) transactions to be submitted via the node's RPC when the global parameter is disabled") //nolint:lll
cmd.Flags().Int32(JSONRPCLogsCap, config.DefaultLogsCap, "Sets the max number of results can be returned from single `eth_getLogs` query")
cmd.Flags().Int32(JSONRPCBlockRangeCap, config.DefaultBlockRangeCap, "Sets the max block range allowed for `eth_getLogs` query")
cmd.Flags().Int(JSONRPCMaxOpenConnections, config.DefaultMaxOpenConnections, "Sets the maximum number of simultaneous connections for the server listener") //nolint:lll
cmd.Flags().Bool(JSONRPCEnableIndexer, false, "Enable the custom tx indexer for json-rpc")
cmd.Flags().Bool(JSONRPCEnableMetrics, false, "Define if EVM rpc metrics server should be enabled")

cmd.Flags().String(EVMTracer, config.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)") //nolint:lll
cmd.Flags().Uint64(EVMMaxTxGasWanted, config.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode") //nolint:lll

cmd.Flags().String(TLSCertPath, "", "the cert.pem file path for the server TLS configuration")
cmd.Flags().String(TLSKeyPath, "", "the key.pem file path for the server TLS configuration")

cmd.Flags().Uint64(ApplyPoolSize, aspecttypes.DefaultAspectPoolSize, "the cache pool size for runtime instances for applying message")
cmd.Flags().Uint64(QueryPoolSize, aspecttypes.DefaultAspectPoolSize, "the cache pool size for runtime instances for querying message")
}

// AddTxFlags adds common flags for commands to post txs
func AddTxFlags(cmd *cobra.Command) (*cobra.Command, error) {
cmd.PersistentFlags().String(flags.FlagChainID, "testnet", "Specify Chain ID for sending Tx")
Expand Down
Loading

0 comments on commit 04dc5d7

Please sign in to comment.