diff options
author | bas-vk <bas-vk@users.noreply.github.com> | 2016-12-11 06:54:58 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2016-12-11 06:54:58 +0800 |
commit | 4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a (patch) | |
tree | cf54f3d14e4ac9f177b6951f92f898d8c7c9a744 /les | |
parent | 0fe35b907addf1c066cb4d7c717bb23f9f2e7be4 (diff) | |
download | dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.gz dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.bz2 dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.lz dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.xz dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.tar.zst dexon-4e36b1e3dadda62a53e309a1b6cf7aed97ea7a3a.zip |
core: bugfix state change race condition in txpool (#3412)
The transaction pool keeps track of the current nonce in its local pendingState. When a
new block comes in the pendingState is reset. During the reset it fetches multiple times
the current state through the use of the currentState callback. When a second block comes
in during the reset its possible that the state changes during the reset. If that block
holds transactions that are currently in the pool the local pendingState that is used to
determine nonces can get out of sync.
Diffstat (limited to 'les')
-rw-r--r-- | les/api_backend.go | 2 | ||||
-rw-r--r-- | les/handler.go | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/les/api_backend.go b/les/api_backend.go index 8df963f6e..7dc548ec3 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -110,7 +110,7 @@ func (b *LesApiBackend) RemoveTx(txHash common.Hash) { b.eth.txPool.RemoveTx(txHash) } -func (b *LesApiBackend) GetPoolTransactions() types.Transactions { +func (b *LesApiBackend) GetPoolTransactions() (types.Transactions, error) { return b.eth.txPool.GetTransactions() } diff --git a/les/handler.go b/les/handler.go index 83d73666f..fdf4e6e8a 100644 --- a/les/handler.go +++ b/les/handler.go @@ -88,7 +88,7 @@ type BlockChain interface { type txPool interface { // AddTransactions should add the given transactions to the pool. - AddBatch([]*types.Transaction) + AddBatch([]*types.Transaction) error } type ProtocolManager struct { @@ -879,7 +879,11 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { if reqCnt > maxReqs || reqCnt > MaxTxSend { return errResp(ErrRequestRejected, "") } - pm.txpool.AddBatch(txs) + + if err := pm.txpool.AddBatch(txs); err != nil { + return errResp(ErrUnexpectedResponse, "msg: %v", err) + } + _, rcost := p.fcClient.RequestProcessed(costs.baseCost + uint64(reqCnt)*costs.reqCost) pm.server.fcCostStats.update(msg.Code, uint64(reqCnt), rcost) |