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

CI script refactoring for more verbose output #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
56 changes: 25 additions & 31 deletions check-finalized-block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function delay(ms) {
}

async function main() {

let paraAddress = "ws://127.0.0.1:9944";
const args = require('minimist')(process.argv.slice(2))
if (args.hasOwnProperty('para_address')) {
Expand All @@ -26,39 +25,34 @@ async function main() {
console.log("Using passed parameter relay_address: " + relayAddress);
}

let targetBlockNum;
if (args.hasOwnProperty('target_block')) {
targetBlockNum = args['target_block'];
console.log("Using passed parameter target_block: " + targetBlockNum);
if (!args.hasOwnProperty('target_block') || (typeof args['target_block'] !== 'number') || !Number.isInteger(args['target_block'])) {
console.log("target_block parameter not provided or not an integer!");
process.exit(1);
}

if(targetBlockNum) {
const paraApi = await createPromiseApi(paraAddress);
const relayApi = await createPromiseApi(relayAddress);
let time = 20 * 60;

while (time > 0) {
const paraHeader = await paraApi.rpc.chain.getHeader();
const paraBlockNum = paraHeader.number.toNumber();

const relayHeader = await relayApi.rpc.chain.getHeader();
const relayBlockNum = relayHeader.number.toNumber();

if(paraBlockNum >= targetBlockNum && relayBlockNum >= targetBlockNum) {
console.log("Successfully finalized para block number " + paraBlockNum);
console.log("Successfully finalized relay block number " + relayBlockNum);
process.exit(0);
}
time-=5;
await delay(1000 * 5)
let targetBlockNum = args['target_block'];
console.log("Using passed parameter target_block: " + targetBlockNum);

const paraApi = await createPromiseApi(paraAddress);
const relayApi = await createPromiseApi(relayAddress);
let timeout = 20 * 60;
let time = timeout;

while (time > 0) {
const paraHeader = await paraApi.rpc.chain.getHeader();
const paraBlockNum = paraHeader.number.toNumber();
const relayHeader = await relayApi.rpc.chain.getHeader();
const relayBlockNum = relayHeader.number.toNumber();
console.log("blocks at " + (timeout - time) + "s: [relay: " + relayBlockNum + ", para: " + paraBlockNum + "]");

if (paraBlockNum >= targetBlockNum && relayBlockNum >= targetBlockNum) {
console.log("Successfully finalized para block number " + paraBlockNum);
console.log("Successfully finalized relay block number " + relayBlockNum);
process.exit(0);
}


console.log("Failed to finalize the target block number " + targetBlockNum);
process.exit(1);
time -= 5;
await delay(1000 * 5)
}

console.log("target_block was not provided!");
console.error("Failed to finalize the target block number " + targetBlockNum);
process.exit(1);
}

Expand Down