From 35df18174ab61c6d4a72bf8f1157584adb14bc4f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 15 Jun 2026 13:01:41 -0700 Subject: Push broadcast txs directly to public explorers After broadcasting an on-chain send via bitcoind, also POST the raw tx to mempool.space and blockstream (fire-and-forget, non-blocking) so those explorers see it immediately instead of waiting ~8s for p2p propagation. Skipped on regtest/testnet. Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/payments.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib') diff --git a/lib/payments.ts b/lib/payments.ts index 30403b6c..489b78d3 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -49,6 +49,21 @@ import { PaymentType } from "$lib/types"; const bc = rpc(config.bitcoin); const lq = rpc(config.liquid); +// Fire-and-forget: push a freshly-broadcast tx straight to public explorers so +// they see it immediately instead of waiting for it to propagate to their node +// over the p2p network (measured ~8s otherwise). Never throws; never blocks. +const broadcastToExplorers = (hex: string) => { + const net = config.bitcoin?.network; + if (net === "regtest" || net === "testnet") return; // public explorers are mainnet + for (const base of ["https://mempool.space/api", "https://blockstream.info/api"]) { + fetch(`${base}/tx`, { + method: "POST", + body: hex, + headers: { "Content-Type": "text/plain" }, + }).catch(() => {}); + } +}; + // Throttled warn — emit at most once per WARN_THROTTLE_MS per (key, message) pair // so a downed external service (lq, bc, etc.) doesn't flood the log every loop tick. const WARN_THROTTLE_MS = 5 * 60 * 1000; @@ -591,6 +606,7 @@ export const sendOnchain = async (params) => { await s(`payment:${p.id}`, p); await node.sendRawTransaction(hex); + broadcastToExplorers(hex); delete inflight[txid]; return p; -- cgit v1.2.3