Skip to content

smartcontract: add TopologyInfo account, flex-algo state, and topology processors#3497

Merged
elitegreg merged 19 commits intomainfrom
bc/rfc18-pr1
Apr 18, 2026
Merged

smartcontract: add TopologyInfo account, flex-algo state, and topology processors#3497
elitegreg merged 19 commits intomainfrom
bc/rfc18-pr1

Conversation

@ben-malbeclabs
Copy link
Copy Markdown
Contributor

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

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) and link_flags (LINK_FLAG_UNICAST_DRAINED); extends Tenant with include_topologies; adds flex_algo_node_segments to Interface V2
  • ActivateLink 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.

Key files (click to expand)
  • 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)

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

@ben-malbeclabs ben-malbeclabs force-pushed the bc/rfc18-pr1 branch 5 times, most recently from 76986c3 to a1a2260 Compare April 9, 2026 21:56
@ben-malbeclabs ben-malbeclabs force-pushed the bc/rfc18-pr1 branch 2 times, most recently from 95364cc to 211dd11 Compare April 15, 2026 01:07
@ben-malbeclabs ben-malbeclabs marked this pull request as ready for review April 15, 2026 04:00
Copy link
Copy Markdown
Contributor

@elitegreg elitegreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I told you to consolidate InterfaceV3 into InterfaceV2. Claude actually got it right the first time. Interface is not like our other accounts, and therefore doesn't support adding new fields to the end.

Comment thread e2e/compatibility_test.go
Comment thread smartcontract/programs/doublezero-serviceability/src/processors/link/activate.rs Outdated
Comment thread smartcontract/programs/doublezero-serviceability/src/processors/link/update.rs Outdated
Comment thread smartcontract/programs/doublezero-serviceability/src/state/topology.rs Outdated
Comment thread smartcontract/programs/doublezero-serviceability/src/state/link.rs Outdated
ben-malbeclabs and others added 13 commits April 17, 2026 20:39
…pport

- Add flex_algo_node_segments field to Interface::V2; add
  deserialize_legacy_v2_interface for reading pre-RFC-18 accounts
- Add MigrateDeviceInterfaces processor: rewrites pre-RFC-18 device
  accounts (no flex_algo bytes) to new V2 layout; idempotent so the
  activator startup sweep can call it unconditionally; accepts
  foundation, device owner, or activator authority as signer
- Wire MigrateDeviceInterfaces into entrypoint and instructions
- Update ActivateLink to pass unicast_default_topology_pda
  unconditionally; processor tags link only when account is initialized
- Update topology backfill/create processors
- Remove V3 discriminant from smartcontract Go SDK; DeserializeInterfaceV2
  now reads flex_algo_node_segments unconditionally (requires migration)
- Register topology commands in Rust SDK
- Add integration tests for MigrateDeviceInterfaces: idempotency,
  authorization (unauthorized/activator/non-signer), legacy account migration
get_topology_pda normalizes via to_ascii_uppercase so any case input
derives the same PDA. The create processor stores the uppercased name,
ensuring names are always uppercase in onchain state and cEOS config.
@elitegreg elitegreg merged commit c60e14d into main Apr 18, 2026
36 checks passed
@elitegreg elitegreg deleted the bc/rfc18-pr1 branch April 18, 2026 17:14
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.

3 participants