Skip to content

Commit

Permalink
fix: resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
will@2012 committed May 6, 2024
2 parents 1b9194f + f42d592 commit e6012b2
Show file tree
Hide file tree
Showing 30 changed files with 622 additions and 91 deletions.
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Changelog

## v0.3.1

This is a minor release for opBNB Mainnet and Testnet.

In this release, we've introduced significant optimizations and enhancements across various modes and functionalities, including PBSS Mode optimizations, the introduction of Fast Node Mode, EVM execution improvements, and a simplified start command, aimed at enhancing performance and user experience.

Upgrading is optional.

### User Facing Changes

- **PBSS Mode Optimizations**: We have made multiple optimizations for PBSS mode, including the implementation of an async buffer, support for obtaining withdrawal proof on PBSS, and the introduction of an HBSS to PBSS convert tool. For more details, please refer to #69, #74, and #79.
- **Fast Node Mode**: We have introduced a new mode called "Fast Node" to improve the performance and reduce the resources required by the node. This enhancement is aimed at providing a more efficient and streamlined experience. Please see more details in #75.
- **EVM Execution Opcode Level Optimization**: Our latest update includes optimizations at the EVM execution opcode level, resulting in improved performance for EVM execution. For a deeper understanding of these changes, please refer to #77 and #81.
- **Simplified Start Command**: We have simplified the start command by enabling the selection of default network configuration through the use of `--opBNBMainnet` or `--opBNBTestnet` in the command. This enhancement aims to streamline the user experience. More information can be found in #91.

### Partial Changelog

- [#69](https://github.com/bnb-chain/op-geth/pull/69): feat: add async buffer
- [#71](https://github.com/bnb-chain/op-geth/pull/71): chore: add miner perf metrics
- [#74](https://github.com/bnb-chain/op-geth/pull/74): feat: support getting withdrawal proof on pbss
- [#75](https://github.com/bnb-chain/op-geth/pull/75): feat: implement fast node
- [#76](https://github.com/bnb-chain/op-geth/pull/76): bugfix: fix Resubscribe deadlock when unsubscribing after inner sub ends
- [#77](https://github.com/bnb-chain/op-geth/pull/77): feat: EVM execution opcode level optimization
- [#79](https://github.com/bnb-chain/op-geth/pull/79): cmd/geth: add hbss to pbss convert tool
- [#81](https://github.com/bnb-chain/op-geth/pull/81): feat: introduce hash cache to improve performance
- [#88](https://github.com/bnb-chain/op-geth/pull/88): fix: fix base buffer concurrent read/write race
- [#91](https://github.com/bnb-chain/op-geth/pull/91): feat: simplify node start

### Docker Images

- ghcr.io/bnb-chain/op-geth:v0.3.1

### Full Changelog

https://github.com/bnb-chain/op-geth/compare/v0.3.0...v0.3.1

## v0.3.0

This is a recommended release for op-geth. This release brings in upstream updates, see https://github.com/bnb-chain/op-geth/pull/58 for the contents. This is also a ready release for the next planed fork, which will bring in canyon fork from upstream as well.
Expand Down
3 changes: 2 additions & 1 deletion build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"time"

"github.com/cespare/cp"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/signify"
"github.com/ethereum/go-ethereum/internal/build"
Expand Down Expand Up @@ -304,7 +305,7 @@ func doTest(cmdline []string) {
gotest := tc.Go("test")

// CI needs a bit more time for the statetests (default 10m).
gotest.Args = append(gotest.Args, "-timeout=20m")
gotest.Args = append(gotest.Args, "-timeout=50m")

// Enable CKZG backend in CI.
gotest.Args = append(gotest.Args, "-tags=ckzg")
Expand Down
20 changes: 20 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ func defaultNodeConfig() node.Config {
return cfg
}

func defaultOpBNBNodeConfig() node.Config {
git, _ := version.VCS()
cfg := node.DefaultOpBNBConfig
cfg.Name = clientIdentifier
cfg.Version = params.VersionWithCommit(git.Commit, git.Date)
cfg.HTTPModules = append(cfg.HTTPModules, "eth")
cfg.WSModules = append(cfg.WSModules, "eth")
cfg.IPCPath = "geth.ipc"
return cfg
}

// loadBaseConfig loads the gethConfig based on the given command line
// parameters and config file.
func loadBaseConfig(ctx *cli.Context) gethConfig {
Expand All @@ -134,6 +145,15 @@ func loadBaseConfig(ctx *cli.Context) gethConfig {
Metrics: metrics.DefaultConfig,
}

if ctx.Bool(utils.OpBNBMainnetFlag.Name) || ctx.Bool(utils.OpBNBTestnetFlag.Name) {
cfg.Eth = ethconfig.OpBNBDefaults
cfg.Node = defaultOpBNBNodeConfig()
if ctx.Bool(utils.OpBNBTestnetFlag.Name) {
cfg.Eth.NetworkId = 5611
cfg.Eth.TrieCommitInterval = 240
}
}

// Load config file.
if file := ctx.String(configFileFlag.Name); file != "" {
if err := loadConfig(file, &cfg); err != nil {
Expand Down
10 changes: 6 additions & 4 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var (
utils.CacheSnapshotFlag,
utils.CacheNoPrefetchFlag,
utils.CachePreimagesFlag,
utils.AllowInsecureNoTriesFlag,
utils.CacheLogSizeFlag,
utils.FDLimitFlag,
utils.CryptoKZGFlag,
Expand Down Expand Up @@ -350,10 +351,11 @@ func prepare(ctx *cli.Context) {
log.Info("Bumping default cache on mainnet", "provided", ctx.Int(utils.CacheFlag.Name), "updated", 4096, "network", ctx.String(utils.OPNetworkFlag.Name))
ctx.Set(utils.CacheFlag.Name, strconv.Itoa(4096))
}
} else if ctx.String(utils.SyncModeFlag.Name) != "light" && !ctx.IsSet(utils.CacheFlag.Name) && ctx.IsSet(utils.OpBNBMainnetFlag.Name) {
// we're really on opBNB mainnet. Bump that cache up
log.Info("Bumping default cache on mainnet", "provided", ctx.Int(utils.CacheFlag.Name), "updated", 4096, "network", ctx.String(utils.OpBNBMainnetFlag.Name))
ctx.Set(utils.CacheFlag.Name, strconv.Itoa(4096))
} else if ctx.String(utils.SyncModeFlag.Name) != "light" && !ctx.IsSet(utils.CacheFlag.Name) &&
(ctx.IsSet(utils.OpBNBMainnetFlag.Name) || ctx.IsSet(utils.OpBNBTestnetFlag.Name)) {
// we're really on opBNB network. Bump that cache up
log.Info("Bumping default cache on opBNB", "provided", ctx.Int(utils.CacheFlag.Name), "updated", 22000)
ctx.Set(utils.CacheFlag.Name, strconv.Itoa(22000))
}
// If we're running a light client on any network, drop the cache to some meaningfully low amount
if ctx.String(utils.SyncModeFlag.Name) == "light" && !ctx.IsSet(utils.CacheFlag.Name) {
Expand Down
72 changes: 71 additions & 1 deletion cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ import (
"os"
"time"

cli "github.com/urfave/cli/v2"

"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state/pruner"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
cli "github.com/urfave/cli/v2"
)

var (
Expand Down Expand Up @@ -147,6 +151,29 @@ as the backend data source, making this command a lot faster.
The argument is interpreted as block number or hash. If none is provided, the latest
block is used.
`,
},
{
Name: "insecure-prune-all",
Usage: "Prune all trie state data except genesis block, it will break storage for fullnode, only suitable for fast node " +
"who do not need trie storage at all",
ArgsUsage: "<pathOfGenesisFile>",
Action: pruneAllState,
Category: "MISCELLANEOUS COMMANDS",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.AncientFlag,
},
Description: `
will prune all historical trie state data except genesis block.
All trie nodes will be deleted from the database.
It expects the genesis file as argument.
WARNING: It's necessary to delete the trie clean cache after the pruning.
If you specify another directory for the trie clean cache via "--cache.trie.journal"
during the use of Geth, please also specify it here for correct deletion. Otherwise
the trie clean cache with default directory will be deleted.
`,
},
},
Expand Down Expand Up @@ -635,3 +662,46 @@ func checkAccount(ctx *cli.Context) error {
log.Info("Checked the snapshot journalled storage", "time", common.PrettyDuration(time.Since(start)))
return nil
}

func pruneAllState(ctx *cli.Context) error {
stack, _ := makeConfigNode(ctx)
defer stack.Close()

genesisPath := ctx.Args().First()
if len(genesisPath) == 0 {
utils.Fatalf("Must supply path to genesis JSON file")
}
file, err := os.Open(genesisPath)
if err != nil {
utils.Fatalf("Failed to read genesis file: %v", err)
}
defer file.Close()

g := new(core.Genesis)
if err := json.NewDecoder(file).Decode(g); err != nil {
cfg := gethConfig{
Eth: ethconfig.Defaults,
Node: defaultNodeConfig(),
Metrics: metrics.DefaultConfig,
}

// Load config file.
if err := loadConfig(genesisPath, &cfg); err != nil {
utils.Fatalf("%v", err)
}
g = cfg.Eth.Genesis
}

chaindb := utils.MakeChainDatabase(ctx, stack, false)
defer chaindb.Close()
pruner, err := pruner.NewAllPruner(chaindb)
if err != nil {
log.Error("Failed to open snapshot tree", "err", err)
return err
}
if err = pruner.PruneAll(g); err != nil {
log.Error("Failed to prune state", "err", err)
return err
}
return nil
}
20 changes: 17 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import (
"time"

"github.com/ethereum/go-ethereum/core/opcodeCompiler/compiler"
pcsclite "github.com/gballet/go-libpcsclite"
gopsutil "github.com/shirou/gopsutil/mem"
"github.com/urfave/cli/v2"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
Expand Down Expand Up @@ -75,9 +78,6 @@ import (
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
pcsclite "github.com/gballet/go-libpcsclite"
gopsutil "github.com/shirou/gopsutil/mem"
"github.com/urfave/cli/v2"
)

// These are all the command line flags we support.
Expand Down Expand Up @@ -270,6 +270,11 @@ var (
Value: 2048,
Category: flags.EthCategory,
}
AllowInsecureNoTriesFlag = &cli.BoolFlag{
Name: "allow-insecure-no-tries",
Usage: `Disable the tries state root verification, the state consistency is no longer 100% guaranteed. Do not enable it unless you know exactly what the consequence it will cause.`,
Category: flags.EthCategory,
}
OverrideCancun = &cli.Uint64Flag{
Name: "override.cancun",
Usage: "Manually specify the Cancun fork timestamp, overriding the bundled setting",
Expand Down Expand Up @@ -1180,6 +1185,8 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls = params.SepoliaBootnodes
case ctx.Bool(GoerliFlag.Name):
urls = params.GoerliBootnodes
case ctx.Bool(OpBNBTestnetFlag.Name):
urls = params.OpBNBTestnetBootnodes
case ctx.Bool(NetworkIdFlag.Name):
if ctx.Uint64(NetworkIdFlag.Name) == params.OpBNBTestnet {
urls = params.OpBNBTestnetBootnodes
Expand Down Expand Up @@ -1636,6 +1643,10 @@ func SetDataDir(ctx *cli.Context, cfg *node.Config) {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "holesky")
case ctx.IsSet(OPNetworkFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), ctx.String(OPNetworkFlag.Name))
case ctx.IsSet(OpBNBMainnetFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "opBNBMainnet")
case ctx.IsSet(OpBNBTestnetFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "opBNBTestnet")
}
}

Expand Down Expand Up @@ -1919,6 +1930,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(CacheLogSizeFlag.Name) {
cfg.FilterLogCacheSize = ctx.Int(CacheLogSizeFlag.Name)
}
if ctx.IsSet(AllowInsecureNoTriesFlag.Name) {
cfg.NoTries = ctx.Bool(AllowInsecureNoTriesFlag.Name)
}
if !ctx.Bool(SnapshotFlag.Name) {
// If snap-sync is requested, this flag is also required
if cfg.SyncMode == downloader.SnapSync {
Expand Down
21 changes: 17 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"sync/atomic"
"time"

"golang.org/x/exp/slices"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/common/mclock"
Expand All @@ -50,7 +52,6 @@ import (
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
"golang.org/x/exp/slices"
)

var (
Expand Down Expand Up @@ -152,6 +153,7 @@ type CacheConfig struct {
TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk
SnapshotLimit int // Memory allowance (MB) to use for caching snapshot entries in memory
Preimages bool // Whether to store preimage of trie key to the disk
NoTries bool // Insecure settings. Do not have any tries in databases if enabled.
StateHistory uint64 // Number of blocks from head whose state histories are reserved.
StateScheme string // Scheme used to store ethereum states and merkle tree nodes on top
PathNodeBuffer pathdb.NodeBufferType // Type of trienodebuffer to cache trie nodes in disklayer
Expand All @@ -166,7 +168,10 @@ type CacheConfig struct {

// triedbConfig derives the configures for trie database.
func (c *CacheConfig) triedbConfig(keepWatchFunc pathdb.KeepRecordWatchFunc) *trie.Config {
config := &trie.Config{Preimages: c.Preimages}
config := &trie.Config{
Preimages: c.Preimages,
NoTries: c.NoTries,
}
if c.StateScheme == rawdb.HashScheme {
config.HashDB = &hashdb.Config{
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
Expand Down Expand Up @@ -384,7 +389,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
// Make sure the state associated with the block is available, or log out
// if there is no available state, waiting for state sync.
head := bc.CurrentBlock()
if !bc.HasState(head.Root) {
if !bc.NoTries() && !bc.HasState(head.Root) {
if head.Number.Uint64() == 0 {
// The genesis state is missing, which is only possible in the path-based
// scheme. This situation occurs when the initial state sync is not finished
Expand Down Expand Up @@ -495,6 +500,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
Recovery: recover,
NoBuild: bc.cacheConfig.SnapshotNoBuild,
AsyncBuild: !bc.cacheConfig.SnapshotWait,
NoTries: bc.stateCache.NoTries(),
}
bc.snaps, _ = snapshot.New(snapconfig, bc.db, bc.triedb, head.Root)
}
Expand Down Expand Up @@ -879,7 +885,7 @@ func (bc *BlockChain) SnapSyncCommitHead(hash common.Hash) error {
return err
}
}
if !bc.HasState(root) {
if !bc.NoTries() && !bc.HasState(root) {
return fmt.Errorf("non existent state [%x..]", root[:4])
}
// If all checks out, manually set the head block.
Expand Down Expand Up @@ -1482,6 +1488,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.

// Commit all cached state changes into underlying memory database.
start = time.Now()
state.SetExpectedStateRoot(block.Root())
root, err := state.Commit(block.NumberU64(), bc.chainConfig.IsEIP158(block.Number()))
if err != nil {
return err
Expand Down Expand Up @@ -1906,6 +1913,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
}
}

statedb.SetExpectedStateRoot(block.Root())

// Process block using the parent state as reference point
pstart = time.Now()
receipts, logs, usedGas, err = bc.processor.Process(block, statedb, bc.vmConfig)
Expand Down Expand Up @@ -2694,3 +2703,7 @@ func (bc *BlockChain) SetTrieFlushInterval(interval time.Duration) {
func (bc *BlockChain) GetTrieFlushInterval() time.Duration {
return time.Duration(bc.flushInterval.Load())
}

func (bc *BlockChain) NoTries() bool {
return bc.stateCache.NoTries()
}
Loading

0 comments on commit e6012b2

Please sign in to comment.