From 4777d6d604c4a308c69ef3c7d625d223ef550270 Mon Sep 17 00:00:00 2001 From: Chris Pacia Date: Mon, 4 Sep 2017 20:09:58 -0400 Subject: [PATCH] Update spvwallet dependency --- Godeps/Godeps.json | 2 +- vendor/github.com/OpenBazaar/spvwallet/eight333.go | 7 +++---- vendor/github.com/OpenBazaar/spvwallet/peers.go | 8 ++++++++ vendor/github.com/OpenBazaar/spvwallet/wallet.go | 3 --- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index f557622b7d..ec435b0639 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -13,7 +13,7 @@ }, { "ImportPath": "github.com/OpenBazaar/spvwallet", - "Rev": "7879ea5ad3653055cec424e76152358bf05732e6" + "Rev": "91328915b0f4004f4c25fac3cf2b80e0d390178c" }, { "ImportPath": "github.com/OpenBazaar/wallet-interface", diff --git a/vendor/github.com/OpenBazaar/spvwallet/eight333.go b/vendor/github.com/OpenBazaar/spvwallet/eight333.go index 05d56d00fc..d75901d1f2 100644 --- a/vendor/github.com/OpenBazaar/spvwallet/eight333.go +++ b/vendor/github.com/OpenBazaar/spvwallet/eight333.go @@ -36,7 +36,6 @@ func (w *SPVWallet) startChainDownload(p *peer.Peer) { log.Info("Chain download complete") w.blockchain.SetChainState(WAITING) w.Rebroadcast() - close(w.blockQueue) } return } @@ -51,7 +50,7 @@ func (w *SPVWallet) onMerkleBlock(p *peer.Peer, m *wire.MsgMerkleBlock) { w.mutex.Lock() defer w.mutex.Unlock() if w.blockchain.ChainState() == SYNCING && w.peerManager.DownloadPeer() != nil && w.peerManager.DownloadPeer().ID() == p.ID() { - queueHash := <-w.blockQueue + queueHash := <-w.peerManager.BlockQueue() headerHash := m.Header.BlockHash() if !headerHash.IsEqual(&queueHash) { log.Errorf("Peer%d is sending us blocks out of order", p.ID()) @@ -93,7 +92,7 @@ func (w *SPVWallet) onMerkleBlock(p *peer.Peer, m *wire.MsgMerkleBlock) { } log.Debugf("Received Merkle Block %s at height %d\n", m.Header.BlockHash().String(), height) - if len(w.blockQueue) == 0 && w.blockchain.ChainState() == SYNCING { + if len(w.peerManager.BlockQueue()) == 0 && w.blockchain.ChainState() == SYNCING { go w.startChainDownload(p) } if w.blockchain.ChainState() == WAITING { @@ -161,7 +160,7 @@ func (w *SPVWallet) onInv(p *peer.Peer, m *wire.MsgInv) { gData.AddInvVect(inv) p.QueueMessage(gData, nil) if w.blockchain.ChainState() == SYNCING && w.peerManager.DownloadPeer() != nil && w.peerManager.DownloadPeer().ID() == p.ID() { - w.blockQueue <- inv.Hash + w.peerManager.BlockQueue() <- inv.Hash } case wire.InvTypeTx: w.peerManager.QueueTxForDownload(p, inv.Hash, 0) diff --git a/vendor/github.com/OpenBazaar/spvwallet/peers.go b/vendor/github.com/OpenBazaar/spvwallet/peers.go index c7ef2003dc..d9488fae11 100644 --- a/vendor/github.com/OpenBazaar/spvwallet/peers.go +++ b/vendor/github.com/OpenBazaar/spvwallet/peers.go @@ -86,6 +86,7 @@ type PeerManager struct { trustedPeer net.Addr downloadPeer *peer.Peer downloadQueues map[int32]map[chainhash.Hash]int32 + blockQueue chan chainhash.Hash getFilter func() (*bloom.Filter, error) startChainDownload func(*peer.Peer) @@ -113,6 +114,7 @@ func NewPeerManager(config *PeerManagerConfig) (*PeerManager, error) { getFilter: config.GetFilter, startChainDownload: config.StartChainDownload, proxy: config.Proxy, + blockQueue: make(chan chainhash.Hash, 32), } targetOutbound := config.TargetOutbound @@ -187,6 +189,10 @@ func (pm *PeerManager) DownloadPeer() *peer.Peer { return pm.downloadPeer } +func (pm *PeerManager) BlockQueue() chan chainhash.Hash { + return pm.blockQueue +} + func (pm *PeerManager) onConnection(req *connmgr.ConnReq, conn net.Conn) { // Don't let the connection manager connect us to the same peer more than once unless we're using a proxy pm.peerMutex.Lock() @@ -269,6 +275,7 @@ func (pm *PeerManager) onDisconnection(req *connmgr.ConnReq) { // If this was our download peer we lost, replace him if pm.downloadPeer != nil && peer != nil { if pm.downloadPeer.ID() == peer.ID() { + close(pm.blockQueue) go pm.selectNewDownloadPeer() } } @@ -285,6 +292,7 @@ func (pm *PeerManager) setDownloadPeer(peer *peer.Peer) { log.Infof("Setting peer%d as download peer\n", peer.ID()) pm.downloadPeer = peer if pm.startChainDownload != nil { + pm.blockQueue = make(chan chainhash.Hash, 32) go pm.startChainDownload(pm.downloadPeer) } } diff --git a/vendor/github.com/OpenBazaar/spvwallet/wallet.go b/vendor/github.com/OpenBazaar/spvwallet/wallet.go index ea497dbdce..2699a68bb8 100644 --- a/vendor/github.com/OpenBazaar/spvwallet/wallet.go +++ b/vendor/github.com/OpenBazaar/spvwallet/wallet.go @@ -40,7 +40,6 @@ type SPVWallet struct { fPositives chan *peer.Peer stopChan chan int fpAccumulator map[int32]int32 - blockQueue chan chainhash.Hash mutex *sync.RWMutex creationDate time.Time @@ -98,7 +97,6 @@ func NewSPVWallet(config *Config) (*SPVWallet, error) { fPositives: make(chan *peer.Peer), stopChan: make(chan int), fpAccumulator: make(map[int32]int32), - blockQueue: make(chan chainhash.Hash, 32), mutex: new(sync.RWMutex), } @@ -390,6 +388,5 @@ func (w *SPVWallet) ReSyncBlockchain(fromDate time.Time) { if err != nil { return } - w.blockQueue = make(chan chainhash.Hash, 32) go w.Start() }