Skip to content

Commit

Permalink
Merge pull request #331 from rsksmart/TBRE-533-federation-throws-a-em…
Browse files Browse the repository at this point in the history
…it-heartbeat-error-and-stops-if-not-part-of-the-federation

Give a warning when addres is not part of the fed
  • Loading branch information
pmprete authored Mar 25, 2022
2 parents dd45378 + ea3d56b commit 06aa85e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion federator/src/lib/Federator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,18 @@ export default abstract class Federator {
this.resetRetries();
const sideChainWeb3 = this.getWeb3(sideChainConfig.host);
const transactionSender = new TransactionSender(sideChainWeb3, this.logger, this.config);
const federationFactory = new FederationFactory();
const fedContract = await federationFactory.createInstance(sideChainConfig, this.config.privateKey);
const from = await transactionSender.getAddress(this.config.privateKey);
const isMember = await fedContract.isMember(from);
if (!isMember) {
this.logger.warn(`This Federator addr:${from} is not part of the federation. Skipping to next scheduled poll.`)
return false;
}
this.logger.upsertContext('Retrie', this.getCurrentRetrie());
try {
while (this.numberOfRetries > 0) {
const bridgeFactory = new BridgeFactory();
const federationFactory = new FederationFactory();
const success: boolean = await this.run({
sideChainConfig,
sideChainWeb3,
Expand Down
3 changes: 2 additions & 1 deletion federator/src/lib/Heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ export class Heartbeat {
const from = await this.transactionSender.getAddress(this.config.privateKey);
const isMember = await fedContract.isMember(from);
if (!isMember) {
throw new Error(`This Federator addr:${from} is not part of the federation`);
this.logger.warn(`This Federator addr:${from} is not part of the federation`)
return false;
}

this.logger.info(`emitHeartbeat(${fedVersion}, ${fedChainsIds}, ${fedChainsBlocks}, ${fedChainInfo})`);
Expand Down
5 changes: 4 additions & 1 deletion federator/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ export class Main {
this.heartBeatScheduler = new Scheduler(heartBeatPollingInterval, this.logger, {
run: async () => {
try {
await this.heartbeat.run();
const result = await this.heartbeat.run();
if (!result) {
this.logger.warn("Heartbeat run run was not successful.")
}
} catch (err) {
this.logger.error('Unhandled Error on runHeartbeat()', err);
process.exit(1);
Expand Down

0 comments on commit 06aa85e

Please sign in to comment.