Skip to content

Commit

Permalink
fix: abort if different bundle round was returned from api (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed Jan 3, 2024
1 parent 800d4a1 commit ccac962
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion common/protocol/src/methods/main/runNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function runNode(this: Validator): Promise<void> {
continue;
}

// temp save proposal creation time to detect if a new proposal is
// temp save proposal creation time to detect if a different proposal is
// available in the meantime
const updatedAt = parseInt(this.pool.bundle_proposal!.updated_at);

Expand Down
6 changes: 3 additions & 3 deletions common/protocol/src/methods/queries/canPropose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export async function canPropose(
};
}

// abort if a new bundle proposal was found
if (parseInt(this.pool.bundle_proposal!.updated_at) > updatedAt) {
// abort if a different bundle proposal was found
if (parseInt(this.pool.bundle_proposal!.updated_at) !== updatedAt) {
return {
possible: false,
reason: "New bundle proposal was found",
reason: "Different bundle proposal was found",
};
}

Expand Down
6 changes: 3 additions & 3 deletions common/protocol/src/methods/queries/canVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export async function canVote(
};
}

// abort if a new bundle proposal was found
if (parseInt(this.pool.bundle_proposal!.updated_at) > updatedAt) {
// abort if a different bundle proposal was found
if (parseInt(this.pool.bundle_proposal!.updated_at) !== updatedAt) {
return {
possible: false,
reason: "New bundle proposal was found",
reason: "Different bundle proposal was found",
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function waitForCacheContinuation(
this: Validator,
updatedAt: number
): Promise<void> {
// continue if a new proposal is available
// continue if a different proposal is available
while (updatedAt === parseInt(this.pool.bundle_proposal!.updated_at)) {
await sleep(1000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export async function waitForNextBundleProposal(
this.m.bundles_wait_for_next_round_time.startTimer();

// continue if the creation time of the bundle proposal increased
// we have an smaller equal check here, because we only want to continue,
// if we find a NEW bundle proposal
while (parseInt(this.pool.bundle_proposal!.updated_at) <= updatedAt) {
await this.syncPoolState();

Expand Down
4 changes: 2 additions & 2 deletions common/protocol/src/methods/validate/saveBundleDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export async function saveBundleDownload(
.plus(this.pool.data!.upload_interval)
.multipliedBy(1000);

// check if new proposal is available in the meantime
if (parseInt(this.pool.bundle_proposal!.updated_at) > updatedAt) {
// check if different proposal is available in the meantime
if (parseInt(this.pool.bundle_proposal!.updated_at) !== updatedAt) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export async function saveLoadValidationBundle(
.plus(this.pool.data!.upload_interval)
.multipliedBy(1000);

// check if new proposal is available in the meantime
if (parseInt(this.pool.bundle_proposal!.updated_at) > updatedAt) {
// check if different proposal is available in the meantime
if (parseInt(this.pool.bundle_proposal!.updated_at) !== updatedAt) {
return null;
}

Expand Down

0 comments on commit ccac962

Please sign in to comment.