Skip to content

Commit 659d80a

Browse files
committed
fix(net):fix the problem of repeated fetch block in FetchBlockService
1 parent 6db2db9 commit 659d80a

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

framework/src/main/java/org/tron/core/net/peer/PeerConnection.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ public static boolean needToLog(Message msg) {
293293
return true;
294294
}
295295

296+
public synchronized boolean checkAndPutAdvInvRequest(Item key, Long value) {
297+
if (advInvRequest.containsKey(key)) {
298+
return false;
299+
}
300+
advInvRequest.put(key, value);
301+
return true;
302+
}
303+
296304
@Override
297305
public boolean equals(Object o) {
298306
if (!(o instanceof PeerConnection)) {

framework/src/main/java/org/tron/core/net/service/adv/AdvService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ private void consumerInvToFetch() {
281281
&& invSender.getSize(peer) < MAX_TRX_FETCH_PER_PEER)
282282
.sorted(Comparator.comparingInt(peer -> invSender.getSize(peer)))
283283
.findFirst().ifPresent(peer -> {
284-
invSender.add(item, peer);
285-
peer.getAdvInvRequest().put(item, now);
284+
if (peer.checkAndPutAdvInvRequest(item, now)) {
285+
invSender.add(item, peer);
286+
}
286287
invToFetch.remove(item);
287288
});
288289
});

framework/src/main/java/org/tron/core/net/service/fetchblock/FetchBlockService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ private void fetchBlockProcess(FetchBlockInfo fetchBlock) {
117117

118118
if (optionalPeerConnection.isPresent()) {
119119
optionalPeerConnection.ifPresent(firstPeer -> {
120-
if (shouldFetchBlock(firstPeer, fetchBlock)) {
121-
firstPeer.getAdvInvRequest().put(item, System.currentTimeMillis());
120+
if (shouldFetchBlock(firstPeer, fetchBlock)
121+
&& firstPeer.checkAndPutAdvInvRequest(item, System.currentTimeMillis())) {
122122
firstPeer.sendMessage(new FetchInvDataMessage(Collections.singletonList(item.getHash()),
123123
item.getType()));
124124
this.fetchBlockInfo = null;

0 commit comments

Comments
 (0)