diff --git a/.changeset/slimy-nails-hope.md b/.changeset/slimy-nails-hope.md new file mode 100644 index 0000000..16e54bd --- /dev/null +++ b/.changeset/slimy-nails-hope.md @@ -0,0 +1,5 @@ +--- +'@rosen-bridge/watcher': patch +--- + +Fix commitment redeem job bug diff --git a/config/default.yaml b/config/default.yaml index 2216e87..fe35c47 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -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 diff --git a/src/config/config.ts b/src/config/config.ts index e3bcacb..7cda738 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -109,7 +109,6 @@ class Config { minimumFeeUpdateInterval: number; observationConfirmation: number; observationValidThreshold: number; - redeemSwapEnabled: boolean; rosenConfigPath: string; rosenTokensPath: string; apiPort: number; @@ -220,7 +219,6 @@ class Config { this.observationValidThreshold = getRequiredNumber( 'observation.validThreshold' ); - this.redeemSwapEnabled = config.get('redeemSwapEnabled'); this.tokenNameInterval = getRequiredNumber('ergo.interval.tokenName'); this.revenueInterval = getRequiredNumber('ergo.interval.revenue'); if (this.ergoInterval <= this.revenueInterval) { diff --git a/src/jobs/commitmentRedeem.ts b/src/jobs/commitmentRedeem.ts index 16b42fd..0fe53c2 100644 --- a/src/jobs/commitmentRedeem.ts +++ b/src/jobs/commitmentRedeem.ts @@ -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' diff --git a/src/transactions/commitmentRedeem.ts b/src/transactions/commitmentRedeem.ts index 8f1a9ab..8264180 100644 --- a/src/transactions/commitmentRedeem.ts +++ b/src/transactions/commitmentRedeem.ts @@ -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); @@ -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`); - }; }