Skip to content
Open
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
6 changes: 3 additions & 3 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
switch typeURL := opts[0].GetTypeUrl(); typeURL {
case "/cosmos.evm.vm.v1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
anteHandler = newMonoEVMAnteHandler(options)
anteHandler = newMonoEVMAnteHandler(ctx, options)
case "/cosmos.evm.types.v1.ExtensionOptionDynamicFeeTx":
// cosmos-sdk tx with dynamic fee extension
anteHandler = NewCosmosAnteHandler(options)
anteHandler = NewCosmosAnteHandler(ctx, options)
default:
return ctx, errorsmod.Wrapf(
errortypes.ErrUnknownExtensionOptions,
Expand All @@ -42,7 +42,7 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
// handle as totally normal Cosmos SDK tx
switch tx.(type) {
case sdk.Tx:
anteHandler = NewCosmosAnteHandler(options)
anteHandler = NewCosmosAnteHandler(ctx, options)
default:
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid transaction type: %T", tx)
}
Expand Down
10 changes: 6 additions & 4 deletions app/ante/ante_cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
cosmosante "github.com/pushchain/push-chain-node/app/cosmos"
)

// newCosmosAnteHandler creates the default ante handler for Cosmos transactions
func NewCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
// NewCosmosAnteHandler creates the default ante handler for Cosmos transactions
func NewCosmosAnteHandler(ctx sdk.Context, options HandlerOptions) sdk.AnteHandler {
feemarketParams := options.FeeMarketKeeper.GetParams(ctx)
txFeeChecker := evmante.NewDynamicFeeChecker(&feemarketParams)

return sdk.ChainAnteDecorators(
cosmosevmcosmosante.NewRejectMessagesDecorator(), // reject MsgEthereumTxs
Expand All @@ -35,9 +37,9 @@ func NewCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
ante.NewValidateMemoDecorator(options.AccountKeeper),
cosmosante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, txFeeChecker),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper, &feemarketParams),
// NewAccountInitDecorator must be called before all signature verification decorators and SetPubKeyDecorator
// - this
// 1. generates the account for the new accounts only for gasless transactions,
Expand Down
6 changes: 5 additions & 1 deletion app/ante/ante_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ func (w evmAccountKeeperWrapper) TryAddUnorderedNonce(_ sdk.Context, _ []byte, _
}

// newMonoEVMAnteHandler creates the sdk.AnteHandler implementation for the EVM transactions.
func newMonoEVMAnteHandler(options HandlerOptions) sdk.AnteHandler {
func newMonoEVMAnteHandler(ctx sdk.Context, options HandlerOptions) sdk.AnteHandler {
evmParams := options.EvmKeeper.GetParams(ctx)
feemarketParams := options.FeeMarketKeeper.GetParams(ctx)
return sdk.ChainAnteDecorators(
evmante.NewEVMMonoDecorator(
evmAccountKeeperWrapper{options.AccountKeeper},
options.FeeMarketKeeper,
options.EvmKeeper,
options.MaxTxGasWanted,
&evmParams,
&feemarketParams,
),
)
}
6 changes: 1 addition & 5 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ type HandlerOptions struct {
ExtensionOptionChecker ante.ExtensionOptionChecker
SignModeHandler *txsigning.HandlerMap
SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params) error
TxFeeChecker ante.TxFeeChecker // safe to be nil

WasmConfig *wasmtypes.NodeConfig
WasmKeeper *wasmkeeper.Keeper
TXCounterStoreService corestoretypes.KVStoreService
Expand All @@ -63,6 +61,7 @@ type HandlerOptions struct {
FeeMarketKeeper anteinterfaces.FeeMarketKeeper
EvmKeeper anteinterfaces.EVMKeeper


IBCKeeper *ibckeeper.Keeper
CircuitKeeper *circuitkeeper.Keeper
}
Expand Down Expand Up @@ -98,9 +97,6 @@ func (options HandlerOptions) Validate() error {
return errorsmod.Wrap(errortypes.ErrLogic, "wasm keeper is required for ante builder")
}

if options.TxFeeChecker == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "tx fee checker is required for AnteHandler")
}
if options.FeeMarketKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "fee market keeper is required for AnteHandler")
}
Expand Down
32 changes: 19 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/msgservice"
signingtype "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -107,10 +108,9 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
cosmosevmante "github.com/cosmos/evm/ante"
cosmosevmevmante "github.com/cosmos/evm/ante/evm"
cosmosevmencoding "github.com/cosmos/evm/encoding"
srvflags "github.com/cosmos/evm/server/flags"
cosmosevmtypes "github.com/cosmos/evm/types"
antetypes "github.com/cosmos/evm/ante/types"
cosmosevmutils "github.com/cosmos/evm/utils"
"github.com/cosmos/evm/x/erc20"
erc20keeper "github.com/cosmos/evm/x/erc20/keeper"
Expand Down Expand Up @@ -232,7 +232,7 @@ var (
BaseDenomUnit int64 = 18

BaseDenom = pushtypes.BaseDenom
DisplayDenom = "MY_DENOM_DISPLAY" // TODO: ?
DisplayDenom = pushtypes.DisplayDenom

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Bech32PrefixAccAddr = Bech32Prefix
Expand Down Expand Up @@ -711,8 +711,9 @@ func NewChainApp(
app.BankKeeper,
app.StakingKeeper,
app.FeeMarketKeeper,
app.ConsensusParamsKeeper,
&app.ConsensusParamsKeeper,
&app.Erc20Keeper,
EVMChainID,
tracer,
)

Expand Down Expand Up @@ -790,10 +791,9 @@ func NewChainApp(
*app.StakingKeeper,
app.DistrKeeper,
app.BankKeeper,
app.Erc20Keeper,
app.TransferKeeper,
&app.Erc20Keeper,
&app.TransferKeeper,
app.IBCKeeper.ChannelKeeper,
app.EVMKeeper,
app.GovKeeper,
app.SlashingKeeper,
appCodec,
Expand Down Expand Up @@ -855,7 +855,6 @@ func NewChainApp(
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]),
app.GetSubspace(ibctransfertypes.ModuleName),
app.RatelimitKeeper, // ICS4Wrapper
//app.IBCFeeKeeper,
app.IBCKeeper.ChannelKeeper,
Expand Down Expand Up @@ -1048,7 +1047,7 @@ func NewChainApp(
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
wasmlc.NewAppModule(app.WasmClientKeeper),
ratelimit.NewAppModule(appCodec, app.RatelimitKeeper),
vm.NewAppModule(app.EVMKeeper, authKeeperEVMWrapper{app.AccountKeeper}, app.AccountKeeper.AddressCodec()),
vm.NewAppModule(app.EVMKeeper, authKeeperEVMWrapper{app.AccountKeeper}, app.BankKeeper, app.AccountKeeper.AddressCodec()),
feemarket.NewAppModule(app.FeeMarketKeeper),
erc20.NewAppModule(app.Erc20Keeper, app.AccountKeeper),
uexecutor.NewAppModule(appCodec, app.UexecutorKeeper, app.EVMKeeper, app.FeeMarketKeeper, app.BankKeeper, app.AccountKeeper, app.UregistryKeeper, app.UvalidatorKeeper),
Expand All @@ -1072,7 +1071,8 @@ func NewChainApp(
// NOTE: upgrade module is required to be prioritized
app.ModuleManager.SetOrderPreBlockers(
upgradetypes.ModuleName,
authtypes.ModuleName, // NEW
authtypes.ModuleName,
evmtypes.ModuleName,
)
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
Expand Down Expand Up @@ -1241,10 +1241,9 @@ func NewChainApp(
CircuitKeeper: &app.CircuitKeeper,

EvmKeeper: app.EVMKeeper,
ExtensionOptionChecker: cosmosevmtypes.HasDynamicFeeExtensionOption,
ExtensionOptionChecker: antetypes.HasDynamicFeeExtensionOption,
SigGasConsumer: cosmosevmante.SigVerificationGasConsumer,
MaxTxGasWanted: cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)),
TxFeeChecker: cosmosevmevmante.NewDynamicFeeChecker(app.FeeMarketKeeper),
})

// must be before Loading version
Expand Down Expand Up @@ -1378,7 +1377,7 @@ func (a *ChainApp) Configurator() module.Configurator {
// InitChainer application update at chain initialization
func (app *ChainApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {

var genesisState cosmosevmtypes.GenesisState
var genesisState map[string]json.RawMessage
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
Expand Down Expand Up @@ -1452,6 +1451,7 @@ func (a *ChainApp) DefaultGenesis() map[string]json.RawMessage {

evmGenState := evmtypes.DefaultGenesisState()
evmGenState.Params.ActiveStaticPrecompiles = evmtypes.AvailableStaticPrecompiles
evmGenState.Params.EvmDenom = BaseDenom
genesis[evmtypes.ModuleName] = a.appCodec.MustMarshalJSON(evmGenState)

// NOTE: for the example chain implementation we are also adding a default token pair,
Expand Down Expand Up @@ -1562,6 +1562,12 @@ func (app *ChainApp) RegisterPendingTxListener(listener func(common.Hash)) {
app.pendingTxListeners = append(app.pendingTxListeners, listener)
}

// GetMempool returns nil — push-chain does not use the EVM experimental mempool.
// This satisfies the evmserver.Application interface added in cosmos/evm v0.5.
func (app *ChainApp) GetMempool() sdkmempool.ExtMempool {
return nil
}

// GetMaccPerms returns a copy of the module account permissions
//
// NOTE: This is solely to be used for testing purposes.
Expand Down
13 changes: 1 addition & 12 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var ChainsCoinInfo = map[string]evmtypes.EvmCoinInfo{
Denom: BaseDenom,
ExtendedDenom: BaseDenom,
DisplayDenom: DisplayDenom,
Decimals: evmtypes.EighteenDecimals,
Decimals: evmtypes.EighteenDecimals.Uint32(),
},
}

Expand Down Expand Up @@ -59,17 +59,6 @@ func EVMAppOptions(chainID string) error {
return err
}

ethCfg := evmtypes.DefaultChainConfig(EVMChainID)

err := evmtypes.NewEVMConfigurator().
WithChainConfig(ethCfg).
// NOTE: we're using the 18 decimals
WithEVMCoinInfo(coinInfo).
Configure()
if err != nil {
return err
}

sealed = true
return nil
}
Expand Down
59 changes: 29 additions & 30 deletions app/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
stakingprecompile "github.com/cosmos/evm/precompiles/staking"
erc20Keeper "github.com/cosmos/evm/x/erc20/keeper"
transferkeeper "github.com/cosmos/evm/x/ibc/transfer/keeper"
evmkeeper "github.com/cosmos/evm/x/vm/keeper"
channelkeeper "github.com/cosmos/ibc-go/v10/modules/core/04-channel/keeper"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -68,10 +67,9 @@ func NewAvailableStaticPrecompiles(
stakingKeeper stakingkeeper.Keeper,
distributionKeeper distributionkeeper.Keeper,
bankKeeper cmn.BankKeeper,
erc20Keeper erc20Keeper.Keeper,
transferKeeper transferkeeper.Keeper,
erc20Kpr *erc20Keeper.Keeper,
transferKeeper *transferkeeper.Keeper,
channelKeeper *channelkeeper.Keeper,
evmKeeper *evmkeeper.Keeper,
govKeeper govkeeper.Keeper,
slashingKeeper slashingkeeper.Keeper,
appCodec codec.Codec,
Expand All @@ -93,46 +91,47 @@ func NewAvailableStaticPrecompiles(
panic(fmt.Errorf("failed to instantiate bech32 precompile: %w", err))
}

stakingPrecompile, err := stakingprecompile.NewPrecompile(stakingKeeper, options.AddressCodec)
if err != nil {
panic(fmt.Errorf("failed to instantiate staking precompile: %w", err))
}
stakingPrecompile := stakingprecompile.NewPrecompile(
stakingKeeper,
stakingkeeper.NewMsgServerImpl(&stakingKeeper),
stakingkeeper.NewQuerier(&stakingKeeper),
bankKeeper,
options.AddressCodec,
)

distributionPrecompile, err := distprecompile.NewPrecompile(
distributionPrecompile := distprecompile.NewPrecompile(
distributionKeeper,
distributionkeeper.NewMsgServerImpl(distributionKeeper),
distributionkeeper.NewQuerier(distributionKeeper),
stakingKeeper,
evmKeeper,
bankKeeper,
options.AddressCodec,
)
if err != nil {
panic(fmt.Errorf("failed to instantiate distribution precompile: %w", err))
}

ibcTransferPrecompile, err := ics20precompile.NewPrecompile(
ibcTransferPrecompile := ics20precompile.NewPrecompile(
bankKeeper,
stakingKeeper,
transferKeeper,
channelKeeper,
evmKeeper,
)
if err != nil {
panic(fmt.Errorf("failed to instantiate ICS20 precompile: %w", err))
}

bankPrecompile, err := bankprecompile.NewPrecompile(bankKeeper, erc20Keeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate bank precompile: %w", err))
}
bankPrecompile := bankprecompile.NewPrecompile(bankKeeper, erc20Kpr)

govPrecompile, err := govprecompile.NewPrecompile(govKeeper, appCodec, options.AddressCodec)
if err != nil {
panic(fmt.Errorf("failed to instantiate gov precompile: %w", err))
}
govPrecompile := govprecompile.NewPrecompile(
govkeeper.NewMsgServerImpl(&govKeeper),
govkeeper.NewQueryServer(&govKeeper),
bankKeeper,
appCodec,
options.AddressCodec,
)

slashingPrecompile, err := slashingprecompile.NewPrecompile(slashingKeeper, options.ValidatorAddrCodec, options.ConsensusAddrCodec)
if err != nil {
panic(fmt.Errorf("failed to instantiate slashing precompile: %w", err))
}
slashingPrecompile := slashingprecompile.NewPrecompile(
slashingKeeper,
slashingkeeper.NewMsgServerImpl(slashingKeeper),
bankKeeper,
options.ValidatorAddrCodec,
options.ConsensusAddrCodec,
)

// Stateless precompiles
precompiles[bech32Precompile.Address()] = bech32Precompile
Expand Down
20 changes: 19 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

evmtypes "github.com/cosmos/evm/x/vm/types"
)

const chainID = "testing"
Expand Down Expand Up @@ -87,6 +89,9 @@ func setup(
bam.SetChainID(chainID),
bam.SetSnapshot(snapshotStore, snapshottypes.SnapshotOptions{KeepRecent: 2}),
)
// Reset test-mode EVM configurator globals after the test so the next test
// can re-initialize them without "already set" panics.
t.Cleanup(func() { evmtypes.NewEVMConfigurator().ResetTestConfig() })
if withGenesis {
return app, app.DefaultGenesis()
}
Expand Down Expand Up @@ -120,6 +125,7 @@ func NewChainAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOpt
options.WasmOpts,
EVMAppOptions,
)
t.Cleanup(func() { evmtypes.NewEVMConfigurator().ResetTestConfig() })
genesisState := app.DefaultGenesis()
genesisState, err = GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
require.NoError(t, err)
Expand Down Expand Up @@ -431,7 +437,19 @@ func GenesisStateWithValSet(
}

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, []banktypes.SendEnabled{})
// Include denom metadata for the EVM base denom so InitEvmCoinInfo can read it during InitGenesis.
evmDenomMetadata := banktypes.Metadata{
Description: "Native 18-decimal denom for push chain",
Base: BaseDenom,
DenomUnits: []*banktypes.DenomUnit{
{Denom: BaseDenom, Exponent: 0},
{Denom: DisplayDenom, Exponent: 18},
},
Name: "Push Chain",
Symbol: "PC",
Display: DisplayDenom,
}
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{evmDenomMetadata}, []banktypes.SendEnabled{})
genesisState[banktypes.ModuleName] = codec.MustMarshalJSON(bankGenesis)

return genesisState, nil
Expand Down
Loading
Loading