Skip to main content

Polygon Verification & RBF

Overview

Forge verifies Polygon proofs by checking on-chain transaction status and confirmation depth. Includes operational tooling for Replace-By-Fee (RBF) when transactions are stuck in the mempool, and New Relic observability for long-pending TX.

Verification flow

Status values on #verifyTransaction OTel span (bcyip:transaction.status):

StatusMeaning
pendingTX in mempool, no block yet
confirmingMined, waiting for minConfirmations
confirmedEnough confirmations
droppedTX gone from mempool

Critical guards (1.0.0)

  • blockNumber null check — never call getBlock(null) (was returning latest block → false confirmed)
  • TransactionDroppedError — mempool drop → status: failed, proof file cleanup
  • Pending is not an error#verifyTransaction returns null, no NR error span

RBF replay API

Unsticks a Polygon transaction with insufficient gas by resubmitting with the same nonce and higher fee.

POST /polygon/replay
Authorization: Bearer <HMAC-rotating-token>
Content-Type: application/json

{ "txHash": "0x..." }

Auth: global AuthGuard — Bearer token is SHA-256 of Forge-{SEED}-{ceil(now/10s)} (current or previous 10s window). Same scheme as other Forge admin routes.

Response:

{
"newTxHash": "0x...",
"updatedProofs": 2
}

Server-side flow:

  1. Fetch original TX (nonce, data, gasLimit)
  2. Query Polygon Gas Station for fast max fee
  3. Broadcast replacement TX (same nonce)
  4. Rewrite local proof files (proofs/<uuid>) with new hash
  5. Update MongoDB polygon proofs (type: polygon filter) atomically

New Relic alerting

NRQL for TX pending > 2 hours:

FROM Span SELECT count(*)
WHERE name = '#verifyTransaction'
AND bcyip.transaction.status = 'pending'
SINCE 2 hours ago
FACET bcyip:transaction.hash

Ops: Retool dashboard + manual RBF button calling POST /polygon/replay.

Configuration

Env varRole
POLYGON_RCP_URLJSON-RPC endpoint
POLYGON_PRIVATE_KEYSigning key for anchor/replay
POLYGON_CONTRACT_ADDRESSAnchor contract
POLYGON_MIN_CONFIRMATIONSRequired confirmations
SEEDHMAC auth seed

Key files

  • src/services/polygon/polygon.service.ts — verify, replay, OTel attributes
  • src/app.service.tsreplayPolygon(), verifyPolygon()
  • src/app.controller.tsPOST /polygon/replay
  • src/database/database.service.tsfailProofs(), hash update helpers
  • scripts/check-polygon-pending.mjs — audit script (repo)