This commit is contained in:
Rishi Panthee 2022-08-05 19:45:33 -04:00
commit 74a4855981
1 changed files with 10 additions and 3 deletions

View File

@ -12,9 +12,10 @@ const { Database } = require('./libs/Database');
program
.option('-n, --node [url]', 'compare with given node', 'https://api.hive-engine.com/rpc')
.option('-h, --head-only', 'compare only the head block')
.parse(process.argv);
const { node } = program;
const { node, headOnly } = program;
let id = 1;
@ -105,7 +106,7 @@ async function findDivergentBlock() {
let block = (await chain.find().sort({ _id: -1 }).limit(1).toArray())[0];
let mainBlock;
if (lightNode) {
if (headOnly) {
let retries = 0;
while (!mainBlock && retries < 10) {
await new Promise(r => setTimeout(r, 1000)); // sleep 1 second
@ -119,12 +120,18 @@ async function findDivergentBlock() {
} else if (mainBlock.hash === block.hash) {
console.log('ok');
} else {
console.log(`head block divergent from ${node}`);
console.log(`head block ${block._id} divergent from ${node}`);
console.log(`hash should be ${mainBlock.hash} is ${block.hash}`);
exitCode = 2;
}
} else {
let low = 0;
if (lightNode) {
const firstBlock = await chain.findOne({ blockNumber: { $gt: 0 } });
if (firstBlock) {
low = firstBlock.blockNumber;
}
}
let high = block._id;
const headBlock = high;
while (high - low >= 1) {