Skip to content

Split 1sat-stack into a mode-selecting binary - #10

Open
shruggr wants to merge 35 commits into
masterfrom
microservice-split
Open

shruggr wants to merge 35 commits into
masterfrom
microservice-split

Conversation

@shruggr

@shruggr shruggr commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Restructures 1sat-stack from a single monolithic server into one binary that runs any subset of its services, selected by a mode config field. mode: all (the default) is the existing monolith and is verified behaviorally equivalent to master at every milestone.

Milestones

  • M1 — pkg/node. Wiring moved out of cmd/server into an importable pkg/node; cmd/server is now a thin caller. Adds mode selection: all, or a comma list like index,opns. mode: all runs whatever is enabled (existing flags unchanged); an explicit list implies enablement.
  • M2 — Queue interface. The q:* sorted-set queues move behind a queue.Queue interface (same keys, no data migration). A queue can point at a store backend independent of the service's data store.
  • M3 — event-driven lifecycle. Overlay modes construct no txo/indexer/auditor; the overlay engine adapter's ingest stays unwired, so ingestion runs through the broadcast→arc path in every mode (mode: all matches master). The pending auditor gains a rollback-event publish (see intentional/deferred below).
  • M4 — remote providers. spends gains an HTTP tier against the index /txo spend routes; bsv21 drops its pkg/indexer and pkg/owner imports and takes injected owner-sync/balance interfaces, with an HTTP mode so a standalone bsv21 process can resolve fee balances from a remote index.
  • M5 — gateway + per-service admin. A gateway proxy mode fronts a multi-process deployment on the existing /1sat/* surface with a merged /1sat/capabilities. Admin's cross-service routes move to the services that own them (admin keeps no cross-service handles). Auth guards and public paths are unchanged.

Verification

  • go test ./... green; gofmt/vet clean.
  • mode: all /1sat/capabilities diff vs a master baseline is empty at every milestone.
  • Three-process smoke (gateway → separate index + opns processes) routes by prefix and merges capabilities; standalone bsv21 resolves balances from a remote index over HTTP.

Intentional / deferred (not defects)

  • The pending auditor's stale-rollback branch is intentionally dormant — an early return keeps it disabled; documented in pending_auditor.go. Enabling automatic rollback of stale unconfirmed txs is a separate decision, not part of this change.
  • Gateway routing for /chaintracks (substrate, not a mode) and /sweep (a UI) is topology-dependent and belongs to the configurator; the current route table covers the clean service modes.
  • The configurator (compose generation) is out of scope for this branch.
  • M4 remote-path hardening (owner-sync idle timeout; spends batch fan-out) is deferred; it affects only the not-yet-deployed remote path.

Per-milestone detail and the decisions behind the split are in docs/plans/microservice-split.md, microservice-split-implementation.md, and the execution log microservice-split-progress.md.

shruggr added 30 commits July 22, 2026 01:15
The call-time IngestTx closure would fire general indexing on overlay
submissions, a path master's init ordering left dormant. Defer wiring this
feedback loop to Milestone 3 (microservice-split.md decision 9) so this
milestone stays behavior-preserving.
Adds an HTTP tier to the spends resolution chain that queries a remote
index service's txo spend endpoints (GET /:outpoint/spend, POST /spends).
Read-only: PutSpend/DeleteSpend are no-ops. Configurable via the spends
chain with provider "http" and http.url, so a chain like [lru, http,
junglebus] is expressible without in-process co-location with the index.
bsv21 no longer imports pkg/indexer or pkg/owner. NewTokenManager and
NewSyncServices take an OwnerSyncer and a new BalanceLookup func; the
embedded owner.NewOwnerSync + outputStore.SearchBalance construction moves
into pkg/node wiring. A new HTTPOwnerClient (pkg/bsv21/ownerclient.go) hits
the index owner routes (GET /sync, GET /:owner/balance) for remote mode.

Config bsv21.owner.mode (embedded|remote, default embedded) + bsv21.owner.url.
Embedded requires the index service in-process; node returns a clear startup
error otherwise. bsv21 routes and token metadata now tolerate a nil txo store,
so a standalone mode:bsv21 process can serve its API with remote owner.
Spends and bsv21 owner/balance can now resolve against a remote index
service, so neither requires in-process co-location with the index.

GATE results:
- go test ./... green; go vet clean.
- mode:all capabilities parity vs baseline: empty diff (identical set
  ["admin","beef","chaintracks","ordfs","pubsub","sweep","txo"]).
- grep -rn "pkg/indexer|pkg/owner" pkg/bsv21/ : empty.

Two-process bsv21-remote smoke (mode:index on :18081, mode:bsv21 on :18082
with bsv21.owner.mode=remote -> :18081/1sat/owner):
- index A capabilities: ["admin","chaintracks","owner","pubsub","sweep","txo"]
- bsv21 B booted standalone, log: "bsv21 owner resolution: remote"
  url=http://localhost:18081/1sat/owner
- bsv21 B capabilities: ["admin","bsv21","chaintracks","overlay","pubsub","sweep"]
  (no txo/owner — isolated)
- B /1sat/txo/../spend and /1sat/owner/../balance -> 404 (routes absent)
- A /1sat/owner/1BitcoinEater.../balance -> {"balance":0,"count":0}
  (exact shape B's HTTPOwnerClient fetches/decodes; encodings covered by
  ownerclient_test against route-faithful mimics)

Note: a fresh standalone bsv21 process holds no ingested token, so the
manager makes no balance call on boot and GET /1sat/bsv21/<token> is 404;
displaying a non-zero credit end-to-end needs chain-synced token data,
beyond a boot smoke. The credits-over-HTTP fetch/decode path is proven by
ownerclient_test + the live index balance endpoint above.
Add a gateway service (pkg/gateway) that fronts a multi-process deployment
with today's public /1sat/* surface via fiber's proxy middleware. The
path->service map mirrors the prefixes node.RegisterRoutes mounts. GET
/1sat/capabilities fans out to each configured backend's capabilities
endpoint (5s per-backend timeout), unions/sorts/dedupes, and omits
unreachable backends.

Wire into pkg/node: gateway.Config (backends map), runsService("gateway")
mounts the proxy instead of local service routes and short-circuits the
service substrate; combining gateway with other modes in one process is a
startup error. mode:all never runs the gateway, so its capability surface
is unchanged (parity verified against baseline).
Admin becomes the control-plane frontend (setup wizard, config CRUD, auth
admin, log viewer, restart). Cross-service admin handlers move to the
services that own their data, mounted by pkg/node at the same public
/admin/api/* paths the UI already calls, so mode:all is unchanged.

Moves:
- store data browser (admin/data_routes.go) -> pkg/txo/admin_routes.go
- bsv21 whitelist/blacklist + token workers    -> pkg/bsv21/admin_routes.go
- opns genesis crawl trigger                    -> pkg/opns/admin_routes.go
- active topics/lookups + topic remotes         -> pkg/overlay/admin_routes.go

admin.InitializeDeps drops Overlay, Engines, Store, BSV21Sync, and
TriggerOpnsCrawl; it now holds only ConfigStore, RequestRestart, LogStore.
The crawl trigger moves to node's opns wiring (svc.OpnsCrawlTrigger). The
per-service groups mount whenever the admin control-plane runs, with
nil-safe deps, so endpoints degrade exactly as the old unconditional admin
surface did (empty lists, 503, or 500) when a service is not in-process.

Admin API paths the UI calls (admin/ui/src/api.ts + sections), all verified
working in mode:all:
  kept in admin/: /admin/setup/{status,,request,check,complete,config},
    /admin/api/{config,progress,progress/:id,users,users/:pubkey,
    requests,requests/:pubkey/approve,requests/:pubkey,restart,logs,
    logs/components}
  moved (same paths): /admin/api/{whitelist,whitelist/:token,blacklist,
    blacklist/:token,bsv21/workers,topics/active,lookups/active,
    topics/:name/remotes,opns/crawl}, and the data browser under
    /admin/api/data/*
Note: ZSetLookup calls /admin/api/zset/:val, which matches no route today
(data browser is /admin/api/data/zset/...) — a pre-existing UI mismatch,
unchanged here.

Deviation from the 4-field brief: also dropped the Overlay handle from
admin (moved topic-remotes to pkg/overlay) so admin holds zero
cross-service handles per requirement R10.
shruggr added 5 commits July 22, 2026 13:25
M1-M5 implemented and gate-verified on branch. mode:all parity holds
(capabilities diff empty); three-process index/opns/gateway smoke passes;
admin UI endpoints verified at unchanged paths. STATUS.md and the plan's
requirements checklist (R1-R10) updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant