@Test public void testGetAfterTheForkChain() { Block forkBlock = null; for (int i = 0; i < 30; i++) { Block bestBlock = chainContainer.getBestBlock(); Block newBlock = newBlock(bestBlock); Result success = chainContainer.verifyAndAddBlock(newBlock, false, true); assertTrue(success.isSuccess()); bestBlock = chainContainer.getBestBlock(); assertEquals(bestBlock.getHeader().getHeight(), 1L + i); if (i == 20) { forkBlock = bestBlock; } } Chain chain = new Chain(); chain.addBlock(forkBlock); Block newBlock = newBlock(forkBlock); chain.addBlock(newBlock); ChainContainer otherChainContainer = new ChainContainer(chain); ChainContainer newForkChainContainer = chainContainer.getAfterTheForkChain(otherChainContainer); assertEquals(newForkChainContainer.getBestBlock().getHeader().getHeight(), 30L); }
public ChainContainer getAfterTheForkChain(ChainContainer chainContainer) { BlockHeader pointBlockHeader = chainContainer.getChain().getStartBlockHeader(); Chain chain = new Chain(); List<Block> blockList = getChain().getAllBlockList(); boolean canAdd = false; for (int i = 0; i < blockList.size(); i++) { Block block = blockList.get(i); if (canAdd) { chain.addBlock(block); } if (pointBlockHeader.getPreHash().equals(block.getHeader().getHash())) { canAdd = true; chain.setPreChainId(getChain().getId()); continue; } } return new ChainContainer(chain); }
ChainContainer implements Cloneable { public ChainContainer getAfterTheForkChain(ChainContainer chainContainer) { BlockHeader pointBlockHeader = chainContainer.getChain().getStartBlockHeader(); Chain chain = new Chain(); List<Block> blockList = getChain().getAllBlockList(); boolean canAdd = false; for (int i = 0; i < blockList.size(); i++) { Block block = blockList.get(i); if (canAdd) { chain.addBlock(block); } if (pointBlockHeader.getPreHash().equals(block.getHeader().getHash())) { canAdd = true; chain.setPreChainId(getChain().getId()); continue; } } return new ChainContainer(chain); } }
ChainContainer implements Cloneable { public ChainContainer getAfterTheForkChain(ChainContainer chainContainer) { BlockHeader pointBlockHeader = chainContainer.getChain().getStartBlockHeader(); Chain chain = new Chain(); List<Block> blockList = getChain().getAllBlockList(); boolean canAdd = false; for (int i = 0; i < blockList.size(); i++) { Block block = blockList.get(i); if (canAdd) { chain.addBlock(block); } if (pointBlockHeader.getPreHash().equals(block.getHeader().getHash())) { canAdd = true; chain.setPreChainId(getChain().getId()); continue; } } return new ChainContainer(chain); } ChainContainer(Chain chain); }
ChainContainer implements Cloneable { public ChainContainer getAfterTheForkChain(ChainContainer chainContainer) { BlockHeader pointBlockHeader = chainContainer.getChain().getStartBlockHeader(); Chain chain = new Chain(); List<Block> blockList = getChain().getAllBlockList(); boolean canAdd = false; for (int i = 0; i < blockList.size(); i++) { Block block = blockList.get(i); if (canAdd) { chain.addBlock(block); } if (pointBlockHeader.getPreHash().equals(block.getHeader().getHash())) { canAdd = true; chain.setPreChainId(getChain().getId()); continue; } } return new ChainContainer(chain); } ChainContainer(Chain chain); boolean addBlock(Block block); Result verifyBlock(Block block); Result verifyBlock(Block block, boolean isDownload, boolean isNeedCheckCoinBaseTx); boolean verifyCoinBaseTx(Block block, MeetingRound currentRound, MeetingMember member); boolean verifyPunishTx(Block block, MeetingRound currentRound, MeetingMember member); Result verifyAndAddBlock(Block block, boolean isDownload, boolean isNeedCheckCoinBaseTx); boolean rollback(Block block); ChainContainer getBeforeTheForkChain(ChainContainer chainContainer); ChainContainer getAfterTheForkChain(ChainContainer chainContainer); MeetingRound getCurrentRound(); MeetingRound getOrResetCurrentRound(); MeetingRound getOrResetCurrentRound(boolean isRealTime); MeetingRound initRound(); void clearRound(int count); Block getBestBlock(); Chain getChain(); void setChain(Chain chain); @Override boolean equals(Object obj); RoundManager getRoundManager(); }
ChainContainer implements Cloneable { public ChainContainer getAfterTheForkChain(ChainContainer chainContainer) { BlockHeader pointBlockHeader = chainContainer.getChain().getStartBlockHeader(); Chain chain = new Chain(); List<Block> blockList = getChain().getAllBlockList(); boolean canAdd = false; for (int i = 0; i < blockList.size(); i++) { Block block = blockList.get(i); if (canAdd) { chain.addBlock(block); } if (pointBlockHeader.getPreHash().equals(block.getHeader().getHash())) { canAdd = true; chain.setPreChainId(getChain().getId()); continue; } } return new ChainContainer(chain); } ChainContainer(Chain chain); boolean addBlock(Block block); Result verifyBlock(Block block); Result verifyBlock(Block block, boolean isDownload, boolean isNeedCheckCoinBaseTx); boolean verifyCoinBaseTx(Block block, MeetingRound currentRound, MeetingMember member); boolean verifyPunishTx(Block block, MeetingRound currentRound, MeetingMember member); Result verifyAndAddBlock(Block block, boolean isDownload, boolean isNeedCheckCoinBaseTx); boolean rollback(Block block); ChainContainer getBeforeTheForkChain(ChainContainer chainContainer); ChainContainer getAfterTheForkChain(ChainContainer chainContainer); MeetingRound getCurrentRound(); MeetingRound getOrResetCurrentRound(); MeetingRound getOrResetCurrentRound(boolean isRealTime); MeetingRound initRound(); void clearRound(int count); Block getBestBlock(); Chain getChain(); void setChain(Chain chain); @Override boolean equals(Object obj); RoundManager getRoundManager();  }