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

Skip unincentivized past rounds #27

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
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
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
Loading