Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon Bear committed Oct 12, 2023
1 parent d836ae6 commit 1bc9e61
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 29 deletions.
22 changes: 11 additions & 11 deletions contracts/scripts/DeployAndCallERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
9 changes: 6 additions & 3 deletions cosmos/runtime/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions cosmos/x/evm/keeper/abci.go
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 10 additions & 3 deletions cosmos/x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
package evm

import (
"context"

gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
"google.golang.org/grpc"
Expand All @@ -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{}
)

// ==============================================================================
Expand Down Expand Up @@ -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)
}
24 changes: 13 additions & 11 deletions cosmos/x/evm/plugins/state/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -198,6 +196,10 @@ func (p *plugin) Error() error {
return p.dbErr
}

func (p *plugin) Finalize() {
p.Controller.Finalize()
}

// ===========================================================================
// Accounts
// ===========================================================================
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions e2e/testapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions eth/core/chain_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions eth/log/imported.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ var (

// Warn is the warning log level.
Warn = log.Warn

Error = log.Error
)
5 changes: 5 additions & 0 deletions eth/polar/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
18 changes: 17 additions & 1 deletion eth/polar/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -39,15 +40,20 @@ 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.
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,
Expand All @@ -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.
Expand Down

0 comments on commit 1bc9e61

Please sign in to comment.