Skip to content

Commit

Permalink
Merge branch 'remove-deadlock-job' into 'dev'
Browse files Browse the repository at this point in the history
remove deadlock job

See merge request ergo/rosen-bridge/watcher!324
  • Loading branch information
zargarzadehm committed Jan 25, 2025
2 parents 11c104b + 8c000d1 commit 62118ad
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 84 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-nails-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/watcher': patch
---

Fix commitment redeem job bug
1 change: 0 additions & 1 deletion config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ healthCheck:
duration: 600 # log duration time check (in seconds)
maxAllowedErrorCount: 1 # maximum allowed error log lines
maxAllowedWarnCount: 10 # maximum allowed warn log lines
redeemSwapEnabled: true # if set true when no permit left, system automatically redeem new commitments and commit again for old observations
rewardCollection:
threshold: 100000 # RSN threshold for reward collection
interval: 600 # reward collection interval in seconds
Expand Down
2 changes: 0 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class Config {
minimumFeeUpdateInterval: number;
observationConfirmation: number;
observationValidThreshold: number;
redeemSwapEnabled: boolean;
rosenConfigPath: string;
rosenTokensPath: string;
apiPort: number;
Expand Down Expand Up @@ -220,7 +219,6 @@ class Config {
this.observationValidThreshold = getRequiredNumber(
'observation.validThreshold'
);
this.redeemSwapEnabled = config.get<boolean>('redeemSwapEnabled');
this.tokenNameInterval = getRequiredNumber('ergo.interval.tokenName');
this.revenueInterval = getRequiredNumber('ergo.interval.revenue');
if (this.ergoInterval <= this.revenueInterval) {
Expand Down
3 changes: 0 additions & 3 deletions src/jobs/commitmentRedeem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ const redeemJob = async () => {
await HealthCheckSingleton.getInstance().getErgoScannerSyncHealth();
if (scannerSyncStatus !== HealthStatusLevel.BROKEN) {
await commitmentRedeemObj.job();
if (getConfig().general.redeemSwapEnabled) {
await commitmentRedeemObj.deadlockJob();
}
} else {
logger.info(
'Scanner is not synced with network, skipping commitment redeem job'
Expand Down
78 changes: 0 additions & 78 deletions src/transactions/commitmentRedeem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { TxType } from '../database/entities/txEntity';
import { TransactionUtils, WatcherUtils } from '../utils/watcherUtils';
import { getConfig } from '../config/config';
import { DefaultLoggerFactory } from '@rosen-bridge/abstract-logger';
import { ERGO_CHAIN_NAME } from '../config/constants';

const logger = DefaultLoggerFactory.getInstance().getLogger(import.meta.url);

Expand Down Expand Up @@ -184,81 +183,4 @@ export class CommitmentRedeem {
count: commitments.length,
});
};

/**
* Redeem the last unspent commitment if there is a missed uncommitted observation
*/
deadlockJob = async () => {
const activeTx =
await this.watcherUtils.dataBase.getActiveTransactionsByType([
TxType.REDEEM,
TxType.COMMITMENT,
]);
if (activeTx.length > 0) {
logger.debug('Has unconfirmed commitment or redeem transactions');
return;
}
const tokenMap = getConfig().token.tokenMap;
const rwtPerCommitment = tokenMap.unwrapAmount(
getConfig().rosen.RWTId,
await Transaction.getInstance().getRequiredPermitsCountPerEvent(),
ERGO_CHAIN_NAME
).amount;
const availablePermits =
((await ErgoUtils.getPermitCount(getConfig().rosen.RWTId)) - 1n) /
rwtPerCommitment;
if (availablePermits >= 1) {
logger.debug(
`Still have [${availablePermits}] available permits, aborting last commit redeem job`
);
return;
}
if (!Transaction.watcherWID) {
logger.warn('Watcher WID is not set. Cannot run commitment redeem job.');
return;
}
try {
if (!(await this.watcherUtils.hasMissedObservation())) {
logger.debug('There is no missed observations');
return;
}
const commitment = await this.watcherUtils.lastCommitment();
logger.info(`Redeeming last commitment with boxId [${commitment.boxId}]`);
const WID = Transaction.watcherWID;
const WIDBox = (await this.boxes.getWIDBox(WID))[0];
logger.info(`Using WID Box [${WIDBox.box_id().to_str()}]`);
const requiredValue =
BigInt(getConfig().general.fee) +
BigInt(getConfig().general.minBoxValue) * 2n;
const feeBoxes: wasm.ErgoBox[] = [];
const widBoxValue = BigInt(WIDBox.value().as_i64().to_str());
if (widBoxValue < requiredValue) {
logger.debug(
`Require more than WID box Ergs. Total: [${widBoxValue}], Required: [${requiredValue}]`
);
feeBoxes.push(
...(await this.boxes.getUserPaymentBox(requiredValue, [
WIDBox.box_id().to_str(),
]))
);
logger.debug(
`Using extra fee boxes in commitment redeem tx: [${feeBoxes.map(
(box) => box.box_id().to_str()
)}] with extra erg [${ErgoUtils.getBoxValuesSum(feeBoxes)}]`
);
}
await this.redeemCommitmentTx(
WID,
WIDBox,
decodeSerializedBox(commitment.boxSerialized),
feeBoxes,
requiredValue
);
} catch (e) {
logger.warn(
`Skipping the last commitment redeem due to occurred error: ${e.message} - ${e.stack}`
);
}
logger.info(`Resolve deadlock job is done`);
};
}

0 comments on commit 62118ad

Please sign in to comment.