Skip to content

Commit 017207e

Browse files
committed
feat(net): adjust the order of field assignment to solve concurrency issues
1 parent 5304d55 commit 017207e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

framework/src/main/java/org/tron/core/net/service/sync/SyncService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ private void invalid(BlockId blockId, PeerConnection peerConnection) {
159159
}
160160

161161
private LinkedList<BlockId> getBlockChainSummary(PeerConnection peer) throws P2pException {
162-
163-
BlockId beginBlockId = peer.getBlockBothHave();
164162
List<BlockId> blockIds = new ArrayList<>(peer.getSyncBlockToFetch());
163+
BlockId beginBlockId = peer.getBlockBothHave();
165164
List<BlockId> forkList = new LinkedList<>();
166165
LinkedList<BlockId> summary = new LinkedList<>();
167166
long syncBeginNumber = tronNetDelegate.getSyncBeginNumber();
@@ -323,9 +322,9 @@ private void processSyncBlock(BlockCapsule block, PeerConnection peerConnection)
323322
for (PeerConnection peer : tronNetDelegate.getActivePeer()) {
324323
BlockId bid = peer.getSyncBlockToFetch().peek();
325324
if (blockId.equals(bid)) {
325+
peer.setBlockBothHave(blockId);
326326
peer.getSyncBlockToFetch().remove(bid);
327327
if (flag) {
328-
peer.setBlockBothHave(blockId);
329328
if (peer.getSyncBlockToFetch().isEmpty() && peer.isFetchAble()) {
330329
syncNext(peer);
331330
}

0 commit comments

Comments
 (0)