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 3 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
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/runtime/txpool/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (m *Mempool) AnteHandle(
msgs := tx.GetMsgs()

// 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 Down
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
118 changes: 21 additions & 97 deletions cosmos/x/evm/types/tx.pb.go

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

41 changes: 5 additions & 36 deletions e2e/testapp/polard/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ import (
"cosmossdk.io/log"
confixcmd "cosmossdk.io/tools/confix/cmd"

evmconfig "github.com/berachain/polaris/cosmos/config"
polarconfig "github.com/berachain/polaris/cosmos/config"
testapp "github.com/berachain/polaris/e2e/testapp"

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

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/debug"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -56,51 +54,22 @@ import (
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
)

// initCometBFTConfig helps to override default CometBFT Config values.
// return cmtcfg.DefaultConfig if no custom configuration is required for
// the application.
func initCometBFTConfig() *cmtcfg.Config {
cfg := cmtcfg.DefaultConfig()
return cfg
}

// initAppConfig helps to override default appConfig template and configs.
// return "", nil if no custom configuration is required for the application.
func initAppConfig() (string, interface{}) {
// The following code snippet is just for reference.

type CustomAppConfig struct {
serverconfig.Config
Polaris evmconfig.Config `mapstructure:"polaris"`
Polaris polarconfig.Config `mapstructure:"polaris"`
}

// Optionally allow the chain developer to overwrite the SDK's default
// server config.
srvCfg := serverconfig.DefaultConfig()
// The SDK's default minimum gas price is set to "" (empty value) inside
// app.toml. If left empty by validators, the node will halt on startup.
// However, the chain developer can set a default app.toml value for their
// validators here.
//
// In summary:
// - if you leave srvCfg.MinGasPrices = "", all validators MUST tweak their
// own app.toml config,
// - if you set srvCfg.MinGasPrices non-empty, validators CAN tweak their
// own app.toml to override, or use this default value.
//
// In simapp, we set the min gas prices to 0.
srvCfg.MinGasPrices = "0stake"
// srvCfg.BaseConfig.IAVLDisableFastNode = true // disable fastnode by default
srvCfg.IAVLCacheSize = 10000

customAppConfig := CustomAppConfig{
Config: *srvCfg,
Polaris: *evmconfig.DefaultConfig(),
Config: *polarconfig.RecommendedServerConfig(),
Polaris: *polarconfig.DefaultPolarisConfig(),
}

customAppConfig.Telemetry.Enabled = true

customAppTemplate := serverconfig.DefaultConfigTemplate + evmconfig.PolarisConfigTemplate
customAppTemplate := serverconfig.DefaultConfigTemplate + polarconfig.PolarisConfigTemplate
Comment on lines +64 to +72
Copy link

Choose a reason for hiding this comment

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

The review comment is partially correct. The initAppConfig function in commands.go has been updated to use polarconfig and seems to be correctly applied. However, there are still references to evmconfig in other parts of the codebase (helpers.go and app.go), which suggests that not all necessary updates have been made to fully transition to polarconfig. These inconsistencies need to be addressed to ensure the new configuration is applied consistently throughout the entire codebase.

Analysis chain

The modification of the initAppConfig function to use polarconfig instead of evmconfig is in line with the package renaming. Verify that the new configuration is correctly applied and does not introduce any issues.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the new configuration is correctly applied in the `initAppConfig` function.
rg 'initAppConfig' --type go -C 10

Length of output: 2915



Script:

#!/bin/bash
# Search for any remaining references to `evmconfig` to ensure all replacements with `polarconfig` have been made.
rg 'evmconfig' --type go

# Check for any other parts of the code that might be affected by the changes in the `initAppConfig` function.
rg 'initAppConfig' --type go -C 30

Length of output: 8328


return customAppTemplate, customAppConfig
}
Expand Down
Loading
Loading