99 "github.com/ethereum/go-ethereum/core/types"
1010 "github.com/ethereum/go-ethereum/event"
1111 "github.com/ethereum/go-ethereum/logger"
12+ "gopkg.in/fatih/set.v0"
1213)
1314
1415var (
@@ -42,7 +43,8 @@ type TxPool struct {
4243 quit chan bool
4344 // The actual pool
4445 //pool *list.List
45- txs map [common.Hash ]* types.Transaction
46+ txs map [common.Hash ]* types.Transaction
47+ invalidHashes * set.Set
4648
4749 SecondaryProcessor TxProcessor
4850
@@ -53,10 +55,11 @@ type TxPool struct {
5355
5456func NewTxPool (eventMux * event.TypeMux ) * TxPool {
5557 return & TxPool {
56- txs : make (map [common.Hash ]* types.Transaction ),
57- queueChan : make (chan * types.Transaction , txPoolQueueSize ),
58- quit : make (chan bool ),
59- eventMux : eventMux ,
58+ txs : make (map [common.Hash ]* types.Transaction ),
59+ queueChan : make (chan * types.Transaction , txPoolQueueSize ),
60+ quit : make (chan bool ),
61+ eventMux : eventMux ,
62+ invalidHashes : set .New (),
6063 }
6164}
6265
@@ -87,20 +90,24 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
8790}
8891
8992func (self * TxPool ) addTx (tx * types.Transaction ) {
90- self .txs [tx .Hash ()] = tx
9193}
9294
9395func (self * TxPool ) add (tx * types.Transaction ) error {
9496 hash := tx .Hash ()
97+
98+ if self .invalidHashes .Has (hash ) {
99+ return fmt .Errorf ("Invalid transaction (%x)" , hash [:4 ])
100+ }
101+
95102 if self .txs [hash ] != nil {
96- return fmt .Errorf ("Known transaction (%x)" , hash [0 :4 ])
103+ return fmt .Errorf ("Known transaction (%x)" , hash [:4 ])
97104 }
98105 err := self .ValidateTransaction (tx )
99106 if err != nil {
100107 return err
101108 }
102109
103- self .addTx ( tx )
110+ self .txs [ hash ] = tx
104111
105112 var toname string
106113 if to := tx .To (); to != nil {
@@ -115,7 +122,9 @@ func (self *TxPool) add(tx *types.Transaction) error {
115122 txplogger .Debugf ("(t) %x => %s (%v) %x\n " , from , toname , tx .Value , tx .Hash ())
116123
117124 // Notify the subscribers
125+ //println("post")
118126 go self .eventMux .Post (TxPreEvent {tx })
127+ //println("done post")
119128
120129 return nil
121130}
@@ -127,6 +136,7 @@ func (self *TxPool) Size() int {
127136func (self * TxPool ) Add (tx * types.Transaction ) error {
128137 self .mu .Lock ()
129138 defer self .mu .Unlock ()
139+
130140 return self .add (tx )
131141}
132142
@@ -183,6 +193,17 @@ func (self *TxPool) RemoveSet(txs types.Transactions) {
183193 }
184194}
185195
196+ func (self * TxPool ) InvalidateSet (hashes * set.Set ) {
197+ self .mu .Lock ()
198+ defer self .mu .Unlock ()
199+
200+ hashes .Each (func (v interface {}) bool {
201+ delete (self .txs , v .(common.Hash ))
202+ return true
203+ })
204+ self .invalidHashes .Merge (hashes )
205+ }
206+
186207func (pool * TxPool ) Flush () {
187208 pool .txs = make (map [common.Hash ]* types.Transaction )
188209}
0 commit comments