@optimystic/db-core 0.13.5 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/cluster/structs.d.ts +13 -0
- package/dist/src/cluster/structs.d.ts.map +1 -1
- package/dist/src/cohort-topic/addressing.d.ts +53 -0
- package/dist/src/cohort-topic/addressing.d.ts.map +1 -0
- package/dist/src/cohort-topic/addressing.js +95 -0
- package/dist/src/cohort-topic/addressing.js.map +1 -0
- package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.d.ts +105 -0
- package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.d.ts.map +1 -0
- package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.js +197 -0
- package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.js.map +1 -0
- package/dist/src/cohort-topic/antidos/bootstrap-evidence.d.ts +50 -0
- package/dist/src/cohort-topic/antidos/bootstrap-evidence.d.ts.map +1 -0
- package/dist/src/cohort-topic/antidos/bootstrap-evidence.js +62 -0
- package/dist/src/cohort-topic/antidos/bootstrap-evidence.js.map +1 -0
- package/dist/src/cohort-topic/antidos/index.d.ts +6 -0
- package/dist/src/cohort-topic/antidos/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/antidos/index.js +6 -0
- package/dist/src/cohort-topic/antidos/index.js.map +1 -0
- package/dist/src/cohort-topic/antidos/rate-limiter.d.ts +95 -0
- package/dist/src/cohort-topic/antidos/rate-limiter.d.ts.map +1 -0
- package/dist/src/cohort-topic/antidos/rate-limiter.js +146 -0
- package/dist/src/cohort-topic/antidos/rate-limiter.js.map +1 -0
- package/dist/src/cohort-topic/antidos/replay-guard.d.ts +37 -0
- package/dist/src/cohort-topic/antidos/replay-guard.d.ts.map +1 -0
- package/dist/src/cohort-topic/antidos/replay-guard.js +78 -0
- package/dist/src/cohort-topic/antidos/replay-guard.js.map +1 -0
- package/dist/src/cohort-topic/antidos/topic-budget.d.ts +50 -0
- package/dist/src/cohort-topic/antidos/topic-budget.d.ts.map +1 -0
- package/dist/src/cohort-topic/antidos/topic-budget.js +95 -0
- package/dist/src/cohort-topic/antidos/topic-budget.js.map +1 -0
- package/dist/src/cohort-topic/antiflood/index.d.ts +3 -0
- package/dist/src/cohort-topic/antiflood/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/antiflood/index.js +3 -0
- package/dist/src/cohort-topic/antiflood/index.js.map +1 -0
- package/dist/src/cohort-topic/antiflood/invariants.d.ts +70 -0
- package/dist/src/cohort-topic/antiflood/invariants.d.ts.map +1 -0
- package/dist/src/cohort-topic/antiflood/invariants.js +86 -0
- package/dist/src/cohort-topic/antiflood/invariants.js.map +1 -0
- package/dist/src/cohort-topic/antiflood/jitter.d.ts +65 -0
- package/dist/src/cohort-topic/antiflood/jitter.d.ts.map +1 -0
- package/dist/src/cohort-topic/antiflood/jitter.js +75 -0
- package/dist/src/cohort-topic/antiflood/jitter.js.map +1 -0
- package/dist/src/cohort-topic/coldstart.d.ts +117 -0
- package/dist/src/cohort-topic/coldstart.d.ts.map +1 -0
- package/dist/src/cohort-topic/coldstart.js +127 -0
- package/dist/src/cohort-topic/coldstart.js.map +1 -0
- package/dist/src/cohort-topic/dmax.d.ts +44 -0
- package/dist/src/cohort-topic/dmax.d.ts.map +1 -0
- package/dist/src/cohort-topic/dmax.js +70 -0
- package/dist/src/cohort-topic/dmax.js.map +1 -0
- package/dist/src/cohort-topic/gossip/bus.d.ts +85 -0
- package/dist/src/cohort-topic/gossip/bus.d.ts.map +1 -0
- package/dist/src/cohort-topic/gossip/bus.js +146 -0
- package/dist/src/cohort-topic/gossip/bus.js.map +1 -0
- package/dist/src/cohort-topic/gossip/index.d.ts +4 -0
- package/dist/src/cohort-topic/gossip/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/gossip/index.js +4 -0
- package/dist/src/cohort-topic/gossip/index.js.map +1 -0
- package/dist/src/cohort-topic/gossip/records.d.ts +12 -0
- package/dist/src/cohort-topic/gossip/records.d.ts.map +1 -0
- package/dist/src/cohort-topic/gossip/records.js +41 -0
- package/dist/src/cohort-topic/gossip/records.js.map +1 -0
- package/dist/src/cohort-topic/gossip/view.d.ts +39 -0
- package/dist/src/cohort-topic/gossip/view.d.ts.map +1 -0
- package/dist/src/cohort-topic/gossip/view.js +30 -0
- package/dist/src/cohort-topic/gossip/view.js.map +1 -0
- package/dist/src/cohort-topic/index.d.ts +21 -0
- package/dist/src/cohort-topic/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/index.js +21 -0
- package/dist/src/cohort-topic/index.js.map +1 -0
- package/dist/src/cohort-topic/load/barometer.d.ts +78 -0
- package/dist/src/cohort-topic/load/barometer.d.ts.map +1 -0
- package/dist/src/cohort-topic/load/barometer.js +93 -0
- package/dist/src/cohort-topic/load/barometer.js.map +1 -0
- package/dist/src/cohort-topic/load/index.d.ts +2 -0
- package/dist/src/cohort-topic/load/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/load/index.js +2 -0
- package/dist/src/cohort-topic/load/index.js.map +1 -0
- package/dist/src/cohort-topic/member-engine.d.ts +134 -0
- package/dist/src/cohort-topic/member-engine.d.ts.map +1 -0
- package/dist/src/cohort-topic/member-engine.js +264 -0
- package/dist/src/cohort-topic/member-engine.js.map +1 -0
- package/dist/src/cohort-topic/membership/index.d.ts +4 -0
- package/dist/src/cohort-topic/membership/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/membership/index.js +4 -0
- package/dist/src/cohort-topic/membership/index.js.map +1 -0
- package/dist/src/cohort-topic/membership/publisher.d.ts +82 -0
- package/dist/src/cohort-topic/membership/publisher.d.ts.map +1 -0
- package/dist/src/cohort-topic/membership/publisher.js +107 -0
- package/dist/src/cohort-topic/membership/publisher.js.map +1 -0
- package/dist/src/cohort-topic/membership/source.d.ts +31 -0
- package/dist/src/cohort-topic/membership/source.d.ts.map +1 -0
- package/dist/src/cohort-topic/membership/source.js +32 -0
- package/dist/src/cohort-topic/membership/source.js.map +1 -0
- package/dist/src/cohort-topic/membership/verifier.d.ts +96 -0
- package/dist/src/cohort-topic/membership/verifier.d.ts.map +1 -0
- package/dist/src/cohort-topic/membership/verifier.js +250 -0
- package/dist/src/cohort-topic/membership/verifier.js.map +1 -0
- package/dist/src/cohort-topic/ports.d.ts +149 -0
- package/dist/src/cohort-topic/ports.d.ts.map +1 -0
- package/dist/src/cohort-topic/ports.js +25 -0
- package/dist/src/cohort-topic/ports.js.map +1 -0
- package/dist/src/cohort-topic/promotion.d.ts +135 -0
- package/dist/src/cohort-topic/promotion.d.ts.map +1 -0
- package/dist/src/cohort-topic/promotion.js +269 -0
- package/dist/src/cohort-topic/promotion.js.map +1 -0
- package/dist/src/cohort-topic/registration/bytes.d.ts +16 -0
- package/dist/src/cohort-topic/registration/bytes.d.ts.map +1 -0
- package/dist/src/cohort-topic/registration/bytes.js +32 -0
- package/dist/src/cohort-topic/registration/bytes.js.map +1 -0
- package/dist/src/cohort-topic/registration/handoff.d.ts +69 -0
- package/dist/src/cohort-topic/registration/handoff.d.ts.map +1 -0
- package/dist/src/cohort-topic/registration/handoff.js +98 -0
- package/dist/src/cohort-topic/registration/handoff.js.map +1 -0
- package/dist/src/cohort-topic/registration/index.d.ts +7 -0
- package/dist/src/cohort-topic/registration/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/registration/index.js +7 -0
- package/dist/src/cohort-topic/registration/index.js.map +1 -0
- package/dist/src/cohort-topic/registration/renewal.d.ts +115 -0
- package/dist/src/cohort-topic/registration/renewal.d.ts.map +1 -0
- package/dist/src/cohort-topic/registration/renewal.js +306 -0
- package/dist/src/cohort-topic/registration/renewal.js.map +1 -0
- package/dist/src/cohort-topic/registration/sharding.d.ts +31 -0
- package/dist/src/cohort-topic/registration/sharding.d.ts.map +1 -0
- package/dist/src/cohort-topic/registration/sharding.js +48 -0
- package/dist/src/cohort-topic/registration/sharding.js.map +1 -0
- package/dist/src/cohort-topic/registration/store.d.ts +13 -0
- package/dist/src/cohort-topic/registration/store.d.ts.map +1 -0
- package/dist/src/cohort-topic/registration/store.js +72 -0
- package/dist/src/cohort-topic/registration/store.js.map +1 -0
- package/dist/src/cohort-topic/registration/types.d.ts +71 -0
- package/dist/src/cohort-topic/registration/types.d.ts.map +1 -0
- package/dist/src/cohort-topic/registration/types.js +27 -0
- package/dist/src/cohort-topic/registration/types.js.map +1 -0
- package/dist/src/cohort-topic/ring-hash.d.ts +27 -0
- package/dist/src/cohort-topic/ring-hash.d.ts.map +1 -0
- package/dist/src/cohort-topic/ring-hash.js +45 -0
- package/dist/src/cohort-topic/ring-hash.js.map +1 -0
- package/dist/src/cohort-topic/service.d.ts +157 -0
- package/dist/src/cohort-topic/service.d.ts.map +1 -0
- package/dist/src/cohort-topic/service.js +237 -0
- package/dist/src/cohort-topic/service.js.map +1 -0
- package/dist/src/cohort-topic/sig/index.d.ts +3 -0
- package/dist/src/cohort-topic/sig/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/sig/index.js +3 -0
- package/dist/src/cohort-topic/sig/index.js.map +1 -0
- package/dist/src/cohort-topic/sig/payloads.d.ts +25 -0
- package/dist/src/cohort-topic/sig/payloads.d.ts.map +1 -0
- package/dist/src/cohort-topic/sig/payloads.js +25 -0
- package/dist/src/cohort-topic/sig/payloads.js.map +1 -0
- package/dist/src/cohort-topic/sig/threshold.d.ts +33 -0
- package/dist/src/cohort-topic/sig/threshold.d.ts.map +1 -0
- package/dist/src/cohort-topic/sig/threshold.js +51 -0
- package/dist/src/cohort-topic/sig/threshold.js.map +1 -0
- package/dist/src/cohort-topic/tiers.d.ts +58 -0
- package/dist/src/cohort-topic/tiers.d.ts.map +1 -0
- package/dist/src/cohort-topic/tiers.js +49 -0
- package/dist/src/cohort-topic/tiers.js.map +1 -0
- package/dist/src/cohort-topic/traffic.d.ts +90 -0
- package/dist/src/cohort-topic/traffic.d.ts.map +1 -0
- package/dist/src/cohort-topic/traffic.js +146 -0
- package/dist/src/cohort-topic/traffic.js.map +1 -0
- package/dist/src/cohort-topic/walk.d.ts +123 -0
- package/dist/src/cohort-topic/walk.d.ts.map +1 -0
- package/dist/src/cohort-topic/walk.js +150 -0
- package/dist/src/cohort-topic/walk.js.map +1 -0
- package/dist/src/cohort-topic/willingness.d.ts +123 -0
- package/dist/src/cohort-topic/willingness.d.ts.map +1 -0
- package/dist/src/cohort-topic/willingness.js +143 -0
- package/dist/src/cohort-topic/willingness.js.map +1 -0
- package/dist/src/cohort-topic/wire/codec.d.ts +42 -0
- package/dist/src/cohort-topic/wire/codec.d.ts.map +1 -0
- package/dist/src/cohort-topic/wire/codec.js +163 -0
- package/dist/src/cohort-topic/wire/codec.js.map +1 -0
- package/dist/src/cohort-topic/wire/index.d.ts +6 -0
- package/dist/src/cohort-topic/wire/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/wire/index.js +6 -0
- package/dist/src/cohort-topic/wire/index.js.map +1 -0
- package/dist/src/cohort-topic/wire/payloads.d.ts +38 -0
- package/dist/src/cohort-topic/wire/payloads.d.ts.map +1 -0
- package/dist/src/cohort-topic/wire/payloads.js +102 -0
- package/dist/src/cohort-topic/wire/payloads.js.map +1 -0
- package/dist/src/cohort-topic/wire/types.d.ts +304 -0
- package/dist/src/cohort-topic/wire/types.d.ts.map +1 -0
- package/dist/src/cohort-topic/wire/types.js +16 -0
- package/dist/src/cohort-topic/wire/types.js.map +1 -0
- package/dist/src/cohort-topic/wire/validate.d.ts +25 -0
- package/dist/src/cohort-topic/wire/validate.d.ts.map +1 -0
- package/dist/src/cohort-topic/wire/validate.js +427 -0
- package/dist/src/cohort-topic/wire/validate.js.map +1 -0
- package/dist/src/collection/collection.d.ts +58 -1
- package/dist/src/collection/collection.d.ts.map +1 -1
- package/dist/src/collection/collection.js +76 -0
- package/dist/src/collection/collection.js.map +1 -1
- package/dist/src/collections/tree/tree.d.ts +58 -2
- package/dist/src/collections/tree/tree.d.ts.map +1 -1
- package/dist/src/collections/tree/tree.js +59 -2
- package/dist/src/collections/tree/tree.js.map +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/log/log.d.ts +42 -4
- package/dist/src/log/log.d.ts.map +1 -1
- package/dist/src/log/log.js +71 -3
- package/dist/src/log/log.js.map +1 -1
- package/dist/src/log/struct.d.ts +122 -2
- package/dist/src/log/struct.d.ts.map +1 -1
- package/dist/src/log/struct.js.map +1 -1
- package/dist/src/matchmaking/capability-filter.d.ts +24 -0
- package/dist/src/matchmaking/capability-filter.d.ts.map +1 -0
- package/dist/src/matchmaking/capability-filter.js +37 -0
- package/dist/src/matchmaking/capability-filter.js.map +1 -0
- package/dist/src/matchmaking/config.d.ts +77 -0
- package/dist/src/matchmaking/config.d.ts.map +1 -0
- package/dist/src/matchmaking/config.js +69 -0
- package/dist/src/matchmaking/config.js.map +1 -0
- package/dist/src/matchmaking/index.d.ts +21 -0
- package/dist/src/matchmaking/index.d.ts.map +1 -0
- package/dist/src/matchmaking/index.js +21 -0
- package/dist/src/matchmaking/index.js.map +1 -0
- package/dist/src/matchmaking/multi-cohort-seeker.d.ts +133 -0
- package/dist/src/matchmaking/multi-cohort-seeker.d.ts.map +1 -0
- package/dist/src/matchmaking/multi-cohort-seeker.js +142 -0
- package/dist/src/matchmaking/multi-cohort-seeker.js.map +1 -0
- package/dist/src/matchmaking/provider.d.ts +70 -0
- package/dist/src/matchmaking/provider.d.ts.map +1 -0
- package/dist/src/matchmaking/provider.js +93 -0
- package/dist/src/matchmaking/provider.js.map +1 -0
- package/dist/src/matchmaking/query-eval.d.ts +53 -0
- package/dist/src/matchmaking/query-eval.d.ts.map +1 -0
- package/dist/src/matchmaking/query-eval.js +69 -0
- package/dist/src/matchmaking/query-eval.js.map +1 -0
- package/dist/src/matchmaking/seeker-walk.d.ts +95 -0
- package/dist/src/matchmaking/seeker-walk.d.ts.map +1 -0
- package/dist/src/matchmaking/seeker-walk.js +75 -0
- package/dist/src/matchmaking/seeker-walk.js.map +1 -0
- package/dist/src/matchmaking/seeker.d.ts +51 -0
- package/dist/src/matchmaking/seeker.d.ts.map +1 -0
- package/dist/src/matchmaking/seeker.js +62 -0
- package/dist/src/matchmaking/seeker.js.map +1 -0
- package/dist/src/matchmaking/topic-anchor.d.ts +54 -0
- package/dist/src/matchmaking/topic-anchor.d.ts.map +1 -0
- package/dist/src/matchmaking/topic-anchor.js +67 -0
- package/dist/src/matchmaking/topic-anchor.js.map +1 -0
- package/dist/src/matchmaking/voting-quorum.d.ts +233 -0
- package/dist/src/matchmaking/voting-quorum.d.ts.map +1 -0
- package/dist/src/matchmaking/voting-quorum.js +238 -0
- package/dist/src/matchmaking/voting-quorum.js.map +1 -0
- package/dist/src/matchmaking/wire.d.ts +259 -0
- package/dist/src/matchmaking/wire.d.ts.map +1 -0
- package/dist/src/matchmaking/wire.js +484 -0
- package/dist/src/matchmaking/wire.js.map +1 -0
- package/dist/src/network/i-repo.d.ts +9 -0
- package/dist/src/network/i-repo.d.ts.map +1 -1
- package/dist/src/network/repo-protocol.d.ts +3 -1
- package/dist/src/network/repo-protocol.d.ts.map +1 -1
- package/dist/src/network/struct.d.ts +23 -1
- package/dist/src/network/struct.d.ts.map +1 -1
- package/dist/src/reactivity/backfill.d.ts +118 -0
- package/dist/src/reactivity/backfill.d.ts.map +1 -0
- package/dist/src/reactivity/backfill.js +137 -0
- package/dist/src/reactivity/backfill.js.map +1 -0
- package/dist/src/reactivity/backpressure.d.ts +99 -0
- package/dist/src/reactivity/backpressure.d.ts.map +1 -0
- package/dist/src/reactivity/backpressure.js +153 -0
- package/dist/src/reactivity/backpressure.js.map +1 -0
- package/dist/src/reactivity/checkpoint.d.ts +165 -0
- package/dist/src/reactivity/checkpoint.d.ts.map +1 -0
- package/dist/src/reactivity/checkpoint.js +232 -0
- package/dist/src/reactivity/checkpoint.js.map +1 -0
- package/dist/src/reactivity/config.d.ts +131 -0
- package/dist/src/reactivity/config.d.ts.map +1 -0
- package/dist/src/reactivity/config.js +135 -0
- package/dist/src/reactivity/config.js.map +1 -0
- package/dist/src/reactivity/dedupe.d.ts +51 -0
- package/dist/src/reactivity/dedupe.d.ts.map +1 -0
- package/dist/src/reactivity/dedupe.js +90 -0
- package/dist/src/reactivity/dedupe.js.map +1 -0
- package/dist/src/reactivity/forwarder.d.ts +50 -0
- package/dist/src/reactivity/forwarder.d.ts.map +1 -0
- package/dist/src/reactivity/forwarder.js +52 -0
- package/dist/src/reactivity/forwarder.js.map +1 -0
- package/dist/src/reactivity/index.d.ts +34 -0
- package/dist/src/reactivity/index.d.ts.map +1 -0
- package/dist/src/reactivity/index.js +34 -0
- package/dist/src/reactivity/index.js.map +1 -0
- package/dist/src/reactivity/notification.d.ts +72 -0
- package/dist/src/reactivity/notification.d.ts.map +1 -0
- package/dist/src/reactivity/notification.js +92 -0
- package/dist/src/reactivity/notification.js.map +1 -0
- package/dist/src/reactivity/policy.d.ts +59 -0
- package/dist/src/reactivity/policy.d.ts.map +1 -0
- package/dist/src/reactivity/policy.js +64 -0
- package/dist/src/reactivity/policy.js.map +1 -0
- package/dist/src/reactivity/push-state.d.ts +140 -0
- package/dist/src/reactivity/push-state.d.ts.map +1 -0
- package/dist/src/reactivity/push-state.js +270 -0
- package/dist/src/reactivity/push-state.js.map +1 -0
- package/dist/src/reactivity/recover.d.ts +75 -0
- package/dist/src/reactivity/recover.d.ts.map +1 -0
- package/dist/src/reactivity/recover.js +105 -0
- package/dist/src/reactivity/recover.js.map +1 -0
- package/dist/src/reactivity/replay-buffer.d.ts +57 -0
- package/dist/src/reactivity/replay-buffer.d.ts.map +1 -0
- package/dist/src/reactivity/replay-buffer.js +88 -0
- package/dist/src/reactivity/replay-buffer.js.map +1 -0
- package/dist/src/reactivity/resume.d.ts +214 -0
- package/dist/src/reactivity/resume.d.ts.map +1 -0
- package/dist/src/reactivity/resume.js +358 -0
- package/dist/src/reactivity/resume.js.map +1 -0
- package/dist/src/reactivity/rotation.d.ts +283 -0
- package/dist/src/reactivity/rotation.d.ts.map +1 -0
- package/dist/src/reactivity/rotation.js +265 -0
- package/dist/src/reactivity/rotation.js.map +1 -0
- package/dist/src/reactivity/subscriber.d.ts +66 -0
- package/dist/src/reactivity/subscriber.d.ts.map +1 -0
- package/dist/src/reactivity/subscriber.js +75 -0
- package/dist/src/reactivity/subscriber.js.map +1 -0
- package/dist/src/reactivity/subscription.d.ts +52 -0
- package/dist/src/reactivity/subscription.d.ts.map +1 -0
- package/dist/src/reactivity/subscription.js +28 -0
- package/dist/src/reactivity/subscription.js.map +1 -0
- package/dist/src/reactivity/topic-anchor.d.ts +46 -0
- package/dist/src/reactivity/topic-anchor.d.ts.map +1 -0
- package/dist/src/reactivity/topic-anchor.js +61 -0
- package/dist/src/reactivity/topic-anchor.js.map +1 -0
- package/dist/src/reactivity/verify.d.ts +41 -0
- package/dist/src/reactivity/verify.d.ts.map +1 -0
- package/dist/src/reactivity/verify.js +48 -0
- package/dist/src/reactivity/verify.js.map +1 -0
- package/dist/src/reactivity/wire-validate.d.ts +28 -0
- package/dist/src/reactivity/wire-validate.d.ts.map +1 -0
- package/dist/src/reactivity/wire-validate.js +79 -0
- package/dist/src/reactivity/wire-validate.js.map +1 -0
- package/dist/src/reactivity/wire.d.ts +102 -0
- package/dist/src/reactivity/wire.d.ts.map +1 -0
- package/dist/src/reactivity/wire.js +129 -0
- package/dist/src/reactivity/wire.js.map +1 -0
- package/dist/src/transaction/coordinator.d.ts +9 -5
- package/dist/src/transaction/coordinator.d.ts.map +1 -1
- package/dist/src/transaction/coordinator.js +48 -25
- package/dist/src/transaction/coordinator.js.map +1 -1
- package/dist/src/transactor/change-notifier.d.ts +74 -0
- package/dist/src/transactor/change-notifier.d.ts.map +1 -0
- package/dist/src/transactor/change-notifier.js +4 -0
- package/dist/src/transactor/change-notifier.js.map +1 -0
- package/dist/src/transactor/index.d.ts +1 -0
- package/dist/src/transactor/index.d.ts.map +1 -1
- package/dist/src/transactor/index.js +1 -0
- package/dist/src/transactor/index.js.map +1 -1
- package/dist/src/transactor/network-transactor.d.ts +34 -2
- package/dist/src/transactor/network-transactor.d.ts.map +1 -1
- package/dist/src/transactor/network-transactor.js +113 -13
- package/dist/src/transactor/network-transactor.js.map +1 -1
- package/package.json +2 -2
- package/src/cluster/structs.ts +13 -0
- package/src/cohort-topic/addressing.ts +112 -0
- package/src/cohort-topic/antidos/bootstrap-evidence-envelope.ts +253 -0
- package/src/cohort-topic/antidos/bootstrap-evidence.ts +94 -0
- package/src/cohort-topic/antidos/index.ts +5 -0
- package/src/cohort-topic/antidos/rate-limiter.ts +210 -0
- package/src/cohort-topic/antidos/replay-guard.ts +109 -0
- package/src/cohort-topic/antidos/topic-budget.ts +145 -0
- package/src/cohort-topic/antiflood/index.ts +2 -0
- package/src/cohort-topic/antiflood/invariants.ts +108 -0
- package/src/cohort-topic/antiflood/jitter.ts +117 -0
- package/src/cohort-topic/coldstart.ts +204 -0
- package/src/cohort-topic/dmax.ts +88 -0
- package/src/cohort-topic/gossip/bus.ts +217 -0
- package/src/cohort-topic/gossip/index.ts +3 -0
- package/src/cohort-topic/gossip/records.ts +45 -0
- package/src/cohort-topic/gossip/view.ts +66 -0
- package/src/cohort-topic/index.ts +20 -0
- package/src/cohort-topic/load/barometer.ts +134 -0
- package/src/cohort-topic/load/index.ts +1 -0
- package/src/cohort-topic/member-engine.ts +409 -0
- package/src/cohort-topic/membership/index.ts +3 -0
- package/src/cohort-topic/membership/publisher.ts +171 -0
- package/src/cohort-topic/membership/source.ts +41 -0
- package/src/cohort-topic/membership/verifier.ts +345 -0
- package/src/cohort-topic/ports.ts +157 -0
- package/src/cohort-topic/promotion.ts +384 -0
- package/src/cohort-topic/registration/bytes.ts +37 -0
- package/src/cohort-topic/registration/handoff.ts +154 -0
- package/src/cohort-topic/registration/index.ts +6 -0
- package/src/cohort-topic/registration/renewal.ts +423 -0
- package/src/cohort-topic/registration/sharding.ts +61 -0
- package/src/cohort-topic/registration/store.ts +81 -0
- package/src/cohort-topic/registration/types.ts +76 -0
- package/src/cohort-topic/ring-hash.ts +50 -0
- package/src/cohort-topic/service.ts +390 -0
- package/src/cohort-topic/sig/index.ts +2 -0
- package/src/cohort-topic/sig/payloads.ts +39 -0
- package/src/cohort-topic/sig/threshold.ts +64 -0
- package/src/cohort-topic/tiers.ts +74 -0
- package/src/cohort-topic/traffic.ts +211 -0
- package/src/cohort-topic/walk.ts +255 -0
- package/src/cohort-topic/willingness.ts +237 -0
- package/src/cohort-topic/wire/codec.ts +204 -0
- package/src/cohort-topic/wire/index.ts +16 -0
- package/src/cohort-topic/wire/payloads.ts +117 -0
- package/src/cohort-topic/wire/types.ts +343 -0
- package/src/cohort-topic/wire/validate.ts +478 -0
- package/src/collection/collection.ts +93 -1
- package/src/collections/tree/tree.ts +84 -3
- package/src/index.ts +3 -0
- package/src/log/log.ts +86 -7
- package/src/log/struct.ts +126 -2
- package/src/matchmaking/capability-filter.ts +45 -0
- package/src/matchmaking/config.ts +98 -0
- package/src/matchmaking/index.ts +21 -0
- package/src/matchmaking/multi-cohort-seeker.ts +234 -0
- package/src/matchmaking/provider.ts +123 -0
- package/src/matchmaking/query-eval.ts +105 -0
- package/src/matchmaking/seeker-walk.ts +127 -0
- package/src/matchmaking/seeker.ts +86 -0
- package/src/matchmaking/topic-anchor.ts +90 -0
- package/src/matchmaking/voting-quorum.ts +394 -0
- package/src/matchmaking/wire.ts +680 -0
- package/src/network/i-repo.ts +9 -0
- package/src/network/repo-protocol.ts +3 -2
- package/src/network/struct.ts +24 -1
- package/src/reactivity/backfill.ts +220 -0
- package/src/reactivity/backpressure.ts +191 -0
- package/src/reactivity/checkpoint.ts +308 -0
- package/src/reactivity/config.ts +172 -0
- package/src/reactivity/dedupe.ts +132 -0
- package/src/reactivity/forwarder.ts +87 -0
- package/src/reactivity/index.ts +34 -0
- package/src/reactivity/notification.ts +123 -0
- package/src/reactivity/policy.ts +79 -0
- package/src/reactivity/push-state.ts +343 -0
- package/src/reactivity/recover.ts +153 -0
- package/src/reactivity/replay-buffer.ts +141 -0
- package/src/reactivity/resume.ts +549 -0
- package/src/reactivity/rotation.ts +415 -0
- package/src/reactivity/subscriber.ts +132 -0
- package/src/reactivity/subscription.ts +66 -0
- package/src/reactivity/topic-anchor.ts +71 -0
- package/src/reactivity/verify.ts +73 -0
- package/src/reactivity/wire-validate.ts +87 -0
- package/src/reactivity/wire.ts +224 -0
- package/src/transaction/coordinator.ts +53 -27
- package/src/transactor/change-notifier.ts +80 -0
- package/src/transactor/index.ts +1 -0
- package/src/transactor/network-transactor.ts +133 -15
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cohort-topic substrate — topic-traffic signal.
|
|
3
|
+
*
|
|
4
|
+
* Transcribed from `docs/cohort-topic.md` §Topic traffic signal. A cohort tracks per-topic flow
|
|
5
|
+
* rates alongside the stock `directParticipants` count and returns them on registration replies so
|
|
6
|
+
* applications can decide whether the current tier is dense enough to settle on.
|
|
7
|
+
*
|
|
8
|
+
* Shape (`TopicTrafficV1` from the wire ticket):
|
|
9
|
+
* - `arrivalsPerMin` — **combines** fresh registrations and renewals into one scalar (the seeker
|
|
10
|
+
* uses renewals as a proxy for active matchable supply); the caller invokes {@link recordArrival}
|
|
11
|
+
* for both.
|
|
12
|
+
* - `queriesPerMin` — application-level query rate.
|
|
13
|
+
* - counts are **exact integers** over `windowSeconds` (default 60), *not* log-bucketed like the
|
|
14
|
+
* load barometer — the consumer-side matchmaking formulas are numeric.
|
|
15
|
+
*
|
|
16
|
+
* Pipeline: each member counts arrivals/queries locally ({@link recordArrival} / {@link recordQuery})
|
|
17
|
+
* over a sliding window; {@link TrafficCounters.publish} freezes the windowed counts into the
|
|
18
|
+
* member's gossiped per-topic summary each gossip round; {@link TrafficCounters.snapshot} returns the
|
|
19
|
+
* **gossip-derived** view (own last-published summary + siblings' last-gossiped summaries from the
|
|
20
|
+
* {@link CohortView}), so the reply lags by at most one round and never recomputes from raw counters
|
|
21
|
+
* at reply time.
|
|
22
|
+
*
|
|
23
|
+
* Resolved open question (GROUNDING): the signal is returned **only** on `accepted` and `promoted`
|
|
24
|
+
* replies (see {@link attachTopicTraffic}); a participant getting `Promoted(d+1)` still receives the
|
|
25
|
+
* outgoing cohort's traffic so it can estimate whether the redirect target is hot.
|
|
26
|
+
*
|
|
27
|
+
* Counters reset to zero on `cohortEpoch` change ({@link TrafficCounters.reset}); the first round
|
|
28
|
+
* after a rotation may under-report, and consumers tolerate a single zero reading.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { bytesKey } from "./registration/bytes.js";
|
|
32
|
+
import type { CohortView } from "./gossip/view.js";
|
|
33
|
+
import type { RegistrationStore } from "./registration/types.js";
|
|
34
|
+
import { bytesToB64url } from "./wire/codec.js";
|
|
35
|
+
import type { CohortTopicSummary, RegisterReplyV1, TopicTrafficV1 } from "./wire/types.js";
|
|
36
|
+
|
|
37
|
+
/** Default observation window for the rate fields (seconds). */
|
|
38
|
+
export const DEFAULT_TRAFFIC_WINDOW_SECONDS = 60;
|
|
39
|
+
|
|
40
|
+
/** Frozen per-topic counts the member last published to gossip. */
|
|
41
|
+
interface PublishedTopic {
|
|
42
|
+
readonly arrivals: number;
|
|
43
|
+
readonly queries: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Local windowed event timestamps (unix ms) for one topic. */
|
|
47
|
+
interface TopicWindow {
|
|
48
|
+
arrivals: number[];
|
|
49
|
+
queries: number[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Per-topic traffic counters with a gossip-derived snapshot. */
|
|
53
|
+
export interface TrafficCounters {
|
|
54
|
+
/** Record a fresh registration **or** a renewal for `topicId` at `now` (combined arrivals). */
|
|
55
|
+
recordArrival(topicId: Uint8Array, now: number): void;
|
|
56
|
+
/** Record an application-level query against `topicId` at `now`. */
|
|
57
|
+
recordQuery(topicId: Uint8Array, now: number): void;
|
|
58
|
+
/**
|
|
59
|
+
* Freeze the current windowed counts into the member's gossiped summary (call once per gossip
|
|
60
|
+
* round, at `now`). The frozen values are what {@link snapshot} and the gossip frame read.
|
|
61
|
+
*/
|
|
62
|
+
publish(topicId: Uint8Array, now: number): PublishedTopic;
|
|
63
|
+
/** Own most-recent published `(arrivals, queries)` for `topicId`, or zeros if never published. */
|
|
64
|
+
published(topicId: Uint8Array): PublishedTopic;
|
|
65
|
+
/**
|
|
66
|
+
* Gossip-derived traffic for `topicId`: own last-published counts plus siblings' last-gossiped
|
|
67
|
+
* summaries (exact-integer sums), with `directParticipants` from the replicated store. Lags ≤ one
|
|
68
|
+
* round; never recomputes from raw counters.
|
|
69
|
+
*/
|
|
70
|
+
snapshot(topicId: Uint8Array): TopicTrafficV1;
|
|
71
|
+
/** Reset all counters to zero (call on `cohortEpoch` change). */
|
|
72
|
+
reset(): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface TrafficCountersDeps {
|
|
76
|
+
/** Merged per-member gossip view — siblings' last-gossiped per-topic summaries. */
|
|
77
|
+
view: CohortView;
|
|
78
|
+
/** Replicated registration store — supplies the cohort-wide `directParticipants` stock count. */
|
|
79
|
+
store: Pick<RegistrationStore, "directParticipants">;
|
|
80
|
+
/** This member's own id, base64url — excluded from the sibling summary scan (counted via own published). */
|
|
81
|
+
selfMember: string;
|
|
82
|
+
/** Observation window (seconds). Default {@link DEFAULT_TRAFFIC_WINDOW_SECONDS}. */
|
|
83
|
+
windowSeconds?: number;
|
|
84
|
+
/** Tier-(d+1) cohort count for a topic (0 if not promoted); the promotion ticket owns this. */
|
|
85
|
+
childCohortCount?: (topicId: Uint8Array) => number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
class WindowedTrafficCounters implements TrafficCounters {
|
|
89
|
+
private readonly windows = new Map<string, TopicWindow>();
|
|
90
|
+
private readonly lastPublished = new Map<string, PublishedTopic>();
|
|
91
|
+
private readonly windowMs: number;
|
|
92
|
+
|
|
93
|
+
constructor(private readonly deps: TrafficCountersDeps) {
|
|
94
|
+
const ws = deps.windowSeconds ?? DEFAULT_TRAFFIC_WINDOW_SECONDS;
|
|
95
|
+
if (!(ws > 0)) {
|
|
96
|
+
throw new RangeError(`windowSeconds must be > 0, got ${ws}`);
|
|
97
|
+
}
|
|
98
|
+
this.windowMs = ws * 1000;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
recordArrival(topicId: Uint8Array, now: number): void {
|
|
102
|
+
this.windowFor(topicId).arrivals.push(now);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
recordQuery(topicId: Uint8Array, now: number): void {
|
|
106
|
+
this.windowFor(topicId).queries.push(now);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
publish(topicId: Uint8Array, now: number): PublishedTopic {
|
|
110
|
+
const w = this.windows.get(bytesKey(topicId));
|
|
111
|
+
const frozen: PublishedTopic = {
|
|
112
|
+
arrivals: w === undefined ? 0 : countWithin(w.arrivals, now, this.windowMs),
|
|
113
|
+
queries: w === undefined ? 0 : countWithin(w.queries, now, this.windowMs),
|
|
114
|
+
};
|
|
115
|
+
this.lastPublished.set(bytesKey(topicId), frozen);
|
|
116
|
+
return frozen;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
published(topicId: Uint8Array): PublishedTopic {
|
|
120
|
+
return this.lastPublished.get(bytesKey(topicId)) ?? { arrivals: 0, queries: 0 };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
snapshot(topicId: Uint8Array): TopicTrafficV1 {
|
|
124
|
+
const topicB64 = bytesToB64url(topicId);
|
|
125
|
+
const own = this.published(topicId);
|
|
126
|
+
let arrivals = own.arrivals;
|
|
127
|
+
let queries = own.queries;
|
|
128
|
+
let childCohortCount = 0;
|
|
129
|
+
for (const [member, contribution] of this.deps.view.all()) {
|
|
130
|
+
if (member === this.deps.selfMember) continue; // own contribution comes from lastPublished
|
|
131
|
+
const summary = contribution.topicSummaries.find((s) => s.topicId === topicB64);
|
|
132
|
+
if (summary === undefined) continue;
|
|
133
|
+
arrivals += summary.arrivalsPerMin;
|
|
134
|
+
queries += summary.queriesPerMin;
|
|
135
|
+
if (summary.childCohortCount > childCohortCount) {
|
|
136
|
+
childCohortCount = summary.childCohortCount;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const childOverride = this.deps.childCohortCount?.(topicId);
|
|
140
|
+
return {
|
|
141
|
+
windowSeconds: this.windowMs / 1000,
|
|
142
|
+
arrivalsPerMin: arrivals,
|
|
143
|
+
queriesPerMin: queries,
|
|
144
|
+
directParticipants: this.deps.store.directParticipants(topicId),
|
|
145
|
+
childCohortCount: childOverride ?? childCohortCount,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
reset(): void {
|
|
150
|
+
this.windows.clear();
|
|
151
|
+
this.lastPublished.clear();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private windowFor(topicId: Uint8Array): TopicWindow {
|
|
155
|
+
const key = bytesKey(topicId);
|
|
156
|
+
let w = this.windows.get(key);
|
|
157
|
+
if (w === undefined) {
|
|
158
|
+
w = { arrivals: [], queries: [] };
|
|
159
|
+
this.windows.set(key, w);
|
|
160
|
+
}
|
|
161
|
+
return w;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Count timestamps within `[now - windowMs, now]`, pruning anything older from `events` in place. */
|
|
166
|
+
function countWithin(events: number[], now: number, windowMs: number): number {
|
|
167
|
+
const cutoff = now - windowMs;
|
|
168
|
+
// Events accumulate in arrival order; drop the stale prefix so the array stays bounded.
|
|
169
|
+
let drop = 0;
|
|
170
|
+
while (drop < events.length && events[drop]! < cutoff) {
|
|
171
|
+
drop++;
|
|
172
|
+
}
|
|
173
|
+
if (drop > 0) {
|
|
174
|
+
events.splice(0, drop);
|
|
175
|
+
}
|
|
176
|
+
return events.length;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Construct empty {@link TrafficCounters}. */
|
|
180
|
+
export function createTrafficCounters(deps: TrafficCountersDeps): TrafficCounters {
|
|
181
|
+
return new WindowedTrafficCounters(deps);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Attach the topic-traffic signal to a reply **only** when the result is `accepted` or `promoted`
|
|
186
|
+
* (GROUNDING-resolved: absent on `no_state`, `unwilling_member`, `unwilling_cohort`). Mutates and
|
|
187
|
+
* returns `reply`. A no-op for non-traffic-bearing results, so callers can pipe every reply through.
|
|
188
|
+
*/
|
|
189
|
+
export function attachTopicTraffic(reply: RegisterReplyV1, traffic: TopicTrafficV1): RegisterReplyV1 {
|
|
190
|
+
if (reply.result === "accepted" || reply.result === "promoted") {
|
|
191
|
+
reply.topicTraffic = traffic;
|
|
192
|
+
}
|
|
193
|
+
return reply;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The own published counts as a `CohortTopicSummary` for the gossip frame. Callers supply tier/promotion fields. */
|
|
197
|
+
export function toCohortTopicSummary(
|
|
198
|
+
topicId: Uint8Array,
|
|
199
|
+
published: PublishedTopic,
|
|
200
|
+
fields: { tier: number; directParticipants: number; promoted: boolean; childCohortCount: number },
|
|
201
|
+
): CohortTopicSummary {
|
|
202
|
+
return {
|
|
203
|
+
topicId: bytesToB64url(topicId),
|
|
204
|
+
tier: fields.tier,
|
|
205
|
+
directParticipants: fields.directParticipants,
|
|
206
|
+
arrivalsPerMin: published.arrivals,
|
|
207
|
+
queriesPerMin: published.queries,
|
|
208
|
+
promoted: fields.promoted,
|
|
209
|
+
childCohortCount: fields.childCohortCount,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cohort-topic substrate — walk-toward-root lookup / registration.
|
|
3
|
+
*
|
|
4
|
+
* Transcribed from `docs/cohort-topic.md` §Tree growth and lookup (§Lookup loop) and folded back
|
|
5
|
+
* from the simulator-validated `packages/substrate-simulator/src/walk.ts`. A participant resolves a
|
|
6
|
+
* topic by walking **toward the root** from `d_max`, probing one tier coordinate per RPC. The walk's
|
|
7
|
+
* single-direction discipline is the anti-flood backbone: it only ever moves inward (toward the root)
|
|
8
|
+
* on `NoState`, and the *only* outward move is following an explicit `Promoted` redirect.
|
|
9
|
+
*
|
|
10
|
+
* Reply handling (§Lookup):
|
|
11
|
+
* - **`accepted`** → done; return the reply (carries `primary`/`backups`/`cohortEpoch` to cache).
|
|
12
|
+
* - **`no_state`** at tier `d` → step one tier toward the root (`d − 1`); no traffic signal. At the
|
|
13
|
+
* root (`d − 1 < 0`) re-issue once at tier 0 with `bootstrap: true` (cold-start request).
|
|
14
|
+
* - **`promoted(targetTier)`** → recompute `coord_targetTier(self, topicId)` and register there — the
|
|
15
|
+
* one outward move, taken only on this explicit redirect.
|
|
16
|
+
* - **`unwilling_member(candidates)`** → retry the **same** coord at a named alternative member
|
|
17
|
+
* (spatial move within the cohort), via a direct dial.
|
|
18
|
+
* - **`unwilling_cohort(retryAfter)`** → back off in **time**; the walk terminates with
|
|
19
|
+
* {@link RetryLaterOutcome} and the caller restarts a fresh {@link WalkEngine.register} after
|
|
20
|
+
* `afterMs` — which begins again at `d_max`, decorrelating retries across the ring (§Anti-flood
|
|
21
|
+
* claim 4: never re-hit the declined coord immediately).
|
|
22
|
+
*
|
|
23
|
+
* This module is FRET-free: it drives the {@link ITopicRouter} port (db-p2p binds it to FRET's
|
|
24
|
+
* `RouteAndMaybeAct` / direct dial) and the {@link TierAddressing} math, and delegates building +
|
|
25
|
+
* signing the {@link RegisterV1} to the injected {@link RegisterMessageFactory} (participant identity
|
|
26
|
+
* and crypto live there, not here).
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import type { ITopicRouter, PeerRef } from "./ports.js";
|
|
30
|
+
import type { TierAddressing } from "./addressing.js";
|
|
31
|
+
import type { DMaxComputer } from "./dmax.js";
|
|
32
|
+
import { backoffRetryMs } from "./willingness.js";
|
|
33
|
+
import { b64urlToBytes, decodeRegisterReplyV1, encodeCohortMessage } from "./wire/codec.js";
|
|
34
|
+
import type { RegisterReplyV1, RegisterV1 } from "./wire/types.js";
|
|
35
|
+
|
|
36
|
+
/** The walk landed: the cohort accepted the registration. `reply` carries the cohort cache fields. */
|
|
37
|
+
export interface AcceptedWalkOutcome {
|
|
38
|
+
readonly kind: "accepted";
|
|
39
|
+
readonly reply: RegisterReplyV1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The walk hit a `Promoted` redirect and the engine was configured **not** to follow it
|
|
44
|
+
* ({@link WalkConfig.followPromoted} `= false`): the caller recomputes `coord_targetTier` and
|
|
45
|
+
* registers there itself. With the default (`followPromoted = true`) the engine follows the redirect
|
|
46
|
+
* internally and this outcome never surfaces.
|
|
47
|
+
*/
|
|
48
|
+
export interface PromotedWalkOutcome {
|
|
49
|
+
readonly kind: "promoted";
|
|
50
|
+
readonly targetTier: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The walk backed off in time (`unwilling_cohort`, exhausted sibling retries, a failed cold-start, or
|
|
55
|
+
* the safety step cap). The caller waits `afterMs` then calls {@link WalkEngine.register} again, which
|
|
56
|
+
* restarts at `d_max`.
|
|
57
|
+
*/
|
|
58
|
+
export interface RetryLaterOutcome {
|
|
59
|
+
readonly kind: "retry_later";
|
|
60
|
+
readonly afterMs: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type WalkOutcome = AcceptedWalkOutcome | PromotedWalkOutcome | RetryLaterOutcome;
|
|
64
|
+
|
|
65
|
+
/** Builds (and signs) the {@link RegisterV1} for one probe; owns participant identity + crypto. */
|
|
66
|
+
export interface RegisterMessageFactory {
|
|
67
|
+
/**
|
|
68
|
+
* Produce a signed `RegisterV1` for this participant at walk position `treeTier`. `bootstrap` is
|
|
69
|
+
* set only on the root cold-start re-issue. `appPayload` is the opaque application slot. On the
|
|
70
|
+
* bootstrap re-issue the factory may additionally mint and attach the signed `bootstrapEvidence`
|
|
71
|
+
* envelope (§Anti-DoS) via the injected builder seam before signing — keyed off `bootstrap`, so no
|
|
72
|
+
* extra build parameter is needed (the walk decides `bootstrap` internally, not the application).
|
|
73
|
+
*/
|
|
74
|
+
build(params: {
|
|
75
|
+
topicId: Uint8Array;
|
|
76
|
+
tier: number;
|
|
77
|
+
treeTier: number;
|
|
78
|
+
bootstrap: boolean;
|
|
79
|
+
/** Read-only lookup probe: the factory stamps `RegisterV1.probe` and never mints bootstrap evidence. */
|
|
80
|
+
probe: boolean;
|
|
81
|
+
appPayload?: Uint8Array;
|
|
82
|
+
}): Promise<RegisterV1>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface WalkConfig {
|
|
86
|
+
/** Cohort size requested from the router (`wantK`). Default 16. */
|
|
87
|
+
wantK?: number;
|
|
88
|
+
/** Threshold signers requested from the router (`minSigs = k − x`). Default 14. */
|
|
89
|
+
minSigs?: number;
|
|
90
|
+
/** Max `unwilling_member` sibling retries at one coord before treating it as a cohort decline. Default `wantK`. */
|
|
91
|
+
maxMemberRetries?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Whether to follow a `Promoted` redirect internally (recompute coord + continue) or surface it as
|
|
94
|
+
* a {@link PromotedWalkOutcome} for the caller to drive. Default `true` (self-contained walk).
|
|
95
|
+
*/
|
|
96
|
+
followPromoted?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Hard cap on probe RPCs in one walk — a safety valve against pathological oscillation between an
|
|
99
|
+
* inward `NoState` step and an outward `Promoted` redirect in a malformed tree. Default scales with
|
|
100
|
+
* `d_max`. Exceeding it yields a {@link RetryLaterOutcome}.
|
|
101
|
+
*/
|
|
102
|
+
maxSteps?: number;
|
|
103
|
+
/** `max_message_bytes` ceiling for the encoded register frame. Defaults to the codec default. */
|
|
104
|
+
maxMessageBytes?: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface WalkEngineDeps {
|
|
108
|
+
router: ITopicRouter;
|
|
109
|
+
addressing: TierAddressing;
|
|
110
|
+
/** Computes the walk start tier `d_max` from the current network-size estimate. */
|
|
111
|
+
dmax: DMaxComputer;
|
|
112
|
+
/** This participant's peer id — the `P` in `coord_d(P, topicId)`. */
|
|
113
|
+
self: Uint8Array;
|
|
114
|
+
/** Builds + signs the per-probe `RegisterV1`. */
|
|
115
|
+
factory: RegisterMessageFactory;
|
|
116
|
+
config?: WalkConfig;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Drives a participant's walk-toward-root registration over the injected router + addressing. */
|
|
120
|
+
export interface WalkEngine {
|
|
121
|
+
/**
|
|
122
|
+
* Walk from `d_max` toward the root registering for `topicId` at op `tier`, following `Promoted`
|
|
123
|
+
* redirects outward. Resolves with the terminal {@link WalkOutcome}. With `opts.probe` the walk is a
|
|
124
|
+
* **read-only lookup**: identical routing discipline, but the terminal cohort classifies rather than
|
|
125
|
+
* admits and the root `no_state` branch backs off instead of issuing a `bootstrap: true` cold-start
|
|
126
|
+
* (a probe never instantiates a cold root).
|
|
127
|
+
*/
|
|
128
|
+
register(topicId: Uint8Array, tier: number, appPayload?: Uint8Array, opts?: { probe?: boolean }): Promise<WalkOutcome>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class RouterWalkEngine implements WalkEngine {
|
|
132
|
+
private readonly wantK: number;
|
|
133
|
+
private readonly minSigs: number;
|
|
134
|
+
private readonly maxMemberRetries: number;
|
|
135
|
+
private readonly followPromoted: boolean;
|
|
136
|
+
private readonly configuredMaxSteps?: number;
|
|
137
|
+
private readonly maxMessageBytes?: number;
|
|
138
|
+
|
|
139
|
+
constructor(private readonly deps: WalkEngineDeps) {
|
|
140
|
+
const cfg = deps.config ?? {};
|
|
141
|
+
this.wantK = cfg.wantK ?? 16;
|
|
142
|
+
this.minSigs = cfg.minSigs ?? 14;
|
|
143
|
+
this.maxMemberRetries = cfg.maxMemberRetries ?? this.wantK;
|
|
144
|
+
this.followPromoted = cfg.followPromoted ?? true;
|
|
145
|
+
this.configuredMaxSteps = cfg.maxSteps;
|
|
146
|
+
this.maxMessageBytes = cfg.maxMessageBytes;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async register(topicId: Uint8Array, tier: number, appPayload?: Uint8Array, opts?: { probe?: boolean }): Promise<WalkOutcome> {
|
|
150
|
+
const dMax = this.deps.dmax.dMax();
|
|
151
|
+
const maxSteps = this.configuredMaxSteps ?? 2 * (dMax + 2) + this.maxMemberRetries + 8;
|
|
152
|
+
const probe = opts?.probe ?? false;
|
|
153
|
+
|
|
154
|
+
let d = dMax;
|
|
155
|
+
let bootstrap = false;
|
|
156
|
+
let memberAttempts = 0;
|
|
157
|
+
let dialTarget: PeerRef | undefined;
|
|
158
|
+
let steps = 0;
|
|
159
|
+
let probeFollowedPromoted = false;
|
|
160
|
+
|
|
161
|
+
for (;;) {
|
|
162
|
+
if (++steps > maxSteps) {
|
|
163
|
+
// Safety valve: a well-formed tree converges well within this bound. Surface a temporal
|
|
164
|
+
// back-off rather than spin.
|
|
165
|
+
return { kind: "retry_later", afterMs: backoffRetryMs(0) };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const reg = await this.deps.factory.build({ topicId, tier, treeTier: d, bootstrap, probe, appPayload });
|
|
169
|
+
const activity = encodeCohortMessage(reg, this.maxMessageBytes);
|
|
170
|
+
const raw = dialTarget !== undefined
|
|
171
|
+
? await this.deps.router.dialMember(dialTarget, activity)
|
|
172
|
+
: await this.deps.router.routeAndAct(this.deps.addressing.coord(d, this.deps.self, topicId), activity, {
|
|
173
|
+
wantK: this.wantK,
|
|
174
|
+
minSigs: this.minSigs,
|
|
175
|
+
});
|
|
176
|
+
const reply = decodeRegisterReplyV1(raw, this.maxMessageBytes);
|
|
177
|
+
|
|
178
|
+
switch (reply.result) {
|
|
179
|
+
case "accepted": {
|
|
180
|
+
return { kind: "accepted", reply };
|
|
181
|
+
}
|
|
182
|
+
case "no_state": {
|
|
183
|
+
// Step toward the root. The cohort served nothing here; no spatial sibling state.
|
|
184
|
+
dialTarget = undefined;
|
|
185
|
+
memberAttempts = 0;
|
|
186
|
+
if (probe && probeFollowedPromoted) {
|
|
187
|
+
// The promoted child is cold (not yet instantiated). A probe never instantiates it,
|
|
188
|
+
// so back off immediately — walking inward to the promoting ancestor would just
|
|
189
|
+
// re-trigger the Promoted redirect and loop.
|
|
190
|
+
return { kind: "retry_later", afterMs: backoffRetryMs(0) };
|
|
191
|
+
}
|
|
192
|
+
const next = d - 1;
|
|
193
|
+
if (next < 0) {
|
|
194
|
+
if (bootstrap) {
|
|
195
|
+
// Already re-issued at the root as a bootstrap and still nothing — no cohort
|
|
196
|
+
// anywhere will instantiate right now. Back off in time.
|
|
197
|
+
return { kind: "retry_later", afterMs: backoffRetryMs(0) };
|
|
198
|
+
}
|
|
199
|
+
if (probe) {
|
|
200
|
+
// A read-only probe never instantiates a cold root: the topic exists nowhere, so
|
|
201
|
+
// resolve "not found / back off" rather than re-issuing with bootstrap:true.
|
|
202
|
+
return { kind: "retry_later", afterMs: backoffRetryMs(0) };
|
|
203
|
+
}
|
|
204
|
+
// Root returned NoState → cold-start: re-issue once at tier 0 with bootstrap:true.
|
|
205
|
+
d = 0;
|
|
206
|
+
bootstrap = true;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
d = next;
|
|
210
|
+
bootstrap = false;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case "promoted": {
|
|
214
|
+
dialTarget = undefined;
|
|
215
|
+
memberAttempts = 0;
|
|
216
|
+
bootstrap = false;
|
|
217
|
+
const targetTier = reply.targetTier ?? d + 1;
|
|
218
|
+
if (probe) {
|
|
219
|
+
probeFollowedPromoted = true;
|
|
220
|
+
}
|
|
221
|
+
if (!this.followPromoted) {
|
|
222
|
+
return { kind: "promoted", targetTier };
|
|
223
|
+
}
|
|
224
|
+
d = targetTier; // the one outward move — recompute coord at the redirect target
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
case "unwilling_member": {
|
|
228
|
+
const candidates = reply.candidateMembers ?? [];
|
|
229
|
+
if (candidates.length === 0 || memberAttempts >= this.maxMemberRetries) {
|
|
230
|
+
// Exhausted the named siblings (or none offered) → fall through to a cohort-level
|
|
231
|
+
// temporal back-off, restarting at d_max on the caller's retry.
|
|
232
|
+
return { kind: "retry_later", afterMs: backoffRetryMs(0) };
|
|
233
|
+
}
|
|
234
|
+
// Retry the SAME coord at a named alternative member (spatial move within the cohort).
|
|
235
|
+
dialTarget = { id: b64urlToBytes(candidates[memberAttempts % candidates.length]!) };
|
|
236
|
+
memberAttempts++;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
case "unwilling_cohort": {
|
|
240
|
+
// Back off in TIME, no spatial move; the caller restarts at d_max after the delay.
|
|
241
|
+
return { kind: "retry_later", afterMs: reply.retryAfterMs ?? backoffRetryMs(0) };
|
|
242
|
+
}
|
|
243
|
+
default: {
|
|
244
|
+
// Exhaustive over RegisterResult; an unknown result is treated as a temporal decline.
|
|
245
|
+
return { kind: "retry_later", afterMs: backoffRetryMs(0) };
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Build a {@link WalkEngine} over the injected router, addressing, `d_max`, and message factory. */
|
|
253
|
+
export function createWalkEngine(deps: WalkEngineDeps): WalkEngine {
|
|
254
|
+
return new RouterWalkEngine(deps);
|
|
255
|
+
}
|