Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TxDAG based Parallel Transaction Execution implementation. #139

Draft
wants to merge 106 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
efc152e
Feat: Parallel Transaction Execution Implementation
sunny2022da Jul 29, 2024
5e7f2e7
Fix: fix incorrectly set origin storage.
DavidZangNR Jul 3, 2024
3e2f523
Feat: TxDAG: support TxDAG
galaio Jul 5, 2024
d3c6705
fix several UT with racing issues (#5)
DavidZangNR Jul 16, 2024
5c81e49
TxDAG: support PEVM static dispatch; (#6)
galaio Jul 18, 2024
0d667e6
fix UT test and contention issue (#7)
DavidZangNR Jul 18, 2024
9fc4328
Fix: dead lock issue
sunny2022da Jul 18, 2024
8ea4d1b
Fix: avoid update the stateObjects at conflict check phase
sunny2022da Jul 18, 2024
74f8119
TxDAG: support TxDAG transfer, it can be used in QA performance testi…
galaio Jul 24, 2024
756e93e
txdag: support write & read TxDAG from file; (#9)
galaio Jul 24, 2024
74cc070
FIX: redundancy execution and incorrect merge of dirty object (#12)
DavidZangNR Jul 29, 2024
7c5bf71
pevm: support delay gas fee calculation & Uts; (#11)
galaio Jul 29, 2024
a4cf50e
FIX: issue in fixUpOriginAndResetPendingStorage (#14)
DavidZangNR Jul 29, 2024
c34a671
Fix: racying issue in fixUpOriginAndResetPendingStorage
sunny2022da Jul 30, 2024
60fbe9b
txdag: remove legacy TxDAG transfer logic; (#16)
galaio Jul 30, 2024
ad37a95
txdag: opt txdag logic & clean todos; (#17)
galaio Jul 31, 2024
1ec90fb
refine lock and fix racying issue (#18)
DavidZangNR Aug 2, 2024
4217365
txdag: opt TxDAG rwset collecting & generating; (#19)
galaio Aug 2, 2024
ba16a56
contention issue fix (#21)
DavidZangNR Aug 5, 2024
60b93b3
txdag: support multi flags, and supported in pevm; (#22)
galaio Aug 6, 2024
9c1c7dd
pevm: opt slot trigger mechanism; (#24)
galaio Aug 6, 2024
f98be3a
fix addBalance for delayGasFee (#25)
DavidZangNR Aug 7, 2024
a81f34d
txdag: opt read txdag file and validation logic; (#26)
galaio Aug 8, 2024
f0744f3
pevm: opt read large txdag logic and add conflict metrics; (#29)
galaio Aug 13, 2024
0de9577
feat: avoid parallel process for block with few txs
sunny2022da Aug 7, 2024
0fac12d
feat: avoid parallel process for block with few txs
sunny2022da Aug 7, 2024
dea715a
fix: avoid rewrite readsCache in slotDB
sunny2022da Aug 8, 2024
37a617a
Fix: incorrect GetState of obsoleted data caused by createObject
sunny2022da Aug 8, 2024
0d683a7
fix: DAG disable access unconfirmedDB
sunny2022da Aug 11, 2024
9babd88
do not check special addr 0x1 for destruct
sunny2022da Aug 11, 2024
73172b3
fix log issue
sunny2022da Aug 12, 2024
3b6b406
fix: false report of conflict
sunny2022da Aug 13, 2024
1654d3f
txDAG transfer (#28)
andyzhang2023 Aug 13, 2024
0e8f822
txdag: using pending writes to accelerate txdag generation, add more …
galaio Aug 13, 2024
29ed6b4
feat: code cleanup (#23)
DavidZangNR Aug 13, 2024
2a1169b
recover test case
sunny2022da Aug 14, 2024
bc852c7
fix ut of txDAG (#32)
andyzhang2023 Aug 14, 2024
7af9f3f
txdag: support reset txdag reader when SetHead; (#31)
galaio Aug 14, 2024
48ac372
txdag: fix system tx finalise issue; (#33)
galaio Aug 14, 2024
36fc3cb
fix: refine the log level of PEVM (#34)
DavidZangNR Aug 14, 2024
2d45d90
mvstates: fix async dep gen deadlock issue & opt mining txdag generat…
galaio Aug 15, 2024
3db0ca9
fix parallel Num (#36)
DavidZangNR Aug 15, 2024
8b839d2
fix: remove unnecessary locks for stateobjects (#37)
DavidZangNR Aug 15, 2024
4a6ec28
mvstates: opt async dep generation; (#38)
galaio Aug 16, 2024
058ff1b
mvstates: fix oom issue when mining is enabled; (#40)
galaio Aug 16, 2024
446db58
reduce overhead of slotDB initialize (#39)
DavidZangNR Aug 19, 2024
3c0058c
mvstates: fix oom issue when mining is enabled;
galaio Aug 16, 2024
ad5f2ef
Fix: contention issue of Trie for PEVM (#41)
DavidZangNR Aug 20, 2024
82d12d1
worker: fix TxDAG generation issues when mining block; (#43)
galaio Aug 20, 2024
5ec1321
pevm-opt: Enable parallel kv conflict check
sunny2022da Aug 21, 2024
d9bbda1
pevm-opt: Add conflict check cache
sunny2022da Aug 21, 2024
54dd397
PEVM-fix: avoid checkout old tx in stage2 conflict check
sunny2022da Aug 22, 2024
2e40b22
pevm: add a side slot to trigger next tx advance;
galaio Aug 23, 2024
c85e980
pevm: fix some bad check & support to fallback to serial processor;
galaio Aug 27, 2024
d1acaf7
pevm: fix some bad check & support to fallback to serial processor;
galaio Aug 27, 2024
3a92a2a
async the merge phase
sunny2022da Aug 28, 2024
4c410a0
disable parallel if parallel.num is low
sunny2022da Aug 30, 2024
f4ab638
do CompareAndSwap only necessary
sunny2022da Aug 30, 2024
7387419
remove uncessary memory overhead and reuse SyncPool
sunny2022da Sep 2, 2024
8e01b25
fix putSyncPool and GC issue
sunny2022da Sep 3, 2024
37a3222
parallelDBManager global
sunny2022da Sep 4, 2024
497d385
pevm-opt: lock free localstateObjects (#167)
sunny2022da Sep 9, 2024
8602936
PEVM-fix: assesslist append and optimize mergeSlotDB (#168)
sunny2022da Sep 10, 2024
0a7a7b8
PEVM-opt: parallel Txs Prepare (#176)
sunny2022da Sep 12, 2024
bfa857b
fix issue after rebase
sunny2022da Sep 25, 2024
a22f951
fix code hash issue after rebase
sunny2022da Sep 26, 2024
2ffe544
fix issue in createObject after rebase
sunny2022da Sep 26, 2024
67fd679
fix: test case issue after rebase (#190)
sunny2022da Sep 29, 2024
cbb0317
fix getcode issue after rebase
sunny2022da Sep 29, 2024
dd5d24d
fix trie prefetch issue after rebase
sunny2022da Oct 8, 2024
eea8553
PEVM-fix: check in ValidatePlainTxDAG (#195)
sunny2022da Oct 11, 2024
4cee5f2
Pevm rebased to v0.5.5 (#192)
andyzhang2023 Oct 11, 2024
7601e06
Fix/pevm v0.5.0 invalid gas used (#199)
andyzhang2023 Oct 18, 2024
0a5e375
rename pevm option (#200)
andyzhang2023 Oct 18, 2024
6ffd3e1
pevm: unordered merge mode flag (#202)
welkin22 Oct 22, 2024
3c2bedf
pevm: remove the ParallelLegacy (#201)
sunny2022da Oct 22, 2024
d00d951
If TxDAG is nil, then use the serial processor to handle it.
welkin22 Oct 22, 2024
9729844
fix: use ParallelTxNum config and uber automaxprocs (#204)
welkin22 Oct 23, 2024
2ac990c
fix: Transient Storage should set its prev value but not delete it wh…
Oct 23, 2024
7cf3d35
bugfix: it panic when accessing storage from a reverted object which …
Oct 25, 2024
3586be6
bugfix: 'invalid mercle root' after reverting an object which had bee…
Oct 25, 2024
5ac0770
UncommittedDB of PEVM shutdown when an invalid snapshot id found (jus…
Oct 25, 2024
4df7b8d
fix: do initParallelRunner() only once no matter how many chains are …
Oct 25, 2024
bc5d72d
fixut: init the runner before running the cases of PevmProcessor, oth…
Oct 25, 2024
0dea5ce
fixut: err should be returned by a seprated method ConflictsToMaindb(…
Oct 25, 2024
b3c941c
increase the conflict counter only if the state of uncommitted db con…
andyzhang2023 Oct 25, 2024
7e7e807
fix ut case of TestBlockchainWithTxDAGDebug (#213)
andyzhang2023 Nov 1, 2024
db297bb
pevm: refactor txdag reader (#212)
welkin22 Nov 1, 2024
c43afd3
use currentBlock for init
welkin22 Oct 31, 2024
a759fdf
doc: add release note for TxDAG-PEVM alpha release (#215)
sunny2022da Nov 4, 2024
ca71a5c
PEVM-fix: clear useless legacy pevm code (#216)
sunny2022da Nov 6, 2024
8fa2772
fix unit test
welkin22 Nov 6, 2024
b230aab
use patch to fix ut instead of changing code
welkin22 Nov 6, 2024
5768dd5
PEVM-fix: Disable prefetch when PEVM enabled (#218)
sunny2022da Nov 12, 2024
617cc39
feat: disable parallel when txs count is low (#226)
sunny2022da Nov 26, 2024
38f0846
feat: PEVM fallback to serial process (#225)
sunny2022da Nov 26, 2024
9e730b3
fix: Add test for PEVM fall back (#231)
sunny2022da Dec 3, 2024
16bbb44
Revert "use patch to fix ut instead of changing code" (#235)
sunny2022da Dec 12, 2024
62093b3
pevm: support parallel merge mode
welkin22 Nov 12, 2024
e9f99d6
pevm-fix: fix journal record in add/sub balance with 0 (#249)
sunny2022da Jan 9, 2025
f8d6a95
PEVM-fix: try load TxDAG from block if fail from file (#253)
sunny2022da Jan 13, 2025
3fd6e45
pevm: fallback to sequencial processor when the TxDAG is too deep (#251)
andyzhang2023 Jan 13, 2025
ffe9dc0
Merge branch 'main' into PEVM-rebase-v054
sunny2022da Jan 14, 2025
921afc5
add metrics for parallel processor (#254)
andyzhang2023 Jan 15, 2025
48aaff6
Fix pevm 20per performance issue (#256)
andyzhang2023 Jan 16, 2025
b7c61bf
PEVM: add beta release note (#259)
sunny2022da Jan 22, 2025
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
path = tests/evm-benchmarks
url = https://github.com/ipsilon/evm-benchmarks
shallow = true
[submodule "tests-dag"]
path = tests-dag
url = https://github.com/welkin22/txdag-test-file.git
shallow = true
145 changes: 145 additions & 0 deletions Release Note - TxDAG based parallel transaction execution (PEVM).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Release Note \- TxDAG based parallel transaction execution (PEVM) \- Alpha

## Version

**Alpha - Not production ready**

**Based on op-geth v0.5.1**

## Description

This is the first release of the op-geth that implements the TxDAG based parallel transaction execution for block synchronization. The goal is to speed up the execution of transactions in blocks by exploiting parallelism in EVM, and improve the performance further with the TxDAG data guidance by reducing the re-execution caused by transaction dependencies.

### Release goals

* Provide the parallel transaction execution implementation that is 100% compatible with the original EVM.
* Provide the raw TxDAG data in file format as a POC for TxDAG guided PEVM execution
* Provide the op-geth binary release that is verified to successfully sync the block from genesis to block \#15000000 with TxDAG and PEVM enabled, and with performance improved in some scenarios and no obvious performance drop overall.
* Provide the methodology to enable and use the TxDAG base PEVM for block syncing of opBNB.
* Provide the preliminary performance data and analysis for further improvement work

### Options Added

* --parallel (default: false) ($GETH\_PARALLEL)

Enable the experimental parallel transaction execution mode, only valid in full
sync mode (default = false)


* --parallel.num value (default: 0\) ($GETH\_PARALLEL\_NUM)

Number of slot for transaction execution, only valid in parallel mode (runtime
calculated, no fixed default value)


* --parallel.txdag (default: false) ($GETH\_PARALLEL\_TXDAG)

Enable the experimental parallel TxDAG generation, only valid in full sync mode
(default = false)


* --parallel.txdagfile value (default: "./parallel-txdag-output.csv") ($GETH\_PARALLEL\_TXDAGFILE)

It indicates the TxDAG file path


* --parallel.unordered-merge (default: false) ($GETH\_PARALLEL\_UNORDERED\_MERGE)

Enable unordered merge mode, during the parallel confirm phase, merge
transaction execution results without following the transaction order.


### Usage

* Get the TxDAG data:
* User could download the TxDAG data from [https://pub-c0627345c16f47ab858c9469133073a8.r2.dev/opbnb-txdag/parallel-txdag-output\_compare\_15000000.csv](https://pub-c0627345c16f47ab858c9469133073a8.r2.dev/opbnb-txdag/parallel-txdag-output_compare_15000000.csv)
* Use the following options of the geth to enable TxDAG based parallel execution
* '--parallel'
* '--parallel.txtag'

Enable the TxDAG functionality of geth, this will tell EVM to check the TxDAG data existence before block execution

* '--parallel.txdagfile=./parallel-txdag-output\_compare\_15000000.csv'

Specify the path of the TxDAG data file

* '--parallel.unordered-merge'

Trust the DAG data, enable the advanced unordered-merge optimization and skip conflict check.
* '--parallel.num=4'

Optional, Specify the parallel execution number, if not assigned, use the core number for the running platform


### Example
```
op-geth \
--datadir="./datadir" \
--verbosity=4 \
--http \
--http.corsdomain="*" \
--http.vhosts="*" \
--http.addr=0.0.0.0 \
--http.port=8545 \
--http.api=net,eth,engine,debug \
--pprof \
--pprof.port=6070 \
--ws \
--ws.addr=0.0.0.0 \
--ws.port=8545 \
--ws.origins="*" \
--ws.api=eth,engine \
--syncmode=full \
--networkid=$CHAIN_ID \
--txpool.globalslots=20000 \
--txpool.globalqueue=5000 \
--txpool.accountqueue=200 \
--txpool.accountslots=200 \
--txpool.nolocals=true \
--txpool.pricelimit=1 \
--cache.preimages \
--allow-insecure-unlock \
--authrpc.addr="0.0.0.0" \
--authrpc.port="8551" \
--authrpc.vhosts="*" \
--authrpc.jwtsecret=./jwt.txt \
--rpc.allow-unprotected-txs \
--parallel \
--parallel.txdag \
--parallel.txdagfile=./parallel-txdag-output.csv \
--parallel.unordered-merge \
--parallel.num=4 \
--gcmode=full \
--metrics \
--metrics.port 6068 \
--metrics.addr 0.0.0.0 \
--rollup.sequencerhttp=$L2_RPC \
--rollup.disabletxpoolgossip=false \
--bootnodes=$P2P_BOOTNODES
```

###

### Performance

| Scenario | Description | mgasps<br/>(Original) | mgasps<br/>(PEVM) | Improvement | Comments |
|-------------|-------------------------------------------------------------------------------------------------------------|----------------------|--------------|-------------|----------------------------------------------------------|
| **A** | **Internal test chain blocks with 250k accounts transfer to another 250k account** | **107** | **202** | **88%** | **conflict rate(avg): ~0%<br/>txs in block(avg): 3103** |
| **B** | **Internal test chain blocks with 250k accounts transfer to 1 fixed account** | **201** | **216** | **7%** | **conflict rate(avg): ~95%<br/>txs in block(avg): 3644** |
| **C** | **Internal test chain blocks contain random selected txs with a mix of smart contract and native transfer** | **155** | **228** | **47%** | **conflict rate(avg): ~81%<br/>txs in block(avg): 1356** |
| **Mainnet** | **opBNB mainnet block range from #9m-9.3m** | **9.3** | **11.2** | **20%** | **conflict rate(avg): ~12%<br/>txs in block(avg): 25** |
| **Mainnet** | **opBNB mainnet block range from #11.9m-12.1m (mostly inscription txs)** | **57** | **61.1** | **7%** | **conflict rate(avg): ~50%<br/>txs in block(avg): 2195** |

### Additional Info

Conclusions for alpha release

* The performance of PEVM is highly depend on scenarios and dependencies between txs in block
* Generally no obvious degradation of performance observed on mainnet sync (from block#1 to #15000000)

#### TxDAG data solution

The current file-based TxDAG data solution will be optimized with an alternative gasless transaction based
TxDAG transfer in the future. It will guarantee that the TxDAG data will be available with the block transactions
as soon as the block is generated.
More details in [BEP-396: Accelerate Block Execution by TxDAG](https://forum.bnbchain.org/t/bep-396-accelerate-block-execution-by-txdag/2869)
2 changes: 1 addition & 1 deletion cmd/evm/blockrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func blockTestCmd(ctx *cli.Context) error {
fmt.Println(string(state.Dump(nil)))
}
}
}); err != nil {
}, "", true, false, false); err != nil {
return fmt.Errorf("test %v: %w", name, err)
}
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,14 @@ var (
utils.RollupComputePendingBlock,
utils.RollupHaltOnIncompatibleProtocolVersionFlag,
utils.RollupSuperchainUpgradesFlag,
utils.ParallelTxFlag,
utils.ParallelTxUnorderedMergeFlag,
utils.ParallelTxParallelMergeFlag,
utils.ParallelTxNumFlag,
utils.ParallelTxDAGFlag,
utils.ParallelTxDAGFileFlag,
utils.ParallelTxDAGSenderPrivFlag,
utils.ParallelTxDATMaxDepthRatioFlag,
configFileFlag,
utils.LogDebugFlag,
utils.LogBacktraceAtFlag,
Expand Down
63 changes: 63 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,50 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Category: flags.MetricsCategory,
}

ParallelTxFlag = &cli.BoolFlag{
Name: "parallel",
Usage: "Enable the experimental parallel transaction execution mode, only valid in full sync mode (default = false)",
Category: flags.VMCategory,
}

ParallelTxUnorderedMergeFlag = &cli.BoolFlag{
Name: "parallel.unordered-merge",
Usage: "Enable unordered merge mode, during the parallel confirm phase, merge transaction execution results without following the transaction order.",
Category: flags.VMCategory,
}

ParallelTxParallelMergeFlag = &cli.BoolFlag{
Name: "parallel.parallel-merge",
Usage: "Enable concurrent merge mode, during the parallel confirm phase, multiple goroutines will be used to perform concurrent merging of execution results. This option will override parallel.unordered-merge",
Category: flags.VMCategory,
}

ParallelTxNumFlag = &cli.IntFlag{
Name: "parallel.num",
Usage: "Number of slot for transaction execution, only valid in parallel mode (runtime calculated, no fixed default value)",
Category: flags.VMCategory,
}

ParallelTxDAGFlag = &cli.BoolFlag{
Name: "parallel.txdag",
Usage: "Enable the experimental parallel TxDAG generation (default = false)",
Category: flags.VMCategory,
}

ParallelTxDAGFileFlag = &cli.StringFlag{
Name: "parallel.txdagfile",
Usage: "It indicates the TxDAG file path",
Value: "./parallel-txdag-output.csv",
Category: flags.VMCategory,
}

ParallelTxDATMaxDepthRatioFlag = &cli.Float64Flag{
Name: "parallel.txdag-max-depth-ratio",
Usage: "A ratio to decide whether or not to execute transactions in parallel, it will fallback to sequencial processor if the depth is larger than this value (default = 0.9)",
Value: 0.9,
Category: flags.VMCategory,
}

VMOpcodeOptimizeFlag = &cli.BoolFlag{
Name: "vm.opcode.optimize",
Usage: "enable opcode optimization",
Expand Down Expand Up @@ -2002,10 +2040,35 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.EnablePreimageRecording = ctx.Bool(VMEnableDebugFlag.Name)
}

if ctx.IsSet(ParallelTxFlag.Name) {
cfg.ParallelTxMode = ctx.Bool(ParallelTxFlag.Name)
}

if ctx.IsSet(ParallelTxUnorderedMergeFlag.Name) {
cfg.ParallelTxUnorderedMerge = ctx.Bool(ParallelTxUnorderedMergeFlag.Name)
}

if ctx.IsSet(ParallelTxParallelMergeFlag.Name) {
cfg.ParallelTxParallelMerge = ctx.Bool(ParallelTxParallelMergeFlag.Name)
}

if ctx.IsSet(ParallelTxNumFlag.Name) {
cfg.ParallelTxNum = ctx.Int(ParallelTxNumFlag.Name)
}
if ctx.IsSet(ParallelTxDAGFlag.Name) {
cfg.EnableParallelTxDAG = ctx.Bool(ParallelTxDAGFlag.Name)
}

if ctx.IsSet(ParallelTxDAGFileFlag.Name) {
cfg.ParallelTxDAGFile = ctx.String(ParallelTxDAGFileFlag.Name)
}

if ctx.IsSet(ParallelTxDATMaxDepthRatioFlag.Name) {
cfg.ParallelTxDAGMaxDepthRatio = ctx.Float64(ParallelTxDATMaxDepthRatioFlag.Name)
} else {
cfg.ParallelTxDAGMaxDepthRatio = ParallelTxDATMaxDepthRatioFlag.Value
}

if ctx.IsSet(ParallelTxDAGSenderPrivFlag.Name) {
priHex := ctx.String(ParallelTxDAGSenderPrivFlag.Name)
if cfg.Miner.ParallelTxDAGSenderPriv, err = crypto.HexToECDSA(priHex); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (beacon *Beacon) Prepare(chain consensus.ChainHeaderReader, header *types.H
}

// Finalize implements consensus.Engine and processes withdrawals on top.
func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state state.StateDBer, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
if !beacon.IsPoSHeader(header) {
beacon.ethone.Finalize(chain, header, state, txs, uncles, nil)
return
Expand Down
2 changes: 1 addition & 1 deletion consensus/beacon/oplegacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (o *OpLegacy) Prepare(chain consensus.ChainHeaderReader, header *types.Head
return fmt.Errorf("cannot prepare for legacy block header: %s (num %d)", header.Hash(), header.Number)
}

func (o *OpLegacy) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
func (o *OpLegacy) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state state.StateDBer, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
panic(fmt.Errorf("cannot finalize legacy block header: %s (num %d)", header.Hash(), header.Number))
}

Expand Down
4 changes: 2 additions & 2 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
lru "github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
Expand Down Expand Up @@ -580,7 +580,7 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header

// Finalize implements consensus.Engine. There is no post-transaction
// consensus rules in clique, do nothing here.
func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state state.StateDBer, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
// No block rewards in PoA, so the state remains as is
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Engine interface {
//
// Note: The state database might be updated to reflect any consensus rules
// that happen at finalization (e.g. block rewards).
Finalize(chain ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
Finalize(chain ChainHeaderReader, header *types.Header, state state.StateDBer, txs []*types.Transaction,
uncles []*types.Header, withdrawals []*types.Withdrawal)

// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
Expand Down
4 changes: 2 additions & 2 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func (ethash *Ethash) Prepare(chain consensus.ChainHeaderReader, header *types.H
}

// Finalize implements consensus.Engine, accumulating the block and uncle rewards.
func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state state.StateDBer, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
// Accumulate any block and uncle rewards
accumulateRewards(chain.Config(), state, header, uncles)
}
Expand Down Expand Up @@ -570,7 +570,7 @@ var (
// AccumulateRewards credits the coinbase of the given block with the mining
// reward. The total reward consists of the static block reward and rewards for
// included uncles. The coinbase of each uncle block is also rewarded.
func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) {
func accumulateRewards(config *params.ChainConfig, state state.StateDBer, header *types.Header, uncles []*types.Header) {
// Select the correct block reward based on chain progression
blockReward := FrontierBlockReward
if config.IsByzantium(header.Number) {
Expand Down
13 changes: 13 additions & 0 deletions consensus/misc/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,16 @@ func ApplyDAOHardFork(statedb *state.StateDB) {
statedb.SetBalance(addr, new(uint256.Int))
}
}

func ApplyDAOHardFork2(statedb state.StateDBer) {
// Retrieve the contract to refund balances into
if !statedb.Exist(params.DAORefundContract) {
statedb.CreateAccount(params.DAORefundContract)
}

// Move every DAO account and extra-balance account funds into the refund contract
for _, addr := range params.DAODrainList() {
statedb.AddBalance(params.DAORefundContract, statedb.GetBalance(addr))
statedb.SetBalance(addr, new(uint256.Int))
}
}
7 changes: 7 additions & 0 deletions consensus/misc/precontract.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ func ApplyPreContractHardFork(statedb *state.StateDB) {
statedb.SetState(WBNBContract, symbolSlot, symbolValue)
statedb.SelfDestruct(governanceToken)
}

// ApplyPreContractHardFork modifies the state database according to the hard-fork rules
func ApplyPreContractHardFork2(statedb state.StateDBer) {
statedb.SetState(WBNBContract, nameSlot, nameValue)
statedb.SetState(WBNBContract, symbolSlot, symbolValue)
statedb.SelfDestruct(governanceToken)
}
2 changes: 1 addition & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {

// ValidateState validates the various changes that happen after a state transition,
// such as amount of used gas, the receipt roots and the state root itself.
func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateDB, receipts types.Receipts, usedGas uint64) error {
func (v *BlockValidator) ValidateState(block *types.Block, statedb state.StateDBer, receipts types.Receipts, usedGas uint64) error {
header := block.Header()
if block.GasUsed() != usedGas {
return fmt.Errorf("invalid gas used (remote: %d local: %d)", block.GasUsed(), usedGas)
Expand Down
Loading
Loading