Skip to content

Commit 0e1b6d9

Browse files
committed
peer, main: allow for queuing multiple invvects
For utreexo tx inv messages, the invvects will be related to each other as the invvect for the tx will be matched with the position invs. It'll look like so: [InvTypeUtreexoTx][TXID1] [InvTypeProofHash][packed positions1.1] (4 positions) [InvTypeProofHash][packed positions1.2] (1 position) At the moment the invvects can only be queued one at a time which may result in the InvTypeProofHash to be separated from the InvTypeUtreexoTx. Allowing for queuing multiple invvects eliminates this problem.
1 parent 8aafeb6 commit 0e1b6d9

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

peer/peer.go

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ type Peer struct {
476476
outputQueue chan outMsg
477477
sendQueue chan outMsg
478478
sendDoneQueue chan struct{}
479-
outputInvChan chan *wire.InvVect
479+
outputInvChan chan []*wire.InvVect
480480
inQuit chan struct{}
481481
queueQuit chan struct{}
482482
outQuit chan struct{}
@@ -1609,23 +1609,27 @@ out:
16091609
val := pendingMsgs.Remove(next)
16101610
p.sendQueue <- val.(outMsg)
16111611

1612-
case iv := <-p.outputInvChan:
1613-
// No handshake? They'll find out soon enough.
1614-
if p.VersionKnown() {
1615-
// If this is a new block, then we'll blast it
1616-
// out immediately, sipping the inv trickle
1617-
// queue.
1618-
if iv.Type == wire.InvTypeBlock ||
1619-
iv.Type == wire.InvTypeUtreexoBlock ||
1620-
iv.Type == wire.InvTypeWitnessBlock ||
1621-
iv.Type == wire.InvTypeWitnessUtreexoBlock {
1622-
1623-
invMsg := wire.NewMsgInvSizeHint(1)
1624-
invMsg.AddInvVect(iv)
1625-
waiting = queuePacket(outMsg{msg: invMsg},
1626-
pendingMsgs, waiting)
1627-
} else {
1628-
invSendQueue.PushBack(iv)
1612+
case ivs := <-p.outputInvChan:
1613+
for i := range ivs {
1614+
iv := ivs[i]
1615+
1616+
// No handshake? They'll find out soon enough.
1617+
if p.VersionKnown() {
1618+
// If this is a new block, then we'll blast it
1619+
// out immediately, sipping the inv trickle
1620+
// queue.
1621+
if iv.Type == wire.InvTypeBlock ||
1622+
iv.Type == wire.InvTypeUtreexoBlock ||
1623+
iv.Type == wire.InvTypeWitnessBlock ||
1624+
iv.Type == wire.InvTypeWitnessUtreexoBlock {
1625+
1626+
invMsg := wire.NewMsgInvSizeHint(1)
1627+
invMsg.AddInvVect(iv)
1628+
waiting = queuePacket(outMsg{msg: invMsg},
1629+
pendingMsgs, waiting)
1630+
} else {
1631+
invSendQueue.PushBack(iv)
1632+
}
16291633
}
16301634
}
16311635

@@ -1849,11 +1853,13 @@ func (p *Peer) QueueMessageWithEncoding(msg wire.Message, doneChan chan<- struct
18491853
// Inventory that the peer is already known to have is ignored.
18501854
//
18511855
// This function is safe for concurrent access.
1852-
func (p *Peer) QueueInventory(invVect *wire.InvVect) {
1853-
// Don't add the inventory to the send queue if the peer is already
1854-
// known to have it.
1855-
if p.knownInventory.Contains(invVect) {
1856-
return
1856+
func (p *Peer) QueueInventory(invVects []*wire.InvVect) {
1857+
for i := 0; i < len(invVects); i++ {
1858+
// Don't add the inventory to the send queue if the peer is already
1859+
// known to have it.
1860+
if p.knownInventory.Contains(invVects[i]) {
1861+
invVects = append(invVects[:i], invVects[i+1:]...)
1862+
}
18571863
}
18581864

18591865
// Avoid risk of deadlock if goroutine already exited. The goroutine
@@ -1863,7 +1869,7 @@ func (p *Peer) QueueInventory(invVect *wire.InvVect) {
18631869
return
18641870
}
18651871

1866-
p.outputInvChan <- invVect
1872+
p.outputInvChan <- invVects
18671873
}
18681874

18691875
// Connected returns whether or not the peer is currently connected.
@@ -2261,7 +2267,7 @@ func newPeerBase(origCfg *Config, inbound bool) *Peer {
22612267
outputQueue: make(chan outMsg, outputBufferSize),
22622268
sendQueue: make(chan outMsg, 1), // nonblocking sync
22632269
sendDoneQueue: make(chan struct{}, 1), // nonblocking sync
2264-
outputInvChan: make(chan *wire.InvVect, outputBufferSize),
2270+
outputInvChan: make(chan []*wire.InvVect, outputBufferSize),
22652271
inQuit: make(chan struct{}),
22662272
queueQuit: make(chan struct{}),
22672273
outQuit: make(chan struct{}),

peer/peer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,9 @@ func TestOutboundPeer(t *testing.T) {
664664
fakeInv := wire.NewInvVect(wire.InvTypeBlock, fakeBlockHash)
665665

666666
// Should be noops as the peer could not connect.
667-
p.QueueInventory(fakeInv)
667+
p.QueueInventory([]*wire.InvVect{fakeInv})
668668
p.AddKnownInventory(fakeInv)
669-
p.QueueInventory(fakeInv)
669+
p.QueueInventory([]*wire.InvVect{fakeInv})
670670

671671
fakeMsg := wire.NewMsgVerAck()
672672
p.QueueMessage(fakeMsg, nil)
@@ -710,7 +710,7 @@ func TestOutboundPeer(t *testing.T) {
710710
}
711711

712712
// Test Queue Inv after connection
713-
p1.QueueInventory(fakeInv)
713+
p1.QueueInventory([]*wire.InvVect{fakeInv})
714714
p1.Disconnect()
715715

716716
// Test regression

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ func (s *server) handleRelayInvMsg(state *peerState, msg relayMsg) {
20352035
// Queue the inventory to be relayed with the next batch.
20362036
// It will be ignored if the peer is already known to
20372037
// have the inventory.
2038-
sp.QueueInventory(msg.invVect)
2038+
sp.QueueInventory([]*wire.InvVect{msg.invVect})
20392039
})
20402040
}
20412041

0 commit comments

Comments
 (0)