feat(provider-b,sdk): automate session reconciliation via Cloudflare cron trigger (#209) - #261
feat(provider-b,sdk): automate session reconciliation via Cloudflare cron trigger (#209)#261Olalolo22 wants to merge 3 commits into
Conversation
|
@Olalolo22 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
The design is right — running reconciliation inside the Durable Object is exactly what #209 asked for, because it serializes against live voucher traffic instead of racing it, and reusing Holding on one thing: The edge worker forwards everything except // worker.ts
const id = env.CHANNEL_SESSION.idFromName(env.CHANNEL_CONTRACT_ID)
return env.CHANNEL_SESSION.get(id).fetch(request)and the DO handles the path before the payment middleware runs: override async fetch(request: Request): Promise<Response> {
const url = new URL(request.url)
if (url.pathname === '/__reconcile' && request.method === 'POST') {
const stats = await this.reconcileSessions()
return Response.json({ status: 'ok', stats })
}
this.app ??= this.buildApp() // routedockHono mounts at '*' below this
return this.app.fetch(request)
}So An unauthenticated public endpoint that initiates on-chain transactions is not something to put in front of a payments provider. Cleanest fix: drop the HTTP surface entirely. // worker.ts scheduled()
const stub = env.CHANNEL_SESSION.get(id)
await stub.reconcileSessions()Then delete the If you would rather keep the HTTP path, it needs both a shared-secret header check and an explicit reject in One smaller note: |
|
Status update — the security point is still open, and the branch now conflicts. 1.
|
Closes #209
What changed
Automated orphaned session recovery by adding a 15-minute Cloudflare cron trigger in
apps/provider-b/wrangler.jsoncand exporting ascheduled()handler inapps/provider-b/src/worker.tsthat forwards triggers directly to theChannelSessionDurable Object. Added areconcileSessions()method and internalPOST /__reconcileendpoint toChannelSessionto query abandonedclosingsessions, settle them viareconcileAbandonedSessionswith the latest signed commitment, and log settlements intotx_log. Re-exportedreconcileAbandonedSessionsandSessionReconcilerOptionsfrom@routedock/routedock/provider/hono.How I verified it
Added unit test suite in
apps/provider-b/src/__tests__/worker.test.ts:scheduled()cron handler forwards executions directly to theChannelSessionDurable Object stub.ChannelSessionhandles internalPOST /__reconcilerequests and returns statusok.pnpm --filter provider-b build.Checklist
node --versionis v22 or newerpnpm --filter @routedock/nulth-sdk build && pnpm --filter @routedock/routedock build) — several packages import its builtdist/pnpm -r typecheckpassespnpm --filter provider-a build/provider-b buildpass if I touched a provider or added a dependency to oneas any,@ts-ignore, or@ts-expect-errorpnpm changeset) if I changed anything underpackages/wrangler.jsoncis committed,.dev.varsis notAnything a maintainer needs to finish
provider-bto Cloudflare so the Cron Trigger activates on live infrastructure.