Skip to content

Commit

Permalink
Trying to broacast pending pegouts
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-then committed Dec 9, 2023
1 parent e5ee454 commit 26bb1a6
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions lib/rsk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ const printFedsLatestBlocks = async (rskTransactionHelpers) => {
console.log('fedLatestBlockNumbers: ', fedLatestBlockNumbers);
};

const waitForPegoutWaitingForSignaturesToBeEmpty = async (rskTransactionHelpers) => {
const rskTxHelper = rskTransactionHelpers[rskTransactionHelpers.length - 1];
const method = async () => {
const currentBridgeState = await getBridgeState(rskTxHelper.getClient());
if(currentBridgeState.pegoutsWaitingForSignatures.length === 0) {
return true; // Returning true to stop the retryWithCheck loop early
}
await wait(1000);
await mineAndSync(rskTransactionHelpers);
return false; // Returning false to make the retryWithCheck loop continue until this check returns true or it reaches the max attempts
};
const wasPegoutBroadcasted = await retryWithCheck(method, pegoutIsBroadcasted => pegoutIsBroadcasted, MAX_ATTEMPTS, CHECK_EVERY_MILLISECONDS);
return wasPegoutBroadcasted;
};

/**
*
* @param {Array<RskTransactionHelper>} rskTransactionHelpers RskTransactionHelper instances each belonging to one federator node to make calls to the rsk network
Expand Down Expand Up @@ -196,18 +211,18 @@ const triggerRelease = async (rskTransactionHelpers, btcClient, callbacks = {})

await printFedsLatestBlocks(rskTransactionHelpers);

const method = async () => {
const currentBridgeState = await getBridgeState(rskTxHelper.getClient());
if(currentBridgeState.pegoutsWaitingForSignatures.length === 0) {
return true; // Returning true to stop the retryWithCheck loop early
}
await wait(1000);
await mineAndSync(rskTransactionHelpers);
return false; // Returning false to make the retryWithCheck loop continue until this check returns true or it reaches the max attempts
};
// const method = async () => {
// const currentBridgeState = await getBridgeState(rskTxHelper.getClient());
// if(currentBridgeState.pegoutsWaitingForSignatures.length === 0) {
// return true; // Returning true to stop the retryWithCheck loop early
// }
// await wait(1000);
// await mineAndSync(rskTransactionHelpers);
// return false; // Returning false to make the retryWithCheck loop continue until this check returns true or it reaches the max attempts
// };


const wasPegoutBroadcasted = await retryWithCheck(method, pegoutIsBroadcasted => pegoutIsBroadcasted, MAX_ATTEMPTS, CHECK_EVERY_MILLISECONDS);
const wasPegoutBroadcasted = await waitForPegoutWaitingForSignaturesToBeEmpty(rskTransactionHelpers);

await printFedsLatestBlocks(rskTransactionHelpers);

Expand Down Expand Up @@ -238,6 +253,10 @@ const triggerRelease = async (rskTransactionHelpers, btcClient, callbacks = {})

await printFedsLatestBlocks(rskTransactionHelpers);

const anyPendingPegoutsWaitingForSignaturesBroadcasted = await waitForPegoutWaitingForSignaturesToBeEmpty(rskTransactionHelpers);

console.log('anyPendingPegoutsWaitingForSignaturesBroadcasted: ', anyPendingPegoutsWaitingForSignaturesBroadcasted);

};

/**
Expand Down

0 comments on commit 26bb1a6

Please sign in to comment.