mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-18 12:51:39 +00:00
core, internal, miner: wrap the block construction as a function
This commit is contained in:
parent
1db7f94df0
commit
e606b6a3d9
4 changed files with 18 additions and 34 deletions
|
|
@ -31,7 +31,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
|
||||||
"github.com/ethereum/go-ethereum/triedb"
|
"github.com/ethereum/go-ethereum/triedb"
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
@ -425,15 +424,8 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
|
||||||
body.Withdrawals = make([]*types.Withdrawal, 0)
|
body.Withdrawals = make([]*types.Withdrawal, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Finalize the state transition by applying operations such as withdrawals,
|
|
||||||
// uncle rewards, and related processing.
|
|
||||||
b.engine.Finalize(cm, b.header, statedb, &body)
|
|
||||||
|
|
||||||
// Calculate the state root after applying all mutations.
|
|
||||||
b.header.Root = statedb.IntermediateRoot(cm.Config().IsEIP158(b.header.Number))
|
|
||||||
|
|
||||||
// Assemble the block for delivery.
|
// Assemble the block for delivery.
|
||||||
block := types.NewBlock(b.header, &body, b.receipts, trie.NewStackTrie(nil))
|
block := AssembleBlock(b.engine, cm, b.header, statedb, &body, b.receipts)
|
||||||
|
|
||||||
// Write state changes to db
|
// Write state changes to db
|
||||||
root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number, b.header.Time))
|
root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number), config.IsCancun(b.header.Number, b.header.Time))
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
"github.com/ethereum/go-ethereum/consensus/misc"
|
"github.com/ethereum/go-ethereum/consensus/misc"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/tracing"
|
"github.com/ethereum/go-ethereum/core/tracing"
|
||||||
|
|
@ -30,6 +31,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/internal/telemetry"
|
"github.com/ethereum/go-ethereum/internal/telemetry"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StateProcessor is a basic Processor, which takes care of transitioning
|
// StateProcessor is a basic Processor, which takes care of transitioning
|
||||||
|
|
@ -372,3 +374,11 @@ func onSystemCallStart(tracer *tracing.Hooks, ctx *tracing.VMContext) {
|
||||||
tracer.OnSystemCallStart()
|
tracer.OnSystemCallStart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AssembleBlock finalizes the state and assembles the block with provided
|
||||||
|
// body and receipts.
|
||||||
|
func AssembleBlock(engine consensus.Engine, chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt) *types.Block {
|
||||||
|
engine.Finalize(chain, header, state, body)
|
||||||
|
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||||
|
return types.NewBlock(header, body, receipts, trie.NewStackTrie(nil))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/internal/ethapi/override"
|
"github.com/ethereum/go-ethereum/internal/ethapi/override"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -421,15 +420,8 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
||||||
}
|
}
|
||||||
chainHeadReader := &simChainHeadReader{ctx, sim.b}
|
chainHeadReader := &simChainHeadReader{ctx, sim.b}
|
||||||
|
|
||||||
// Finalize the state transition by applying operations such as withdrawals,
|
// Assemble the block
|
||||||
// uncle rewards, and related processing.
|
b := core.AssembleBlock(sim.b.Engine(), chainHeadReader, header, sim.state, blockBody, receipts)
|
||||||
sim.b.Engine().Finalize(chainHeadReader, header, sim.state, blockBody)
|
|
||||||
|
|
||||||
// Calculate the state root after applying all mutations.
|
|
||||||
header.Root = sim.state.IntermediateRoot(chainHeadReader.Config().IsEIP158(header.Number))
|
|
||||||
|
|
||||||
// Assemble the block for delivery.
|
|
||||||
b := types.NewBlock(header, blockBody, receipts, trie.NewStackTrie(nil))
|
|
||||||
|
|
||||||
repairLogs(callResults, b.Hash())
|
repairLogs(callResults, b.Hash())
|
||||||
return b, callResults, senders, nil
|
return b, callResults, senders, nil
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/internal/telemetry"
|
"github.com/ethereum/go-ethereum/internal/telemetry"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -226,21 +225,10 @@ func (miner *Miner) generateWork(ctx context.Context, genParam *generateParams,
|
||||||
reqHash := types.CalcRequestsHash(requests)
|
reqHash := types.CalcRequestsHash(requests)
|
||||||
work.header.RequestsHash = &reqHash
|
work.header.RequestsHash = &reqHash
|
||||||
}
|
}
|
||||||
// Finalize the state transition by applying operations such as withdrawals,
|
|
||||||
// uncle rewards, and related processing.
|
|
||||||
_, _, finalizeSpanEnd := telemetry.StartSpan(ctx, "miner.Finalize")
|
|
||||||
miner.engine.Finalize(miner.chain, work.header, work.state, &body)
|
|
||||||
finalizeSpanEnd(nil)
|
|
||||||
|
|
||||||
// Calculate the state root after applying all mutations.
|
|
||||||
_, _, rootSpanEnd := telemetry.StartSpan(ctx, "miner.IntermediateRoot")
|
|
||||||
work.header.Root = work.state.IntermediateRoot(miner.chain.Config().IsEIP158(work.header.Number))
|
|
||||||
rootSpanEnd(nil)
|
|
||||||
|
|
||||||
// Assemble the block for delivery.
|
// Assemble the block for delivery.
|
||||||
_, _, blockSpanEnd := telemetry.StartSpan(ctx, "miner.NewBlock")
|
_, _, assembleSpanEnd := telemetry.StartSpan(ctx, "miner.AssembleBlock")
|
||||||
block := types.NewBlock(work.header, &body, work.receipts, trie.NewStackTrie(nil))
|
block := core.AssembleBlock(miner.engine, miner.chain, work.header, work.state, &body, work.receipts)
|
||||||
blockSpanEnd(nil)
|
assembleSpanEnd(nil)
|
||||||
|
|
||||||
return &newPayloadResult{
|
return &newPayloadResult{
|
||||||
block: block,
|
block: block,
|
||||||
|
|
@ -439,6 +427,7 @@ func (miner *Miner) applyTransaction(env *environment, tx *types.Transaction) (*
|
||||||
func (miner *Miner) commitTransactions(ctx context.Context, env *environment, plainTxs, blobTxs *transactionsByPriceAndNonce, interrupt *atomic.Int32) error {
|
func (miner *Miner) commitTransactions(ctx context.Context, env *environment, plainTxs, blobTxs *transactionsByPriceAndNonce, interrupt *atomic.Int32) error {
|
||||||
ctx, _, spanEnd := telemetry.StartSpan(ctx, "miner.commitTransactions")
|
ctx, _, spanEnd := telemetry.StartSpan(ctx, "miner.commitTransactions")
|
||||||
defer spanEnd(nil)
|
defer spanEnd(nil)
|
||||||
|
|
||||||
isCancun := miner.chainConfig.IsCancun(env.header.Number, env.header.Time)
|
isCancun := miner.chainConfig.IsCancun(env.header.Number, env.header.Time)
|
||||||
for {
|
for {
|
||||||
// Check interruption signal and abort building if it's fired.
|
// Check interruption signal and abort building if it's fired.
|
||||||
|
|
@ -555,6 +544,7 @@ func (miner *Miner) commitTransactions(ctx context.Context, env *environment, pl
|
||||||
func (miner *Miner) fillTransactions(ctx context.Context, interrupt *atomic.Int32, env *environment) (err error) {
|
func (miner *Miner) fillTransactions(ctx context.Context, interrupt *atomic.Int32, env *environment) (err error) {
|
||||||
ctx, span, spanEnd := telemetry.StartSpan(ctx, "miner.fillTransactions")
|
ctx, span, spanEnd := telemetry.StartSpan(ctx, "miner.fillTransactions")
|
||||||
defer spanEnd(&err)
|
defer spanEnd(&err)
|
||||||
|
|
||||||
miner.confMu.RLock()
|
miner.confMu.RLock()
|
||||||
tip := miner.config.GasPrice
|
tip := miner.config.GasPrice
|
||||||
prio := miner.prio
|
prio := miner.prio
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue