Skip to content

Commit

Permalink
[debug] fixed parameters error
Browse files Browse the repository at this point in the history
  • Loading branch information
welbon committed Jun 29, 2024
1 parent b178572 commit d8b2cdf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.starcoin.scan.service.vo.DIAppConfigVo;
import org.starcoin.scan.service.vo.DIBlocksAndEdgesAndHeightGroupsVo;

import java.util.List;

@Api(tags = "dag-inspector")
@RestController
@RequestMapping("v2/dag-inspector")
Expand All @@ -26,12 +24,12 @@ public DIBlocksAndEdgesAndHeightGroupsVo getBlocksBetweenHeights(
return dagInspectorService.getBlocksAndEdgesAndHeightGroups(network, startHeight, endHeight);
}

@GetMapping("/{network}/header")
public DIBlocksAndEdgesAndHeightGroupsVo header(
@GetMapping("/{network}/head")
public DIBlocksAndEdgesAndHeightGroupsVo head(
@PathVariable("network") String network,
@RequestParam Long heightDifferent
@RequestParam Long heightDifference
) throws Exception {
return dagInspectorService.getHead(network, heightDifferent);
return dagInspectorService.getHead(network, heightDifference);
}

@GetMapping("/{network}/blockHash")
Expand All @@ -46,10 +44,10 @@ public DIBlocksAndEdgesAndHeightGroupsVo getBlockHash(
@GetMapping("/{network}/blockDAAScore")
public DIBlocksAndEdgesAndHeightGroupsVo getBlockDAAScore(
@PathVariable("network") String network,
@RequestParam Long daaScore,
@RequestParam Long blockDAAScore,
@RequestParam Long heightDifference
) throws Exception {
return dagInspectorService.getBlockDAAScore(network, daaScore, heightDifference);
return dagInspectorService.getBlockDAAScore(network, blockDAAScore, heightDifference);
}

@GetMapping("/{network}/appConfig")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.starcoin.scan.service.vo.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -53,12 +54,26 @@ public DIBlocksAndEdgesAndHeightGroupsVo getBlocksAndEdgesAndHeightGroups(String
}

groups.setBlocks(blockList);
groups.setEdges(getEdgeList(network, startHeight, endHeight));

List<DagInspectorEdge> blockEdges = getEdgeList(network, startHeight, endHeight);
groups.setEdges(blockEdges);

Set<Long> heightList =
blockList.stream()
.map(DagInspectorBlock::getHeight)
.collect(Collectors.toSet());

// Add edges FromHeight and ToHeight
heightList.addAll(
blockEdges.stream()
.map(DagInspectorEdge::getFromHeight)
.collect(Collectors.toSet())
);
heightList.addAll(
blockEdges.stream()
.map(DagInspectorEdge::getToHeight)
.collect(Collectors.toSet())
);
groups.setHeightGroups(getHeightGroup(network, heightList));

return groups;
Expand Down Expand Up @@ -111,11 +126,20 @@ private List<DagInspectorBlock> getBlockList(String network, Long startHeight, L
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("height").gte(startHeight).lte(endHeight)));
sourceBuilder.sort("height", SortOrder.ASC);
sourceBuilder.size(endHeight.intValue() - startHeight.intValue());
//sourceBuilder.size(endHeight.intValue() - startHeight.intValue());
sourceBuilder.size(1000);
searchRequest.source(sourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
Result<DagInspectorBlock> result = ServiceUtils.getSearchResult(searchResponse, DagInspectorBlock.class);
return result.getContents();
return result.getContents().stream().peek(block -> {
if (block.getMergeSetBlueIds() == null) {
block.setMergeSetBlueIds(new ArrayList<>());
}

if (block.getMergeSetRedIds() == null) {
block.setMergeSetRedIds(new ArrayList<>());
}
}).collect(Collectors.toList());
}

/**
Expand All @@ -132,7 +156,9 @@ List<DagInspectorEdge> getEdgeList(String network, Long startHeight, Long endHei
RangeQueryBuilder toHeightQuery = QueryBuilders.rangeQuery("to_height").lte(endHeight);
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder()
.query(QueryBuilders.boolQuery().must(fromHeightQuery).must(toHeightQuery))
.sort("to_height", SortOrder.ASC);
.sort("to_height", SortOrder.ASC)
.size(100);

searchRequest.source(sourceBuilder);
SearchResponse searchResponse;
try {
Expand All @@ -156,7 +182,8 @@ protected List<DagInspectorHeightGroup> getHeightGroup(String network, Set<Long>
SearchRequest searchRequest = new SearchRequest(getIndex(network, Constant.DAG_INSPECT_HEIGHT_GROUP));
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder()
.query(QueryBuilders.termsQuery("height", heights));
sourceBuilder.size(heights.size());
//sourceBuilder.size(heights.size());
sourceBuilder.size(1000);
searchRequest.source(sourceBuilder);
SearchResponse searchResponse;
try {
Expand All @@ -170,7 +197,13 @@ protected List<DagInspectorHeightGroup> getHeightGroup(String network, Set<Long>
}

public DIAppConfigVo getAppConfig(String network) {
return new DIAppConfigVo();
DIAppConfigVo configVo = new DIAppConfigVo();
configVo.setApiVersion("2.0.0");
configVo.setNetwork(network);
configVo.setProcessingVersion("0.0.1");
configVo.setWebVersion("0.0.1");
configVo.setStarcoinVersion("2.0.0");
return configVo;
}

private Long getMaxHeightFromStorage(String network) throws IOException {
Expand Down

0 comments on commit d8b2cdf

Please sign in to comment.