Skip to content

Commit

Permalink
Merge branch 'bugfix/required-commitment-count' into 'dev'
Browse files Browse the repository at this point in the history
Fix required commitment count to match with the formula

See merge request ergo/rosen-bridge/watcher!321
  • Loading branch information
vorujack committed Dec 25, 2024
2 parents 9d71ff5 + ac9e5b7 commit 62f4a00
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-wombats-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/watcher': patch
---

Fix required commitment count to match with the smart contract computations
5 changes: 2 additions & 3 deletions src/ergo/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down
6 changes: 2 additions & 4 deletions src/transactions/commitmentReveal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 62f4a00

Please sign in to comment.