Skip to content

Commit ec5ae54

Browse files
committed
all: move err to the last position of return values
1 parent cd74961 commit ec5ae54

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

consensus/tests/engine_v1_tests/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func createBlockFromHeader(bc *core.BlockChain, customHeader *types.Header, txs
374374
var receipts types.Receipts
375375
for i, tx := range txs {
376376
statedb.SetTxContext(tx.Hash(), i)
377-
receipt, _, err, _ := core.ApplyTransaction(bc.Config(), nil, bc, &header.Coinbase, gp, statedb, nil, &header, tx, gasUsed, vm.Config{})
377+
receipt, _, _, err := core.ApplyTransaction(bc.Config(), nil, bc, &header.Coinbase, gp, statedb, nil, &header, tx, gasUsed, vm.Config{})
378378
if err != nil {
379379
return nil, fmt.Errorf("%v when applying transaction", err)
380380
}

consensus/tests/engine_v2_tests/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ func createBlockFromHeader(bc *core.BlockChain, customHeader *types.Header, txs
903903
var receipts types.Receipts
904904
for i, tx := range txs {
905905
statedb.SetTxContext(tx.Hash(), i)
906-
receipt, _, err, _ := core.ApplyTransaction(bc.Config(), nil, bc, &header.Coinbase, gp, statedb, nil, &header, tx, gasUsed, vm.Config{})
906+
receipt, _, _, err := core.ApplyTransaction(bc.Config(), nil, bc, &header.Coinbase, gp, statedb, nil, &header, tx, gasUsed, vm.Config{})
907907
if err != nil {
908908
return nil, fmt.Errorf("%v when applying transaction", err)
909909
}

core/chain_makers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (b *BlockGen) addTx(bc *BlockChain, vmConfig vm.Config, tx *types.Transacti
8787
}
8888
feeCapacity := state.GetTRC21FeeCapacityFromState(b.statedb)
8989
b.statedb.SetTxContext(tx.Hash(), len(b.txs))
90-
receipt, gas, err, tokenFeeUsed := ApplyTransaction(b.config, feeCapacity, bc, &b.header.Coinbase, b.gasPool, b.statedb, nil, b.header, tx, &b.header.GasUsed, vmConfig)
90+
receipt, gas, tokenFeeUsed, err := ApplyTransaction(b.config, feeCapacity, bc, &b.header.Coinbase, b.gasPool, b.statedb, nil, b.header, tx, &b.header.GasUsed, vmConfig)
9191
if err != nil {
9292
panic(err)
9393
}

core/state_processor.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, tra
131131
}
132132
statedb.SetTxContext(tx.Hash(), i)
133133

134-
receipt, gas, err, tokenFeeUsed := ApplyTransactionWithEVM(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv, balanceFee, coinbaseOwner)
134+
receipt, gas, tokenFeeUsed, err := ApplyTransactionWithEVM(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv, balanceFee, coinbaseOwner)
135135
if err != nil {
136136
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
137137
}
@@ -222,7 +222,7 @@ func (p *StateProcessor) ProcessBlockNoValidator(cBlock *CalculatedBlock, stated
222222
return nil, nil, 0, err
223223
}
224224
statedb.SetTxContext(tx.Hash(), i)
225-
receipt, gas, err, tokenFeeUsed := ApplyTransactionWithEVM(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv, balanceFee, coinbaseOwner)
225+
receipt, gas, tokenFeeUsed, err := ApplyTransactionWithEVM(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv, balanceFee, coinbaseOwner)
226226
if err != nil {
227227
return nil, nil, 0, err
228228
}
@@ -247,7 +247,7 @@ func (p *StateProcessor) ProcessBlockNoValidator(cBlock *CalculatedBlock, stated
247247
// ApplyTransactionWithEVM attempts to apply a transaction to the given state database
248248
// and uses the input parameters for its environment similar to ApplyTransaction. However,
249249
// this method takes an already created EVM instance as input.
250-
func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, balanceFee *big.Int, coinbaseOwner common.Address) (receipt *types.Receipt, gasUsed uint64, err error, tokenFeeUsed bool) {
250+
func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, balanceFee *big.Int, coinbaseOwner common.Address) (receipt *types.Receipt, gasUsed uint64, tokenFeeUsed bool, err error) {
251251
to := tx.To()
252252
if to != nil {
253253
if *to == common.BlockSignersBinary && config.IsTIPSigning(blockNumber) {
@@ -428,7 +428,7 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
428428
// Apply the transaction to the current state (included in the env)
429429
result, err := ApplyMessage(evm, msg, gp, coinbaseOwner)
430430
if err != nil {
431-
return nil, 0, err, false
431+
return nil, 0, false, err
432432
}
433433

434434
// Update the state with pending changes.
@@ -465,7 +465,7 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
465465
if balanceFee != nil && result.Failed() {
466466
state.PayFeeWithTRC21TxFail(statedb, msg.From, *to)
467467
}
468-
return receipt, result.UsedGas, err, balanceFee != nil
468+
return receipt, result.UsedGas, balanceFee != nil, nil
469469
}
470470

471471
func getCoinbaseOwner(bc *BlockChain, statedb *state.StateDB, header *types.Header, author *common.Address) common.Address {
@@ -483,7 +483,7 @@ func getCoinbaseOwner(bc *BlockChain, statedb *state.StateDB, header *types.Head
483483
// and uses the input parameters for its environment. It returns the receipt
484484
// for the transaction, gas used and an error if the transaction failed,
485485
// indicating the block was invalid.
486-
func ApplyTransaction(config *params.ChainConfig, tokensFee map[common.Address]*big.Int, bc *BlockChain, author *common.Address, gp *GasPool, statedb *state.StateDB, XDCxState *tradingstate.TradingStateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, uint64, error, bool) {
486+
func ApplyTransaction(config *params.ChainConfig, tokensFee map[common.Address]*big.Int, bc *BlockChain, author *common.Address, gp *GasPool, statedb *state.StateDB, XDCxState *tradingstate.TradingStateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, uint64, bool, error) {
487487
var balanceFee *big.Int
488488
if tx.To() != nil {
489489
if value, ok := tokensFee[*tx.To()]; ok {
@@ -497,13 +497,13 @@ func ApplyTransaction(config *params.ChainConfig, tokensFee map[common.Address]*
497497
signer := types.MakeSigner(config, header.Number)
498498
msg, err := TransactionToMessage(tx, signer, balanceFee, header.Number, header.BaseFee)
499499
if err != nil {
500-
return nil, 0, err, false
500+
return nil, 0, false, err
501501
}
502502
coinbaseOwner := getCoinbaseOwner(bc, statedb, header, author)
503503
return ApplyTransactionWithEVM(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv, balanceFee, coinbaseOwner)
504504
}
505505

506-
func ApplySignTransaction(config *params.ChainConfig, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64) (*types.Receipt, uint64, error, bool) {
506+
func ApplySignTransaction(config *params.ChainConfig, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64) (*types.Receipt, uint64, bool, error) {
507507
// Update the state with pending changes
508508
var root []byte
509509
if config.IsByzantium(blockNumber) {
@@ -513,13 +513,13 @@ func ApplySignTransaction(config *params.ChainConfig, statedb *state.StateDB, bl
513513
}
514514
from, err := types.Sender(types.MakeSigner(config, blockNumber), tx)
515515
if err != nil {
516-
return nil, 0, err, false
516+
return nil, 0, false, err
517517
}
518518
nonce := statedb.GetNonce(from)
519519
if nonce < tx.Nonce() {
520-
return nil, 0, ErrNonceTooHigh, false
520+
return nil, 0, false, ErrNonceTooHigh
521521
} else if nonce > tx.Nonce() {
522-
return nil, 0, ErrNonceTooLow, false
522+
return nil, 0, false, ErrNonceTooLow
523523
}
524524
statedb.SetNonce(from, nonce+1)
525525
// Create a new receipt for the transaction, storing the intermediate root and gas used by the tx
@@ -538,10 +538,10 @@ func ApplySignTransaction(config *params.ChainConfig, statedb *state.StateDB, bl
538538
receipt.BlockHash = blockHash
539539
receipt.BlockNumber = blockNumber
540540
receipt.TransactionIndex = uint(statedb.TxIndex())
541-
return receipt, 0, nil, false
541+
return receipt, 0, false, nil
542542
}
543543

544-
func ApplyEmptyTransaction(config *params.ChainConfig, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64) (*types.Receipt, uint64, error, bool) {
544+
func ApplyEmptyTransaction(config *params.ChainConfig, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64) (*types.Receipt, uint64, bool, error) {
545545
// Update the state with pending changes
546546
var root []byte
547547
if config.IsByzantium(blockNumber) {
@@ -565,7 +565,7 @@ func ApplyEmptyTransaction(config *params.ChainConfig, statedb *state.StateDB, b
565565
receipt.BlockHash = blockHash
566566
receipt.BlockNumber = blockNumber
567567
receipt.TransactionIndex = uint(statedb.TxIndex())
568-
return receipt, 0, nil, false
568+
return receipt, 0, false, nil
569569
}
570570

571571
func InitSignerInTransactions(config *params.ChainConfig, header *types.Header, txs types.Transactions) {

eth/tracers/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ func (api *API) traceTx(ctx context.Context, tx *types.Transaction, message *cor
892892

893893
// Call SetTxContext to clear out the statedb access list
894894
statedb.SetTxContext(txctx.TxHash, txctx.TxIndex)
895-
_, _, err, _ = core.ApplyTransactionWithEVM(message, api.backend.ChainConfig(), new(core.GasPool).AddGas(message.GasLimit), statedb, vmctx.BlockNumber, txctx.BlockHash, tx, &usedGas, vmenv, balance, common.Address{})
895+
_, _, _, err = core.ApplyTransactionWithEVM(message, api.backend.ChainConfig(), new(core.GasPool).AddGas(message.GasLimit), statedb, vmctx.BlockNumber, txctx.BlockHash, tx, &usedGas, vmenv, balance, common.Address{})
896896
if err != nil {
897897
return nil, fmt.Errorf("tracing failed: %w", err)
898898
}

miner/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ func (w *Work) commitTransactions(mux *event.TypeMux, balanceFee map[common.Addr
11341134
func (w *Work) commitTransaction(balanceFee map[common.Address]*big.Int, tx *types.Transaction, bc *core.BlockChain, coinbase common.Address, gp *core.GasPool) ([]*types.Log, bool, uint64, error) {
11351135
snap := w.state.Snapshot()
11361136

1137-
receipt, gas, err, tokenFeeUsed := core.ApplyTransaction(w.config, balanceFee, bc, &coinbase, gp, w.state, w.tradingState, w.header, tx, &w.header.GasUsed, vm.Config{})
1137+
receipt, gas, tokenFeeUsed, err := core.ApplyTransaction(w.config, balanceFee, bc, &coinbase, gp, w.state, w.tradingState, w.header, tx, &w.header.GasUsed, vm.Config{})
11381138
if err != nil {
11391139
w.state.RevertToSnapshot(snap)
11401140
return nil, false, 0, err

0 commit comments

Comments
 (0)