1

When I watch the ethereum file work.go ,the method commitNewWork, fragments as follows:

if !noempty {
            // Create an empty block based on temporary copied state for sealing in advance without waiting block
            // execution finished.
            w.commit(uncles, nil, false, tstart)
        }

    // Fill the block with all available pending transactions.
    pending, err := w.eth.TxPool().Pending()
    if err != nil {
        log.Error("Failed to fetch pending transactions", "err", err)
        return
    }
    // Short circuit if there is no available pending transactions
    if len(pending) == 0 {
        w.updateSnapshot()
        return
    }
    // Split the pending transactions into locals and remotes
    localTxs, remoteTxs := make(map[common.Address]types.Transactions), pending
    for _, account := range w.eth.TxPool().Locals() {
        if txs := remoteTxs[account]; len(txs) > 0 {
            delete(remoteTxs, account)
            localTxs[account] = txs
        }
    }
    if len(localTxs) > 0 {
        txs := types.NewTransactionsByPriceAndNonce(w.current.signer, localTxs)
        if w.commitTransactions(txs, w.coinbase, interrupt) {
            return
        }
    }
    if len(remoteTxs) > 0 {
        txs := types.NewTransactionsByPriceAndNonce(w.current.signer, remoteTxs)
        if w.commitTransactions(txs, w.coinbase, interrupt) {
            return
        }
    }
    w.commit(uncles, w.fullTaskHook, true, tstart)

Why block with txs interrupt the empty block? in my opinion, commit the block with txs first, then commit empty if no block with txs, so the code should be transfer to the function defer , and the empty could not interrupt the block with txs when same block num .

emptyFun := func() {
        if !noempty {
            // Create an empty block based on temporary copied state for sealing in advance without waiting block
            // execution finished.
            w.commit(uncles, nil, false, tstart)
        }
    }
defer emptyFun()

same question ,visit github question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.