diff --git a/services/admin.ts b/services/admin.ts index b1ad385..87eca35 100644 --- a/services/admin.ts +++ b/services/admin.ts @@ -162,48 +162,44 @@ export class AdminZkRandService extends BaseService { } while (this.running) { - try { - const contractPhase = await this.state.zkRandContract.contractPhase() - console.log("contractPhase", contractPhase) - if (contractPhase == Status.Registered) { - // all the nodes have registered; start nidkg - const ret = await this.state.zkRandContract.startNidkg({gasLimit: gasLimitLow}) - console.log("transaction hash for startNiDkg:", ret.hash) - await ret.wait() - } else if (contractPhase == Status.NidkgComplete) { - // nidkg has completed; calculate global public parameters - await this.createGpp() - } else if (contractPhase == Status.Ready) { - const currentRoundNum: BigNumber = await this.state.zkRandContract.currentRoundNum() - console.log("currentRoundNum", currentRoundNum.toString()) - if (Date.now() < this.state.startDate) { - const begin = new Date(this.state.startDate); - console.log("randomness generation will begin at", begin.toUTCString()) + const contractPhase = await this.state.zkRandContract.contractPhase() + console.log("contractPhase", contractPhase) + if (contractPhase == Status.Registered) { + // all the nodes have registered; start nidkg + const ret = await this.state.zkRandContract.startNidkg({gasLimit: gasLimitLow}) + console.log("transaction hash for startNiDkg:", ret.hash) + await ret.wait() + } else if (contractPhase == Status.NidkgComplete) { + // nidkg has completed; calculate global public parameters + await this.createGpp() + } else if (contractPhase == Status.Ready) { + const currentRoundNum: BigNumber = await this.state.zkRandContract.currentRoundNum() + console.log("currentRoundNum", currentRoundNum.toString()) + if (Date.now() < this.state.startDate) { + const begin = new Date(this.state.startDate); + console.log("randomness generation will begin at", begin.toUTCString()) + } else { + if (currentRoundNum.eq(zero)) { + // random generation starts from 1 + await this.initiateRand() } else { - if (currentRoundNum.eq(zero)) { - // random generation starts from 1 - await this.initiateRand() - } else { - const submissionCount = await this.state.zkRandContract.roundSubmissionCount(currentRoundNum) - const roundToRandom = await this.state.zkRandContract.roundToRandom(currentRoundNum) - - if (roundToRandom.value === bytes32Zero && submissionCount >= this.options.threshold) { - await this.createRandom(currentRoundNum) - } - - const secondsElapsed = Math.floor( - (Date.now() - this.state.timeOfLastRound) / 1000 - ) - console.log('Seconds elapsed since last random initiation:', secondsElapsed) - - if (secondsElapsed > this.options.randGenInterval && roundToRandom.value !== bytes32Zero) { - await this.initiateRand(); - } + const submissionCount = await this.state.zkRandContract.roundSubmissionCount(currentRoundNum) + const roundToRandom = await this.state.zkRandContract.roundToRandom(currentRoundNum) + + if (roundToRandom.value === bytes32Zero && submissionCount >= this.options.threshold) { + await this.createRandom(currentRoundNum) + } + + const secondsElapsed = Math.floor( + (Date.now() - this.state.timeOfLastRound) / 1000 + ) + console.log('Seconds elapsed since last random initiation:', secondsElapsed) + + if (secondsElapsed > this.options.randGenInterval && roundToRandom.value !== bytes32Zero) { + await this.initiateRand(); } } } - } catch (error) { - console.warn("admin script error:", error) } await sleep(this.options.pollingInterval) diff --git a/services/node.ts b/services/node.ts index d6b14b9..4419a34 100644 --- a/services/node.ts +++ b/services/node.ts @@ -127,7 +127,7 @@ export class NodeZkRandService extends BaseService { } } } catch (error) { - console.warn("node script error:", error) + console.error("node script error:", error) } await sleep(this.options.pollingInterval)