mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
dev: chg: further fixes merging develop into upstream-merge
This commit is contained in:
parent
8562597c6c
commit
b5571e97fb
4 changed files with 37 additions and 389 deletions
|
|
@ -50,7 +50,7 @@ type ParallelStateProcessor struct {
|
||||||
engine consensus.Engine // Consensus engine used for block rewards
|
engine consensus.Engine // Consensus engine used for block rewards
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStateProcessor initialises a new StateProcessor.
|
// NewParallelStateProcessor NewStateProcessor initialises a new StateProcessor.
|
||||||
func NewParallelStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consensus.Engine) *ParallelStateProcessor {
|
func NewParallelStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consensus.Engine) *ParallelStateProcessor {
|
||||||
return &ParallelStateProcessor{
|
return &ParallelStateProcessor{
|
||||||
config: config,
|
config: config,
|
||||||
|
|
@ -60,7 +60,7 @@ func NewParallelStateProcessor(config *params.ChainConfig, bc *BlockChain, engin
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExecutionTask struct {
|
type ExecutionTask struct {
|
||||||
msg types.Message
|
msg Message
|
||||||
config *params.ChainConfig
|
config *params.ChainConfig
|
||||||
|
|
||||||
gasLimit uint64
|
gasLimit uint64
|
||||||
|
|
@ -93,14 +93,14 @@ type ExecutionTask struct {
|
||||||
|
|
||||||
func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (err error) {
|
func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (err error) {
|
||||||
task.statedb = task.cleanStateDB.Copy()
|
task.statedb = task.cleanStateDB.Copy()
|
||||||
task.statedb.Prepare(task.tx.Hash(), task.index)
|
task.statedb.SetTxContext(task.tx.Hash(), task.index)
|
||||||
task.statedb.SetMVHashmap(mvh)
|
task.statedb.SetMVHashmap(mvh)
|
||||||
task.statedb.SetIncarnation(incarnation)
|
task.statedb.SetIncarnation(incarnation)
|
||||||
|
|
||||||
evm := vm.NewEVM(task.blockContext, vm.TxContext{}, task.statedb, task.config, task.evmConfig)
|
evm := vm.NewEVM(task.blockContext, vm.TxContext{}, task.statedb, task.config, task.evmConfig)
|
||||||
|
|
||||||
// Create a new context to be used in the EVM environment.
|
// Create a new context to be used in the EVM environment.
|
||||||
txContext := NewEVMTxContext(task.msg)
|
txContext := NewEVMTxContext(&task.msg)
|
||||||
evm.Reset(txContext, task.statedb)
|
evm.Reset(txContext, task.statedb)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -136,7 +136,7 @@ func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (er
|
||||||
task.shouldRerunWithoutFeeDelay = true
|
task.shouldRerunWithoutFeeDelay = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
task.result, err = ApplyMessage(evm, task.msg, new(GasPool).AddGas(task.gasLimit), nil)
|
task.result, err = ApplyMessage(evm, &task.msg, new(GasPool).AddGas(task.gasLimit), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if task.statedb.HadInvalidRead() || err != nil {
|
if task.statedb.HadInvalidRead() || err != nil {
|
||||||
|
|
@ -174,13 +174,13 @@ func (task *ExecutionTask) Dependencies() []int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (task *ExecutionTask) Settle() {
|
func (task *ExecutionTask) Settle() {
|
||||||
task.finalStateDB.Prepare(task.tx.Hash(), task.index)
|
task.finalStateDB.SetTxContext(task.tx.Hash(), task.index)
|
||||||
|
|
||||||
coinbaseBalance := task.finalStateDB.GetBalance(task.coinbase)
|
coinbaseBalance := task.finalStateDB.GetBalance(task.coinbase)
|
||||||
|
|
||||||
task.finalStateDB.ApplyMVWriteSet(task.statedb.MVFullWriteList())
|
task.finalStateDB.ApplyMVWriteSet(task.statedb.MVFullWriteList())
|
||||||
|
|
||||||
for _, l := range task.statedb.GetLogs(task.tx.Hash(), task.blockHash) {
|
for _, l := range task.statedb.GetLogs(task.tx.Hash(), task.blockNumber.Uint64(), task.blockHash) {
|
||||||
task.finalStateDB.AddLog(l)
|
task.finalStateDB.AddLog(l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,7 +198,7 @@ func (task *ExecutionTask) Settle() {
|
||||||
AddFeeTransferLog(
|
AddFeeTransferLog(
|
||||||
task.finalStateDB,
|
task.finalStateDB,
|
||||||
|
|
||||||
task.msg.From(),
|
task.msg.From,
|
||||||
task.coinbase,
|
task.coinbase,
|
||||||
|
|
||||||
task.result.FeeTipped,
|
task.result.FeeTipped,
|
||||||
|
|
@ -237,12 +237,12 @@ func (task *ExecutionTask) Settle() {
|
||||||
receipt.GasUsed = task.result.UsedGas
|
receipt.GasUsed = task.result.UsedGas
|
||||||
|
|
||||||
// If the transaction created a contract, store the creation address in the receipt.
|
// If the transaction created a contract, store the creation address in the receipt.
|
||||||
if task.msg.To() == nil {
|
if task.msg.To == nil {
|
||||||
receipt.ContractAddress = crypto.CreateAddress(task.msg.From(), task.tx.Nonce())
|
receipt.ContractAddress = crypto.CreateAddress(task.msg.From, task.tx.Nonce())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the receipt logs and create the bloom filter.
|
// Set the receipt logs and create the bloom filter.
|
||||||
receipt.Logs = task.finalStateDB.GetLogs(task.tx.Hash(), task.blockHash)
|
receipt.Logs = task.finalStateDB.GetLogs(task.tx.Hash(), task.blockNumber.Uint64(), task.blockHash)
|
||||||
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
||||||
receipt.BlockHash = task.blockHash
|
receipt.BlockHash = task.blockHash
|
||||||
receipt.BlockNumber = task.blockNumber
|
receipt.BlockNumber = task.blockNumber
|
||||||
|
|
@ -296,7 +296,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
|
|
||||||
// Iterate over and process the individual transactions
|
// Iterate over and process the individual transactions
|
||||||
for i, tx := range block.Transactions() {
|
for i, tx := range block.Transactions() {
|
||||||
msg, err := tx.AsMessage(types.MakeSigner(p.config, header.Number), header.BaseFee)
|
msg, err := TransactionToMessage(tx, types.MakeSigner(p.config, header.Number), header.BaseFee)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("error creating message", "err", err)
|
log.Error("error creating message", "err", err)
|
||||||
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
|
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
|
||||||
|
|
@ -304,13 +304,13 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
|
|
||||||
cleansdb := statedb.Copy()
|
cleansdb := statedb.Copy()
|
||||||
|
|
||||||
if msg.From() == coinbase {
|
if msg.From == coinbase {
|
||||||
shouldDelayFeeCal = false
|
shouldDelayFeeCal = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(header.TxDependency) != len(block.Transactions()) {
|
if len(header.TxDependency) != len(block.Transactions()) {
|
||||||
task := &ExecutionTask{
|
task := &ExecutionTask{
|
||||||
msg: msg,
|
msg: *msg,
|
||||||
config: p.config,
|
config: p.config,
|
||||||
gasLimit: block.GasLimit(),
|
gasLimit: block.GasLimit(),
|
||||||
blockNumber: blockNumber,
|
blockNumber: blockNumber,
|
||||||
|
|
@ -323,7 +323,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
header: header,
|
header: header,
|
||||||
evmConfig: cfg,
|
evmConfig: cfg,
|
||||||
shouldDelayFeeCal: &shouldDelayFeeCal,
|
shouldDelayFeeCal: &shouldDelayFeeCal,
|
||||||
sender: msg.From(),
|
sender: msg.From,
|
||||||
totalUsedGas: usedGas,
|
totalUsedGas: usedGas,
|
||||||
receipts: &receipts,
|
receipts: &receipts,
|
||||||
allLogs: &allLogs,
|
allLogs: &allLogs,
|
||||||
|
|
@ -335,7 +335,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
tasks = append(tasks, task)
|
tasks = append(tasks, task)
|
||||||
} else {
|
} else {
|
||||||
task := &ExecutionTask{
|
task := &ExecutionTask{
|
||||||
msg: msg,
|
msg: *msg,
|
||||||
config: p.config,
|
config: p.config,
|
||||||
gasLimit: block.GasLimit(),
|
gasLimit: block.GasLimit(),
|
||||||
blockNumber: blockNumber,
|
blockNumber: blockNumber,
|
||||||
|
|
@ -348,7 +348,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
header: header,
|
header: header,
|
||||||
evmConfig: cfg,
|
evmConfig: cfg,
|
||||||
shouldDelayFeeCal: &shouldDelayFeeCal,
|
shouldDelayFeeCal: &shouldDelayFeeCal,
|
||||||
sender: msg.From(),
|
sender: msg.From,
|
||||||
totalUsedGas: usedGas,
|
totalUsedGas: usedGas,
|
||||||
receipts: &receipts,
|
receipts: &receipts,
|
||||||
allLogs: &allLogs,
|
allLogs: &allLogs,
|
||||||
|
|
@ -409,7 +409,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
|
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
|
||||||
p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles())
|
p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), nil)
|
||||||
|
|
||||||
return receipts, allLogs, *usedGas, nil
|
return receipts, allLogs, *usedGas, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,9 @@ import (
|
||||||
// ExecutionResult includes all output after executing given evm
|
// ExecutionResult includes all output after executing given evm
|
||||||
// message no matter the execution itself is successful or not.
|
// message no matter the execution itself is successful or not.
|
||||||
type ExecutionResult struct {
|
type ExecutionResult struct {
|
||||||
UsedGas uint64 // Total used gas but include the refunded gas
|
UsedGas uint64 // Total used gas but include the refunded gas
|
||||||
Err error // Any error encountered during the execution(listed in core/vm/errors.go)
|
Err error // Any error encountered during the execution(listed in core/vm/errors.go)
|
||||||
ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)
|
ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)
|
||||||
SenderInitBalance *big.Int
|
SenderInitBalance *big.Int
|
||||||
FeeBurnt *big.Int
|
FeeBurnt *big.Int
|
||||||
BurntContractAddress common.Address
|
BurntContractAddress common.Address
|
||||||
|
|
@ -182,7 +182,7 @@ func ApplyMessage(evm *vm.EVM, msg *Message, gp *GasPool, interruptCtx context.C
|
||||||
}
|
}
|
||||||
|
|
||||||
func ApplyMessageNoFeeBurnOrTip(evm *vm.EVM, msg Message, gp *GasPool, interruptCtx context.Context) (*ExecutionResult, error) {
|
func ApplyMessageNoFeeBurnOrTip(evm *vm.EVM, msg Message, gp *GasPool, interruptCtx context.Context) (*ExecutionResult, error) {
|
||||||
st := NewStateTransition(evm, msg, gp)
|
st := NewStateTransition(evm, &msg, gp)
|
||||||
st.noFeeBurnAndTip = true
|
st.noFeeBurnAndTip = true
|
||||||
|
|
||||||
return st.TransitionDb(interruptCtx)
|
return st.TransitionDb(interruptCtx)
|
||||||
|
|
@ -217,6 +217,11 @@ type StateTransition struct {
|
||||||
initialGas uint64
|
initialGas uint64
|
||||||
state vm.StateDB
|
state vm.StateDB
|
||||||
evm *vm.EVM
|
evm *vm.EVM
|
||||||
|
|
||||||
|
// If true, fee burning and tipping won't happen during transition. Instead, their values will be included in the
|
||||||
|
// ExecutionResult, which caller can use the values to update the balance of burner and coinbase account.
|
||||||
|
// This is useful during parallel state transition, where the common account read/write should be minimized.
|
||||||
|
noFeeBurnAndTip bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStateTransition initialises and returns a new state transition object.
|
// NewStateTransition initialises and returns a new state transition object.
|
||||||
|
|
@ -324,7 +329,7 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
|
||||||
input1 := st.state.GetBalance(st.msg.From)
|
input1 := st.state.GetBalance(st.msg.From)
|
||||||
var input2 *big.Int
|
var input2 *big.Int
|
||||||
if !st.noFeeBurnAndTip {
|
if !st.noFeeBurnAndTip {
|
||||||
input2 := st.state.GetBalance(st.evm.Context.Coinbase)
|
input2 = st.state.GetBalance(st.evm.Context.Coinbase)
|
||||||
}
|
}
|
||||||
// First check this message satisfies all consensus rules before
|
// First check this message satisfies all consensus rules before
|
||||||
// applying the message. The rules include these clauses
|
// applying the message. The rules include these clauses
|
||||||
|
|
@ -449,11 +454,10 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return &ExecutionResult{
|
return &ExecutionResult{
|
||||||
UsedGas: st.gasUsed(),
|
UsedGas: st.gasUsed(),
|
||||||
Err: vmerr,
|
Err: vmerr,
|
||||||
ReturnData: ret,
|
ReturnData: ret,
|
||||||
SenderInitBalance: input1,
|
SenderInitBalance: input1,
|
||||||
FeeBurnt: burnAmount,
|
FeeBurnt: burnAmount,
|
||||||
BurntContractAddress: burntContractAddress,
|
BurntContractAddress: burntContractAddress,
|
||||||
|
|
|
||||||
7
go.mod
7
go.mod
|
|
@ -5,7 +5,6 @@ go 1.19
|
||||||
require (
|
require (
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0
|
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0
|
||||||
github.com/BurntSushi/toml v1.2.0
|
github.com/BurntSushi/toml v1.2.0
|
||||||
github.com/JekaMas/crand v1.0.1
|
|
||||||
github.com/JekaMas/go-grpc-net-conn v0.0.0-20220708155319-6aff21f2d13d
|
github.com/JekaMas/go-grpc-net-conn v0.0.0-20220708155319-6aff21f2d13d
|
||||||
github.com/JekaMas/workerpool v1.1.5
|
github.com/JekaMas/workerpool v1.1.5
|
||||||
github.com/VictoriaMetrics/fastcache v1.6.0
|
github.com/VictoriaMetrics/fastcache v1.6.0
|
||||||
|
|
@ -44,7 +43,6 @@ require (
|
||||||
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
|
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
|
||||||
github.com/hashicorp/hcl/v2 v2.10.1
|
github.com/hashicorp/hcl/v2 v2.10.1
|
||||||
github.com/heimdalr/dag v1.2.1
|
github.com/heimdalr/dag v1.2.1
|
||||||
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e
|
|
||||||
github.com/holiman/bloomfilter/v2 v2.0.3
|
github.com/holiman/bloomfilter/v2 v2.0.3
|
||||||
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c
|
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c
|
||||||
github.com/huin/goupnp v1.0.3
|
github.com/huin/goupnp v1.0.3
|
||||||
|
|
@ -143,8 +141,6 @@ require (
|
||||||
gonum.org/v1/gonum v0.11.0
|
gonum.org/v1/gonum v0.11.0
|
||||||
google.golang.org/grpc v1.51.0
|
google.golang.org/grpc v1.51.0
|
||||||
google.golang.org/protobuf v1.28.1
|
google.golang.org/protobuf v1.28.1
|
||||||
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6
|
|
||||||
gopkg.in/urfave/cli.v1 v1.20.0
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
gotest.tools v2.2.0+incompatible
|
gotest.tools v2.2.0+incompatible
|
||||||
|
|
@ -182,9 +178,6 @@ require (
|
||||||
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8 // indirect
|
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8 // indirect
|
||||||
github.com/cosmos/ledger-cosmos-go v0.10.3 // indirect
|
github.com/cosmos/ledger-cosmos-go v0.10.3 // indirect
|
||||||
github.com/cosmos/ledger-go v0.9.2 // indirect
|
github.com/cosmos/ledger-go v0.9.2 // indirect
|
||||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
|
|
||||||
github.com/deepmap/oapi-codegen v1.8.2 // indirect
|
|
||||||
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect
|
|
||||||
github.com/emirpasic/gods v1.18.1
|
github.com/emirpasic/gods v1.18.1
|
||||||
github.com/etcd-io/bbolt v1.3.3 // indirect
|
github.com/etcd-io/bbolt v1.3.3 // indirect
|
||||||
github.com/go-kit/kit v0.10.0 // indirect
|
github.com/go-kit/kit v0.10.0 // indirect
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue