From a4a2343cdc1946e38da1aea1476642d1744c1354 Mon Sep 17 00:00:00 2001 From: gary rong Date: Mon, 2 Jul 2018 16:16:30 +0800 Subject: ethdb, core: implement delete for db batch (#17101) --- light/txpool.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'light') diff --git a/light/txpool.go b/light/txpool.go index 5b4d06d90..767a797bd 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -199,15 +199,17 @@ func (pool *TxPool) checkMinedTxs(ctx context.Context, hash common.Hash, number // rollbackTxs marks the transactions contained in recently rolled back blocks // as rolled back. It also removes any positional lookup entries. func (pool *TxPool) rollbackTxs(hash common.Hash, txc txStateChanges) { + batch := pool.chainDb.NewBatch() if list, ok := pool.mined[hash]; ok { for _, tx := range list { txHash := tx.Hash() - rawdb.DeleteTxLookupEntry(pool.chainDb, txHash) + rawdb.DeleteTxLookupEntry(batch, txHash) pool.pending[txHash] = tx txc.setState(txHash, false) } delete(pool.mined, hash) } + batch.Write() } // reorgOnNewHead sets a new head header, processing (and rolling back if necessary) @@ -504,14 +506,16 @@ func (self *TxPool) Content() (map[common.Address]types.Transactions, map[common func (self *TxPool) RemoveTransactions(txs types.Transactions) { self.mu.Lock() defer self.mu.Unlock() + var hashes []common.Hash + batch := self.chainDb.NewBatch() for _, tx := range txs { - //self.RemoveTx(tx.Hash()) hash := tx.Hash() delete(self.pending, hash) - self.chainDb.Delete(hash[:]) + batch.Delete(hash.Bytes()) hashes = append(hashes, hash) } + batch.Write() self.relay.Discard(hashes) } -- cgit