Skip to content

fix: fund identities through DAPI Core, with Insight only as a fallback - #53

Merged
PastaPastaPasta merged 7 commits into
masterfrom
fix/dapi-core-funding
Sep 27, 2026
Merged

PastaPastaPasta merged 7 commits into
masterfrom
fix/dapi-core-funding

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

Why

Since 2026-09-27 05:49Z, devnet moutai's Insight explorer (insight.moutai.networks.dash.org) has answered every request with 503 Back-end server is at capacity. Identity funding depended on that one server in all three places:

  • tools/mint-identity fund-from-key;
  • dg auth new;
  • in-browser identity creation.

So every mint stopped, and nine QA streams were stuck in retry loops. A single explorer is also a poor fit for a forge meant to have no server to trust.

The evonodes already serve Core over DAPI (dapi-grpc core.proto: broadcastTransaction, getTransaction, getBlockchainStatus, getBestBlockHeight, subscribeToTransactionsWithProofs). This PR makes those the primary path and leaves Insight as an optional fallback. Every RPC used is in core.proto at the pinned v4.2.0-beta.4 tag, and rs-dapi serves it.

What changes

dg auth new (crates/forge-core/src/funding.rs, platform/core_chain.rs, crates/dg/src/auth/new.rs)

  • New SDK-free CoreChain / CoreTxFeed traits, implemented on PlatformClient through the SDK's DAPI client.
  • Deposit detection: a subscribeToTransactionsWithProofs feed with a BIP37 filter on the deposit address (BLOOM_UPDATE_ALL, sized for 50 elements so matched outpoints do not saturate it). It replays from the Core height recorded in the journal before the address is shown, less 6 blocks for node lag, then follows the mempool and new blocks.
    • DepositTracker builds the unspent outputs from raw transactions whose txid it computes itself.
    • Reconnects resume past the blocks already replayed.
    • A journal from before this change rewinds from its start time, capped at about a week.
  • Broadcast and height: broadcast goes through DAPI first, and the asset lock's height comes from getTransaction.
  • Explorer fallback: Insight is asked only when the feed is idle or DAPI fails.
  • --restart: the funds check treats a DAPI-only zero as unknown, because history mode leaves out the mempool.

Web (forge-web/lib/auth/dapi-core.ts, asset-lock.ts, create-identity.ts)

  • The browser talks gRPC-web to the evonodes directly. Their gateway allows cross-origin x-grpc-web, and evo-sdk exposes no Core client.
  • dapi-core.ts adds:
    • hand-framed unary calls;
    • a streaming subscribeToTransactionsWithProofs reader;
    • murmur3 and the BIP37 filter, checked against the rust-dashcore reference vectors.
  • Deposit and broadcast: the deposit is watched on the DAPI feed, and broadcast and height go DAPI first.
  • Explorer fallback: Insight is asked only when DAPI cannot answer.
  • Journal: the IndexedDB journal records startHeight.
  • Copy: the text under the QR and the Settings label now say the explorer is a fallback.

tools/mint-identity

  • Explorer fallback: broadcast, tx status and raw transactions try Insight first and fall back to DAPI Core on a 5xx, 429 or timeout. After that, Insight is skipped for 5 minutes.
  • Funding UTXO ledger: Core has no address index, so fund-from-key keeps a ledger next to the key file.
    • The ledger is 0600 and holds no keys.
    • A token and heartbeat lock serialises parallel mints, so they chain change outputs instead of racing.
    • Seed it once with FORGE_FUNDING_BOOTSTRAP_TXIDS.
    • This follows the approach of the QA stream S1 DAPI-backed Insight shim (a set of known transactions), made concurrency-safe.
  • Deposits: a deposit is found from the outpoint the tool paid.
  • Every input value is re-read from raw transaction bytes that hash to its txid. An under-reporting explorer or node therefore cannot turn a deposit into miner fees.
  • Ambiguous broadcast failures: a failure such as a timeout or a lost response re-sends the same signed bytes. Inputs switch only after a node rejects the transaction outright, so a recipient is never paid twice.
  • CI: a new mint-identity job, because nothing ran these tests before.

Tests (fail before, pass after)

  • crates/forge-core funding::tests::insight_503_*: a local server answers every Insight request with 503.
    • The deposit is seen, broadcast and mined through DAPI, with no explorer request.
    • With no deposit, the watch times out cleanly, and a DAPI-only zero is "unknown".
    • On master, the same 503 server makes the deposit watch fail. This was checked by porting the test to a master checkout.
  • tools/mint-identity/test/dapi-fallback.test.mjs:
    • Insight 503 → fund-from-key broadcasts via DAPI and spends the ledger.
    • Three parallel fundings chain their change with no double spend.
    • An explorer that under-reports a value is refused.
    • A node returning bytes for another tx is refused.
    • An ambiguous failure re-sends the same bytes.
    • The lock keeps a live holder, breaks a dead one, and releases only its own lock.
    • The grpc-web framing works.
  • forge-web/lib/auth/dapi-core.test.ts:
    • grpc-web framing, including split chunks;
    • murmur3 reference vectors;
    • filter sizing;
    • Insight 503 → the deposit is seen on the feed, and broadcast and height go via DAPI;
    • where the watch starts;
    • a DAPI-only zero is not "empty".
  • Local runs: cargo test -p forge-core -p dg and cargo clippy -D warnings pass; pnpm test gives 950 passed; typecheck and lint are clean; npm test in mint-identity gives 23 passed.

Live verification on moutai, with Insight returning 503 throughout

  • qa mint harness dapi-test 1, using this branch's mint-identity with no shim: identity 6cfpN7yze1fdcKzG5eU11vtUUHo8R8jbZJ7xUeeWk4qY. Funding tx 0d9919e8…, asset lock 027b62f3…, chain proof at 88861.
  • dg auth new --json: identity EPZW3kHi5m3DMRCY1kHJeeZGLKUcxwVWeoLZcMXhWTe5. Deposit seen on the DAPI bloom feed, asset lock e337224d…, chain proof.
  • Web, Playwright e2e/v2-auth.spec.ts a2 ("create an identity in the browser"): passed in 3.5 min, identity Gn9Cgzx4kxaV….
  • After the review fixes, a mint and dg auth new ran at the same time from the shared ledger. Each spent its own chained change output (84262710… and 3e8de4be…).

Notes

  • --funding manual in mint-identity still needs Insight to notice a payment nobody told it about. DAPI has no address index, and the tool has no feed.
  • mint-identity behaves as before on testnet (TESTNET has no DAPI list, so it stays Insight-only). dg and the web watch through DAPI on every network: dg uses the nodes its SDK client is connected to, and the web uses the deployment file's dapiAddresses. InstantSend proofs on testnet are unchanged.

🤖 Generated with Claude Code

PastaPastaPasta and others added 7 commits September 27, 2026 02:35
Broadcast, tx status and raw transactions now go to Insight first and fall back to DAPI Core over gRPC-web (broadcastTransaction, getTransaction) on a 5xx, 429 or timeout. Core has no address index, so fund-from-key keeps a funding UTXO ledger next to the key file, serialised by a lock file so parallel mints chain change outputs, and deposits are found from the outpoint this tool paid. Same approach as the QA harness's DAPI-backed Insight shim, made concurrency-safe.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
dg auth new now sees the deposit on a bloom-filtered subscribeToTransactionsWithProofs feed of the address, replayed from the Core height recorded when the creation started, and reads the asset lock's height with getTransaction. Insight is only asked when the feed is idle or unavailable. Values still come from raw transactions whose txid is computed locally.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The browser talks gRPC-web to the evonodes' Core service directly: a bloom-filtered transaction feed watches the deposit address, broadcastTransaction sends the asset lock and getTransaction reads its height. Insight becomes an optional fallback asked when DAPI cannot answer.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… never pay twice

Values come from raw transactions that hash to the expected txid (DAPI's and Insight's alike), so an under-reporting source cannot turn a deposit into fees. The ledger lock carries a token and a heartbeat and is broken only when its holder is gone, by renaming it aside; release frees only our own lock. An ambiguous broadcast failure re-sends the same signed bytes and switches inputs only after an explicit rejection. CI now runs the mint-identity tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Size the BLOOM_UPDATE_ALL filter for 50 elements so matched outpoints do not saturate it. Record the start height when the journal is created, before the address is shown, and start a few blocks earlier for node lag. Cap an unknown-start rewind at about a week and resume a reconnect past the blocks already replayed. A DAPI-only zero before --restart counts as unknown, since its history leaves out the mempool.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Same fixes as the CLI: a 50-element filter, the start height recorded only when this call created the journal (less a margin), a capped rewind, a timeout on the discard check, a DAPI-only zero treated as unknown, and no unobserved rejection from an in-flight read.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 9b55033c-6101-4d61-a4d8-6c782c7222e9

📥 Commits

Reviewing files that changed from the base of the PR and between aa49f24 and 7e2db9a.

📒 Files selected for processing (27)
  • .github/workflows/ci.yml
  • crates/dg/src/auth/new.rs
  • crates/forge-core/src/funding.rs
  • crates/forge-core/src/platform/core_chain.rs
  • crates/forge-core/src/platform/mod.rs
  • docs/design/ux-dx-spec.md
  • docs/guides/identity-and-keys.md
  • forge-web/components/auth/create-identity-flow.tsx
  • forge-web/components/keys-panel.tsx
  • forge-web/e2e/v2-auth.spec.ts
  • forge-web/lib/auth/asset-lock.ts
  • forge-web/lib/auth/auth-v2.test.ts
  • forge-web/lib/auth/create-identity.ts
  • forge-web/lib/auth/dapi-core.test.ts
  • forge-web/lib/auth/dapi-core.ts
  • tools/mint-identity/README.md
  • tools/mint-identity/mint.mjs
  • tools/mint-identity/src/chain.mjs
  • tools/mint-identity/src/dapi-core.mjs
  • tools/mint-identity/src/deposit.mjs
  • tools/mint-identity/src/flow.mjs
  • tools/mint-identity/src/funding.mjs
  • tools/mint-identity/src/insight.mjs
  • tools/mint-identity/src/lock.mjs
  • tools/mint-identity/src/tx.mjs
  • tools/mint-identity/src/utxo-ledger.mjs
  • tools/mint-identity/test/dapi-fallback.test.mjs

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.

@PastaPastaPasta
PastaPastaPasta merged commit e546f82 into master Sep 27, 2026
22 checks passed
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.

1 participant