Skip to content

Commit

Permalink
tx: Removed checking quit chan in Write* functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin committed Apr 20, 2020
1 parent 4838a27 commit a1dab59
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
16 changes: 8 additions & 8 deletions tx/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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])
}
}

Expand Down
2 changes: 1 addition & 1 deletion tx/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 5 additions & 10 deletions tx/rawdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a1dab59

Please sign in to comment.