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 6 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.

25 changes: 15 additions & 10 deletions cosmos/runtime/txpool/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/berachain/polaris/cosmos/x/evm/types"
"github.com/berachain/polaris/lib/utils"

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

"github.com/ethereum/go-ethereum/common"
Expand All @@ -42,8 +43,10 @@ func (m *Mempool) AnteHandle(
) (sdk.Context, error) {
msgs := tx.GetMsgs()

// Record the time it takes to build a payload.

// We only want to eject transactions from comet on recheck.
if ctx.ExecMode() == sdk.ExecModeReCheck {
if ctx.ExecMode() == sdk.ExecModeCheck || ctx.ExecMode() == sdk.ExecModeReCheck {
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved
if wet, ok := utils.GetAs[*types.WrappedEthereumTransaction](msgs[0]); ok {
if m.shouldEjectFromCometMempool(ctx.BlockTime(), wet.Unwrap()) {
return ctx, errors.New("eject from comet mempool")
Expand All @@ -57,6 +60,7 @@ func (m *Mempool) AnteHandle(
func (m *Mempool) shouldEjectFromCometMempool(
currentTime time.Time, tx *ethtypes.Transaction,
) bool {
defer telemetry.MeasureSince(time.Now(), MetricKeyTimeShouldEject)
if tx == nil {
return false
}
Expand All @@ -66,21 +70,22 @@ func (m *Mempool) shouldEjectFromCometMempool(
// 1. If the transaction has been included in a block.
// 2. If the transaction is unknown to the node.
// 3. If the transaction has been in the mempool for longer than the configured timeout.
return txStatus == txpool.TxStatusIncluded || txStatus == txpool.TxStatusUnknown ||
return txStatus == txpool.TxStatusIncluded ||
currentTime.Sub(tx.Time()) > m.lifetime
}

// txStatus returns the status of the transaction.
func (m *Mempool) txStatus(hash common.Hash) txpool.TxStatus {
// Looking for the transaction in txpool first.
status := m.txpool.Status(hash)
// // Looking for the transaction in txpool first.
// status := m.txpool.Status(hash)

// If the transaction is unknown to the pool, try looking it up locally.
if status == txpool.TxStatusUnknown {
lookup := m.chain.GetTransactionLookup(hash)
if lookup != nil {
status = txpool.TxStatusIncluded
}
// // If the transaction is unknown to the pool, try looking it up locally.
// if status == txpool.TxStatusUnknown {
var status txpool.TxStatus
lookup := m.chain.GetTransactionLookup(hash)
if lookup != nil {
status = txpool.TxStatusIncluded
}
// }
return status
}
4 changes: 3 additions & 1 deletion cosmos/runtime/txpool/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ func (h *handler) broadcastTransaction(tx *ethtypes.Transaction, retries int) {
return
}

if rsp == nil || rsp.Code == 0 {
// If rsp == 1, likely the txn is already in a block, and thus the broadcast failing is actually
// the desired behaviour.
if rsp == nil || rsp.Code == 0 || rsp.Code == 1 {
return
}

Expand Down
2 changes: 1 addition & 1 deletion cosmos/runtime/txpool/mocks/geth_tx_pool.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/runtime/txpool/mocks/lifecycle.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/runtime/txpool/mocks/sdk_tx.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/runtime/txpool/mocks/subscription.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/runtime/txpool/mocks/tx_broadcaster.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/runtime/txpool/mocks/tx_serializer.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/runtime/txpool/mocks/tx_sub_provider.go

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

1 change: 1 addition & 0 deletions cosmos/runtime/txpool/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ package txpool
const (
MetricKeyMempoolFull = "polaris_cometbft_mempool_full"
MetricKeyBroadcastFailure = "polaris_cometbft_broadcast_failure"
MetricKeyTimeShouldEject = "polaris_cometbft_time_should_eject"
)
2 changes: 1 addition & 1 deletion cosmos/x/evm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var _ = Describe("Genesis", func() {
BeforeEach(func() {
ctx, ak, _, _ = testutil.SetupMinimalKeepers(log.NewTestLogger(GinkgoT()))
ctx = ctx.WithBlockHeight(0)
cfg := config.DefaultConfig()
cfg := config.DefaultPolarisConfig()
ethGen.Config = params.DefaultChainConfig
cfg.Node.DataDir = GinkgoT().TempDir()
cfg.Node.KeyStoreDir = GinkgoT().TempDir()
Expand Down
Loading
Loading