Skip to content

fix: abort v17 pre-submit recheck on RPC error instead of proceeding with stale data - #353

Open
Ayomisco wants to merge 1 commit into
dcccrypto:mainfrom
Ayomisco:fix/keeper-7-liquidate-silent-catch
Open

fix: abort v17 pre-submit recheck on RPC error instead of proceeding with stale data#353
Ayomisco wants to merge 1 commit into
dcccrypto:mainfrom
Ayomisco:fix/keeper-7-liquidate-silent-catch

Conversation

@Ayomisco

@Ayomisco Ayomisco commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Closes #352

What

Replace the bare catch {} at liquidation.ts:1244 with a named catch that logs a warning and returns null.

Why

The bare catch silently swallows RPC errors thrown during the pre-submit portfolio recheck. The oracle drift guard (lines 1171-1187) lives inside that try block. When the catch fires and execution falls through, the drift guard is bypassed and the keeper submits the liquidation using scan-time closeQ and scanPriceE6, regardless of how much the oracle has moved since scan.

The on-chain program may still reject if the position is already closed, but it cannot enforce the keeper-side drift budget. Returning null puts the position back in the scan queue for the next cycle so the drift guard runs on fresh data.

Change

// before
} catch {
  // ...proceed cautiously
}

// after
} catch (recheckErr) {
  logger.warn("v17 liquidate: pre-submit recheck threw -- aborting to avoid stale submission", {
    portfolio: v17PortfolioPubkey.toBase58().slice(0, 8),
    slabAddress: slabAddress.toBase58().slice(0, 8),
    error: recheckErr instanceof Error ? recheckErr.message : String(recheckErr),
  });
  return null;
}

…with stale data

The catch block at liquidation.ts:1244 was bare — any RPC failure during the
pre-submit portfolio recheck (getAccountInfo, fetchSlabWithRetry, getSlot) would
silently swallow the error and fall through to submitting the liquidation with
scan-time data. The oracle drift guard (checking freshPrice vs scanPriceE6) lives
inside this try block, so it was also bypassed on failure, allowing a stale-price
liquidation when the oracle had moved more than MAX_LIQUIDATION_DRIFT_BPS between
scan and submit.

Fail closed: log a warn and return null so the position is re-scanned next cycle.
The on-chain program check that was cited as the safety net does not apply here
because the drift guard must run before the send, not after.
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

LiquidationService.liquidate() now aborts v17 liquidation submission when the pre-submit recheck throws, after logging the portfolio, slab, and error details.

Changes

v17 liquidation recheck failure handling

Layer / File(s) Summary
Abort on recheck error
src/services/liquidation.ts
The v17 pre-submit recheck catch block now logs the thrown error with portfolio and slab identifiers, then returns null to stop liquidation submission.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A rabbit saw the recheck sigh,
And bounded up to catch it nigh.
No stale-price hops shall pass this way,
Just log, लौट? no—return and stay.
🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: failing closed on v17 pre-submit RPC recheck errors to avoid stale-data liquidation.
Linked Issues check ✅ Passed The change matches #352 by logging the recheck error and aborting submission so the oracle drift guard is not bypassed.
Out of Scope Changes check ✅ Passed The PR stays scoped to the v17 liquidation recheck behavior in liquidation.ts and introduces no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CRITICAL] liquidation.ts: silent catch{} in v17 pre-submit recheck bypasses oracle drift guard on RPC failure

1 participant