Skip to content

Commit

Permalink
Merge branch 'main' into mat/stringer-protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasmatt authored May 15, 2024
2 parents a98447f + aeff126 commit 2568e04
Show file tree
Hide file tree
Showing 66 changed files with 2,362 additions and 537 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1855](https://github.com/NibiruChain/nibiru/pull/1855) - feat(eth-pubsub): Implement in-memory EventBus for real-time topic management and event distribution
- [#1856](https://github.com/NibiruChain/nibiru/pull/1856) - feat(eth-rpc): Conversion types and functions between Ethereum txs and blocks and Tendermint ones.
- [#1861](https://github.com/NibiruChain/nibiru/pull/1861) - feat(eth-rpc): RPC backend, Ethereum tracer, KV indexer, and RPC APIs
- [#1869](https://github.com/NibiruChain/nibiru/pull/1869) - feat(eth): Module and start of keeper tests
- [#1869](https://github.com/NibiruChain/nibiru/pull/1869) - feat(eth): Module and start of keeper tests
- [#1871](https://github.com/NibiruChain/nibiru/pull/1871) - feat(evm): app config and json-rpc
- [#1873](https://github.com/NibiruChain/nibiru/pull/1873) - feat(evm): keeper collections and grpc query impls for EthAccount, NibiruAccount

#### Dapp modules: perp, spot, oracle, etc

Expand Down
47 changes: 27 additions & 20 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,8 @@ type AnteHandlerOptions struct {
// numbers, checks signatures and account numbers, and deducts fees from the
// first signer.
func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, AnteHandlerError("account keeper")
}
if options.BankKeeper == nil {
return nil, AnteHandlerError("bank keeper")
}
if options.SignModeHandler == nil {
return nil, AnteHandlerError("sign mode handler")
}
if options.SigGasConsumer == nil {
options.SigGasConsumer = sdkante.DefaultSigVerificationGasConsumer
}
if options.WasmConfig == nil {
return nil, AnteHandlerError("wasm config")
}
if options.DevGasKeeper == nil {
return nil, AnteHandlerError("devgas keeper")
}
if options.IBCKeeper == nil {
return nil, AnteHandlerError("ibc keeper")
if err := options.ValidateAndClean(); err != nil {
return nil, err
}

anteDecorators := []sdk.AnteDecorator{
Expand Down Expand Up @@ -80,6 +62,31 @@ func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
return sdk.ChainAnteDecorators(anteDecorators...), nil
}

func (opts *AnteHandlerOptions) ValidateAndClean() error {
if opts.AccountKeeper == nil {
return AnteHandlerError("account keeper")
}
if opts.BankKeeper == nil {
return AnteHandlerError("bank keeper")
}
if opts.SignModeHandler == nil {
return AnteHandlerError("sign mode handler")
}
if opts.SigGasConsumer == nil {
opts.SigGasConsumer = sdkante.DefaultSigVerificationGasConsumer
}
if opts.WasmConfig == nil {
return AnteHandlerError("wasm config")
}
if opts.DevGasKeeper == nil {
return AnteHandlerError("devgas keeper")
}
if opts.IBCKeeper == nil {
return AnteHandlerError("ibc keeper")
}
return nil
}

func AnteHandlerError(shortDesc string) error {
return sdkerrors.Wrapf(errors.ErrLogic, "%s is required for AnteHandler", shortDesc)
}
2 changes: 1 addition & 1 deletion app/ante/fixed_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (suite *AnteTestSuite) TestOraclePostPriceTransactionsHaveFixedPrice() {
Amount: sdk.NewCoins(sdk.NewInt64Coin(appconst.BondDenom, 200)),
},
},
expectedGas: 62288,
expectedGas: 67193,
expectedErr: nil,
},
}
Expand Down
2 changes: 1 addition & 1 deletion app/ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (suite *AnteTestSuite) SetupTest() {
// Set up base app and ctx
testapp.EnsureNibiruPrefix()
encodingConfig := app.MakeEncodingConfig()
suite.app = testapp.NewNibiruTestApp(app.NewDefaultGenesisState(encodingConfig.Marshaler))
suite.app = testapp.NewNibiruTestApp(app.NewDefaultGenesisState(encodingConfig.Codec))
chainId := "test-chain-id"
ctx := suite.app.NewContext(true, tmproto.Header{
Height: 1,
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func NewNibiruApp(
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *NibiruApp {
appCodec := encodingConfig.Marshaler
appCodec := encodingConfig.Codec
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig
Expand Down
2 changes: 1 addition & 1 deletion app/appconst/appconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
GoArch = runtime.GOARCH
}

func Version() string {
func RuntimeVersion() string {
return fmt.Sprintf(
"Version %s (%s)\nCompiled at %s using Go %s (%s)",
AppVersion,
Expand Down
4 changes: 2 additions & 2 deletions app/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
Expand All @@ -25,7 +25,7 @@ func MakeEncodingConfig() EncodingConfig {

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
Codec: marshaler,
TxConfig: txCfg,
Amino: amino,
}
Expand Down
2 changes: 1 addition & 1 deletion app/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func SetupNibiruTestingApp() (

// Create genesis state
encCdc := app.MakeEncodingConfig()
genesisState := app.NewDefaultGenesisState(encCdc.Marshaler)
genesisState := app.NewDefaultGenesisState(encCdc.Codec)
testapp.SetDefaultSudoGenesis(genesisState)

return nibiruApp, genesisState
Expand Down
8 changes: 6 additions & 2 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import (
// ---------------------------------------------------------------
// Nibiru Custom Modules

"github.com/NibiruChain/nibiru/eth"
"github.com/NibiruChain/nibiru/x/common"
"github.com/NibiruChain/nibiru/x/devgas/v1"
devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper"
Expand Down Expand Up @@ -280,11 +281,12 @@ func (app *NibiruApp) InitKeepers(
// seal capability keeper after scoping modules
// app.capabilityKeeper.Seal()

// add keepers
// TODO: chore(upgrade): Potential breaking change on AccountKeeper dur
// to ProtoBaseAccount replacement.
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec,
keys[authtypes.StoreKey],
authtypes.ProtoBaseAccount,
eth.ProtoBaseAccount,
maccPerms,
sdk.GetConfig().GetBech32AccountAddrPrefix(),
govModuleAddr,
Expand Down Expand Up @@ -396,6 +398,8 @@ func (app *NibiruApp) InitKeepers(
keys[evm.StoreKey],
tkeys[evm.TransientKey],
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
)

// ---------------------------------- IBC keepers
Expand Down
10 changes: 5 additions & 5 deletions app/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func (s *TestSuite) SetupSuite() {
}

func (s *TestSuite) DefaultGenesisCopy() app.GenesisState {
return app.NewDefaultGenesisState(s.encCfg.Marshaler)
return app.NewDefaultGenesisState(s.encCfg.Codec)
}

func (s *TestSuite) TestGenesis() {
getDefaultStakingGenesis := func() *stakingtypes.GenesisState {
genStaking := new(stakingtypes.GenesisState)
s.encCfg.Marshaler.MustUnmarshalJSON(
app.StakingModule{}.DefaultGenesis(s.encCfg.Marshaler),
s.encCfg.Codec.MustUnmarshalJSON(
app.StakingModule{}.DefaultGenesis(s.encCfg.Codec),
genStaking,
)
return genStaking
Expand Down Expand Up @@ -61,9 +61,9 @@ func (s *TestSuite) TestGenesis() {
},
} {
s.T().Run(tc.name, func(t *testing.T) {
genStakingJson := s.encCfg.Marshaler.MustMarshalJSON(tc.gen)
genStakingJson := s.encCfg.Codec.MustMarshalJSON(tc.gen)
err := app.StakingModule{}.ValidateGenesis(
s.encCfg.Marshaler,
s.encCfg.Codec,
s.encCfg.TxConfig,
genStakingJson,
)
Expand Down
2 changes: 1 addition & 1 deletion app/server/config/server_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func GetAPINamespaces() []string {
// DefaultJSONRPCConfig returns an EVM config with the JSON-RPC API enabled by default
func DefaultJSONRPCConfig() *JSONRPCConfig {
return &JSONRPCConfig{
Enable: false,
Enable: true,
API: GetDefaultAPINamespaces(),
Address: DefaultJSONRPCAddress,
WsAddress: DefaultJSONRPCWsAddress,
Expand Down
93 changes: 93 additions & 0 deletions app/server/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package server

import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// Tendermint/cosmos-sdk full-node start flags
const (
WithTendermint = "with-tendermint"
Address = "address"
Transport = "transport"
TraceStore = "trace-store"
CPUProfile = "cpu-profile"
// The type of database for application and snapshots databases
AppDBBackend = "app-db-backend"
)

// GRPC-related flags.
const (
GRPCOnly = "grpc-only"
GRPCEnable = "grpc.enable"
GRPCAddress = "grpc.address"
GRPCWebEnable = "grpc-web.enable"
GRPCWebAddress = "grpc-web.address"
)

// Cosmos API flags
const (
RPCEnable = "api.enable"
EnabledUnsafeCors = "api.enabled-unsafe-cors"
)

// JSON-RPC flags
const (
JSONRPCEnable = "json-rpc.enable"
JSONRPCAPI = "json-rpc.api"
JSONRPCAddress = "json-rpc.address"
JSONWsAddress = "json-rpc.ws-address"
JSONRPCGasCap = "json-rpc.gas-cap"
JSONRPCEVMTimeout = "json-rpc.evm-timeout"
JSONRPCTxFeeCap = "json-rpc.txfee-cap"
JSONRPCFilterCap = "json-rpc.filter-cap"
JSONRPCLogsCap = "json-rpc.logs-cap"
JSONRPCBlockRangeCap = "json-rpc.block-range-cap"
JSONRPCHTTPTimeout = "json-rpc.http-timeout"
JSONRPCHTTPIdleTimeout = "json-rpc.http-idle-timeout"
JSONRPCAllowUnprotectedTxs = "json-rpc.allow-unprotected-txs"
JSONRPCMaxOpenConnections = "json-rpc.max-open-connections"
JSONRPCEnableIndexer = "json-rpc.enable-indexer"
JSONRPCEnableMetrics = "metrics"
)

// EVM flags
const (
EVMTracer = "evm.tracer"
EVMMaxTxGasWanted = "evm.max-tx-gas-wanted"
)

// TLS flags
const (
TLSCertPath = "tls.certificate-path"
TLSKeyPath = "tls.key-path"
)

// AddTxFlags adds common flags for commands to post tx
func AddTxFlags(cmd *cobra.Command) (*cobra.Command, error) {
cmd.PersistentFlags().String(flags.FlagChainID, "", "Specify Chain ID for sending Tx")
cmd.PersistentFlags().String(flags.FlagFrom, "", "Name or address of private key with which to sign")
cmd.PersistentFlags().String(flags.FlagFees, "", "Fees to pay along with transaction; eg: 5000unibi")
cmd.PersistentFlags().String(flags.FlagGasPrices, "", "Gas prices to determine the transaction fee (e.g. 5000unibi)")
cmd.PersistentFlags().String(flags.FlagNode, "tcp://localhost:26657", "<host>:<port> to tendermint rpc interface for this chain") //nolint:lll
cmd.PersistentFlags().Float64(flags.FlagGasAdjustment, flags.DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ") //nolint:lll
cmd.PersistentFlags().StringP(flags.FlagBroadcastMode, "b", flags.BroadcastSync, "Transaction broadcasting mode (sync|async)")
cmd.PersistentFlags().String(flags.FlagKeyringBackend, keyring.BackendOS, "Select keyring's backend")

// --gas can accept integers and "simulate"
// cmd.PersistentFlags().Var(&flags.GasFlagVar, "gas", fmt.Sprintf(
// "gas limit to set per-transaction; set to %q to calculate required gas automatically (default %d)",
// flags.GasFlagAuto, flags.DefaultGasLimit,
// ))

// viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))
if err := viper.BindPFlag(flags.FlagNode, cmd.PersistentFlags().Lookup(flags.FlagNode)); err != nil {
return nil, err
}
if err := viper.BindPFlag(flags.FlagKeyringBackend, cmd.PersistentFlags().Lookup(flags.FlagKeyringBackend)); err != nil {
return nil, err
}
return cmd, nil
}
Loading

0 comments on commit 2568e04

Please sign in to comment.