diff --git a/.changeset/smart-wombats-lie.md b/.changeset/smart-wombats-lie.md new file mode 100644 index 0000000..496948e --- /dev/null +++ b/.changeset/smart-wombats-lie.md @@ -0,0 +1,5 @@ +--- +'@rosen-bridge/watcher': patch +--- + +Fix required commitment count to match with the smart contract computations diff --git a/src/ergo/utils.ts b/src/ergo/utils.ts index 630ce20..4a6607c 100644 --- a/src/ergo/utils.ts +++ b/src/ergo/utils.ts @@ -335,9 +335,8 @@ export class ErgoUtils { const min = BigInt(configs[2]); const percentage = parseInt(configs[1]); const watcherCount = Number(R5.to_i64().to_str()); - const formula = - min + BigInt(Math.ceil((percentage * (watcherCount - 1)) / 100)); - return max < formula ? max : formula; + const formula = min + BigInt(Math.floor((percentage * watcherCount) / 100)); + return (max < formula ? max : formula) + 1n; }; /** diff --git a/src/transactions/commitmentReveal.ts b/src/transactions/commitmentReveal.ts index 3408012..2c29cac 100644 --- a/src/transactions/commitmentReveal.ts +++ b/src/transactions/commitmentReveal.ts @@ -140,11 +140,9 @@ export class CommitmentReveal { repoConfigBox ); logger.info( - `Valid commitments: [${validCommitments.length}/${ - requiredCommitments + 1n - }]` + `Valid commitments: [${validCommitments.length}/${requiredCommitments}]` ); - if (BigInt(validCommitments.length) > requiredCommitments) { + if (BigInt(validCommitments.length) >= requiredCommitments) { const commitmentBoxes = await Promise.all( validCommitments.map(async (commitment) => { return await ErgoNetwork.unspentErgoBoxById(commitment.boxId);