Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class PeerConnection {

@Getter
@Setter
private TronState tronState = TronState.INIT;
private volatile TronState tronState = TronState.INIT;

@Autowired
private TronNetDelegate tronNetDelegate;
Expand Down Expand Up @@ -123,15 +123,15 @@ public class PeerConnection {
private Map<Item, Long> advInvRequest = new ConcurrentHashMap<>();

@Setter
private BlockId fastForwardBlock;
private volatile BlockId fastForwardBlock;

@Getter
private BlockId blockBothHave = new BlockId();
private volatile BlockId blockBothHave = new BlockId();
@Getter
private volatile long blockBothHaveUpdateTime = System.currentTimeMillis();
@Setter
@Getter
private BlockId lastSyncBlockId;
private volatile BlockId lastSyncBlockId;
@Setter
@Getter
private volatile long remainNum;
Expand All @@ -146,7 +146,7 @@ public class PeerConnection {
private Map<BlockId, Long> syncBlockRequested = new ConcurrentHashMap<>();
@Setter
@Getter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why syncBlockToFetch here not add this volatile, as you change the logic order at SyncService.java

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field does not have a second assignment, so it does not need to be modified by volatile.

private Pair<Deque<BlockId>, Long> syncChainRequested = null;
private volatile Pair<Deque<BlockId>, Long> syncChainRequested = null;
@Setter
@Getter
private Set<BlockId> syncBlockInProcess = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ private void invalid(BlockId blockId, PeerConnection peerConnection) {
}

private LinkedList<BlockId> getBlockChainSummary(PeerConnection peer) throws P2pException {

BlockId beginBlockId = peer.getBlockBothHave();
List<BlockId> blockIds = new ArrayList<>(peer.getSyncBlockToFetch());
BlockId beginBlockId = peer.getBlockBothHave();
List<BlockId> forkList = new LinkedList<>();
LinkedList<BlockId> summary = new LinkedList<>();
long syncBeginNumber = tronNetDelegate.getSyncBeginNumber();
Expand Down Expand Up @@ -323,9 +322,9 @@ private void processSyncBlock(BlockCapsule block, PeerConnection peerConnection)
for (PeerConnection peer : tronNetDelegate.getActivePeer()) {
BlockId bid = peer.getSyncBlockToFetch().peek();
if (blockId.equals(bid)) {
peer.setBlockBothHave(blockId);
peer.getSyncBlockToFetch().remove(bid);
if (flag) {
peer.setBlockBothHave(blockId);
if (peer.getSyncBlockToFetch().isEmpty() && peer.isFetchAble()) {
syncNext(peer);
}
Expand Down