dev: chg: further fixes merging develop into upstream-merge

This commit is contained in:
marcello33 2023-06-13 13:01:18 +02:00
parent 8562597c6c
commit b5571e97fb
4 changed files with 37 additions and 389 deletions

View file

@ -50,7 +50,7 @@ type ParallelStateProcessor struct {
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 {
return &ParallelStateProcessor{
config: config,
@ -60,7 +60,7 @@ func NewParallelStateProcessor(config *params.ChainConfig, bc *BlockChain, engin
}
type ExecutionTask struct {
msg types.Message
msg Message
config *params.ChainConfig
gasLimit uint64
@ -93,14 +93,14 @@ type ExecutionTask struct {
func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (err error) {
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.SetIncarnation(incarnation)
evm := vm.NewEVM(task.blockContext, vm.TxContext{}, task.statedb, task.config, task.evmConfig)
// Create a new context to be used in the EVM environment.
txContext := NewEVMTxContext(task.msg)
txContext := NewEVMTxContext(&task.msg)
evm.Reset(txContext, task.statedb)
defer func() {
@ -136,7 +136,7 @@ func (task *ExecutionTask) Execute(mvh *blockstm.MVHashMap, incarnation int) (er
task.shouldRerunWithoutFeeDelay = true
}
} 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 {
@ -174,13 +174,13 @@ func (task *ExecutionTask) Dependencies() []int {
}
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)
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)
}
@ -198,7 +198,7 @@ func (task *ExecutionTask) Settle() {
AddFeeTransferLog(
task.finalStateDB,
task.msg.From(),
task.msg.From,
task.coinbase,
task.result.FeeTipped,
@ -237,12 +237,12 @@ func (task *ExecutionTask) Settle() {
receipt.GasUsed = task.result.UsedGas
// If the transaction created a contract, store the creation address in the receipt.
if task.msg.To() == nil {
receipt.ContractAddress = crypto.CreateAddress(task.msg.From(), task.tx.Nonce())
if task.msg.To == nil {
receipt.ContractAddress = crypto.CreateAddress(task.msg.From, task.tx.Nonce())
}
// 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.BlockHash = task.blockHash
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
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 {
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)
@ -304,13 +304,13 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
cleansdb := statedb.Copy()
if msg.From() == coinbase {
if msg.From == coinbase {
shouldDelayFeeCal = false
}
if len(header.TxDependency) != len(block.Transactions()) {
task := &ExecutionTask{
msg: msg,
msg: *msg,
config: p.config,
gasLimit: block.GasLimit(),
blockNumber: blockNumber,
@ -323,7 +323,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
header: header,
evmConfig: cfg,
shouldDelayFeeCal: &shouldDelayFeeCal,
sender: msg.From(),
sender: msg.From,
totalUsedGas: usedGas,
receipts: &receipts,
allLogs: &allLogs,
@ -335,7 +335,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
tasks = append(tasks, task)
} else {
task := &ExecutionTask{
msg: msg,
msg: *msg,
config: p.config,
gasLimit: block.GasLimit(),
blockNumber: blockNumber,
@ -348,7 +348,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
header: header,
evmConfig: cfg,
shouldDelayFeeCal: &shouldDelayFeeCal,
sender: msg.From(),
sender: msg.From,
totalUsedGas: usedGas,
receipts: &receipts,
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)
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
}

View file

@ -32,9 +32,9 @@ import (
// ExecutionResult includes all output after executing given evm
// message no matter the execution itself is successful or not.
type ExecutionResult struct {
UsedGas uint64 // Total used gas but include the refunded gas
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)
UsedGas uint64 // Total used gas but include the refunded gas
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)
SenderInitBalance *big.Int
FeeBurnt *big.Int
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) {
st := NewStateTransition(evm, msg, gp)
st := NewStateTransition(evm, &msg, gp)
st.noFeeBurnAndTip = true
return st.TransitionDb(interruptCtx)
@ -217,6 +217,11 @@ type StateTransition struct {
initialGas uint64
state vm.StateDB
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.
@ -324,7 +329,7 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
input1 := st.state.GetBalance(st.msg.From)
var input2 *big.Int
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
// applying the message. The rules include these clauses
@ -449,11 +454,10 @@ func (st *StateTransition) TransitionDb(interruptCtx context.Context) (*Executio
)
}
return &ExecutionResult{
UsedGas: st.gasUsed(),
Err: vmerr,
ReturnData: ret,
UsedGas: st.gasUsed(),
Err: vmerr,
ReturnData: ret,
SenderInitBalance: input1,
FeeBurnt: burnAmount,
BurntContractAddress: burntContractAddress,

7
go.mod
View file

@ -5,7 +5,6 @@ go 1.19
require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.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/workerpool v1.1.5
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/hcl/v2 v2.10.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/uint256 v1.2.2-0.20230321075855-87b91420868c
github.com/huin/goupnp v1.0.3
@ -143,8 +141,6 @@ require (
gonum.org/v1/gonum v0.11.0
google.golang.org/grpc v1.51.0
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.v3 v3.0.1 // indirect
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/ledger-cosmos-go v0.10.3 // 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/etcd-io/bbolt v1.3.3 // indirect
github.com/go-kit/kit v0.10.0 // indirect

361
go.sum

File diff suppressed because it is too large Load diff