diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-22 05:20:27 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-23 17:50:11 +0800 |
commit | 7138404cb09aebb990fcce589b87173e66355987 (patch) | |
tree | 22231a6f9972bf822ce44a58fcafb05ddaafee4e /core/transaction_pool.go | |
parent | 4feb5f6f9cd5128b4645c1265d814edb443ef43b (diff) | |
download | go-tangerine-7138404cb09aebb990fcce589b87173e66355987.tar go-tangerine-7138404cb09aebb990fcce589b87173e66355987.tar.gz go-tangerine-7138404cb09aebb990fcce589b87173e66355987.tar.bz2 go-tangerine-7138404cb09aebb990fcce589b87173e66355987.tar.lz go-tangerine-7138404cb09aebb990fcce589b87173e66355987.tar.xz go-tangerine-7138404cb09aebb990fcce589b87173e66355987.tar.zst go-tangerine-7138404cb09aebb990fcce589b87173e66355987.zip |
core: only post event once per tx & fixed test
Diffstat (limited to 'core/transaction_pool.go')
-rw-r--r-- | core/transaction_pool.go | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/core/transaction_pool.go b/core/transaction_pool.go index 92a2462c6..bc6e70c7a 100644 --- a/core/transaction_pool.go +++ b/core/transaction_pool.go @@ -125,11 +125,6 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error { return nil } -func (self *TxPool) addTx(tx *types.Transaction) { - from, _ := tx.From() - self.queue[from] = append(self.queue[from], tx) -} - func (self *TxPool) add(tx *types.Transaction) error { hash := tx.Hash() @@ -147,7 +142,7 @@ func (self *TxPool) add(tx *types.Transaction) error { return err } - self.addTx(tx) + self.queueTx(tx) var toname string if to := tx.To(); to != nil { @@ -226,6 +221,19 @@ func (pool *TxPool) Stop() { glog.V(logger.Info).Infoln("TX Pool stopped") } +func (self *TxPool) queueTx(tx *types.Transaction) { + from, _ := tx.From() + self.queue[from] = append(self.queue[from], tx) +} + +func (pool *TxPool) addTx(tx *types.Transaction) { + if _, ok := pool.txs[tx.Hash()]; !ok { + pool.txs[tx.Hash()] = tx + // Notify the subscribers + pool.eventMux.Post(TxPreEvent{tx}) + } +} + // check queue will attempt to insert func (pool *TxPool) checkQueue() { pool.mu.Lock() @@ -257,9 +265,7 @@ func (pool *TxPool) checkQueue() { } enonce++ - pool.txs[tx.Hash()] = tx - // Notify the subscribers - go pool.eventMux.Post(TxPreEvent{tx}) + pool.addTx(tx) } //pool.queue[address] = txs[i:] // delete the entire queue entry if it's empty. There's no need to keep it |