From a1dab595693bf81601316a6dd8da7d1bd5bf16c4 Mon Sep 17 00:00:00 2001 From: Jin Date: Mon, 20 Apr 2020 13:20:06 +0900 Subject: [PATCH] tx: Removed checking quit chan in `Write*` functions. --- tx/manager.go | 16 ++++++++-------- tx/manager_test.go | 2 +- tx/rawdb.go | 15 +++++---------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tx/manager.go b/tx/manager.go index f85456338..4ecc9963d 100644 --- a/tx/manager.go +++ b/tx/manager.go @@ -227,7 +227,7 @@ func (tm *TransactionManager) Add(account accounts.Account, raw *RawTransaction, // enqueue raw transaction tm.pending[addr] = append(tm.pending[addr], raw) - WritePendingTxs(tm.db, tm.quit, addr, tm.pending[addr]) + WritePendingTxs(tm.db, addr, tm.pending[addr]) log.Info("Raw transaction added", "caption", raw.getCaption(), "from", raw.From) @@ -335,7 +335,7 @@ func (tm *TransactionManager) Start(wg *sync.WaitGroup) { raw.LastSentBlockNumber = blockNumber tm.lock.Lock() - WritePendingTxs(tm.db, tm.quit, addr, tm.pending[addr]) + WritePendingTxs(tm.db, addr, tm.pending[addr]) tm.lock.Unlock() err = tm.backend.SendTransaction(context.Background(), signedTx) @@ -618,8 +618,8 @@ func (tm *TransactionManager) clearQueue(addr common.Address) { if l != 0 { tm.unconfirmed[addr] = append(tm.unconfirmed[addr], minedRaws...) tm.pending[addr] = tm.pending[addr][l:] - WritePendingTxs(tm.db, tm.quit, addr, tm.pending[addr]) - WriteUnconfirmedTxs(tm.db, tm.quit, addr, tm.unconfirmed[addr]) + WritePendingTxs(tm.db, addr, tm.pending[addr]) + WriteUnconfirmedTxs(tm.db, addr, tm.unconfirmed[addr]) } } @@ -664,8 +664,8 @@ func (tm *TransactionManager) confirmQueue(addr common.Address) { tm.unconfirmed[addr] = newUnconfirmed sort.Sort(RawTransactionsByIndex(tm.pending[addr])) - WriteUnconfirmedTxs(tm.db, tm.quit, addr, tm.unconfirmed[addr]) - WritePendingTxs(tm.db, tm.quit, addr, tm.pending[addr]) + WriteUnconfirmedTxs(tm.db, addr, tm.unconfirmed[addr]) + WritePendingTxs(tm.db, addr, tm.pending[addr]) } // remove already confirmed raw transactions @@ -690,8 +690,8 @@ func (tm *TransactionManager) confirmQueue(addr common.Address) { // update database if i != 0 { tm.unconfirmed[addr] = tm.unconfirmed[addr][i:] - WriteNumConfirmedRawTxs(tm.db, tm.quit, addr, numConfirmed) - WriteUnconfirmedTxs(tm.db, tm.quit, addr, tm.unconfirmed[addr]) + WriteNumConfirmedRawTxs(tm.db, addr, numConfirmed) + WriteUnconfirmedTxs(tm.db, addr, tm.unconfirmed[addr]) } } diff --git a/tx/manager_test.go b/tx/manager_test.go index 521a9710d..5eaa51534 100644 --- a/tx/manager_test.go +++ b/tx/manager_test.go @@ -186,7 +186,7 @@ func TestRestart(t *testing.T) { for i := 0; i < n1; i++ { rawTx := NewRawTransaction(addrs[0], 21000, &addrs[1], big.NewInt(int64(1e18+i)), []byte{}, false, fmt.Sprintf("raw tx %d", i)) - if err := tm.Add(accs[0], rawTx,false); err != nil { + if err := tm.Add(accs[0], rawTx, false); err != nil { t.Fatalf("Failed to add rawTx: %v", err) } log.Debug(fmt.Sprintf("raw tx %d added", i)) diff --git a/tx/rawdb.go b/tx/rawdb.go index 818498755..05408d8fa 100644 --- a/tx/rawdb.go +++ b/tx/rawdb.go @@ -198,18 +198,13 @@ func ReadNumConfirmedRawTxs(db ethdb.Reader, addr common.Address) uint64 { return n } -func WriteNumConfirmedRawTxs(db ethdb.KeyValueWriter, quit chan struct{}, addr common.Address, n uint64) { +func WriteNumConfirmedRawTxs(db ethdb.KeyValueWriter, addr common.Address, n uint64) { data, err := rlp.EncodeToBytes(n) if err != nil { log.Crit("Failed to encode number of raw transactions", "err", err) } - select { - case <-quit: - return - default: - if err := db.Put(unconfirmedTxsKey(addr), data); err != nil { - log.Crit("Failed to store unconfirmed transactions", "err", err) - } + if err := db.Put(numConfirmedRawTxsKey(addr), data); err != nil { + log.Crit("Failed to store number of raw transactions", "err", err) } } @@ -263,7 +258,7 @@ func ReadUnconfirmedTxs(db ethdb.Reader, addr common.Address) RawTransactions { return txs } -func WriteUnconfirmedTxs(db ethdb.KeyValueWriter, quit chan struct{}, addr common.Address, txs RawTransactions) { +func WriteUnconfirmedTxs(db ethdb.KeyValueWriter, addr common.Address, txs RawTransactions) { data, err := rlp.EncodeToBytes(txs) if err != nil { log.Crit("Failed to encode unconfirmed transactions", "err", err) @@ -293,7 +288,7 @@ func ReadPendingTxs(db ethdb.Reader, addr common.Address) RawTransactions { return txs } -func WritePendingTxs(db ethdb.KeyValueWriter, quit chan struct{}, addr common.Address, txs RawTransactions) { +func WritePendingTxs(db ethdb.KeyValueWriter, addr common.Address, txs RawTransactions) { data, err := rlp.EncodeToBytes(txs) if err != nil { log.Crit("Failed to encode pending transactions", "err", err)