Skip to content

feat(net): add volatile modifier to peer attribute variables #6360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: release_v4.8.1
Choose a base branch
from
Open
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
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