Skip to content

Commit 996fb34

Browse files
committed
there is not the most recent common ancestor, need to remove all blocks in the fork chain
1 parent d0146e1 commit 996fb34

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/main/java/org/tron/core/db/KhaosDatabase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ public BlockCapsule getParentBlock(Sha256Hash hash) {
350350
.map(KhaosBlock::getParent)
351351
.map(khaosBlock -> khaosBlock == null ? null : khaosBlock.blk)
352352
.filter(Objects::nonNull)
353+
.filter(b -> containBlock(b.getBlockId()))
353354
.findFirst()
354355
.orElse(null);
355356
}

src/main/java/org/tron/core/db/Manager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,8 @@ private void switchFork(BlockCapsule newHead)
594594
logger.info("there is not the most recent common ancestor, need to remove all blocks in the fork chain.");
595595
BlockCapsule tmp = newHead;
596596
while (tmp != null) {
597-
BlockCapsule parent = khaosDb.getParentBlock(tmp.getBlockId());
598597
khaosDb.removeBlk(tmp.getBlockId());
599-
tmp = parent;
598+
tmp = khaosDb.getBlock(tmp.getParentHash());
600599
}
601600

602601
throw e;

0 commit comments

Comments
 (0)