diff --git a/starcoin-indexer/src/main/java/org/starcoin/indexer/handler/DagInspectorIndexer.java b/starcoin-indexer/src/main/java/org/starcoin/indexer/handler/DagInspectorIndexer.java index 4b29ee2..7529c5d 100644 --- a/starcoin-indexer/src/main/java/org/starcoin/indexer/handler/DagInspectorIndexer.java +++ b/starcoin-indexer/src/main/java/org/starcoin/indexer/handler/DagInspectorIndexer.java @@ -87,7 +87,7 @@ protected void executeInternal(JobExecutionContext jobExecutionContext) { long headHeight = chainHeader.getHeight(); long bulkNumber = Math.min(headHeight - localBlockOffset.getBlockHeight(), bulkSize); int index = 1; - Map blockMap = new HashMap<>(); + List blockList = new ArrayList<>(); while (index <= bulkNumber) { long currentBlockHeight = localBlockOffset.getBlockHeight() + index; @@ -98,14 +98,14 @@ protected void executeInternal(JobExecutionContext jobExecutionContext) { return; } - blockMap.put(block.getHeader().getBlockHash(), block); + blockList.add(block); //update current header currentHandleHeader = block.getHeader(); index++; logger.info("add block: {}", block.getHeader()); } - inspectorHandler.upsertDagInfoFromBlocks(new ArrayList<>(blockMap.values())); + inspectorHandler.upsertDagInfoFromBlocks(blockList); // Update offset localBlockOffset.setBlockHeight(currentHandleHeader.getHeight()); diff --git a/starcoin-indexer/src/main/java/org/starcoin/indexer/handler/DagInspectorIndexerHandler.java b/starcoin-indexer/src/main/java/org/starcoin/indexer/handler/DagInspectorIndexerHandler.java index f0e5fd0..f5c9437 100644 --- a/starcoin-indexer/src/main/java/org/starcoin/indexer/handler/DagInspectorIndexerHandler.java +++ b/starcoin-indexer/src/main/java/org/starcoin/indexer/handler/DagInspectorIndexerHandler.java @@ -82,20 +82,20 @@ public void upsertDagInfoFromBlocks(List blockList) throws IOException, J ); // Build block node data - blockList.forEach(blockInfo -> { - String currentBlockHash = blockInfo.getHeader().getBlockHash(); + blockList.forEach(block -> { + String currentBlockHash = block.getHeader().getBlockHash(); DagInspectorBlock dagBlock = dagBlockMap.get(currentBlockHash); if (dagBlock == null) { try { BlockGhostdagData ghostdagData = blockRPCClient.getBlockGhostdagData(currentBlockHash); dagBlock = new DagInspectorBlock(); dagBlock.setBlockHash(currentBlockHash); - dagBlock.setTimestamp(blockInfo.getHeader().getTimestamp()); + dagBlock.setTimestamp(block.getHeader().getTimestamp()); dagBlock.setColor(NODE_COLOR_GRAY); dagBlock.setDaaScore(ghostdagData.getBlueScore()); - dagBlock.setHeight(blockInfo.getHeader().getHeight()); + dagBlock.setHeight(block.getHeader().getHeight()); dagBlock.setSelectedParentHash(ghostdagData.getSelectedParent()); - dagBlock.setParentIds(blockInfo.getHeader().getParentsHash()); + dagBlock.setParentIds(block.getHeader().getParentsHash()); // Block is the virtual selected parent chain because the list read from block height dagBlock.setInVirtualSelectedParentChain(true); @@ -148,7 +148,7 @@ List buildEdgeDataFromDagBlockDataMaybeUpate( DagInspectorBlock parentDagBlock = dagBlockMap.get(parentHash); if (parentDagBlock == null) { logger.info("Parent block not found: {} ", parentHash); - parentDagBlock = getDagInspectorBlockInfoFromHash(parentHash, heightGroupList); + parentDagBlock = getDagInspectorBlockFromHash(parentHash, heightGroupList); // Put into buffer list newDagBlocks.add(parentDagBlock); @@ -323,24 +323,24 @@ private List getGroupHeightSizeFromStorage(List h } - protected DagInspectorBlock getDagInspectorBlockInfoFromHash( + protected DagInspectorBlock getDagInspectorBlockFromHash( String blockHash, List heightGroupList ) throws JSONRPC2SessionException { - Block blockInfo = blockRPCClient.getBlockByHash(blockHash); + Block block = blockRPCClient.getBlockByHash(blockHash); BlockGhostdagData blockGhostdagData = blockRPCClient.getBlockGhostdagData(blockHash); DagInspectorBlock dagBlock = new DagInspectorBlock(); - Long blockHeight = blockInfo.getHeader().getHeight(); + Long blockHeight = block.getHeader().getHeight(); dagBlock.setBlockHash(blockHash); - dagBlock.setTimestamp(blockInfo.getHeader().getTimestamp()); + dagBlock.setTimestamp(block.getHeader().getTimestamp()); dagBlock.setColor(NODE_COLOR_GRAY); dagBlock.setDaaScore(blockGhostdagData.getBlueScore()); - dagBlock.setHeight(blockInfo.getHeader().getHeight()); + dagBlock.setHeight(block.getHeader().getHeight()); dagBlock.setSelectedParentHash(blockGhostdagData.getSelectedParent()); - dagBlock.setParentIds(blockInfo.getHeader().getParentsHash()); + dagBlock.setParentIds(block.getHeader().getParentsHash()); dagBlock.setInVirtualSelectedParentChain(false); // Height group list index @@ -350,7 +350,7 @@ protected DagInspectorBlock getDagInspectorBlockInfoFromHash( logger.info("Get block info from hash: {}, height: {}, heightGroupIndex: {}", blockHash, - blockInfo.getHeader().getHeight(), + block.getHeader().getHeight(), dagBlock.getHeightGroupIndex() ); return dagBlock;