Skip to content

Commit ffe9dc0

Browse files
committed
Merge branch 'main' into PEVM-rebase-v054
2 parents 3fd6e45 + e6d8251 commit ffe9dc0

25 files changed

+1650
-1058
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Changelog
22

3+
## v0.5.4
4+
5+
This is a minor release for opBNB Mainnet and Testnet.
6+
7+
It enables the TxDAG generation feature.
8+
When it's enabled in the sequencer, it will generate TxDAG of the block and append it to the last transaction calldata.
9+
The TxDAG can be used for acceleration of the block execution along with the parallel evm feature released in [v0.5.1-pevm.alpha](https://github.com/bnb-chain/op-geth/releases/tag/v0.5.1-pevm.alpha).
10+
11+
It's optional to upgrade to this version since the new feature only works in the sequencer node.
12+
13+
### What's Changed
14+
* feat: TxDAG generation v0.1 version by @welkin22 in https://github.com/bnb-chain/op-geth/pull/187
15+
16+
### Docker Images
17+
ghcr.io/bnb-chain/op-geth:v0.5.4
18+
19+
**Full Changelog**: https://github.com/bnb-chain/op-geth/compare/v0.5.3...v0.5.4
20+
321
## v0.5.3
422

523
This is a minor release for opBNB Mainnet and Testnet.

cmd/evm/blockrunner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func blockTestCmd(ctx *cli.Context) error {
8686
continue
8787
}
8888
test := tests[name]
89-
if err := test.Run(false, rawdb.HashScheme, tracer, func(res error, chain *core.BlockChain) {
89+
if err := test.Run(false, rawdb.HashScheme, tracer, false, func(res error, chain *core.BlockChain) {
9090
if ctx.Bool(DumpFlag.Name) {
9191
if state, _ := chain.State(); state != nil {
9292
fmt.Println(string(state.Dump(nil)))

cmd/utils/flags.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
11251125

11261126
ParallelTxDAGFlag = &cli.BoolFlag{
11271127
Name: "parallel.txdag",
1128-
Usage: "Enable the experimental parallel TxDAG generation, only valid in full sync mode (default = false)",
1128+
Usage: "Enable the experimental parallel TxDAG generation (default = false)",
11291129
Category: flags.VMCategory,
11301130
}
11311131

@@ -2055,7 +2055,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
20552055
if ctx.IsSet(ParallelTxNumFlag.Name) {
20562056
cfg.ParallelTxNum = ctx.Int(ParallelTxNumFlag.Name)
20572057
}
2058-
20592058
if ctx.IsSet(ParallelTxDAGFlag.Name) {
20602059
cfg.EnableParallelTxDAG = ctx.Bool(ParallelTxDAGFlag.Name)
20612060
}

core/blockchain.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ type BlockChain struct {
320320
forker *ForkChoice
321321
vmConfig vm.Config
322322

323+
// parallel EVM related
323324
enableTxDAG bool
324325
txDAGWriteCh chan TxDAGOutputItem
325326
txDAGReader *TxDAGFileReader
@@ -2113,27 +2114,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
21132114
vtime := time.Since(vstart)
21142115
proctime := time.Since(start) // processing + validation
21152116

2116-
if bc.enableTxDAG && !bc.vmConfig.EnableParallelExec {
2117-
// compare input TxDAG when it enable in consensus
2118-
dag, err := statedb.ResolveTxDAG(len(block.Transactions()), []common.Address{block.Coinbase(), params.OptimismBaseFeeRecipient, params.OptimismL1FeeRecipient})
2119-
if err == nil {
2120-
// TODO(galaio): check TxDAG correctness?
2121-
log.Debug("Process TxDAG result", "block", block.NumberU64(), "txDAG", dag)
2122-
if metrics.EnabledExpensive {
2123-
go types.EvaluateTxDAGPerformance(dag, statedb.ResolveStats())
2124-
}
2125-
// try to write txDAG into file
2126-
if bc.txDAGWriteCh != nil && dag != nil {
2127-
bc.txDAGWriteCh <- TxDAGOutputItem{
2128-
blockNumber: block.NumberU64(),
2129-
txDAG: dag,
2130-
}
2131-
}
2132-
} else {
2133-
log.Error("ResolveTxDAG err", "block", block.NumberU64(), "tx", len(block.Transactions()), "err", err)
2134-
}
2135-
}
2136-
21372117
// Update the metrics touched during block processing and validation
21382118
timers := statedb.Timers()
21392119
accountReadTimer.Update(timers.AccountReads) // Account reads are complete(in processing)

core/state/interface.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ type StateDBer interface {
8484
StopPrefetcher()
8585
StartPrefetcher(namespace string)
8686
SetExpectedStateRoot(root common.Hash)
87-
ResolveTxDAG(txCnt int, gasFeeReceivers []common.Address) (types.TxDAG, error)
88-
ResolveStats() map[int]*types.ExeStat
8987
IntermediateRoot(deleteEmptyObjects bool) common.Hash
9088
Error() error
9189
Timers() *Timers
@@ -112,7 +110,6 @@ type StateDBer interface {
112110
setError(err error)
113111
getTrieParallelLock() *sync.Mutex
114112
timeAddStorageReads(du time.Duration)
115-
RecordWrite(key types.RWKey, value interface{})
116113
timeAddStorageUpdates(du time.Duration)
117114
countAddStorageDeleted(diff int)
118115
countAddStorageUpdated(diff int)
@@ -125,4 +122,5 @@ type StateDBer interface {
125122
timeAddStorageCommits(du time.Duration)
126123
getOrNewStateObject(addr common.Address) *stateObject
127124
prefetchAccount(address common.Address)
125+
CheckFeeReceiversRWSet()
128126
}

core/state/pevm_statedb.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ type UncommittedDB struct {
7373
isMainDBIsParallelDB bool
7474
}
7575

76+
func (pst *UncommittedDB) CheckFeeReceiversRWSet() {
77+
//TODO implement me
78+
return
79+
}
80+
7681
func NewUncommittedDB(maindb StateDBer) *UncommittedDB {
7782
_, ok := maindb.(*ParallelStateDB)
7883
return &UncommittedDB{
@@ -1571,15 +1576,6 @@ func (p *ParallelStateDB) StartPrefetcher(namespace string) {
15711576
}
15721577
}
15731578

1574-
func (p *ParallelStateDB) ResolveTxDAG(txCnt int, gasFeeReceivers []common.Address) (types.TxDAG, error) {
1575-
//do nothing
1576-
return nil, nil
1577-
}
1578-
1579-
func (p *ParallelStateDB) ResolveStats() map[int]*types.ExeStat {
1580-
return nil
1581-
}
1582-
15831579
func (p *ParallelStateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
15841580
// Finalise all the dirty storage states and write them into the tries
15851581
p.Finalise(deleteEmptyObjects)
@@ -2401,10 +2397,6 @@ func (p *ParallelStateDB) timeAddStorageReads(du time.Duration) {
24012397
p.StorageReads += du
24022398
}
24032399

2404-
func (p *ParallelStateDB) RecordWrite(key types.RWKey, value interface{}) {
2405-
//do nothing
2406-
}
2407-
24082400
func (p *ParallelStateDB) timeAddStorageUpdates(du time.Duration) {
24092401
p.StorageUpdates += du
24102402
}
@@ -2449,3 +2441,7 @@ func (p *ParallelStateDB) setStateObjectIfEmpty(obj *stateObject) bool {
24492441
_, loaded := p.stateObjects.LoadOrStore(obj.address, obj)
24502442
return !loaded
24512443
}
2444+
2445+
func (s *ParallelStateDB) CheckFeeReceiversRWSet() {
2446+
return
2447+
}

core/state/state_object.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ package state
1919
import (
2020
"bytes"
2121
"fmt"
22+
"golang.org/x/exp/slices"
2223
"io"
2324
"sync"
2425
"time"
2526

26-
"github.com/ethereum/go-ethereum/core/opcodeCompiler/compiler"
27-
"golang.org/x/exp/slices"
28-
2927
"github.com/ethereum/go-ethereum/common"
28+
"github.com/ethereum/go-ethereum/core/opcodeCompiler/compiler"
3029
"github.com/ethereum/go-ethereum/core/types"
3130
"github.com/ethereum/go-ethereum/crypto"
3231
"github.com/ethereum/go-ethereum/metrics"
@@ -228,7 +227,6 @@ func (s *stateObject) empty() bool {
228227
// Slot 0 tx 2: GetNonce, lightCopy based on main DB(balance = 100) , not empty
229228

230229
if !s.dbItf.GetBalance(s.address).IsZero() { // check balance first, since it is most likely not zero
231-
232230
return false
233231
}
234232
if s.dbItf.GetNonce(s.address) != 0 {
@@ -261,7 +259,6 @@ func newObject(dbItf StateDBer, isParallel bool, address common.Address, acct *t
261259
}
262260

263261
// dirty data when create a new account
264-
265262
if created {
266263
s.dirtyBalance = new(uint256.Int).Set(acct.Balance)
267264
s.dirtyNonce = new(uint64)
@@ -439,6 +436,7 @@ func (s *stateObject) finalise(prefetch bool) {
439436
s.data.Nonce = *s.dirtyNonce
440437
s.dirtyNonce = nil
441438
}
439+
442440
if s.dirtyBalance != nil {
443441
s.data.Balance = s.dirtyBalance
444442
s.dirtyBalance = nil
@@ -447,6 +445,7 @@ func (s *stateObject) finalise(prefetch bool) {
447445
s.data.CodeHash = s.dirtyCodeHash
448446
s.dirtyCodeHash = nil
449447
}
448+
450449
if s.dbItf.getPrefetcher() != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != types.EmptyRootHash {
451450
s.dbItf.getTrieParallelLock().Lock()
452451
s.dbItf.getPrefetcher().prefetch(s.addrHash, s.data.Root, s.address, slotsToPrefetch)
@@ -458,24 +457,30 @@ func (s *stateObject) finalise(prefetch bool) {
458457
}
459458

460459
func (s *stateObject) finaliseRWSet() {
460+
if s.isParallel {
461+
return
462+
}
463+
db := s.dbItf.(*StateDB)
464+
if db.mvStates == nil {
465+
return
466+
}
467+
ms := db.mvStates
461468
s.dirtyStorage.Range(func(key, value interface{}) bool {
462-
// three are some unclean dirtyStorage from previous reverted txs, it will skip finalise
463-
// so add a new rule, if val has no change, then skip it
464469
if value == s.GetCommittedState(key.(common.Hash)) {
465470
return true
466471
}
467-
s.dbItf.RecordWrite(types.StorageStateKey(s.address, key.(common.Hash)), value.(common.Hash))
472+
ms.RecordStorageWrite(s.address, key.(common.Hash))
468473
return true
469474
})
470475

471476
if s.dirtyNonce != nil && *s.dirtyNonce != s.data.Nonce {
472-
s.dbItf.RecordWrite(types.AccountStateKey(s.address, types.AccountNonce), *s.dirtyNonce)
477+
ms.RecordAccountWrite(s.address, types.AccountNonce)
473478
}
474479
if s.dirtyBalance != nil && s.dirtyBalance.Cmp(s.data.Balance) != 0 {
475-
s.dbItf.RecordWrite(types.AccountStateKey(s.address, types.AccountBalance), new(uint256.Int).Set(s.dirtyBalance))
480+
ms.RecordAccountWrite(s.address, types.AccountBalance)
476481
}
477482
if s.dirtyCodeHash != nil && !slices.Equal(s.dirtyCodeHash, s.data.CodeHash) {
478-
s.dbItf.RecordWrite(types.AccountStateKey(s.address, types.AccountCodeHash), s.dirtyCodeHash)
483+
ms.RecordAccountWrite(s.address, types.AccountCodeHash)
479484
}
480485
}
481486

@@ -718,9 +723,16 @@ func (s *stateObject) deepCopy(db *StateDB) *stateObject {
718723
object.selfDestructed = s.selfDestructed
719724
object.dirtyCode = s.dirtyCode
720725
object.deleted = s.deleted
721-
object.dirtyBalance = s.dirtyBalance
722-
object.dirtyNonce = s.dirtyNonce
723-
object.dirtyCodeHash = s.dirtyCodeHash
726+
if s.dirtyBalance != nil {
727+
object.dirtyBalance = new(uint256.Int).Set(s.dirtyBalance)
728+
}
729+
if s.dirtyNonce != nil {
730+
object.dirtyNonce = new(uint64)
731+
*object.dirtyNonce = *s.dirtyNonce
732+
}
733+
if s.dirtyCodeHash != nil {
734+
object.dirtyCodeHash = s.dirtyCodeHash
735+
}
724736
return object
725737
}
726738

0 commit comments

Comments
 (0)