mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 19:00:46 +00:00
eth/catalyst: fill block with txs from txpool if nil transactions
This commit is contained in:
parent
c654f467d5
commit
0c5ba499c1
3 changed files with 13 additions and 7 deletions
|
|
@ -32,12 +32,16 @@ func RegisterTestingAPI(stack *node.Node, backend *eth.Ethereum) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (api *TestingAPI) BuildBlockV1(parentHash common.Hash, payloadAttributes engine.PayloadAttributes, transactions []hexutil.Bytes, extraData *hexutil.Bytes) (*engine.ExecutionPayloadEnvelope, error) {
|
||||
func (api *TestingAPI) BuildBlockV1(parentHash common.Hash, payloadAttributes engine.PayloadAttributes, transactions *[]hexutil.Bytes, extraData *hexutil.Bytes) (*engine.ExecutionPayloadEnvelope, error) {
|
||||
if api.eth.BlockChain().CurrentBlock().Hash() != parentHash {
|
||||
return nil, errors.New("parentHash is not current head")
|
||||
}
|
||||
dec := make([][]byte, 0, len(transactions))
|
||||
for _, tx := range transactions {
|
||||
// If transactions is empty but not nil, build an empty block
|
||||
// If the transactions is nil, build a block with the current transactions from the txpool
|
||||
// If the transactions is not nil and not empty, build a block with the transactions
|
||||
buildEmpty := transactions != nil && len(*transactions) == 0
|
||||
dec := make([][]byte, 0, len(*transactions))
|
||||
for _, tx := range *transactions {
|
||||
dec = append(dec, tx)
|
||||
}
|
||||
txs, err := engine.DecodeTransactions(dec)
|
||||
|
|
@ -56,5 +60,5 @@ func (api *TestingAPI) BuildBlockV1(parentHash common.Hash, payloadAttributes en
|
|||
Withdrawals: payloadAttributes.Withdrawals,
|
||||
BeaconRoot: payloadAttributes.BeaconRoot,
|
||||
}
|
||||
return api.eth.Miner().BuildTestingPayload(args, txs, extra)
|
||||
return api.eth.Miner().BuildTestingPayload(args, txs, buildEmpty, extra)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ func (miner *Miner) buildPayload(args *BuildPayloadArgs, witness bool) (*Payload
|
|||
return payload, nil
|
||||
}
|
||||
|
||||
func (miner *Miner) BuildTestingPayload(args *BuildPayloadArgs, transactions []*types.Transaction, extraData []byte) (*engine.ExecutionPayloadEnvelope, error) {
|
||||
func (miner *Miner) BuildTestingPayload(args *BuildPayloadArgs, transactions []*types.Transaction, empty bool, extraData []byte) (*engine.ExecutionPayloadEnvelope, error) {
|
||||
fullParams := &generateParams{
|
||||
timestamp: args.Timestamp,
|
||||
forceTime: true,
|
||||
|
|
@ -283,7 +283,7 @@ func (miner *Miner) BuildTestingPayload(args *BuildPayloadArgs, transactions []*
|
|||
random: args.Random,
|
||||
withdrawals: args.Withdrawals,
|
||||
beaconRoot: args.BeaconRoot,
|
||||
noTxs: false,
|
||||
noTxs: !empty,
|
||||
forceOverrides: true,
|
||||
overrideExtraData: extraData,
|
||||
overrideTxs: transactions,
|
||||
|
|
|
|||
|
|
@ -136,7 +136,9 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
|
|||
work.size += uint64(genParam.withdrawals.Size())
|
||||
|
||||
if !genParam.noTxs {
|
||||
if genParam.forceOverrides {
|
||||
// If forceOverrides is true and overrideTxs is not empty, commit the override transactions
|
||||
// otherwise, fill the block with the current transactions from the txpool
|
||||
if genParam.forceOverrides && len(genParam.overrideTxs) > 0 {
|
||||
if work.gasPool == nil {
|
||||
work.gasPool = new(core.GasPool).AddGas(work.header.GasLimit)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue