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

fix(mempool): Prevent runTx failures #1425

Merged
merged 57 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
b8ff23d
checktx
itsdevbear Jan 14, 2024
d20570d
x
itsdevbear Jan 14, 2024
b697a60
config
itsdevbear Jan 14, 2024
838fd0c
added
itsdevbear Jan 14, 2024
d50e582
bing bong
itsdevbear Jan 14, 2024
7a2ea33
rc5
itsdevbear Jan 14, 2024
e8f31ad
default gas price
itsdevbear Jan 14, 2024
a8bc57d
removeyeet
itsdevbear Jan 14, 2024
1cb455c
bing bong
itsdevbear Jan 14, 2024
a77f174
bing bong
itsdevbear Jan 14, 2024
69329b1
preparecheckstate
itsdevbear Jan 14, 2024
bc65f34
bing bong
itsdevbear Jan 14, 2024
5262965
fix
itsdevbear Jan 14, 2024
9e56706
removing
itsdevbear Jan 14, 2024
cf9c1d5
state mgmt pt 1
calbera Jan 15, 2024
1fdca16
state mgmt pt 2
calbera Jan 16, 2024
ace17c4
cleanup latest query context
calbera Jan 16, 2024
127a25f
eviction from comet mempool
calbera Jan 16, 2024
0e03eff
bump sdk
itsdevbear Jan 16, 2024
324e24a
deletion from timeInserted map
calbera Jan 16, 2024
6bd959e
fire chain head
calbera Jan 16, 2024
0c0b3d0
comet remote cache
calbera Jan 16, 2024
f686f83
minor
calbera Jan 16, 2024
dc6302c
default removal to false
calbera Jan 16, 2024
c1a9e54
rw lock on block building
calbera Jan 16, 2024
51e7c77
unfuck
itsdevbear Jan 16, 2024
40303ec
test1
itsdevbear Jan 16, 2024
d5d59b7
hack7
itsdevbear Jan 16, 2024
49eb151
bet
itsdevbear Jan 16, 2024
a76c9b5
bet
itsdevbear Jan 16, 2024
7c420b0
semver
itsdevbear Jan 16, 2024
7c758a1
tag
itsdevbear Jan 16, 2024
deff092
experimental
itsdevbear Jan 16, 2024
0292437
bet
itsdevbear Jan 16, 2024
af457a4
Merge branch 'main' into 222
itsdevbear Jan 17, 2024
c82042a
bet
itsdevbear Jan 17, 2024
92cadd1
merge
itsdevbear Jan 17, 2024
a8222c0
remove pebble from geth
itsdevbear Jan 17, 2024
66e3f65
merge
itsdevbear Jan 17, 2024
ba7c9dc
bet
itsdevbear Jan 17, 2024
f2c30d6
remove unused flag
itsdevbear Jan 17, 2024
e0e30d7
bet
itsdevbear Jan 17, 2024
9f08107
lint
itsdevbear Jan 17, 2024
bd216d5
bet
itsdevbear Jan 17, 2024
3fc2ac1
focus
itsdevbear Jan 17, 2024
e50a5e9
ooga booga
itsdevbear Jan 17, 2024
c2870a8
ci
itsdevbear Jan 17, 2024
2c752d7
not gonna break on ci
itsdevbear Jan 17, 2024
80533a6
fix
itsdevbear Jan 17, 2024
1cc85b8
scam
itsdevbear Jan 17, 2024
8c96574
format
itsdevbear Jan 17, 2024
8a521ab
bet
itsdevbear Jan 17, 2024
9b8fc41
attemp to fix
itsdevbear Jan 17, 2024
a4363aa
hood
itsdevbear Jan 17, 2024
9d39963
fix unit tests
itsdevbear Jan 17, 2024
fce00ab
bet
itsdevbear Jan 17, 2024
b75cafa
bet
itsdevbear Jan 17, 2024
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

Large diffs are not rendered by default.

217 changes: 46 additions & 171 deletions cosmos/api/polaris/evm/v1alpha1/tx.pulsar.go

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions cosmos/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import (
"github.com/berachain/polaris/cosmos/config/flags"
"github.com/berachain/polaris/eth"
"github.com/berachain/polaris/eth/accounts"
"github.com/berachain/polaris/eth/node"
"github.com/berachain/polaris/eth/polar"

sdkflags "github.com/cosmos/cosmos-sdk/client/flags"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
version "github.com/cosmos/cosmos-sdk/version"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search results indicate that the DefaultConfig function is indeed used in various places within the codebase. Specifically, it is referenced in files such as eth/node/config.go, eth/polar/config.go, cosmos/precompile/governance/testutil.go, and several times within cosmos/config/default.go.

Given this information, it appears that the removal of the DefaultConfig function from cosmos/config/config.go could potentially impact other parts of the codebase where this function is expected to exist.

Analysis chain

The removal of the DefaultConfig function is not mentioned in the summary. Please confirm that this function is not used elsewhere in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for usage of DefaultConfig in the codebase.
rg --type go 'DefaultConfig\(\)'

Length of output: 445


"github.com/ethereum/go-ethereum/common/hexutil"
)

type Config = eth.Config
Expand All @@ -49,17 +50,6 @@ func SetupCosmosConfig() {
config.Seal()
}

// DefaultConfig returns the default configuration for a polaris chain.
func DefaultConfig() *Config {
nodeCfg := node.DefaultConfig()
nodeCfg.DataDir = ""
nodeCfg.KeyStoreDir = ""
return &Config{
Polar: *polar.DefaultConfig(),
Node: *nodeCfg,
}
}

// MustReadConfigFromAppOpts reads the configuration options from the given
// application options. Panics if the configuration cannot be read.
func MustReadConfigFromAppOpts(opts servertypes.AppOptions) *Config {
Expand Down Expand Up @@ -105,6 +95,17 @@ func readConfigFromAppOptsParser(parser AppOptionsParser) (*Config, error) {
parser.GetHexutilBytes(flags.MinerExtraData); err != nil {
return nil, err
}

if len(conf.Polar.Miner.ExtraData) == 0 {
commit := version.NewInfo().GitCommit
if len(commit) != 40 { //nolint:gomnd // its okay.
return nil, err
}
conf.Polar.Miner.ExtraData = hexutil.Bytes(
commit[32:40],
)
}

if conf.Polar.Miner.GasFloor, err =
parser.GetUint64(flags.MinerGasFloor); err != nil {
return nil, err
Expand Down
72 changes: 72 additions & 0 deletions cosmos/config/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 config

import (
"github.com/berachain/polaris/eth/node"
"github.com/berachain/polaris/eth/polar"

cmtcfg "github.com/cometbft/cometbft/config"

serverconfig "github.com/cosmos/cosmos-sdk/server/config"
)

// RecommendedCometBFTConfig returns the recommended CometBFT config
// for the application.
func RecommendedCometBFTConfig() *cmtcfg.Config {
cfg := cmtcfg.DefaultConfig()
cfg.Mempool.Size = 30000
cfg.Mempool.CacheSize = 30000
cfg.Mempool.Recheck = true
cfg.Mempool.Type = "flood"

cfg.P2P.MaxNumInboundPeers = 10
cfg.P2P.MaxNumOutboundPeers = 15

cfg.TxIndex.Indexer = "null"

cfg.Instrumentation.Prometheus = true
return cfg
}

// RecommendedServerConfig returns the recommended server config.
func RecommendedServerConfig() *serverconfig.Config {
cfg := serverconfig.DefaultConfig()
cfg.MinGasPrices = "0abera"
cfg.API.Enable = true
cfg.Telemetry.Enabled = true
cfg.Telemetry.PrometheusRetentionTime = 180
cfg.Telemetry.EnableHostnameLabel = true
cfg.Telemetry.GlobalLabels = [][]string{}
cfg.IAVLCacheSize = 20000
return cfg
}

// DefaultPolarisConfig returns the default polaris config.
func DefaultPolarisConfig() *Config {
nodeCfg := node.DefaultConfig()
nodeCfg.DataDir = ""
nodeCfg.KeyStoreDir = ""
return &Config{
Polar: *polar.DefaultConfig(),
Node: *nodeCfg,
}
}
2 changes: 1 addition & 1 deletion cosmos/config/mocks/app_options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/cockroachdb/pebble => github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
// We replace `go-ethereum` with `polaris-geth` in order include our required changes.
github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0
github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20240114134402-f43e40102ad1
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
Expand Down
4 changes: 2 additions & 2 deletions cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0 h1:jGah7o6k6xytfTFH7hIKmfJZOPnAhCb9bmCb+lRS4Bk=
github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA=
github.com/berachain/polaris-geth v0.0.0-20240114134402-f43e40102ad1 h1:Rh5+bQB/Z1fdQhVT7ltZQRAVNOn3KJe6zsA5gUXnPDc=
github.com/berachain/polaris-geth v0.0.0-20240114134402-f43e40102ad1/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA=
github.com/berachain/polaris/contracts v0.1.0-alpha h1:ZRkh0JyMHp11Xe8z7gcJhfnn9X6vU6/3iSG3Bdi/kJQ=
github.com/berachain/polaris/contracts v0.1.0-alpha/go.mod h1:Sm1T+tIQGuP0wEJnF/TlgZiJ+NPHgOZWO7vAz7FkwVs=
github.com/berachain/polaris/eth v0.1.2-alpha h1:kKp2peFLTGK3LaupZcngycSHk+zRxmczGKgsiU59R08=
Expand Down
8 changes: 5 additions & 3 deletions cosmos/runtime/chain/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ func (wbc *WrappedBlockchain) ProcessProposal(
}, err
}

spf := wbc.StatePluginFactory()
spf.SetInsertChainContext(ctx)
// Set the insert chain context for processing the block. NOTE: We insert to the chain but do
// NOT set the chain head using this context.
wbc.StatePluginFactory().SetInsertChainContext(ctx)
wbc.PreparePlugins(ctx)

// Insert the block into the chain.å
// Insert the block into the chain.
if err = wbc.InsertBlockWithoutSetHead(block); err != nil {
ctx.Logger().Error("failed to insert block", "err", err)
return &abci.ResponseProcessProposal{
Expand Down
8 changes: 0 additions & 8 deletions cosmos/runtime/miner/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ import (
abci "github.com/cometbft/cometbft/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ethereum/go-ethereum/common"
)

// emptyHash is a common.Hash initialized to all zeros.
var emptyHash = common.Hash{}

// PrepareProposal implements baseapp.PrepareProposal.
func (m *Miner) PrepareProposal(
ctx sdk.Context, req *abci.RequestPrepareProposal,
Expand All @@ -43,9 +38,6 @@ func (m *Miner) PrepareProposal(
ethGasUsed uint64
)

// Set the mining context for the state plugin factory.
m.spf.SetLatestMiningContext(ctx)

// Trigger the geth miner to build a block.
if payloadEnvelopeBz, ethGasUsed, err = m.buildBlock(ctx); err != nil {
return nil, err
Expand Down
3 changes: 0 additions & 3 deletions cosmos/runtime/miner/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
package miner

import (
"context"

"github.com/berachain/polaris/eth/core"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -45,7 +43,6 @@ type (
EVMKeeper interface {
// Setup initializes the EVM keeper.
Setup(core.Blockchain) error
SetLatestQueryContext(context.Context) error
GetHost() core.PolarisHostChain
}
)
46 changes: 28 additions & 18 deletions cosmos/runtime/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import (
"context"
"errors"
"time"

"github.com/cosmos/gogoproto/proto"
Expand All @@ -41,9 +42,10 @@

// Miner implements the baseapp.TxSelector interface.
type Miner struct {
miner eth.Miner
app TxDecoder
spf core.StatePluginFactory
miner eth.Miner
app TxDecoder
bc core.Blockchain

valTxSelector baseapp.TxSelector
serializer EnvelopeSerializer
allowedValMsgs map[string]sdk.Msg
Expand All @@ -52,12 +54,12 @@

// New produces a cosmos miner from a geth miner.
func New(
miner eth.Miner, app TxDecoder, spf core.StatePluginFactory, allowedValMsgs map[string]sdk.Msg,
miner eth.Miner, app TxDecoder, allowedValMsgs map[string]sdk.Msg, bc core.Blockchain,
) *Miner {
return &Miner{
miner: miner,
app: app,
spf: spf,
bc: bc,
allowedValMsgs: allowedValMsgs,
valTxSelector: baseapp.NewDefaultTxSelector(),
}
Expand All @@ -76,6 +78,7 @@
// Record the time it takes to build a payload.
defer telemetry.MeasureSince(time.Now(), MetricKeyBuildBlock)

// Submit payload for building with the given context.
if err := m.submitPayloadForBuilding(ctx); err != nil {
return nil, 0, err
}
Expand All @@ -87,13 +90,18 @@
// submitPayloadForBuilding submits a payload for building.
func (m *Miner) submitPayloadForBuilding(ctx context.Context) error {
var (
err error
payload *miner.Payload
sCtx = sdk.UnwrapSDKContext(ctx)
err error
payload *miner.Payload
sCtx = sdk.UnwrapSDKContext(ctx)
payloadArgs = m.constructPayloadArgs(uint64(sCtx.BlockTime().Unix()))
)

// Build Payload
if payload, err = m.miner.BuildPayload(m.constructPayloadArgs(sCtx)); err != nil {
// Set the mining context for geth to build the payload with.
m.bc.StatePluginFactory().SetLatestMiningContext(ctx)
m.bc.PreparePlugins(ctx)

// Build Payload.
if payload, err = m.miner.BuildPayload(payloadArgs); err != nil {
sCtx.Logger().Error("failed to build payload", "err", err)
return err
}
Expand All @@ -103,13 +111,13 @@
}

// constructPayloadArgs builds a payload to submit to the miner.
func (m *Miner) constructPayloadArgs(ctx sdk.Context) *miner.BuildPayloadArgs {
func (m *Miner) constructPayloadArgs(blockTime uint64) *miner.BuildPayloadArgs {
return &miner.BuildPayloadArgs{
Timestamp: uint64(ctx.BlockTime().Unix()),
Timestamp: blockTime,
FeeRecipient: m.miner.Etherbase(),
Random: common.Hash{}, /* todo: generated random */
Withdrawals: make(ethtypes.Withdrawals, 0),
BeaconRoot: &emptyHash,
BeaconRoot: nil, // Add this when implementing Cancun.
}
}

Expand Down Expand Up @@ -141,13 +149,15 @@
// processValidatorMsgs processes the validator messages.
func (m *Miner) processValidatorMsgs(
ctx sdk.Context, maxTxBytes int64, ethGasUsed uint64, txs [][]byte,
) ([][]byte, error) { //nolint:unparam // should be handled better.

Check failure on line 152 in cosmos/runtime/miner/miner.go

View workflow job for this annotation

GitHub Actions / ci (lint, polaris-linux-latest, 1.21.6)

directive `//nolint:unparam // should be handled better.` is unused for linter "unparam" (nolintlint)
var maxBlockGas uint64
if b := ctx.ConsensusParams().Block; b != nil {
maxBlockGas = uint64(b.MaxGas)
b := ctx.ConsensusParams().Block
if b == nil {
return nil, errors.New("consensus params block is nil")
}

blockGasRemaining := maxBlockGas - ethGasUsed
if uint64(b.MaxGas) < ethGasUsed {
return nil, errors.New("eth gas used exceeds comet block max gas")
}
blockGasRemaining := uint64(b.MaxGas) - ethGasUsed

for _, txBz := range txs {
tx, err := m.app.TxDecode(txBz)
Expand Down
13 changes: 5 additions & 8 deletions cosmos/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package runtime

import (
"context"
"time"

cosmoslog "cosmossdk.io/log"
Expand Down Expand Up @@ -54,9 +53,8 @@ import (
// EVMKeeper is an interface that defines the methods needed for the EVM setup.
type EVMKeeper interface {
// Setup initializes the EVM keeper.
Setup(core.Blockchain) error
Setup(core.Blockchain, *txpool.Mempool) error
GetStatePluginFactory() core.StatePluginFactory
SetLatestQueryContext(context.Context) error
GetHost() core.PolarisHostChain
}

Expand Down Expand Up @@ -137,9 +135,7 @@ func (p *Polaris) Build(
) error {
// Wrap the geth miner and txpool with the cosmos miner and txpool.
p.WrappedMiner = miner.New(
p.ExecutionLayer.Backend().Miner(), app,
ek.GetHost().GetStatePluginFactory(),
allowedValMsgs,
p.ExecutionLayer.Backend().Miner(), app, allowedValMsgs, p.Backend().Blockchain(),
)
p.WrappedBlockchain = chain.New(
p.ExecutionLayer.Backend().Blockchain(), app,
Expand All @@ -154,7 +150,7 @@ func (p *Polaris) Build(
app.SetPrepareProposal(p.ProposalProvider.PrepareProposal)
app.SetProcessProposal(p.ProposalProvider.ProcessProposal)

if err := ek.Setup(p.WrappedBlockchain); err != nil {
if err := ek.Setup(p.WrappedBlockchain, p.WrappedTxPool); err != nil {
return err
}

Expand Down Expand Up @@ -224,5 +220,6 @@ func (p *Polaris) LoadLastState(cms storetypes.CommitMultiStore, appHeight uint6
WithBlockHeight(int64(appHeight)).
WithGasMeter(storetypes.NewInfiniteGasMeter()).
WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).WithEventManager(sdk.NewEventManager())
return p.Backend().Blockchain().LoadLastState(cmsCtx, appHeight)
p.Backend().Blockchain().PreparePlugins(cmsCtx)
return p.Backend().Blockchain().LoadLastState(appHeight)
}
Loading
Loading