Go-Ethereum

從 geth 的 txpool 中刪除的待處理交易

  • September 14, 2017

我們一直致力於使用 geth 和 Web3j 對我們的私有區塊鍊網路進行負載測試。交易是使用 Web3j 發送的。

我們發送 100 筆交易,其中每個區塊有大約 25 筆交易的空間(由於 gas 限制)。當我們的本地節點收到交易時,會列印:

TRACE[07-26|10:15:53] Pooled new future transaction            hash=20453e…f2ec96 from=0x992a03b1bb4cc56929f2d21eaf34779d0562c9a7 to=0x32f1e2e74122efd01bd666750c5afc18c4ce3f91
TRACE[07-26|10:15:53] Promoting queued transaction             hash=20453e…f2ec96
INFO [07-26|10:15:53] Submitted transaction                    fullhash=0x20453ef67cba4d3549603f7a0bc0505d170a8fc2adeac849dc1a8c2fa3f2ec96 recipient=0x32f1e2e74122efd01bd666750c5afc18c4ce3f91
TRACE[07-26|10:15:53] Broadcast transaction                    hash=20453e…f2ec96 recipients=2
DEBUG[07-26|10:15:54] Transaction pool status report           executable=43 queued=0 stales=9

當所有交易都發送完畢後,我們本地節點的交易池為 txpool.status:

{
 pending: 100,
 queued: 0
}  

然後我們開始在本地節點上探勘。

INFO [07-26|10:20:41] Starting mining operation 
TRACE[07-26|10:20:41] Gas limit exceeded for current block     sender=0x992a03b1bb4cc56929f2d21eaf34779d0562c9a7
INFO [07-26|10:20:41] Commit new mining work                   number=8383 txs=25 uncles=0 elapsed=18.063ms
TRACE[07-26|10:20:41] Started ethash search for new nonces     miner=0 seed=4567440808604611913
DEBUG[07-26|10:20:42] Transaction pool status report           executable=100 queued=0 stales=8
TRACE[07-26|10:20:48] Ethash nonce found and reported          miner=0 attempts=313611  nonce=4567440808604925524
INFO [07-26|10:20:48] Successfully sealed new block            number=8383 hash=774d72…ba62fc
DEBUG[07-26|10:20:48] Trie cache stats after commit            misses=11 unloads=2
INFO [07-26|10:20:48] 🔗 block reached canonical chain          number=8378 hash=81b120…f0867f
INFO [07-26|10:20:48] 🔨 mined potential block                  number=8383 hash=774d72…ba62fc
TRACE[07-26|10:20:48] Transaction failed, will be removed      hash=05c537…979f0b err="invalid nonce: have 731, expected 756"
INFO [07-26|10:20:48] Commit new mining work                   number=8384 txs=0  uncles=0 elapsed=957.166µs
TRACE[07-26|10:20:48] Propagated block                         hash=774d72…ba62fc recipients=1 duration=2562047h47m16.854s
TRACE[07-26|10:20:48] Announced block                          hash=774d72…ba62fc recipients=2 duration=2562047h47m16.8

在用 25 個交易探勘一個區塊後,我們的 txpool 現在是空的

{
 pending: 0,
 queued: 0
}

總共 100 筆交易中只有 25 筆被探勘,其餘被刪除(它們似乎被聲明為舊的待處理交易)。我的問題是。這是預期的行為,還是我們遺漏了什麼?如果是故意的,有沒有人有關於如何解決從同一地址和節點發送多個交易的提示?

編輯:

我們創建了一個主管來檢查確認的交易,並在交易失去時嘗試重新發送交易。重新發送交易時,我們收到錯誤:

-32000 know transaction: transaction_hash

但是,當手動發送 eth.getTransactionReciept(transaction_hash) 時,會返回 null。

已知交易儲存在哪裡,為什麼它們沒有被探勘?(它們不在 txpool 中)

結果沒問題。一開始,我發送了 110 個 txs,txpool.status 的結果

{
   pending: 110,
   queued: 0
}

然後開始挖礦,所有的交易都被挖了。如下所示 在此處輸入圖像描述 ,tx_pool 不會丟棄任何事務。在 go-ethereum 源文件中,tx_pool.go 文件處理事務邏輯,如果 tx_pool 已滿,池大小超過 4096+1024,部分事務將被刪除,原始碼如下:

// If the transaction pool is full, discard underpriced transactions
if uint64(len(pool.all)) >= pool.config.GlobalSlots+pool.config.GlobalQueue {
   // If the new transaction is underpriced, don't accept it
   if pool.priced.Underpriced(tx, pool.locals) {
       log.Trace("Discarding underpriced transaction", "hash", hash, "price", tx.GasPrice())
       underpricedTxCounter.Inc(1)
       return false, ErrUnderpriced
   }
   // New transaction is better than our worse ones, make room for it
   drop := pool.priced.Discard(len(pool.all)-int(pool.config.GlobalSlots+pool.config.GlobalQueue-1), pool.locals)
   for _, tx := range drop {
       log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "price", tx.GasPrice())
       underpricedTxCounter.Inc(1)
       pool.removeTx(tx.Hash())
   }
}

所以沒有溢出。

看起來像是剛剛修復的錯誤:https ://github.com/ethereum/go-ethereum/issues/14893

引用自:https://ethereum.stackexchange.com/questions/23073