routing/chainview: fix race condition in neutrino implementation

This commit is contained in:
Olaoluwa Osuntokun
2017-06-06 12:01:15 -07:00
parent 9fd70958f4
commit 7d30634757
3 changed files with 21 additions and 9 deletions

View File

@@ -22,7 +22,14 @@ import (
"github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil"
// Required to auto-register the btcd backed ChainNotifier
// implementation.
_ "github.com/lightningnetwork/lnd/chainntnfs/btcdnotify"
// Required to auto-register the neutrino backed ChainNotifier
// implementation.
_ "github.com/lightningnetwork/lnd/chainntnfs/neutrinonotify"
_ "github.com/roasbeef/btcwallet/walletdb/bdb" // Required to register the boltdb walletdb implementation.
)

View File

@@ -156,7 +156,7 @@ func testFilterBlockNotifications(node *rpctest.Harness,
case filteredBlock := <-blockChan:
assertFilteredBlock(t, filteredBlock, currentHeight,
newBlockHashes[0], []*chainhash.Hash{})
case <-time.After(time.Second * 10):
case <-time.After(time.Second * 20):
t.Fatalf("filtered block notification didn't arrive")
}
@@ -229,7 +229,7 @@ func testFilterBlockNotifications(node *rpctest.Harness,
case filteredBlock := <-blockChan:
assertFilteredBlock(t, filteredBlock, currentHeight+1,
newBlockHashes[0], []*chainhash.Hash{spendTxid1})
case <-time.After(time.Second * 10):
case <-time.After(time.Second * 20):
t.Fatalf("filtered block notification didn't arrive")
}
@@ -248,7 +248,7 @@ func testFilterBlockNotifications(node *rpctest.Harness,
case filteredBlock := <-blockChan:
assertFilteredBlock(t, filteredBlock, currentHeight+2,
newBlockHashes[0], []*chainhash.Hash{spendTxid2})
case <-time.After(time.Second * 10):
case <-time.After(time.Second * 20):
t.Fatalf("filtered block notification didn't arrive")
}
}
@@ -282,7 +282,7 @@ func testUpdateFilterBackTrack(node *rpctest.Harness, chainView FilteredChainVie
case filteredBlock := <-blockChan:
assertFilteredBlock(t, filteredBlock, currentHeight,
initBlockHashes[0], []*chainhash.Hash{})
case <-time.After(time.Second * 10):
case <-time.After(time.Second * 20):
t.Fatalf("filtered block notification didn't arrive")
}
@@ -314,7 +314,7 @@ func testUpdateFilterBackTrack(node *rpctest.Harness, chainView FilteredChainVie
case filteredBlock := <-blockChan:
assertFilteredBlock(t, filteredBlock, currentHeight+1,
newBlockHashes[0], []*chainhash.Hash{})
case <-time.After(time.Second * 10):
case <-time.After(time.Second * 20):
t.Fatalf("filtered block notification didn't arrive")
}
@@ -332,7 +332,7 @@ func testUpdateFilterBackTrack(node *rpctest.Harness, chainView FilteredChainVie
case filteredBlock := <-blockChan:
assertFilteredBlock(t, filteredBlock, currentHeight+1,
newBlockHashes[0], []*chainhash.Hash{spendTxid})
case <-time.After(time.Second * 10):
case <-time.After(time.Second * 20):
t.Fatalf("filtered block notification didn't arrive")
}
}
@@ -373,7 +373,7 @@ func testFilterSingleBlock(node *rpctest.Harness, chainView FilteredChainView,
case filteredBlock := <-blockChan:
assertFilteredBlock(t, filteredBlock, currentHeight,
newBlockHashes[0], []*chainhash.Hash{})
case <-time.After(time.Second * 10):
case <-time.After(time.Second * 20):
t.Fatalf("filtered block notification didn't arrive")
}
@@ -414,7 +414,7 @@ func testFilterSingleBlock(node *rpctest.Harness, chainView FilteredChainView,
case filteredBlock := <-blockChan:
assertFilteredBlock(t, filteredBlock, currentHeight+1,
block.Hash(), []*chainhash.Hash{})
case <-time.After(time.Second * 10):
case <-time.After(time.Second * 20):
t.Fatalf("filtered block notification didn't arrive")
}

View File

@@ -258,7 +258,12 @@ func (c *CfFilteredChainView) FilterBlock(blockHash *chainhash.Hash) (*FilteredB
for _, tx := range block.Transactions() {
for _, txIn := range tx.MsgTx().TxIn {
prevOp := txIn.PreviousOutPoint
if _, ok := c.chainFilter[prevOp]; ok {
c.filterMtx.RLock()
_, ok := c.chainFilter[prevOp]
c.filterMtx.RUnlock()
if ok {
filteredTxns = append(filteredTxns, tx.MsgTx())
c.filterMtx.Lock()