Skip to content

Commit 4b96329

Browse files
authored
chore: only send want if there are missing parts (#2322)
Closes #2317
1 parent b64f875 commit 4b96329

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

consensus/propagation/have_wants.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,9 @@ func (blockProp *Reactor) requestFromPeer(ps *PeerState) {
140140
}
141141

142142
var (
143-
wants *proptypes.WantParts
144-
parts *proptypes.CombinedPartSet
145-
missingPartsCount int32
146-
fullReqs *bits.BitArray
143+
wants *proptypes.WantParts
144+
parts *proptypes.CombinedPartSet
145+
fullReqs *bits.BitArray
147146
)
148147
for i := min(canSend, int64(len(ps.receivedHaves))); i > 0; {
149148
if len(ps.receivedHaves) == 0 {
@@ -159,7 +158,6 @@ func (blockProp *Reactor) requestFromPeer(ps *PeerState) {
159158
// haves for a new height, resetting
160159
wants = nil
161160
parts = nil
162-
missingPartsCount = 0
163161
}
164162

165163
if !blockProp.relevantHave(have.height, have.round) {
@@ -173,7 +171,12 @@ func (blockProp *Reactor) requestFromPeer(ps *PeerState) {
173171
blockProp.Logger.Error("couldn't find proposal when filtering requests", "height", have.height, "round", have.round)
174172
break
175173
}
176-
missingPartsCount = countRemainingParts(int(parts.Total()), len(parts.BitArray().GetTrueIndices()))
174+
}
175+
176+
missingPartsCount := countRemainingParts(int(parts.Total()), len(parts.BitArray().GetTrueIndices()))
177+
if missingPartsCount == 0 {
178+
// we can ignore this have in this case
179+
continue
177180
}
178181

179182
// don't request a part that is already downloaded
@@ -205,10 +208,9 @@ func (blockProp *Reactor) requestFromPeer(ps *PeerState) {
205208

206209
if wants == nil {
207210
wants = &proptypes.WantParts{
208-
Height: have.height,
209-
Round: have.round,
210-
Parts: bits.NewBitArray(int(parts.Total())),
211-
MissingPartsCount: missingPartsCount,
211+
Height: have.height,
212+
Round: have.round,
213+
Parts: bits.NewBitArray(int(parts.Total())),
212214
}
213215
}
214216

@@ -221,6 +223,12 @@ func (blockProp *Reactor) requestFromPeer(ps *PeerState) {
221223
if wants == nil {
222224
continue
223225
}
226+
missingPartsCount := countRemainingParts(int(parts.Total()), len(parts.BitArray().GetTrueIndices()))
227+
if missingPartsCount == 0 {
228+
// no need to send the want in this case
229+
continue
230+
}
231+
wants.MissingPartsCount = missingPartsCount
224232

225233
err := blockProp.sendWantsThenBroadcastHaves(ps, wants)
226234
if err != nil {

0 commit comments

Comments
 (0)