Skip to content

Commit

Permalink
refactored some names
Browse files Browse the repository at this point in the history
  • Loading branch information
ironoa committed Aug 13, 2020
1 parent 2794c4d commit 3a93d4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ export class Subscriber {
this.validators = cfg.validators

this._initializedTransactions = {};
for (const subscription of this.subscribe.transactions) {
this._initializedTransactions[subscription.name] = false;
if(this.subscribe.transactions){
for (const subscription of this.subscribe.transactions) {
this._initializedTransactions[subscription.name] = false;
}
}
}

Expand Down Expand Up @@ -190,9 +192,9 @@ export class Subscriber {
});

this.api.rpc.chain.subscribeNewHeads(async (lastHeader) => {
let isHeadAfterMidSession = await this._isHeadAfterMidSession(lastHeader)
let isHeartbeatExpected = await this._isHeadAfterHeartbeatBlockThreshold(lastHeader)
await asyncForEach(this.validators, async (account) => {
if( isHeadAfterMidSession && ! await this._hasValidatorAuthoredBlocks(account) && ! await this._hasValidatorSentHeartbeat(account) ){
if( isHeartbeatExpected && ! await this._hasValidatorAuthoredBlocks(account) && ! await this._hasValidatorSentHeartbeat(account) ){
this.logger.info(`Target ${account.name} has either not authored any block or sent any heartbeat yet`);
this.promClient.setStateValidatorOfflineSessionReports(account.name)
}
Expand All @@ -211,7 +213,7 @@ export class Subscriber {
return this.api.query.imOnline.heartbeatAfter()
}

private async _isHeadAfterMidSession(header: Header) : Promise<boolean> {
private async _isHeadAfterHeartbeatBlockThreshold(header: Header) : Promise<boolean> {
let currentBlock = header.number.toBn()
let blockThreshold = await this._getHeartbeatBlockThreshold()
return currentBlock.cmp(blockThreshold) > 0
Expand All @@ -234,7 +236,6 @@ export class Subscriber {
let validatorIndex = validators.indexOf(validator.address)

let hb = await this.api.query.imOnline.receivedHeartbeats(sessionIndex,validatorIndex)

return hb.toHuman() ? true : false
}

Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"target": "es6",
"skipLibCheck": true,
"outDir": "./dist",
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
Expand Down

0 comments on commit 3a93d4f

Please sign in to comment.