Skip to content

Commit

Permalink
Merge pull request #27 from noislabs/skip-unincentivized-past-rounds
Browse files Browse the repository at this point in the history
Skip unincentivized past rounds
  • Loading branch information
webmaster128 authored Sep 25, 2023
2 parents aceb54c + 41a595a commit b9afb11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ if (import.meta.main) {
past,
future,
);
submitter.submitPastRounds(past);
submitter.handlePastRoundsWithJobs(past);
};

// Check jobs every 1.5s, shifted 1200ms from the drand receiving
Expand Down
30 changes: 23 additions & 7 deletions submitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SigningCosmWasmClient,
TendermintClient,
} from "./deps.ts";
import { makeAddBeaconMessage } from "./drand_contract.ts";
import { makeAddBeaconMessage, queryIsIncentivized } from "./drand_contract.ts";
import { ibcPacketsSent } from "./ibc.ts";
import { BeaconCache } from "./cache.ts";

Expand Down Expand Up @@ -62,14 +62,30 @@ export class Submitter {
this.submitted = new Set();
}

public async submitPastRounds(rounds: number[]): Promise<void> {
// TODO: Check if incentivised before submistting
await Promise.all(rounds.map((round) => this.submitRound(round)));
/** Handle jobs for which the round should be public */
public async handlePastRoundsWithJobs(rounds: number[]): Promise<void> {
await Promise.all(rounds.map((round) => this.handlePastRoundWithJobs(round)));
}

private async submitRound(round: number): Promise<void> {
const signature = await this.cache.get(round);
await this.submit({ round, signature });
private async handlePastRoundWithJobs(round: number): Promise<void> {
// Query IsIncentovized and get beacon in parallel
const isIncentivizedPromise = queryIsIncentivized(
this.client,
this.drandAddress,
round,
this.botAddress,
).catch(
(_err) => false,
);
const signaturePromise = this.cache.get(round);

if (await isIncentivizedPromise) {
const signature = await signaturePromise;
await this.submit({ round, signature });
} else {
console.log(`Skipping unincentivized past round #${round}.`);
}

return;
}

Expand Down

0 comments on commit b9afb11

Please sign in to comment.