Skip to content

Commit bacd8c2

Browse files
committed
fix(net): use khaosdb to judge if beginBlockId exists
1 parent c7268c4 commit bacd8c2

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

chainbase/src/main/java/org/tron/core/ChainBaseManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ public boolean containBlockInMainChain(BlockId blockId) {
362362
}
363363
}
364364

365+
public BlockCapsule getKhaosDbHead(){
366+
return this.khaosDb.getHead();
367+
}
365368

366369
/**
367370
* Get a BlockCapsule by id.

framework/src/main/java/org/tron/core/net/TronNetDelegate.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public BlockId getHeadBlockId() {
146146
return chainBaseManager.getHeadBlockId();
147147
}
148148

149+
public BlockId getKhaosDbHeadBlockId() {
150+
return chainBaseManager.getKhaosDbHead().getBlockId();
151+
}
152+
149153
public BlockId getSolidBlockId() {
150154
return chainBaseManager.getSolidBlockId();
151155
}

framework/src/main/java/org/tron/core/net/messagehandler/ChainInventoryMsgHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void processMessage(PeerConnection peer, TronMessage msg) throws P2pExcep
7272
try {
7373
BlockId blockId = null;
7474
while (!peer.getSyncBlockToFetch().isEmpty() && tronNetDelegate
75-
.containBlockInMainChain(peer.getSyncBlockToFetch().peek())) {
75+
.containBlock(peer.getSyncBlockToFetch().peek())) {
7676
blockId = peer.getSyncBlockToFetch().pop();
7777
peer.setBlockBothHave(blockId);
7878
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ private LinkedList<BlockId> getBlockChainSummary(PeerConnection peer) throws P2p
169169
if (beginBlockId.getNum() == 0) {
170170
highNoFork = high = tronNetDelegate.getHeadBlockId().getNum();
171171
} else {
172-
if (tronNetDelegate.containBlockInMainChain(beginBlockId)) {
172+
if (tronNetDelegate.getKhaosDbHeadBlockId().compareTo(beginBlockId) == 0
173+
|| tronNetDelegate.containBlockInMainChain(beginBlockId)) {
173174
highNoFork = high = beginBlockId.getNum();
174175
} else {
175176
forkList = tronNetDelegate.getBlockChainHashesOnFork(beginBlockId);

0 commit comments

Comments
 (0)