Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<fix>(perf): fix ChainContinuityTester. #174

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 78 additions & 49 deletions src/main/java/org/fisco/bcos/sdk/demo/ChainContinuityTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicLong;

import me.tongfei.progressbar.ProgressBar;
import me.tongfei.progressbar.ProgressBarBuilder;
import me.tongfei.progressbar.ProgressBarStyle;
Expand Down Expand Up @@ -81,7 +82,7 @@ public static void main(String[] args) throws InterruptedException {
System.out.println("===================================================");
for (Map.Entry<String, ConcurrentHashMap<Long, BcosBlock.Block>> concurrentHashMapEntry :
nodeBlockMap.entrySet()) {
checkBlockContinuity(concurrentHashMapEntry);
checkBlockContinuity(concurrentHashMapEntry, threadPoolService);
}
System.out.println("Check continuity finished.");
System.out.println("===================================================");
Expand All @@ -95,47 +96,68 @@ public static void main(String[] args) throws InterruptedException {
ProgressBar checkBar =
new ProgressBarBuilder()
.setTaskName("Checking :")
.setInitialMax(toBlock.intValue())
.setInitialMax(toBlock.intValue()- fromBlock.intValue())
.setStyle(ProgressBarStyle.UNICODE_BLOCK)
.build();
for (long i = fromBlock.longValue(); i < toBlock.longValue(); i++) {
BcosBlock.Block block = values.get(0).get(i);
if (block == null) {
checkBar.close();
break;
}
for (int j = 1; j < nodeBlockMap.size(); j++) {
BcosBlock.Block block1 = values.get(j).get(i);
if (block1 == null) {
checkBar.step();
break;
}
boolean equals = block1.equals(block);
equals = equals && (block1.getTimestamp() == block.getTimestamp());
equals =
equals
&& (Objects.equals(
block1.getReceiptsRoot(), block.getReceiptsRoot()));
equals =
equals
&& (Objects.equals(
block1.getTransactionsRoot(), block.getTransactionsRoot()));
equals = equals && (Objects.equals(block.getStateRoot(), block1.getStateRoot()));
equals = equals && block1.getHash().equals(block.getHash());
equals = equals && block1.getGasUsed().equals(block.getGasUsed());
if (!equals) {
System.out.println("ERROR: block continuity check failed, blockNumber:" + i);
}
checkBar.step();
}
checkBar.close();
long finalI = i;
threadPoolService
.getThreadPool()
.execute(
() -> {
BcosBlock.Block block = values.get(0).get(finalI);
if (block == null) {
checkBar.close();
return;
}
for (int j = 1; j < nodeBlockMap.size(); j++) {
BcosBlock.Block block1 = values.get(j).get(finalI);
if (block1 == null) {
checkBar.step();
break;
}
boolean equals = block1.equals(block);
equals =
equals
&& (block1.getTimestamp()
== block.getTimestamp());
equals =
equals
&& (Objects.equals(
block1.getReceiptsRoot(),
block.getReceiptsRoot()));
equals =
equals
&& (Objects.equals(
block1.getTransactionsRoot(),
block.getTransactionsRoot()));
equals =
equals
&& (Objects.equals(
block.getStateRoot(),
block1.getStateRoot()));
equals = equals && block1.getHash().equals(block.getHash());
equals =
equals
&& block1.getGasUsed()
.equals(block.getGasUsed());
if (!equals) {
System.out.println(
"ERROR: block continuity check failed, blockNumber:"
+ finalI);
}
checkBar.step();
}
});
}
checkBar.close();
System.out.println("===================================================");
System.exit(0);
}

private static void checkBlockContinuity(
Map.Entry<String, ConcurrentHashMap<Long, BcosBlock.Block>> concurrentHashMapEntry) {
Map.Entry<String, ConcurrentHashMap<Long, BcosBlock.Block>> concurrentHashMapEntry,
ThreadPoolService threadPoolService) {
String nodeId = concurrentHashMapEntry.getKey();
ConcurrentHashMap<Long, BcosBlock.Block> blockConcurrentHashMap =
concurrentHashMapEntry.getValue();
Expand All @@ -156,19 +178,26 @@ private static void checkBlockContinuity(
+ lastTimestamp);
}
lastTimestamp.set(block.getTimestamp());
block.getTransactionHashes()
.forEach(
transactionHash -> {
if (!transactionHashes.add(transactionHash.get())) {
System.out.println(
"ERROR: block continuity transactionHash check failed, nodeId:"
+ nodeId
+ ", blockNumber:"
+ blockNumber
+ ", transactionHash:"
+ transactionHash.get());
}
});
List<BcosBlock.TransactionHash> transactionHashes1 =
block.getTransactionHashes();
for (int i = 0; i < transactionHashes1.size(); i++) {
int finalI = i;
threadPoolService
.getThreadPool()
.execute(
() -> {
String txHash = transactionHashes1.get(finalI).get();
if (!transactionHashes.add(txHash)) {
System.out.println(
"ERROR: block continuity transactionHash check failed, nodeId:"
+ nodeId
+ ", blockNumber:"
+ blockNumber
+ ", transactionHash:"
+ txHash);
}
});
}
});
}

Expand All @@ -191,17 +220,17 @@ public static void getNodeBlocks(
+ ", toBlock:"
+ toBlock.intValue());

CountDownLatch countDownLatch = new CountDownLatch(toBlock.intValue());
CountDownLatch countDownLatch = new CountDownLatch(toBlock.intValue() - fromBlk.intValue());
ProgressBar sentBar =
new ProgressBarBuilder()
.setTaskName("Send :")
.setInitialMax(toBlock.intValue())
.setInitialMax(toBlock.intValue() - fromBlk.intValue())
.setStyle(ProgressBarStyle.UNICODE_BLOCK)
.build();
ProgressBar receivedBar =
new ProgressBarBuilder()
.setTaskName("Receive:")
.setInitialMax(toBlock.intValue())
.setInitialMax(toBlock.intValue() - fromBlk.intValue())
.setStyle(ProgressBarStyle.UNICODE_BLOCK)
.build();
for (long i = fromBlk.longValue(); i < toBlock.longValue(); i++) {
Expand Down