diff --git a/contracts/scripts/DeployAndCallERC20.sol b/contracts/scripts/DeployAndCallERC20.sol index 8ebc5109d..9e8a7c019 100644 --- a/contracts/scripts/DeployAndCallERC20.sol +++ b/contracts/scripts/DeployAndCallERC20.sol @@ -27,20 +27,20 @@ pragma solidity ^0.8.17; import "../lib/forge-std/src/Script.sol"; import "../src/testing/SolmateERC20.sol"; +import "../src/testing/ConsumeGas.sol"; contract DeployAndCallERC20 is Script { - function run() public { - address dropAddress = address(12); - uint256 quantity = 50000; + function run() public { + address dropAddress = address(12); + uint256 quantity = 50000; - vm.startBroadcast(); - SolmateERC20 drop = new SolmateERC20(); + vm.startBroadcast(); + ConsumeGas drop = new ConsumeGas(); - for (uint256 i = 0; i < 66; i++) { - quantity += 50000; - drop.mint(dropAddress, quantity); - } - - vm.stopBroadcast(); + for (uint256 i = 0; i < 10; i++) { + drop.consumeGas(500000); } + + vm.stopBroadcast(); + } } diff --git a/cosmos/runtime/depinject.go b/cosmos/runtime/depinject.go index 9478cb46b..d6ada38e1 100644 --- a/cosmos/runtime/depinject.go +++ b/cosmos/runtime/depinject.go @@ -60,11 +60,14 @@ func ProvidePolarisRuntime(input DepInjectInput) DepInjectOutput { func(r *ethlog.Record) error { polarisGethLogger := input.Logger.With("module", "polaris-geth") switch r.Lvl { //nolint:nolintlint,exhaustive // linter is bugged. - case ethlog.LvlTrace, ethlog.LvlDebug: + case ethlog.LvlTrace: + case ethlog.LvlDebug: polarisGethLogger.Debug(r.Msg, r.Ctx...) - case ethlog.LvlInfo, ethlog.LvlWarn: + case ethlog.LvlInfo: polarisGethLogger.Info(r.Msg, r.Ctx...) - case ethlog.LvlError, ethlog.LvlCrit: + case ethlog.LvlWarn: + case ethlog.LvlCrit: + case ethlog.LvlError: polarisGethLogger.Error(r.Msg, r.Ctx...) } return nil diff --git a/cosmos/x/evm/keeper/abci.go b/cosmos/x/evm/keeper/abci.go new file mode 100644 index 000000000..a38757f57 --- /dev/null +++ b/cosmos/x/evm/keeper/abci.go @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package keeper + +import ( + "context" +) + +func (k *Keeper) PrepareCheckState(ctx context.Context) error { + k.sp.Prepare(ctx) + return nil +} diff --git a/cosmos/x/evm/module.go b/cosmos/x/evm/module.go index c3b1cc6e3..871dfe0c8 100644 --- a/cosmos/x/evm/module.go +++ b/cosmos/x/evm/module.go @@ -21,6 +21,8 @@ package evm import ( + "context" + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" "google.golang.org/grpc" @@ -41,9 +43,10 @@ import ( const ConsensusVersion = 1 var ( - _ appmodule.HasServices = AppModule{} - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasPrepareCheckState = AppModule{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} ) // ============================================================================== @@ -121,3 +124,7 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } + +func (am AppModule) PrepareCheckState(ctx context.Context) error { + return am.keeper.PrepareCheckState(ctx) +} diff --git a/cosmos/x/evm/plugins/state/plugin.go b/cosmos/x/evm/plugins/state/plugin.go index 4289bb76f..1ee99123f 100644 --- a/cosmos/x/evm/plugins/state/plugin.go +++ b/cosmos/x/evm/plugins/state/plugin.go @@ -115,6 +115,8 @@ type plugin struct { dbErr error mu sync.Mutex + + latestState sdk.Context } // NewPlugin returns a plugin with the given context and keepers. @@ -136,14 +138,10 @@ func (p *plugin) SetPrecompileLogFactory(plf events.PrecompileLogFactory) { p.plf = plf } -// Prepare sets up the context on the state plugin for a new block. It sets the gas configs to be 0 -// so that query calls to the EVM (ones that do not invoke a new transaction) do not charge gas. -// +// Prepare sets up the context on the state plugin for use in JSON-RPC calls. // Prepare implements `core.StatePlugin`. func (p *plugin) Prepare(ctx context.Context) { - p.ctx = sdk.UnwrapSDKContext(ctx). - WithKVGasConfig(storetypes.GasConfig{}). - WithTransientKVGasConfig(storetypes.GasConfig{}) + p.latestState = sdk.UnwrapSDKContext(ctx) } // Reset sets up the state plugin for execution of a new transaction. It sets up the snapshottable @@ -198,6 +196,10 @@ func (p *plugin) Error() error { return p.dbErr } +func (p *plugin) Finalize() { + p.Controller.Finalize() +} + // =========================================================================== // Accounts // =========================================================================== @@ -539,12 +541,12 @@ func (p *plugin) StateAtBlockNumber(number uint64) (core.StatePlugin, error) { int64Number := int64(number) // TODO: the GTE may be hiding a larger issue with the timing of the NewHead channel stuff. // Investigate and hopefully remove this GTE. - if int64Number >= p.ctx.BlockHeight() { + if int64Number >= p.latestState.BlockHeight() { // TODO: Manager properly - if p.ctx.MultiStore() == nil { - ctx = p.ctx.WithEventManager(sdk.NewEventManager()) + if p.latestState.MultiStore() == nil { + ctx = p.latestState.WithEventManager(sdk.NewEventManager()) } else { - ctx, _ = p.ctx.CacheContext() + ctx, _ = p.latestState.CacheContext() } } else { // Get the query context at the given height. @@ -558,7 +560,7 @@ func (p *plugin) StateAtBlockNumber(number uint64) (core.StatePlugin, error) { // Create a State Plugin with the requested chain height. sp := NewPlugin(p.ak, p.storeKey, p.plf) // TODO: Manager properly - if p.ctx.MultiStore() != nil { + if p.latestState.MultiStore() != nil { sp.Reset(ctx) } return sp, nil diff --git a/e2e/testapp/app_config.go b/e2e/testapp/app_config.go index ca2eade79..d49a7fcca 100644 --- a/e2e/testapp/app_config.go +++ b/e2e/testapp/app_config.go @@ -123,6 +123,9 @@ func MakeAppConfig(bech32Prefix string) depinject.Config { // there is nothing left over in the validator fee pool, so as to keep the // CanWithdrawInvariant invariant. // NOTE: staking module is required if HistoricalEntries param > 0 + PrepareCheckStaters: []string{ + evmtypes.ModuleName, + }, PreBlockers: []string{ upgradetypes.ModuleName, }, diff --git a/eth/core/chain_resources.go b/eth/core/chain_resources.go index 96f3b43b2..9627211b6 100644 --- a/eth/core/chain_resources.go +++ b/eth/core/chain_resources.go @@ -48,6 +48,7 @@ func (bc *blockchain) StateAtBlockNumber(number uint64) (state.StateDB, error) { if err != nil { return nil, err } + return state.NewStateDB(sp, bc.pp), nil } diff --git a/eth/log/imported.go b/eth/log/imported.go index 1a567bbfb..3759c7c57 100644 --- a/eth/log/imported.go +++ b/eth/log/imported.go @@ -61,4 +61,6 @@ var ( // Warn is the warning log level. Warn = log.Warn + + Error = log.Error ) diff --git a/eth/polar/backend.go b/eth/polar/backend.go index fc18724ad..cf9f3ff05 100644 --- a/eth/polar/backend.go +++ b/eth/polar/backend.go @@ -134,6 +134,11 @@ func NewWithNetworkingStack( // Init initializes the Polaris struct. func (pl *Polaris) Init() error { var err error + + // Run safety message for feedback to the user if they are running + // with development configs. + pl.config.SafetyMessage() + // For now, we only have a legacy pool, we will implement blob pool later. legacyPool := legacypool.New( pl.config.LegacyTxPool, pl.Blockchain(), diff --git a/eth/polar/config.go b/eth/polar/config.go index 6a3d5b418..aa47c46b0 100644 --- a/eth/polar/config.go +++ b/eth/polar/config.go @@ -30,6 +30,7 @@ import ( "github.com/ethereum/go-ethereum/miner" "pkg.berachain.dev/polaris/eth/common" + "pkg.berachain.dev/polaris/eth/log" "pkg.berachain.dev/polaris/eth/params" ) @@ -39,6 +40,11 @@ const ( // gpoDefault is the default gpo starting point. gpoDefault = 1000000000 + + // developmentCoinbase is the address used for development. + // DO NOT USE IN PRODUCTION. + // 0xf8637fa70e8e329ecb8463b788d96914f8cfe191d15ae36f161227629e3f5693. + developmentCoinbase = "0xAf15f95bed0D3913a29092Fd7837451Ce4de64D3" ) // DefaultConfig returns the default JSON-RPC config. @@ -46,8 +52,8 @@ func DefaultConfig() *Config { gpoConfig := ethconfig.FullNodeGPO gpoConfig.Default = big.NewInt(gpoDefault) minerCfg := miner.DefaultConfig + minerCfg.Etherbase = common.HexToAddress(developmentCoinbase) // TODO: setup proper command line flags - minerCfg.Etherbase = common.Address{1} return &Config{ Chain: *params.DefaultChainConfig, Miner: minerCfg, @@ -59,6 +65,16 @@ func DefaultConfig() *Config { } } +// SafetyMessage is a safety check for the JSON-RPC config. +func (c *Config) SafetyMessage() { + if c.Miner.Etherbase == common.HexToAddress(developmentCoinbase) { + log.Error( + "development etherbase in use - please verify this is intentional", "address", + c.Miner.Etherbase, + ) + } +} + // Config represents the configurable parameters for Polaris. type Config struct { // The chain configuration to use.