@optimystic/db-core 0.13.4 → 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 +29 -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 +19 -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 +44 -2
- package/dist/src/transactor/network-transactor.d.ts.map +1 -1
- package/dist/src/transactor/network-transactor.js +132 -17
- package/dist/src/transactor/network-transactor.js.map +1 -1
- package/package.json +3 -2
- package/src/cluster/structs.ts +86 -57
- 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 +19 -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 +162 -19
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cohort-topic substrate — correlation-id replay guard (anti-DoS).
|
|
3
|
+
*
|
|
4
|
+
* Transcribed from `docs/cohort-topic.md` §Anti-DoS bullet 3. Every `RegisterV1` carries a
|
|
5
|
+
* `correlationId` (16 random bytes) and a signature over `(topicId, tier, correlationId, timestamp)`.
|
|
6
|
+
* The signature (verified elsewhere — the participant-key check) proves authorship; this guard adds
|
|
7
|
+
* **freshness**: it drops a registration whose `timestamp` is outside the accepted skew window
|
|
8
|
+
* (stale, or implausibly far in the future) and drops a `correlationId` it has already seen inside the
|
|
9
|
+
* window (a captured-and-replayed registration).
|
|
10
|
+
*
|
|
11
|
+
* Because a stale registration is rejected outright, the guard only needs to remember correlation ids
|
|
12
|
+
* for one `maxAgeMs` window: an id older than that would be rejected on timestamp alone, so its record
|
|
13
|
+
* can be pruned. Pruning runs on access, bounding memory to the live window's worth of registrations.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { bytesKey } from "../registration/bytes.js";
|
|
17
|
+
import { createLogger } from "../../logger.js";
|
|
18
|
+
|
|
19
|
+
const log = createLogger("cohort-topic:antidos");
|
|
20
|
+
|
|
21
|
+
/** Default acceptance window: a registration timestamped older than this (relative to `now`) is stale. */
|
|
22
|
+
export const DEFAULT_REPLAY_MAX_AGE_MS = 60_000;
|
|
23
|
+
/** Default tolerated forward clock skew: a timestamp this far past `now` is rejected as implausible. */
|
|
24
|
+
export const DEFAULT_REPLAY_MAX_FUTURE_SKEW_MS = 5_000;
|
|
25
|
+
|
|
26
|
+
export interface CorrelationReplayGuardConfig {
|
|
27
|
+
/** A timestamp older than `now − maxAgeMs` is stale. Default {@link DEFAULT_REPLAY_MAX_AGE_MS}. */
|
|
28
|
+
maxAgeMs?: number;
|
|
29
|
+
/** A timestamp newer than `now + maxFutureSkewMs` is rejected. Default {@link DEFAULT_REPLAY_MAX_FUTURE_SKEW_MS}. */
|
|
30
|
+
maxFutureSkewMs?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Freshness + anti-replay gate over registration `correlationId`s and timestamps. */
|
|
34
|
+
export interface CorrelationReplayGuard {
|
|
35
|
+
/**
|
|
36
|
+
* Accept `correlationId` (from `peerId`, stamped `timestamp`) evaluated at `now`. Returns `false`
|
|
37
|
+
* — and records nothing — when the timestamp is stale or implausibly future, or when this
|
|
38
|
+
* `correlationId` was already accepted inside the window (replay). Returns `true` and remembers the
|
|
39
|
+
* id on first sight of a fresh registration.
|
|
40
|
+
*/
|
|
41
|
+
accept(correlationId: Uint8Array, peerId: Uint8Array, timestamp: number, now: number): boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A remembered acceptance, kept until its timestamp ages out of the window. */
|
|
45
|
+
interface SeenEntry {
|
|
46
|
+
timestamp: number;
|
|
47
|
+
peer: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class WindowedReplayGuard implements CorrelationReplayGuard {
|
|
51
|
+
private readonly seen = new Map<string, SeenEntry>();
|
|
52
|
+
private readonly maxAgeMs: number;
|
|
53
|
+
private readonly maxFutureSkewMs: number;
|
|
54
|
+
/** `now` of the last prune, so pruning amortizes rather than scanning on every call. */
|
|
55
|
+
private lastPruneAt = -Infinity;
|
|
56
|
+
|
|
57
|
+
constructor(config: CorrelationReplayGuardConfig = {}) {
|
|
58
|
+
this.maxAgeMs = config.maxAgeMs ?? DEFAULT_REPLAY_MAX_AGE_MS;
|
|
59
|
+
if (!(this.maxAgeMs > 0)) {
|
|
60
|
+
throw new RangeError(`maxAgeMs must be > 0, got ${this.maxAgeMs}`);
|
|
61
|
+
}
|
|
62
|
+
this.maxFutureSkewMs = config.maxFutureSkewMs ?? DEFAULT_REPLAY_MAX_FUTURE_SKEW_MS;
|
|
63
|
+
if (!(this.maxFutureSkewMs >= 0)) {
|
|
64
|
+
throw new RangeError(`maxFutureSkewMs must be >= 0, got ${this.maxFutureSkewMs}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
accept(correlationId: Uint8Array, peerId: Uint8Array, timestamp: number, now: number): boolean {
|
|
69
|
+
if (timestamp < now - this.maxAgeMs) {
|
|
70
|
+
log("replay-guard reject: stale timestamp age=%d > maxAge=%d", now - timestamp, this.maxAgeMs);
|
|
71
|
+
return false; // stale
|
|
72
|
+
}
|
|
73
|
+
if (timestamp > now + this.maxFutureSkewMs) {
|
|
74
|
+
log("replay-guard reject: future timestamp skew=%d > maxSkew=%d", timestamp - now, this.maxFutureSkewMs);
|
|
75
|
+
return false; // implausibly future
|
|
76
|
+
}
|
|
77
|
+
this.maybePrune(now);
|
|
78
|
+
const key = bytesKey(correlationId);
|
|
79
|
+
const prior = this.seen.get(key);
|
|
80
|
+
if (prior !== undefined) {
|
|
81
|
+
// Attribute the replay to the *original* accepter: the correlationId (not the peer id) is the
|
|
82
|
+
// anti-replay key, so a replayer that spoofs a different source id is still caught here.
|
|
83
|
+
log("replay-guard reject: replayed correlationId (first seen from peer=%s)", prior.peer);
|
|
84
|
+
return false; // replay
|
|
85
|
+
}
|
|
86
|
+
this.seen.set(key, { timestamp, peer: bytesKey(peerId) });
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Forget ids whose timestamp has aged past the window — they would be rejected as stale anyway. */
|
|
91
|
+
private maybePrune(now: number): void {
|
|
92
|
+
// Amortize: prune at most once per window rather than scanning on every accept.
|
|
93
|
+
if (now - this.lastPruneAt < this.maxAgeMs) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.lastPruneAt = now;
|
|
97
|
+
const cutoff = now - this.maxAgeMs;
|
|
98
|
+
for (const [key, entry] of this.seen) {
|
|
99
|
+
if (entry.timestamp < cutoff) {
|
|
100
|
+
this.seen.delete(key);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Build a {@link CorrelationReplayGuard} over the configured staleness window and forward skew. */
|
|
107
|
+
export function createCorrelationReplayGuard(config: CorrelationReplayGuardConfig = {}): CorrelationReplayGuard {
|
|
108
|
+
return new WindowedReplayGuard(config);
|
|
109
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cohort-topic substrate — per-cohort topic budget (anti-DoS).
|
|
3
|
+
*
|
|
4
|
+
* Transcribed from `docs/cohort-topic.md` §Anti-DoS bullet 2. A cohort holds forwarder state for at
|
|
5
|
+
* most `topics_max` (default 2048) topics. Once the budget is full a request to instantiate a **new**
|
|
6
|
+
* topic is refused (the caller answers `UnwillingCohort`); topics already in the budget continue to
|
|
7
|
+
* serve. To keep room for genuinely active topics, the budget evicts cold ones: eviction order is
|
|
8
|
+
* **LRU by participant count**, with **zero-recent-registration topics dropped first** — a topic that
|
|
9
|
+
* carries no direct participants is the cheapest to shed and is shed before any populated topic.
|
|
10
|
+
*
|
|
11
|
+
* `admit` only ever evicts a *zero-participant* topic. If every resident topic still carries
|
|
12
|
+
* participants the budget is genuinely saturated and the new instantiation is refused — an attacker
|
|
13
|
+
* cannot, by flooding new topic ids, evict a topic that real participants are using. LRU ordering
|
|
14
|
+
* uses a monotonic access counter bumped on every `admit`/`touch`, so it is deterministic and needs
|
|
15
|
+
* no wall clock.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { bytesKey } from "../registration/bytes.js";
|
|
19
|
+
import { createLogger } from "../../logger.js";
|
|
20
|
+
|
|
21
|
+
const log = createLogger("cohort-topic:antidos");
|
|
22
|
+
|
|
23
|
+
/** Default per-cohort forwarder-topic ceiling — `topics_max`. */
|
|
24
|
+
export const DEFAULT_TOPICS_MAX = 2048;
|
|
25
|
+
|
|
26
|
+
export interface TopicBudgetConfig {
|
|
27
|
+
/** Max topics with forwarder state. Default {@link DEFAULT_TOPICS_MAX}. */
|
|
28
|
+
topicsMax?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Per-cohort cap on the number of topics with forwarder state, with LRU eviction of cold topics. */
|
|
32
|
+
export interface TopicBudget {
|
|
33
|
+
/**
|
|
34
|
+
* Admit `topicId` to the forwarder-state budget. Returns `true` if it is already resident or there
|
|
35
|
+
* is (or can be freed) room; `false` when the budget is full of populated topics, in which case the
|
|
36
|
+
* caller answers `UnwillingCohort` for the new instantiation. Admitting a *new* topic when full
|
|
37
|
+
* evicts the coldest zero-participant resident first.
|
|
38
|
+
*/
|
|
39
|
+
admit(topicId: Uint8Array): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Record the current direct-participant count for a resident topic (LRU bookkeeping). Updates the
|
|
42
|
+
* eviction key and bumps the topic's recency; a no-op for a topic that is not resident.
|
|
43
|
+
*/
|
|
44
|
+
touch(topicId: Uint8Array, participantCount: number): void;
|
|
45
|
+
/** Whether `topicId` currently holds forwarder state. */
|
|
46
|
+
has(topicId: Uint8Array): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The direct-participant count last reported for a resident `topicId` (the eviction key), or
|
|
49
|
+
* `undefined` when the topic is not resident. A resident reporting `0` is cold/evictable. Read-only
|
|
50
|
+
* introspection for tests/diagnostics — eviction policy reads the same field internally.
|
|
51
|
+
*/
|
|
52
|
+
participantCount(topicId: Uint8Array): number | undefined;
|
|
53
|
+
/** Number of resident topics. */
|
|
54
|
+
readonly size: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Per-resident eviction bookkeeping. */
|
|
58
|
+
interface ResidentState {
|
|
59
|
+
/** Direct-participant count last reported via `touch` (eviction primary key; ascending = colder). */
|
|
60
|
+
participantCount: number;
|
|
61
|
+
/** Monotonic access sequence (LRU tiebreaker; lower = least-recently used). */
|
|
62
|
+
seq: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class LruTopicBudget implements TopicBudget {
|
|
66
|
+
private readonly residents = new Map<string, ResidentState>();
|
|
67
|
+
private readonly topicsMax: number;
|
|
68
|
+
private seqCounter = 0;
|
|
69
|
+
|
|
70
|
+
constructor(config: TopicBudgetConfig = {}) {
|
|
71
|
+
this.topicsMax = config.topicsMax ?? DEFAULT_TOPICS_MAX;
|
|
72
|
+
if (!Number.isInteger(this.topicsMax) || this.topicsMax <= 0) {
|
|
73
|
+
throw new RangeError(`topicsMax must be a positive integer, got ${this.topicsMax}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get size(): number {
|
|
78
|
+
return this.residents.size;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
has(topicId: Uint8Array): boolean {
|
|
82
|
+
return this.residents.has(bytesKey(topicId));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
participantCount(topicId: Uint8Array): number | undefined {
|
|
86
|
+
return this.residents.get(bytesKey(topicId))?.participantCount;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
admit(topicId: Uint8Array): boolean {
|
|
90
|
+
const key = bytesKey(topicId);
|
|
91
|
+
const existing = this.residents.get(key);
|
|
92
|
+
if (existing !== undefined) {
|
|
93
|
+
existing.seq = ++this.seqCounter; // already resident — refresh recency, always allowed
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (this.residents.size < this.topicsMax) {
|
|
97
|
+
this.residents.set(key, { participantCount: 0, seq: ++this.seqCounter });
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
// Full: only a zero-participant resident may be evicted to make room for a new topic.
|
|
101
|
+
const victim = this.coldestEvictable();
|
|
102
|
+
if (victim === undefined) {
|
|
103
|
+
log("topic-budget full size=%d max=%d — refuse new topic", this.residents.size, this.topicsMax);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
this.residents.delete(victim);
|
|
107
|
+
this.residents.set(key, { participantCount: 0, seq: ++this.seqCounter });
|
|
108
|
+
log("topic-budget evicted cold topic to admit new (size=%d max=%d)", this.residents.size, this.topicsMax);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
touch(topicId: Uint8Array, participantCount: number): void {
|
|
113
|
+
const key = bytesKey(topicId);
|
|
114
|
+
const state = this.residents.get(key);
|
|
115
|
+
if (state === undefined) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
state.participantCount = participantCount;
|
|
119
|
+
state.seq = ++this.seqCounter;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The coldest evictable resident key: among zero-participant topics, the least-recently used.
|
|
124
|
+
* `undefined` when every resident still carries participants (nothing may be evicted for a new topic).
|
|
125
|
+
*/
|
|
126
|
+
private coldestEvictable(): string | undefined {
|
|
127
|
+
let victim: string | undefined;
|
|
128
|
+
let victimSeq = Infinity;
|
|
129
|
+
for (const [key, state] of this.residents) {
|
|
130
|
+
if (state.participantCount > 0) {
|
|
131
|
+
continue; // populated topics continue — never evicted for a new instantiation
|
|
132
|
+
}
|
|
133
|
+
if (state.seq < victimSeq) {
|
|
134
|
+
victim = key;
|
|
135
|
+
victimSeq = state.seq;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return victim;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Build a {@link TopicBudget} over the configured `topics_max`. */
|
|
143
|
+
export function createTopicBudget(config: TopicBudgetConfig = {}): TopicBudget {
|
|
144
|
+
return new LruTopicBudget(config);
|
|
145
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cohort-topic substrate — anti-flood structural invariants (centralized for the e2e suite).
|
|
3
|
+
*
|
|
4
|
+
* Transcribed from `docs/cohort-topic.md` §Anti-flood properties. Three of the five named floods are
|
|
5
|
+
* defended *by construction* in the walk / promotion machinery already; this module does not
|
|
6
|
+
* re-implement that machinery — it provides pure, dependency-free predicates over a recorded walk
|
|
7
|
+
* trace so the unit and e2e suites can assert the invariants hold on the real engine's behaviour,
|
|
8
|
+
* the same way `packages/substrate-simulator/src/walk-metrics.ts` instruments
|
|
9
|
+
* `outwardMovesArePromoted` / `unwillingRetriesRestartAtDMax` on the simulator side.
|
|
10
|
+
*
|
|
11
|
+
* The caller records one {@link WalkProbe} per probe RPC the {@link import("../walk.js").WalkEngine}
|
|
12
|
+
* issues (its `treeTier` and the reply `result`), grouping the probes of one
|
|
13
|
+
* {@link import("../walk.js").WalkEngine.register} call into a {@link WalkTrace}. The predicates then
|
|
14
|
+
* check the anti-flood discipline:
|
|
15
|
+
*
|
|
16
|
+
* - **claim 3 — no speculative outward probe:** {@link outwardMovesArePromoted}. The only tier
|
|
17
|
+
* *increase* between consecutive probes is one taken immediately after a `promoted` reply.
|
|
18
|
+
* - **walk discipline — inward only on `no_state`:** {@link inwardStepsFollowNoState}. Every single
|
|
19
|
+
* tier *decrease* is the response to a `no_state` (no inward move on any other reply).
|
|
20
|
+
* - **claim 4 — inward retry restarts at `d_max`:** {@link retriesRestartAtDMax}. A fresh walk (the
|
|
21
|
+
* restart after an `unwilling_cohort` / cohort-level back-off) begins at `d_max`, never re-hitting
|
|
22
|
+
* the declined coord.
|
|
23
|
+
* - **claim 5 — sticky promotion:** {@link DEFAULT_T_PROMOTE_STICKY_MS} re-exported as the canonical
|
|
24
|
+
* sticky window; the promotion lifecycle (`promotion.ts`) enforces it and `promotion.spec.ts`
|
|
25
|
+
* covers the no-flap behaviour. {@link stickyHolds} is the predicate the e2e suite uses to confirm
|
|
26
|
+
* a freshly-promoted cohort refuses demotion within the window.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import type { RegisterResult } from "../wire/types.js";
|
|
30
|
+
import { DEFAULT_T_PROMOTE_STICKY_MS } from "../promotion.js";
|
|
31
|
+
|
|
32
|
+
export { DEFAULT_T_PROMOTE_STICKY_MS };
|
|
33
|
+
|
|
34
|
+
/** One probe RPC in a walk: the tier it was issued at and the reply result it drew. */
|
|
35
|
+
export interface WalkProbe {
|
|
36
|
+
/** Walk position `d` the probe was issued at. */
|
|
37
|
+
readonly treeTier: number;
|
|
38
|
+
/** The cohort reply classification. */
|
|
39
|
+
readonly result: RegisterResult;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The ordered probe log of a single {@link import("../walk.js").WalkEngine.register} call. */
|
|
43
|
+
export interface WalkTrace {
|
|
44
|
+
/** `d_max` the walk started from. */
|
|
45
|
+
readonly dMax: number;
|
|
46
|
+
/** Probes in issue order. */
|
|
47
|
+
readonly probes: readonly WalkProbe[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Claim 3 (no speculative outward probe): every tier *increase* between consecutive probes is taken
|
|
52
|
+
* only in response to a `promoted` redirect on the preceding probe. Any outward move not preceded by
|
|
53
|
+
* `promoted` is a speculative deeper probe — the flood this invariant forbids.
|
|
54
|
+
*/
|
|
55
|
+
export function outwardMovesArePromoted(trace: WalkTrace): boolean {
|
|
56
|
+
const { probes } = trace;
|
|
57
|
+
for (let i = 1; i < probes.length; i++) {
|
|
58
|
+
const moveOutward = probes[i]!.treeTier > probes[i - 1]!.treeTier;
|
|
59
|
+
if (moveOutward && probes[i - 1]!.result !== "promoted") {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Walk discipline: every single inward step (`treeTier` decreased by exactly 1, or reset to 0 at the
|
|
68
|
+
* root cold-start) is the response to a `no_state`. The walk never moves toward the root on any other
|
|
69
|
+
* reply, so inward traffic is one-hop-per-`no_state`, not a storm.
|
|
70
|
+
*/
|
|
71
|
+
export function inwardStepsFollowNoState(trace: WalkTrace): boolean {
|
|
72
|
+
const { probes } = trace;
|
|
73
|
+
for (let i = 1; i < probes.length; i++) {
|
|
74
|
+
const moveInward = probes[i]!.treeTier < probes[i - 1]!.treeTier;
|
|
75
|
+
if (moveInward && probes[i - 1]!.result !== "no_state") {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Claim 4 (inward retry restarts at `d_max`): each fresh walk in a re-registration sequence starts at
|
|
84
|
+
* its `d_max`, so a participant that drew `unwilling_cohort` backs off in *time* and re-walks from the
|
|
85
|
+
* top rather than re-hitting the declined coord. `traces` are consecutive `register` calls by one
|
|
86
|
+
* participant; the first probe of each must sit at that walk's `d_max`.
|
|
87
|
+
*/
|
|
88
|
+
export function retriesRestartAtDMax(traces: readonly WalkTrace[]): boolean {
|
|
89
|
+
for (const trace of traces) {
|
|
90
|
+
const first = trace.probes[0];
|
|
91
|
+
if (first === undefined) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (first.treeTier !== trace.dMax) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Claim 5 (sticky promotion): a cohort promoted at `promotedAt` must not be reconsidered for demotion
|
|
103
|
+
* before `promotedAt + stickyMs`. Returns whether `now` is still inside the sticky window — the e2e
|
|
104
|
+
* suite asserts the promotion lifecycle refuses demotion exactly while this is `true`.
|
|
105
|
+
*/
|
|
106
|
+
export function stickyHolds(promotedAt: number, now: number, stickyMs: number = DEFAULT_T_PROMOTE_STICKY_MS): boolean {
|
|
107
|
+
return now - promotedAt < stickyMs;
|
|
108
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cohort-topic substrate — re-registration jitter (anti-flood claim 2).
|
|
3
|
+
*
|
|
4
|
+
* Transcribed from `docs/cohort-topic.md` §Anti-flood properties (claim 2: "Re-registration storm
|
|
5
|
+
* after cohort failure") and folded back from the simulator-validated
|
|
6
|
+
* `packages/substrate-simulator/src/walk.ts` (`rejoinStagger` / `rateLimitedStagger`). When a cohort
|
|
7
|
+
* fails, every participant it served re-registers at once; without staggering, the recovering or
|
|
8
|
+
* replacement cohort takes the whole wave in a single instant and is shoved straight past
|
|
9
|
+
* `cap_promote`. Spreading the wave over `T_rejoin_jitter` (default 30 s, widened with the observed
|
|
10
|
+
* FRET cohort-failure rate) bounds the recovering cohort's inbound rate to
|
|
11
|
+
* `cap_promote / T_rejoin_jitter`.
|
|
12
|
+
*
|
|
13
|
+
* Two staggering forms, both exposed here:
|
|
14
|
+
* - {@link RejoinJitter.scheduleRejoin} — a single participant draws a uniform offset over the
|
|
15
|
+
* jitter window. Decorrelates one participant's retry from its peers (the production API: a
|
|
16
|
+
* participant that loses its cohort calls this once). Random, so the bound holds *in expectation*.
|
|
17
|
+
* - {@link RejoinJitter.scheduleWave} — a whole wave of `count` rejoiners is placed at a fixed
|
|
18
|
+
* interval `windowMs / cap_promote`, so **any** `windowMs`-long window contains at most
|
|
19
|
+
* `cap_promote` arrivals *by construction*. This is the hard-bound form the e2e suite asserts
|
|
20
|
+
* against; it widens the span past one window when `count > cap_promote` so the rate ceiling
|
|
21
|
+
* `cap_promote / T_rejoin_jitter` is never exceeded.
|
|
22
|
+
*
|
|
23
|
+
* This module is FRET-free and side-effect-free apart from the injected RNG: the caller schedules a
|
|
24
|
+
* timer at the returned timestamp.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { createLogger } from "../../logger.js";
|
|
28
|
+
|
|
29
|
+
const log = createLogger("cohort-topic:antiflood");
|
|
30
|
+
|
|
31
|
+
/** Default jitter window `T_rejoin_jitter` (ms) — `docs/cohort-topic.md` §Configuration. */
|
|
32
|
+
export const DEFAULT_T_REJOIN_JITTER_MS = 30_000;
|
|
33
|
+
/** Default `cap_promote` — sets the inbound-rate ceiling `cap_promote / T_rejoin_jitter`. */
|
|
34
|
+
export const DEFAULT_REJOIN_CAP_PROMOTE = 64;
|
|
35
|
+
|
|
36
|
+
export interface RejoinJitterConfig {
|
|
37
|
+
/** Base jitter window `T_rejoin_jitter` (ms). Default {@link DEFAULT_T_REJOIN_JITTER_MS}. */
|
|
38
|
+
tRejoinJitterMs?: number;
|
|
39
|
+
/** Acceptance ceiling per window; the rate bound is `capPromote / T_rejoin_jitter`. Default 64. */
|
|
40
|
+
capPromote?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Multiplier applied to the base window to track the observed FRET cohort-failure rate (claim 2:
|
|
43
|
+
* "scaled with cohort failure rate observed from FRET"). A higher failure rate → a wider window so
|
|
44
|
+
* the larger expected re-registration wave still respects the rate ceiling. Default 1 (steady FRET).
|
|
45
|
+
*/
|
|
46
|
+
failureRateScale?: number;
|
|
47
|
+
/** Uniform RNG in `[0, 1)`. Injected for determinism in tests; defaults to `Math.random`. */
|
|
48
|
+
random?: () => number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Staggers post-cohort-failure re-registration so the recovering cohort isn't stormed. */
|
|
52
|
+
export interface RejoinJitter {
|
|
53
|
+
/**
|
|
54
|
+
* Jittered re-registration timestamp for **one** participant: `now + ⌊U[0, windowMs)⌋`. Random,
|
|
55
|
+
* so a wave of independent callers spreads roughly uniformly over the window.
|
|
56
|
+
*/
|
|
57
|
+
scheduleRejoin(now: number): number;
|
|
58
|
+
/**
|
|
59
|
+
* Rate-bounded timestamps for a whole re-registration wave of `count` participants. Arrivals are
|
|
60
|
+
* evenly spaced at `windowMs / capPromote`, so any `windowMs`-long sliding window holds at most
|
|
61
|
+
* `capPromote` of them — the `cap_promote / T_rejoin_jitter` ceiling, exactly rather than in
|
|
62
|
+
* expectation. Returns one timestamp per participant, ascending.
|
|
63
|
+
*/
|
|
64
|
+
scheduleWave(count: number, now: number): number[];
|
|
65
|
+
/** Effective jitter window (ms) = base `T_rejoin_jitter` × `failureRateScale`. */
|
|
66
|
+
readonly windowMs: number;
|
|
67
|
+
/** Per-window acceptance ceiling (`capPromote`); the inbound-rate bound's numerator. */
|
|
68
|
+
readonly capPromote: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class StaggeredRejoinJitter implements RejoinJitter {
|
|
72
|
+
readonly windowMs: number;
|
|
73
|
+
readonly capPromote: number;
|
|
74
|
+
private readonly random: () => number;
|
|
75
|
+
|
|
76
|
+
constructor(config: RejoinJitterConfig = {}) {
|
|
77
|
+
const base = config.tRejoinJitterMs ?? DEFAULT_T_REJOIN_JITTER_MS;
|
|
78
|
+
if (!(base > 0)) {
|
|
79
|
+
throw new RangeError(`tRejoinJitterMs must be > 0, got ${base}`);
|
|
80
|
+
}
|
|
81
|
+
const scale = config.failureRateScale ?? 1;
|
|
82
|
+
if (!(scale >= 1)) {
|
|
83
|
+
throw new RangeError(`failureRateScale must be >= 1, got ${scale}`);
|
|
84
|
+
}
|
|
85
|
+
this.capPromote = config.capPromote ?? DEFAULT_REJOIN_CAP_PROMOTE;
|
|
86
|
+
if (!Number.isInteger(this.capPromote) || this.capPromote <= 0) {
|
|
87
|
+
throw new RangeError(`capPromote must be a positive integer, got ${this.capPromote}`);
|
|
88
|
+
}
|
|
89
|
+
this.windowMs = base * scale;
|
|
90
|
+
this.random = config.random ?? ((): number => Math.random());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
scheduleRejoin(now: number): number {
|
|
94
|
+
const offset = Math.floor(this.random() * this.windowMs);
|
|
95
|
+
return now + offset;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
scheduleWave(count: number, now: number): number[] {
|
|
99
|
+
if (!Number.isInteger(count) || count < 0) {
|
|
100
|
+
throw new RangeError(`count must be a non-negative integer, got ${count}`);
|
|
101
|
+
}
|
|
102
|
+
// Even spacing at windowMs/capPromote guarantees ≤ capPromote arrivals in any windowMs window;
|
|
103
|
+
// for count > capPromote the wave necessarily spans more than one window, holding the rate.
|
|
104
|
+
const interval = this.windowMs / this.capPromote;
|
|
105
|
+
const out = new Array<number>(count);
|
|
106
|
+
for (let i = 0; i < count; i++) {
|
|
107
|
+
out[i] = now + Math.floor(i * interval);
|
|
108
|
+
}
|
|
109
|
+
log("scheduleWave count=%d window=%d cap=%d span=%d", count, this.windowMs, this.capPromote, count > 0 ? out[count - 1]! - now : 0);
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Build a {@link RejoinJitter} over the configured window, rate ceiling, and (test-injectable) RNG. */
|
|
115
|
+
export function createRejoinJitter(config: RejoinJitterConfig = {}): RejoinJitter {
|
|
116
|
+
return new StaggeredRejoinJitter(config);
|
|
117
|
+
}
|