Skip to content
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ test: test-unit
test-all: test-race test-cover test-system

test-unit: build-dkls23
@VERSION=$(VERSION) LD_LIBRARY_PATH=$$(pwd)/../dkls23-rs/wrapper/go-wrappers:$$(pwd)/../dkls23-rs/target/release:$$LD_LIBRARY_PATH go test -mod=readonly -tags="ledger test_ledger_mock" ./...
@VERSION=$(VERSION) LD_LIBRARY_PATH=$$(pwd)/../dkls23-rs/wrapper/go-wrappers:$$(pwd)/../dkls23-rs/target/release:$$LD_LIBRARY_PATH go test -mod=readonly -tags="ledger test_ledger_mock test" ./...

test-race: build-dkls23
@VERSION=$(VERSION) LD_LIBRARY_PATH=$$(pwd)/../dkls23-rs/wrapper/go-wrappers:$$(pwd)/../dkls23-rs/target/release:$$LD_LIBRARY_PATH go test -mod=readonly -race -tags='ledger test_ledger_mock' ./...
@VERSION=$(VERSION) LD_LIBRARY_PATH=$$(pwd)/../dkls23-rs/wrapper/go-wrappers:$$(pwd)/../dkls23-rs/target/release:$$LD_LIBRARY_PATH go test -mod=readonly -race -tags='ledger test_ledger_mock test' ./...

test-cover: build-dkls23
@LD_LIBRARY_PATH=$$(pwd)/../dkls23-rs/wrapper/go-wrappers:$$(pwd)/../dkls23-rs/target/release:$$LD_LIBRARY_PATH go test -mod=readonly -timeout 30m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' ./...
@LD_LIBRARY_PATH=$$(pwd)/../dkls23-rs/wrapper/go-wrappers:$$(pwd)/../dkls23-rs/target/release:$$LD_LIBRARY_PATH go test -mod=readonly -timeout 30m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock test' ./...

benchmark: build-dkls23
@LD_LIBRARY_PATH=$$(pwd)/../dkls23-rs/wrapper/go-wrappers:$$(pwd)/../dkls23-rs/target/release:$$LD_LIBRARY_PATH go test -mod=readonly -bench=. ./...
Expand Down
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
29 changes: 27 additions & 2 deletions app/ante/ante_evm.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
package ante

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
evmante "github.com/cosmos/evm/ante/evm"
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
)

// evmAccountKeeperWrapper adapts push-chain's AccountKeeper to satisfy the
// cosmos/evm interfaces.AccountKeeper, which requires unordered-tx methods not
// present in cosmos-sdk v0.50.x. Stubs return safe no-op values because
// unordered transactions are not enabled on this chain.
type evmAccountKeeperWrapper struct {
AccountKeeper
}

var _ anteinterfaces.AccountKeeper = evmAccountKeeperWrapper{}

func (w evmAccountKeeperWrapper) UnorderedTransactionsEnabled() bool { return false }

func (w evmAccountKeeperWrapper) RemoveExpiredUnorderedNonces(_ sdk.Context) error { return nil }

func (w evmAccountKeeperWrapper) TryAddUnorderedNonce(_ sdk.Context, _ []byte, _ time.Time) error {
return nil
}

// 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(
options.AccountKeeper,
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
97 changes: 76 additions & 21 deletions app/app.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"sort"
"sync"
"time"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
Expand Down Expand Up @@ -53,6 +54,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/msgservice"
signingtype "github.com/cosmos/cosmos-sdk/types/tx/signing"
Expand Down Expand Up @@ -106,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"
antetypes "github.com/cosmos/evm/ante/types"
cosmosevmencoding "github.com/cosmos/evm/encoding"
srvflags "github.com/cosmos/evm/server/flags"
cosmosevmtypes "github.com/cosmos/evm/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 @@ -154,6 +155,7 @@ import (
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"

// "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/common"
cosmoscorevm "github.com/ethereum/go-ethereum/core/vm"
chainante "github.com/pushchain/push-chain-node/app/ante"

Expand Down Expand Up @@ -185,7 +187,8 @@ const (
NodeDir = ".pchain"
Bech32Prefix = "push"

ChainID = "localchain_9000-1"
ChainID = "localchain_9000-1"
EVMChainID = uint64(9000)
)

var (
Expand All @@ -198,6 +201,20 @@ var (
}
)

// authKeeperEVMWrapper adapts cosmos-sdk v0.50.x AccountKeeper to satisfy the
// cosmos/evm AccountKeeper interfaces, which require unordered-tx methods not
// present in sdk v0.50. Stubs are safe no-ops because this chain does not
// enable unordered transactions.
type authKeeperEVMWrapper struct {
authkeeper.AccountKeeper
}

func (w authKeeperEVMWrapper) UnorderedTransactionsEnabled() bool { return false }
func (w authKeeperEVMWrapper) RemoveExpiredUnorderedNonces(_ sdk.Context) error { return nil }
func (w authKeeperEVMWrapper) TryAddUnorderedNonce(_ sdk.Context, _ []byte, _ time.Time) error {
return nil
}

func init() {
// manually update the power reduction based on the base denom unit (10^18 [evm] or 10^6 [cosmos])
sdk.DefaultPowerReduction = math.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(BaseDenomUnit), nil))
Expand All @@ -215,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 @@ -269,10 +286,12 @@ type PacketDataUnmarshaler interface {
// ChainApp extended ABCI application
type ChainApp struct {
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry types.InterfaceRegistry
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry types.InterfaceRegistry
clientCtx client.Context
pendingTxListeners []func(common.Hash)

// keys to access the substores
keys map[string]*storetypes.KVStoreKey
Expand Down Expand Up @@ -345,7 +364,7 @@ func NewChainApp(

// TODO: verify

encodingConfig := cosmosevmencoding.MakeConfig()
encodingConfig := cosmosevmencoding.MakeConfig(EVMChainID)
interfaceRegistry := encodingConfig.InterfaceRegistry
appCodec := encodingConfig.Codec
legacyAmino := encodingConfig.Amino
Expand Down Expand Up @@ -679,12 +698,15 @@ func NewChainApp(
appCodec,
keys[evmtypes.StoreKey],
tkeys[evmtypes.TransientKey],
keys,
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper,
authKeeperEVMWrapper{app.AccountKeeper},
app.BankKeeper,
app.StakingKeeper,
app.FeeMarketKeeper,
&app.ConsensusParamsKeeper,
&app.Erc20Keeper,
EVMChainID,
tracer,
)

Expand Down Expand Up @@ -777,13 +799,12 @@ 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,
app.EvidenceKeeper,
appCodec,
)

// usigverifier precompile (0xEC..01) — core precompile range
Expand Down Expand Up @@ -833,7 +854,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 @@ -1026,7 +1046,7 @@ func NewChainApp(
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
wasmlc.NewAppModule(app.WasmClientKeeper),
ratelimit.NewAppModule(appCodec, app.RatelimitKeeper),
vm.NewAppModule(app.EVMKeeper, app.AccountKeeper),
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 @@ -1050,7 +1070,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 @@ -1219,10 +1240,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 @@ -1356,7 +1376,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 @@ -1428,15 +1448,34 @@ func (a *ChainApp) DefaultGenesis() map[string]json.RawMessage {
mintGenState.Params.MintDenom = BaseDenom
genesis[minttypes.ModuleName] = a.appCodec.MustMarshalJSON(mintGenState)

// Register bank denom metadata for the EVM base denom. In cosmos/evm v0.5
// the EVM module's InitGenesis derives coin info (decimals/display) from this
// metadata via LoadEvmCoinInfo, so a fresh chain must carry it in genesis.
var bankGenState banktypes.GenesisState
a.appCodec.MustUnmarshalJSON(genesis[banktypes.ModuleName], &bankGenState)
bankGenState.DenomMetadata = append(bankGenState.DenomMetadata, banktypes.Metadata{
Description: "Native token of Push Chain",
DenomUnits: []*banktypes.DenomUnit{
{Denom: BaseDenom, Exponent: 0},
{Denom: DisplayDenom, Exponent: 18},
},
Base: BaseDenom,
Display: DisplayDenom,
Name: "Push Chain",
Symbol: "PC",
})
genesis[banktypes.ModuleName] = a.appCodec.MustMarshalJSON(&bankGenState)

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,
// which is the base denomination of the chain (i.e. the WTOKEN contract)
erc20GenState := erc20types.DefaultGenesisState()
erc20GenState.TokenPairs = ExampleTokenPairs
erc20GenState.Params.NativePrecompiles = append(erc20GenState.Params.NativePrecompiles, WTokenContractMainnet)
erc20GenState.NativePrecompiles = append(erc20GenState.NativePrecompiles, WTokenContractMainnet)
genesis[erc20types.ModuleName] = a.appCodec.MustMarshalJSON(erc20GenState)

return genesis
Expand Down Expand Up @@ -1530,6 +1569,22 @@ func (app *ChainApp) RegisterNodeService(clientCtx client.Context, cfg config.Co
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg)
}

// SetClientCtx sets the client context on the app (required by evmserver.Application).
func (app *ChainApp) SetClientCtx(clientCtx client.Context) {
app.clientCtx = clientCtx
}

// RegisterPendingTxListener registers a listener for pending EVM transactions (required by evmserver.Application).
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
Loading
Loading