Repository navigation
Speak the @bsv/sdk 4.1.1 overlay wire for lookup and broadcast - #21
Merged
Merged
Conversation
Live SHIP/SLAP hosts run @bsv/sdk 4.1.1 and Overlay Express. Align the lookup, broadcast and advertisement rules with them. Lookup: - Aggregated octet-stream answers give each output Atomic BEEF for its own transaction, with its txid and context. Before, every output got the shared BEEF, so readers saw one transaction for all outpoints. - JSON answers accept beef as a byte array, plus optional context and txid, and ignore unknown keys. - Any 2xx status is success; non-octet-stream bodies parse as JSON. - Output lists win over freeform answers. All hosts failing still throws noSuccessfulResponses. - Per-output context may be up to 1 MiB. Broadcast: - Read camelCase STEAK keys as well as Go's PascalCase. - Send X-Topics comma-separated. - Send off-chain values with x-includes-off-chain-values and a length-prefixed body instead of dropping them. - Send each host only the topics it advertised. - Accept host origins with one trailing slash. Advertisements: - Require the locking key to be the identity's BRC-42 SHIP/SLAP child, and verify the signature under it (new unlinkedLockingKey error). - Apply TS URI, field-size, identity-key and DER rules. - Discovery requires one-satoshi outputs and normalizes advertised origins. - Topic and service names follow the TS grammar. Rulings COMP-053, 058 and 061 record the changes.
Broadcast: - Follow @bsv/sdk SHIPBroadcaster acknowledgment rules. By default some host must acknowledge every topic and other hosts may fail, so one bogus advertisement no longer fails every broadcast. - Report each host's acknowledged topics and failures through broadcastDetailed. An empty STEAK is a failed host. - Hosts past the host limit are left out instead of throwing. - Acknowledgment keys must be https origins. Lookup: - Leave out an output whose transaction cannot be read, as TS does, and report it, with failed hosts, through resolveDetailed. - Make OutputListItem.transaction(beefLimits:) public. - Normalize caller-supplied https hosts so they dedupe with discovered ones. - Skip discovered hosts on loopback, private or reserved addresses by default, matching createPublicNetworkFetch. Advertisement URIs: - Parse IPv4 and IPv6 hosts as WHATWG URL does: reject invalid addresses and write numeric aliases in canonical form. Wire: - Only a missing ancestor falls back to the shared BEEF. - Atomic BEEF keeps Merkle paths in TS order and follows a record's own path only. - Read JSON output lists straight from the bytes, so byte arrays do not balloon through JSONSerialization. - Bound freeform result text. - Read an empty instruction object as no instructions. - Deprecate OverlayHTTPConfiguration.maximumContextByteCount in favor of OverlayLimits.maximumLookupContextByteCount. Tests add the TypeScript 2-BUMP Atomic BEEF vector, WHATWG host and public-address tables from Bun, and the new resolver and broadcaster behavior.
Keep the @bsv/sdk 4.1.1 overlay status and content-type rules alongside main's NetworkLog logging and rejection messages. Add plain-word descriptions for the overlay value, advertisement and policy errors, and log hosts and outputs the resolver and broadcaster leave out.
SLAP discovery threw limitExceeded once trackers listed more hosts than the limit, so a flood of one-satoshi advertisements could stop every lookup for a service. Keep caller hosts and fill the rest of the limit in tracker order, as LookupHostQueue does in @bsv/sdk 4.1.1, and log how many hosts were left out by the resolver and the broadcaster.
Each distinct transaction in an aggregated answer gets its own Atomic BEEF, and for a chain of unproven transactions those grow with the chain, so a 1 MB answer could build hundreds of megabytes before the answer limit was checked. Count generated and extracted bytes as they are built and stop at the answer limit, as extractAtomicOutputs does in @bsv/sdk 4.1.1, and hash each record once instead of once per output. Log the BEEF error before it is mapped to an overlay error.
Lookup discovery now gives each SLAP tracker an equal share of the host limit and takes hosts from the trackers in turn, as @bsv/sdk 4.1.1 does, so one tracker or one flood of advertisements cannot fill every place. The broadcaster keeps places for hosts named in acknowledgment requirements, and a named host that discovery did not return fails its requirement. LookupResolution and OverlayBroadcastReport count skipped hosts, and failed trackers are logged and reported. Refuse discovered domains with empty labels or only digits and dots, log hosts as scheme, host and port only, log why an advertisement or BEEF could not be used, treat an empty STEAK instruction object as a failed host, and report an oversized JSON answer as a resource limit. Document that discovered domains are not resolved before use.
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.
Before: Swift overlay lookup and broadcast (BRC-22/24) differed from @bsv/sdk 4.1.1 in STEAK keys, aggregated Atomic BEEF, SHIP/SLAP admin token checks, headers and off-chain values, so TS overlay services and Swift clients could not fully talk. One failing or bogus host also made a whole broadcast fail.
After: lookup and broadcast match TS 4.1.1 on the wire, host discovery and acknowledgment follow TS rules, and hostile hosts can't exhaust memory or crowd out honest hosts.
How: codecs and resolver/broadcaster logic follow the TS source (LookupResolver, SHIPBroadcaster, LookupHostQueue, createPublicNetworkFetch), with TS vectors in the tests. Details in COMP-053, COMP-058 and COMP-061.
Behaviour changes
toBinaryAtomic(BUMP order can still differ when a child precedes its parents; both are valid).X-Topicsand off-chain values follow TS; any 2xx passes and anything not octet-stream is read as JSON.acknowledgmentByHostkeep their places.broadcastDetailedreturns anOverlayBroadcastReportper host.resolveDetailedreturnsLookupResolutionwith host failures, tracker failures, rejected outputs and skipped host count.OverlayDiscoveredHostPolicy,.anyHTTPSOriginturns it off). Hosts are parsed like WHATWG URL (checked against Node 22 on 21,147 URIs). A domain that resolves to a private address is not checked (documented in COMP-061).OutputListItem.transaction(beefLimits:),LookupResolution,OverlayHostFailure,LookupOutputRejection,OverlayDiscoveredHostPolicy,broadcastDetailed,OverlayBroadcastReport; new caseOverlayPolicyError.invalidSteak;OverlayHTTPConfiguration.maximumContextByteCountdeprecated.OverlayLogandNetworkLog(hosts logged as scheme/host/port only); errors have plain-word descriptions.Testing
swift testin swift:6.1 (Linux) after merging main: 968 tests passed, XCTest 155 passed, 0 failures; only live and opt-in tests skipped. Reviewed against TS 4.1.1 in three rounds with probes (memory, URI parsing, malformed JSON).