OSDN Git Service

Fix pool bug (#1254)
authorPaladz <yzhu101@uottawa.ca>
Tue, 14 Aug 2018 11:19:33 +0000 (19:19 +0800)
committerGitHub <noreply@github.com>
Tue, 14 Aug 2018 11:19:33 +0000 (19:19 +0800)
* fix use wrong type of lock bug

* fix wrong type of lock bug

protocol/txpool.go

index 6edbc45..6924e5b 100644 (file)
@@ -96,8 +96,8 @@ func (tp *TxPool) AddErrCache(txHash *bc.Hash, err error) {
 
 // ExpireOrphan expire all the orphans that before the input time range
 func (tp *TxPool) ExpireOrphan(now time.Time) {
-       tp.mtx.RLock()
-       defer tp.mtx.RUnlock()
+       tp.mtx.Lock()
+       defer tp.mtx.Unlock()
 
        for hash, orphan := range tp.orphans {
                if orphan.expiration.Before(now) {
@@ -193,8 +193,8 @@ func (tp *TxPool) HaveTransaction(txHash *bc.Hash) bool {
 
 // ProcessTransaction is the main entry for txpool handle new tx
 func (tp *TxPool) ProcessTransaction(tx *types.Tx, statusFail bool, height, fee uint64) (bool, error) {
-       tp.mtx.RLock()
-       defer tp.mtx.RUnlock()
+       tp.mtx.Lock()
+       defer tp.mtx.Unlock()
 
        txD := &TxDesc{
                Tx:         tx,