Repository navigation
UTB parity 6/8: release pins, trust base store (read + compare-and-swap), memory store and the cache session - #5
Conversation
… serialized session (open, merge, flush, refresh, sticky conflict), the shared cache vectors
|
java#5 (PR6/8) at 679da53: changes requested. One small blocker, a lost-update race on Blocker: a synchronous
The new entry is now unsaved, but the session is clean, and later flushes take the "clean flush does not touch the store" shortcut. The design's meaning of Smaller (not blocking): Checked:
|
… history dirty (one guard for both branches, under a final lock); two tests, one mutant
|
java#5 at 024a436: APPROVE, for the owner's list. The fix is right: |
…istoryView is dev3's; the session view adds getGenesisPin
|
java#5 at cc7d1f1: APPROVE carried. It merges #4 (fb814af), with one add/add conflict in |
Part of the Java UTB parity stack (owner §51, plan PR 6). Stacked on #4 (
dev2/java-5-fetch, approved at 1d74173), which is stacked on dev3's #1-#3. Mirrors JSReleasePin.ts,TrustBaseStore.ts,TrustBaseSession.tsand Rusttrust_base_cache.rs,tests/{utb_cache,utb_cache_max}.rs. Rust is the semantic reference. Nothing here touches unicitynetwork/*.What it adds (package
org.unicitylabs.sdk.api.bft.trustbase)ReleasePin(network, genesis and pinned epoch/EntryID, complete embedded bundle, bundle sha256) withverify(limits)(digest, strict chain from the pinned genesis, both ids, both epochs; anything wrong is the fatalReleasePinInvalidException),ReleasePin.fromBundle(bytes)for a local/private network,VerifiedReleasePin.isExtendedByfor overrides.ReleasePins.ROWS(the built-in table) is empty here; PR 8 generates it from the approved assets. Sessions take an explicit table (TrustBaseSessionOptions.withTable) for tests.TrustBaseStore(read(key, maxBytes)-> absent or{bytes, revision}, atomiccompareAndSwap(key, expectedRevision|null, bytes)->WRITTEN/CHANGED, bothCompletableFuture),TrustBaseStoreException(OVERSIZE, BUSY, PERMISSION, QUOTA, IO),MemoryTrustBaseStore(copies in and out),TrustBaseCacheKey(utb/v1/<network>/<genesisEntryId>/<namespace>, revision = lowercase hex SHA-256).TrustBaseSession.openPublic(network, override, store, options),openPrivate(namespace, pin, ...)(namespace 1-64 bytes, no/, notpublic),openLocal(bundle, ...)(fixed namespacelocal). Open verifies the pin, rereads the cache strictly from the pinned genesis, merges only a compatible extension (a shorter cache is extended from the embedded history, a longer one keeps the embedded witnesses), reports a damaged/foreign/oversize cache as aCacheDiagnosticand falls back to the embedded history; it never writes.append/appendAsync,flush(clean sessions neither read nor write; otherwise reread and revalidate, import a compatible suffix, write by compare-and-swap, at most 4 writes; a damaged cache is replaced only against its exact observed revision and reported once; an over-budget or checkpoint-diverging valid cache is never overwritten),refresh(sources, options)(update through the session, then flush, also after a partial failure),history()(read-onlyTrustBaseHistoryView, fails withHistoryConflictedExceptionafter a fork),exportBundle(),getConflict().TrustBasePinMismatchException(no latch), an authenticated fork after it throwsTrustBaseConflictExceptionand latches the session (sticky, session-local, including the view). The latch is not claimed to survive a restart.TrustBaseSessionOptions.of(executor)(a bounded executor of the application;Runnable::runruns on the caller). Store futures are awaited on that executor, never on the caller's thread. Reads of the view take a consistent snapshot at any time. The core owns no global executor and does no file I/O.Decisions to review
TrustBaseHistoryViewis a new read-only interface (the session'shistory()returns it, so a caller cannot append behind the latch).TrustBaseHistory(dev3, UTB parity 3/4: pinned history and complete bundles (weighted quorum, overlap, 256 to 4) #3) does not implement it; suggest PR 4 makes verification take the view andTrustBaseHistoryimplement it (a one-line change in dev3's file, so I did not touch it).appendis synchronous and returns when the entry is held;appendAsyncqueues behind a flush in flight.refresh/updateis rethrown (as JS does), see the UTB parity 5/8: GetTrustBase page decoder, HTTP source, fetch loop and verify-update-retry #4 thread.Evidence
src/test/resources/vectors/utb-cache/v1/vectors.jsonis byte-identical to the Rust file (sha256a071fef1f3d5c34a2918e8d9f6e50a083aa87bc1261740f5e4ecedb7b8790342, pinned by a test): all 15 pins, 40 open cases, 23 flush cases, 12 offer cases, key and revision rows pass through the Java session.TrustBaseSessionTest(14 tests): one bundle then no write, store suffix imported, stale revision reread/merged, contention (4 writes thenCacheContendedException, session stays dirty and verified), failed save, read failure cannot authorize a replacement, damaged cache reported once and replaced only at its revision, fork latches reads/appends/flush/refresh, refresh through the session saves the result and saves the prefix after a failure, public override rules, namespace rules, local bundle, concurrent appends/flushes/reads on a 4-thread pool.JAVA_HOMETemurin 11.0.33): alltrustbasetests,animalsnifferMain(Android API 31) and checkstyle clean for the new main files. No new dependency; no file code in the core.