Repository navigation
friglet: remove duplicated Electrum request handling (SNB-665) - #46
Closed
setavenger wants to merge 1 commit into
Closed
setavenger wants to merge 1 commit into
setavenger wants to merge 1 commit into
Conversation
The Electrum server built the same things in several places. One copy of each now: - notification(): the JSON-RPC notification line (was written out four times); sp_subscription(): the SP subscription object and its notification, shared by the push task and the subscribe handler. - invalid_param(): the -32602 answer for a missing or mistyped first parameter (block.header, scripthash.subscribe/get_history, transaction.get); the messages are unchanged. - save_header_sidecar(): the header-sidecar write after a backfill and after a reorg. - Peer::header_by_hash() takes one hash (its only caller passed a one-element slice) and returns only a header with that hash, so the two re-checks of the same hash in ChainSource::header and backfill_header go. - relay: connect_settled() (connect + settle, the 2 s literal is now p2p::SETTLE_WAIT, also used by ChainSource::fee_filter), Candidate::wire_tx() and Signals::announce() replace two or three copies each. - index_unconfirmed_tx: two match arms that both did nothing are one condition. - Two tests build their request with call() like the others. The bytes on the wire are unchanged: a scripted session of 52 requests and 8 push batches gives byte-identical output before and after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 3, 2026
Owner
Author
|
Merged into |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the friglet cleanup (SNB-661). Implements SNB-665. Net −68 lines, no behaviour change.
What was merged and why it was duplicated
notification(). The SP subscription object + history notification was built twice (push task andblockchain.silentpayments.subscribe) →sp_subscription().block.header,scripthash.subscribe,scripthash.get_history,transaction.get) →invalid_param(), same messages.save_header_sidecar(). The two failure messages are kept; the reorg path's "write task failed" log line now also carries thepathfield.Peer::headers_by_hash(&[hash])was only ever called with one hash. It is nowheader_by_hash(hash)and returns only a header whose hash ishash, so the re-checks inChainSource::headerandbackfill_header(both unreachable) are gone.2 sliteral (×3, plus the literal inChainSource::fee_filter) →connect_settled()andp2p::SETTLE_WAIT; wire-tx re-encode ×2 →Candidate::wire_tx(); announce-then-wait ×2 →Signals::announce(). Inbroadcast()the settle moved from the top ofdrive()to just before it: a settle error still returnsErr(it happened before any hand-over, whereClosedwas never a rejection).index_unconfirmed_tx: two match arms that both did nothing → oneany()check.JsonRpcRequestby hand now usecall().Why behaviour is unchanged
Scripted Electrum session (verification only, not committed): 52 requests through
handle_requestplus 8 batches of push lines, written raw to a file, onintegrationa9ff4d6 and on this branch. It covers server.*, fees, unknown method,headers.subscribe(tip with stored header, no tip, header unavailable),block.header(stored, P2P backfill by checkpoint with a FakePeer, unknown block, missing/mistyped/negative/float param),scripthash.subscribe/get_history(known, unknown, missing, mistyped),transaction.get,silentpayments.subscribe/unsubscribeat progress 0.37 and 1.0,broadcast(missing, mistyped, bad hex, short tx, no inputs, no peer, already confirmed, accepted, resent, fee-bump replacement, peer disconnect, missing inputs) and the push lines after each step.(Push lines from a HashMap are sorted within each batch before comparing; two runs on the base were identical too.)
Verification
cargo check --workspace --all-targets --all-features: 0 warningscargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings: cleancargo fmt -p friglet -p friglet-ipc -p friglet-tray -- --check: cleancargo test --workspace: 254 passed, 1 ignored, 0 failed (same as base; 58.8 s)Left out on purpose
jsonrpcrequest field (kept, with itsallow(dead_code)): removing it changes how a malformed request is answered. Today{"jsonrpc":2,...}fails to parse (-32700 Parse error); without the field it would be answered normally.index_unconfirmed_tx(kept): I could not prove it unreachable. It runs when the history holds a txid whose raw tx is not inidx.txs. One candidate path: a resend after an inconclusive wait finds the tx in the peer's mempool after the scanner already indexed it as confirmed (the oracle can be ahead of the peer).accept_pendingthen adds height-0 entries that are never promoted. A later reorg drops the raw txs of the disconnected blocks but keeps height-0 entries.