Skip to content

Commit ea45d2a

Browse files
authored
Merge pull request #355 from tronprotocol/fixCircularRef
Fix circular ref
2 parents 5439f46 + b61b8e7 commit ea45d2a

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/main/java/org/tron/common/overlay/server/SyncPool.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
3232
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.context.ApplicationContext;
3334
import org.springframework.stereotype.Component;
3435
import org.tron.common.overlay.client.PeerClient;
3536
import org.tron.common.overlay.discover.Node;
@@ -52,6 +53,8 @@ public class SyncPool {
5253
private NodeManager nodeManager;
5354

5455
@Autowired
56+
private ApplicationContext ctx;
57+
5558
private ChannelManager channelManager;
5659

5760
private PeerConnectionDelegate peerDel;
@@ -70,10 +73,11 @@ public class SyncPool {
7073
public SyncPool(PeerConnectionDelegate peerDel, PeerClient peerClient) {
7174
this.peerDel = peerDel;
7275
this.peerClient = peerClient;
73-
init();
7476
}
7577

7678
public void init() {
79+
channelManager = ctx.getBean(ChannelManager.class);
80+
7781
poolLoopExecutor.scheduleWithFixedDelay(() -> {
7882
try {
7983
fillUp();

src/main/java/org/tron/core/net/node/NodeDelegateImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.tron.core.net.node;
22

33
import com.google.common.primitives.Longs;
4+
import java.util.ArrayList;
45
import java.util.Collections;
56
import java.util.Deque;
67
import java.util.LinkedList;
@@ -129,9 +130,10 @@ public LinkedList<BlockId> getLostBlockIds(List<BlockId> blockChainSummary)
129130
}
130131

131132
@Override
132-
public Deque<BlockId> getBlockChainSummary(BlockId beginBLockId, Deque<BlockId> blockIds) {
133+
public Deque<BlockId> getBlockChainSummary(BlockId beginBLockId, Deque<BlockId> blockIdsToFetch) {
133134

134135
Deque<BlockId> retSummary = new LinkedList<>();
136+
List<BlockId> blockIds = new ArrayList<>(blockIdsToFetch);
135137
long highBlkNum;
136138
long highNoForkBlkNum;
137139
long lowBlkNum = 0;
@@ -166,7 +168,7 @@ public Deque<BlockId> getBlockChainSummary(BlockId beginBLockId, Deque<BlockId>
166168
} else if (lowBlkNum <= highBlkNum) {
167169
retSummary.offer(forkList.get((int) (lowBlkNum - highNoForkBlkNum - 1)));
168170
} else {
169-
retSummary.offer(blockIds.poll());
171+
retSummary.offer(blockIds.get((int) (lowBlkNum - highBlkNum - 1)));
170172
}
171173
lowBlkNum += (realHighBlkNum - lowBlkNum + 2) / 2;
172174
} while (lowBlkNum <= realHighBlkNum);

src/main/java/org/tron/core/net/node/NodeImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ public void broadcast(Message msg) {
227227

228228
@Override
229229
public void listen() {
230+
pool.init();
230231
isAdvertiseActive = true;
231232
isFetchActive = true;
232233
isHandleSyncBlockActive = true;
@@ -557,7 +558,7 @@ private void onHandleBlockMessage(PeerConnection peer, BlockMessage blkMsg) {
557558
//processSyncBlock(blkMsg.getBlockCapsule());
558559
if (!peer.isBusy()) {
559560
if (peer.getUnfetchSyncNum() > 0
560-
&& peer.getSyncBlockToFetch().size() < NodeConstant.SYNC_FETCH_BATCH_NUM) {
561+
&& peer.getSyncBlockToFetch().size() <= NodeConstant.SYNC_FETCH_BATCH_NUM) {
561562
syncNextBatchChainIds(peer);
562563
} else {
563564
//TODO: here should be a loop do this thing

0 commit comments

Comments
 (0)