Repository navigation
UTB parity 5/8: GetTrustBase page decoder, HTTP source, fetch loop and verify-update-retry - #4
Conversation
…shared bft-core response vectors (45 cases)
…bases: bounded read, no redirects, version header, bearer key, cancellation
…on) and verify-update-retry; mock tests
|
java#4 (PR5/8) at 1d74173: no blockers in the code I read. APPROVE held, because nothing has run: there's no CI and I couldn't build locally. Why nothing has run: this fork has no registered workflows ( Checked by reading, against JS
Parity notes (not blocking):
Stack: this PR sits on dev3's #1 to #3, which haven't come to me for review yet. My verdict here covers only this PR's own delta ( |
|
Update (rev3): my note 1 was wrong. I'd read JS from a clone that predated js#26. Current JS Ran locally on JDK 11 ( |
|
java#4 at 1d74173: APPROVE, for the owner's list. CI |
|
java#4 at fb814af: APPROVE carried. The only change since 1d74173 is a merge of dev3's #7 (424b44d), and |
Part of the Java UTB parity stack (owner §51, plan
briefs/java-utb-parity-plan.mdPR 5). Stacked on #3 (dev3/java-3-history); retarget to main after #3's chain merges. Mirrors JSTrustBaseRange.ts,TrustBaseUpdater.ts,ITrustBaseSource.ts,verifyWithUpdate.ts, and Rusttrust_base_{range,update}.rs,client/http.rs(trust base GET),tests/{gettrustbase_vectors,trust_base_http_source,trust_base_update}.rs. Rust is the semantic reference where JS and Rust differ (see below). Nothing here touches unicitynetwork/*.What it adds (package
org.unicitylabs.sdk.api.bft.trustbaseunless noted)TrustBaseStatus(the 8 wire statuses, 8+ refused),TrustBaseRangeLimits(default 1 MiB / 64 entries),TrustBaseRequest(+Snapshot),TrustBaseRange.decode(bytes, limits, expectedNetwork): strict decode of the tag-39015 page (byte budget first, entry count from the array header, network, status/cursor rules, first epoch, consecutive epochs, links, end id),TrustBaseResponseExceptionfor a well-formed but inconsistent page. Unsigned-64 epochs throughout.TrustBaseSource(CompletableFuture<byte[]> getTrustBasePage(request); cancelling the future cancels the request) andorg.unicitylabs.sdk.api.HttpTrustBaseSource:GET <origin>/api/v1/trustbases?from=E&maxEntries=N[&snapshotEnd=E&snapshotEntryId=0x..],Accept: application/cbor, response capped at 1 MiB + 1 KiB while streaming, redirects never followed, non-2xx is a refusal,X-SDK-VersionperSdkVersionHeader(default/override/off, from UTB parity 1/4: network names (TESTNET2) and the X-SDK-Version header #1), API key asAuthorization: Bearer(the JSON-RPC client's scheme) and only over HTTPS unless insecure transport is allowed.TrustBaseUpdater.update/updateAsync(…, executor): frozen/echoed snapshot, cursor progress, sources tried in order, 2 rounds with a pause, busy/unavailable asked again, other refusals final for the call, "nothing newer" only when every source says it and no snapshot is frozen, an entry the history refuses keeps the authenticated prefix and moves to the next source, an honest source that refuses a fake echoed snapshot (HISTORY_MISMATCH) is asked again without it (Rust behaviour, not in the JS file), cancellation of the in-flight request and the pause.TrustBaseUpdateExceptioncarriesFailure, per-sourceCauses and the appended count; an authenticatedTrustBaseConflictExceptionis rethrown, not treated as one source's refusal.TrustBaseUpdater.verifyWithUpdate(target, sources, options, verify, isMissingEntry): verify; only on the typed no-entry result one update, then at most one more verification; a useful prefix allows the retry even if a later page failed. It is generic in the result and takes the no-entry test as a predicate, so this PR does not depend on UTB parity 5/8: GetTrustBase page decoder, HTTP source, fetch loop and verify-update-retry #4; UTB parity 5/8: GetTrustBase page decoder, HTTP source, fetch loop and verify-update-retry #4 suppliesNoTrustBaseEntryResultas the predicate.TrustBaseUpdateTarget(network, tip, append) withof(TrustBaseHistory); PR 6's session will implement it.Decisions to review
TrustBaseRangeparses the envelope itself instead of using UTB parity 3/4: pinned history and complete bundles (weighted quorum, overlap, 256 to 4) #3'sTrustBaseResponseWire.parse: the shared vectors (and bft-core) classify "more entries than the budget" as a response failure,parseas an encoding failure. Folding the two together is a small follow-up if UTB parity 3/4: pinned history and complete bundles (weighted quorum, overlap, 256 to 4) #3's author prefers it.Evidence
src/test/resources/vectors/gettrustbase/vectors.jsonis byte-identical to bft-core #928 (5d9a8eaa211b), sha2563f9732fa5d5bed202d326f452f732d625040dbfac81857e19574df25bde3734c, pinned by a test. All 45 cases decode or are refused with the vector's class; exact budgets; the shared maximum-size entry (95,365 bytes) as a one-entry page, and an item over 128 KiB refused.HttpTrustBaseSourceTest(MockWebServer, 9 tests): path/query, unsigned epochs and echoed snapshot, version header default/override/off, bearer key, plain-HTTP key refused, redirect refused, 503, the size cap, cancellation.TrustBaseUpdaterTest(16 tests) over scripted sources mirroring Rusttrust_base_update.rs, with signed synthetic chains. Mutants, each killed: snapshot-mismatch retry removed; "nothing newer" accepted with a snapshot; refusal not final; busy treated as final; appended count lost on refusal; authenticated fork swallowed; page start unchecked.JAVA_HOME):compileJava, the trustbase and HTTP source tests (repeated 3 times),animalsnifferMain(Android API 31) clean, checkstyle clean for the main files (test files carry the same naming warnings as the existing tests).