From ccac96240ddd4550d15d0970f7e4ffb33feeb188 Mon Sep 17 00:00:00 2001 From: Troy Kessler <43882936+troykessler@users.noreply.github.com> Date: Wed, 3 Jan 2024 14:20:14 +0100 Subject: [PATCH] fix: abort if different bundle round was returned from api (#113) --- common/protocol/src/methods/main/runNode.ts | 2 +- common/protocol/src/methods/queries/canPropose.ts | 6 +++--- common/protocol/src/methods/queries/canVote.ts | 6 +++--- .../src/methods/timeouts/waitForCacheContinuation.ts | 2 +- .../src/methods/timeouts/waitForNextBundleProposal.ts | 2 ++ common/protocol/src/methods/validate/saveBundleDownload.ts | 4 ++-- .../src/methods/validate/saveLoadValidationBundle.ts | 4 ++-- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/common/protocol/src/methods/main/runNode.ts b/common/protocol/src/methods/main/runNode.ts index 1a214007..3b85718a 100644 --- a/common/protocol/src/methods/main/runNode.ts +++ b/common/protocol/src/methods/main/runNode.ts @@ -44,7 +44,7 @@ export async function runNode(this: Validator): Promise { 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); diff --git a/common/protocol/src/methods/queries/canPropose.ts b/common/protocol/src/methods/queries/canPropose.ts index b69fd9ee..cd4552ba 100644 --- a/common/protocol/src/methods/queries/canPropose.ts +++ b/common/protocol/src/methods/queries/canPropose.ts @@ -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", }; } diff --git a/common/protocol/src/methods/queries/canVote.ts b/common/protocol/src/methods/queries/canVote.ts index 4d5d063e..8a08ded6 100644 --- a/common/protocol/src/methods/queries/canVote.ts +++ b/common/protocol/src/methods/queries/canVote.ts @@ -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", }; } diff --git a/common/protocol/src/methods/timeouts/waitForCacheContinuation.ts b/common/protocol/src/methods/timeouts/waitForCacheContinuation.ts index 035adfcb..12b3e6cd 100644 --- a/common/protocol/src/methods/timeouts/waitForCacheContinuation.ts +++ b/common/protocol/src/methods/timeouts/waitForCacheContinuation.ts @@ -15,7 +15,7 @@ export async function waitForCacheContinuation( this: Validator, updatedAt: number ): Promise { - // 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); } diff --git a/common/protocol/src/methods/timeouts/waitForNextBundleProposal.ts b/common/protocol/src/methods/timeouts/waitForNextBundleProposal.ts index 2a5c5a6e..9c282a43 100644 --- a/common/protocol/src/methods/timeouts/waitForNextBundleProposal.ts +++ b/common/protocol/src/methods/timeouts/waitForNextBundleProposal.ts @@ -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(); diff --git a/common/protocol/src/methods/validate/saveBundleDownload.ts b/common/protocol/src/methods/validate/saveBundleDownload.ts index 4345cc08..5bccc0d2 100644 --- a/common/protocol/src/methods/validate/saveBundleDownload.ts +++ b/common/protocol/src/methods/validate/saveBundleDownload.ts @@ -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; } diff --git a/common/protocol/src/methods/validate/saveLoadValidationBundle.ts b/common/protocol/src/methods/validate/saveLoadValidationBundle.ts index 32440431..38000e11 100644 --- a/common/protocol/src/methods/validate/saveLoadValidationBundle.ts +++ b/common/protocol/src/methods/validate/saveLoadValidationBundle.ts @@ -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; }