Skip to content

Commit

Permalink
Merge pull request #225 from bitcoin-sv/fix/blocktx-fill-gaps
Browse files Browse the repository at this point in the history
fix/block-fill-gaps
  • Loading branch information
boecklim authored Dec 20, 2023
2 parents 5f65147 + c124823 commit a1b79c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
11 changes: 10 additions & 1 deletion blocktx/block_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,24 @@ func NewBlockNotifier(storeI store.Interface, l utils.Logger, blockCh chan *bloc
bn.quitFillBlockGapComplete <- struct{}{}
}()

peerIndex := 0
for {
select {
case <-bn.quitFillBlockGap:
return
case <-bn.fillGapsTicker.C:
err := peerHandler.FillGaps(peers[0])
if peerIndex >= len(peers) {
peerIndex = 0
}

l.Infof("requesting missing blocks from peer %d", peerIndex)

err := peerHandler.FillGaps(peers[peerIndex])
if err != nil {
l.Errorf("failed to fill gaps: %v", err)
}

peerIndex++
}
}
}()
Expand Down
16 changes: 15 additions & 1 deletion blocktx/block_notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,28 @@ func TestNewBlockNotifier(t *testing.T) {
ZMQ: 28332,
},
},
{
Host: "127.0.0.2",
Port: config.PeerPort{
P2P: 18333,
ZMQ: 28332,
},
},
{
Host: "127.0.0.3",
Port: config.PeerPort{
P2P: 18333,
ZMQ: 28332,
},
},
}

logger := gocore.Log("test", gocore.NewLogLevelFromString("INFO"))
peerHandler := NewPeerHandler(logger, storeMock, blockCh, 100)
notifier, err := NewBlockNotifier(storeMock, logger, blockCh, peerHandler, peerSettings, wire.TestNet3, WithFillGapsInterval(time.Millisecond*30))
require.NoError(t, err)

time.Sleep(55 * time.Millisecond)
time.Sleep(120 * time.Millisecond)
peerHandler.Shutdown()
notifier.Shutdown()
})
Expand Down
2 changes: 1 addition & 1 deletion blocktx/peer_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (bs *PeerHandler) FillGaps(peer p2p.PeerI) error {
return nil
}

bs.logger.Infof("filling block gap for hash %s at height %d", gaps.Hash.String(), gaps.Height)
bs.logger.Infof("requesting missing block hash %s at height %d", gaps.Hash.String(), gaps.Height)

pair := utils.NewPair(gaps.Hash, peer)
utils.SafeSend(bs.workerCh, pair)
Expand Down

0 comments on commit a1b79c6

Please sign in to comment.