MCPcopy Create free account
hub / github.com/CPChain/chain / commitTransactions

Method commitTransactions

miner/engine.go:490–574  ·  view source on GitHub ↗

transactions are applied in ascending nonce order of each account.

(mux *event.TypeMux, txs *types.TransactionsByPriceAndNonce, bc *core.BlockChain, coinbase common.Address, breakTimer time.Time)

Source from the content-addressed store, hash-verified

488
489// transactions are applied in ascending nonce order of each account.
490func (w *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsByPriceAndNonce, bc *core.BlockChain, coinbase common.Address, breakTimer time.Time) {
491 if w.gasPool == nil {
492 w.gasPool = new(core.GasPool).AddGas(w.header.GasLimit)
493 }
494
495 var coalescedLogs []*types.Log
496
497 for {
498
499 // If break timer is up, break now
500 if time.Now().After(breakTimer) {
501 break
502 }
503
504 // If we don't have enough gas for any further transactions then we're done
505 if w.gasPool.Gas() < configs.TxGas {
506 log.Debug("Not enough gas for further transactions", "have", w.gasPool, "want", configs.TxGas)
507 break
508 }
509 // Retrieve the next transaction and abort if all done
510 tx := txs.Peek()
511 if tx == nil {
512 break
513 }
514 // Error may be ignored here. The error has already been checked
515 // during transaction acceptance is the transaction pool.
516 //
517 from, _ := types.Sender(w.signer, tx)
518
519 // Start executing the transaction
520 w.pubState.Prepare(tx.Hash(), common.Hash{}, w.tcount)
521 w.privState.Prepare(tx.Hash(), common.Hash{}, w.tcount)
522
523 err, logs := w.commitTransaction(tx, bc, coinbase, w.gasPool)
524 switch err {
525 case core.ErrGasLimitReached:
526 // Pop the current out-of-gas transaction without shifting in the next from the account
527 log.Debug("Gas limit exceeded for current block", "sender", from)
528 // we remove all the transactions associated with the account.
529 txs.Pop()
530
531 case core.ErrNonceTooLow:
532 // New head notification data race between the transaction pool and miner, shift
533 log.Debug("Skipping transaction with low nonce", "sender", from, "nonce", tx.Nonce())
534 txs.Shift()
535
536 case core.ErrNonceTooHigh:
537 // Reorg notification data race between the transaction pool and miner, skip account =
538 log.Debug("Skipping account with high nonce", "sender", from, "nonce", tx.Nonce())
539 txs.Pop()
540
541 case nil:
542 // Everything ok, collect the logs and shift in the next transaction from the same account
543 coalescedLogs = append(coalescedLogs, logs...)
544 w.tcount++
545 txs.Shift()
546
547 default:

Callers 2

updateMethod · 0.80
commitNewWorkMethod · 0.80

Calls 12

commitTransactionMethod · 0.95
AddGasMethod · 0.80
DebugMethod · 0.80
PeekMethod · 0.80
PrepareMethod · 0.80
ShiftMethod · 0.80
NowMethod · 0.65
GasMethod · 0.65
SenderMethod · 0.65
HashMethod · 0.65
NonceMethod · 0.65
PopMethod · 0.45

Tested by

no test coverage detected