Skip to content

activator,sdk: add topology event handler and update Python/TypeScript SDKs for RFC-18#3514

Open
ben-malbeclabs wants to merge 5 commits intobc/rfc18-pr2from
bc/rfc18-pr4
Open

activator,sdk: add topology event handler and update Python/TypeScript SDKs for RFC-18#3514
ben-malbeclabs wants to merge 5 commits intobc/rfc18-pr2from
bc/rfc18-pr4

Conversation

@ben-malbeclabs
Copy link
Copy Markdown
Contributor

@ben-malbeclabs ben-malbeclabs commented Apr 10, 2026

RFC-18 flex-algo · PR 4 of 5 · see rfcs/rfc-0018-flex-algo.md
Depends on: #3512 (PR 2)
Series: #3497 · #3512 · #3513 · #3514 · #3515

Summary of Changes

  • Adds process_topology_event to the activator: when a TopologyInfo account is created or updated, the activator calls BackfillTopology on all devices that have an activated VPNv4 loopback (idempotent — skips devices that already have a segment for this topology)
  • Adds --enable-flex-algo flag to the activator (default: off); topology events are ignored unless the flag is set
  • Updates Python SDK to deserialize TopologyConstraint, TopologyInfo, and FlexAlgoNodeSegment, and reads flex_algo_node_segments from V2 interface accounts
  • Updates TypeScript SDK to deserialize FlexAlgoNodeSegment from V2 interface accounts and adds a configurable request timeout to the RPC client
  • Updates binary fixtures for device, link, and tenant accounts to include the new V2 interface format fields

Diff Breakdown

Category Files Lines (+/-) Net
Core logic 7 +308 / -28 +280
Scaffolding 5 +16 / -0 +16
Tests 1 +3 / -2 +1
Fixtures 4 Bin changes

Mostly core logic concentrated in the new topology event handler and Python SDK deserialization.

Key files (click to expand)
  • activator/src/process/topology.rs — new: topology event handler; lists all active devices, filters to those with activated VPNv4 loopbacks, batches BackfillTopology calls
  • activator/src/process/iface_mgr.rs — calls backfill after a VPNv4 loopback is activated, so newly provisioned devices immediately get node segments for existing topologies
  • activator/src/process/device.rs — topology-aware device processing
  • activator/src/processor.rs — wires in process_topology_event for AccountData::Topology events; adds enable_flex_algo guard
  • sdk/serviceability/python/serviceability/state.py — adds TopologyConstraint enum, TopologyInfo dataclass, FlexAlgoNodeSegment dataclass; reads flex_algo_node_segments vec from V2 interface accounts
  • sdk/serviceability/typescript/serviceability/state.ts — adds FlexAlgoNodeSegment type; reads it from V2 interface accounts
  • sdk/serviceability/typescript/serviceability/rpc.ts — adds configurable request timeout

Testing Verification

  • cargo test -p doublezero-activator — 76 tests pass
  • Python SDK: 115 tests pass (pytest, including fixture deserialization)
  • TypeScript SDK: 138 tests pass (bun test, including fixture deserialization)
  • cargo clippy -- -D warnings clean after fixing for_kv_map lint in topology.rs

@ben-malbeclabs ben-malbeclabs marked this pull request as ready for review April 15, 2026 04:00
elitegreg added a commit that referenced this pull request Apr 18, 2026
…y processors (#3497)

RFC-18 flex-algo · PR 1 of 5 · see `rfcs/rfc-0018-flex-algo.md`
Series: #3497 · #3512 · #3513 · #3514 · #3515

## Summary of Changes
- Adds `TopologyInfo` onchain account (RFC-18 flex-algo) with
`admin_group_bit`, `flex_algo_number`, and `TopologyConstraint`; creates
`AdminGroupBits` resource extension singleton for bit allocation
- Adds four new foundation-only instructions (107–110):
`CreateTopology`, `DeleteTopology`, `ClearTopology`, `BackfillTopology`
- Extends `Link` with `link_topologies` (Vec<Pubkey>) and `link_flags`
(LINK_FLAG_UNICAST_DRAINED); extends `Tenant` with `include_topologies`;
adds `flex_algo_node_segments` to Interface V2
- `CreateLink` now requires the unicast-default topology account and
auto-tags the link into it
- `UpdateLink` gains foundation-gated `link_topologies` update and
contributor-gated `unicast_drained` flag

## Diff Breakdown
| Category    | Files | Lines (+/-)   | Net   |
|-------------|-------|---------------|-------|
| Core logic  |    22 | +1,306 / -38  | +1,268|
| Scaffolding |    49 | +133 / -3     |  +130 |
| Tests       |    27 | +4,592 / -74  | +4,518|

The scaffolding is mechanical struct field additions (`link_topologies:
vec![]`, `include_topologies: vec![]`, `flex_algo_node_segments:
vec![]`) across CLI, SDK, activator, and client to keep the workspace
compiling. Core logic is concentrated in the new topology processors,
state types, and link/activate updates.

<details>
<summary>Key files (click to expand)</summary>

-
`smartcontract/programs/doublezero-serviceability/src/state/interface.rs`
— updates Interface V2 (discriminant 1) to include
`flex_algo_node_segments: Vec<FlexAlgoNodeSegment>`; V1 accounts
(pre-CYOA format) are left as-is; pre-RFC-18 V2 accounts on mainnet are
upgraded in-place by `MigrateDeviceInterfaces` before this
deserialization path is used
-
`smartcontract/programs/doublezero-serviceability/src/state/topology.rs`
— new `TopologyInfo` account: `admin_group_bit` (u8), `flex_algo_number`
(128+bit), `TopologyConstraint` (IncludeAny/Exclude)
-
`smartcontract/programs/doublezero-serviceability/src/processors/topology/`
— five new processors: create (allocates AdminGroupBit, validates
IdRange 1–127), delete, clear (removes topology from all links),
backfill (allocates FlexAlgoNodeSegment on all device interfaces)
-
`smartcontract/programs/doublezero-serviceability/src/processors/link/update.rs`
— adds foundation-gated `link_topologies` update (validates each
topology account onchain) and contributor-gated `unicast_drained` flag
(LINK_FLAG_UNICAST_DRAINED bit 0)
-
`smartcontract/programs/doublezero-serviceability/src/processors/link/activate.rs`
— requires `unicast_default_topology_account` as a mandatory account;
auto-tags new link into the unicast-default topology on activation
-
`smartcontract/programs/doublezero-serviceability/src/processors/globalconfig/set.rs`
— creates `AdminGroupBits` ResourceExtension PDA on global config
initialization
- `smartcontract/programs/doublezero-serviceability/src/state/link.rs` —
adds `link_topologies: Vec<Pubkey>`, `link_flags: u64`, and
`LINK_FLAG_UNICAST_DRAINED = 0x01`
- `smartcontract/programs/doublezero-serviceability/src/instructions.rs`
— registers four new instruction variants (CreateTopology=107,
DeleteTopology=108, ClearTopology=109, BackfillTopology=110)

</details>

## Testing Verification
- `make rust-lint` and `make rust-test` pass clean on this branch
- `topology_test.rs` (~2,400 lines) covers all four topology processors:
create/delete/clear/backfill, including error paths (duplicate names,
out-of-range bits, unauthorized signers, invalid topology accounts),
segment allocation, and multi-topology backfill
- Existing `link_wan_test.rs`, `tenant_test.rs`, and telemetry tests
updated to account for the new mandatory
`unicast_default_topology_account` in `ActivateLink`

---------

Co-authored-by: Greg Mitchell <greg@malbeclabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant