Skip to content

Commit

Permalink
Merge pull request #238 from welkin22/feature/TxDAG-PEVM-parallel-merge
Browse files Browse the repository at this point in the history
pevm: support parallel merge mode
  • Loading branch information
welkin22 authored Jan 2, 2025
2 parents 16bbb44 + d0e7d6e commit 9c30172
Show file tree
Hide file tree
Showing 33 changed files with 2,363 additions and 350 deletions.
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
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)))
}
}
}, "", true); err != nil {
}, "", true, false, false); err != nil {
return fmt.Errorf("test %v: %w", name, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ var (
utils.RollupSuperchainUpgradesFlag,
utils.ParallelTxFlag,
utils.ParallelTxUnorderedMergeFlag,
utils.ParallelTxParallelMergeFlag,
utils.ParallelTxNumFlag,
utils.ParallelThresholdFlag,
utils.ParallelTxDAGFlag,
utils.ParallelTxDAGFileFlag,
utils.ParallelTxDAGSenderPrivFlag,
Expand Down
20 changes: 10 additions & 10 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,15 +1111,15 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
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)",
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,
}

ParallelThresholdFlag = &cli.IntFlag{
Name: "parallel.threshold",
Usage: "Threshold of transaction count to trigger parallel execution, only valid in parallel mode (runtime calculated, no fixed default value)",
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,
}

Expand Down Expand Up @@ -2041,12 +2041,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.ParallelTxUnorderedMerge = ctx.Bool(ParallelTxUnorderedMergeFlag.Name)
}

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

if ctx.IsSet(ParallelThresholdFlag.Name) {
cfg.ParallelThreshold = ctx.Int(ParallelThresholdFlag.Name)
if ctx.IsSet(ParallelTxNumFlag.Name) {
cfg.ParallelTxNum = ctx.Int(ParallelTxNumFlag.Name)
}

if ctx.IsSet(ParallelTxDAGFlag.Name) {
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

0 comments on commit 9c30172

Please sign in to comment.