Skip to content

smartcontract: fix BackfillTopology account ordering and SID collision#3580

Merged
elitegreg merged 4 commits intomainfrom
bc/rfc18-backfill-fix
Apr 24, 2026
Merged

smartcontract: fix BackfillTopology account ordering and SID collision#3580
elitegreg merged 4 commits intomainfrom
bc/rfc18-backfill-fix

Conversation

@ben-malbeclabs
Copy link
Copy Markdown
Contributor

Summary of Changes

  • Account ordering fix: payer and system_program must come after the variable-length device list. They were incorrectly placed before it, meaning the program consumed them as device accounts. SDK command updated to match.
  • SID collision fix: when base node_segment_idx values are assigned outside the SegmentRoutingIds allocator (e.g. activator off-chain path), the on-chain bitmap has no record of them. Backfill now pre-collects all base SIDs in use and skips conflicting allocations, so flex-algo SIDs never duplicate a base SID.

Diff Breakdown

Category Files Lines (+/-) Net
Core logic 2 +43 / -6 +37
Tests 1 +33 / -33 0
Scaffolding 1 +4 / -4 0
Key files (click to expand)
  • smartcontract/programs/doublezero-serviceability/src/processors/topology/backfill.rs — account ordering fix, SID collision avoidance
  • smartcontract/sdk/rs/src/commands/topology/backfill.rs — remove payer/system_program from per-batch fixed accounts
  • smartcontract/programs/doublezero-serviceability/tests/topology_test.rs — updated for new account ordering; SID collision test now expects index 2 (not 1)

Testing Verification

  • All 4 backfill integration tests pass
  • End-to-end verified on local devnet: dz1 got base SID=1 and flex-algo SID=3; dz2 got base SID=2 and flex-algo SID=4 — no collisions

Two bugs in the BackfillTopology instruction:

1. Account ordering: payer and system_program must come *after* the
   variable-length device account list, not before it. The processor
   now collects all remaining accounts and slices off the last two
   as payer/system_program. The SDK command is updated to match —
   payer and system_program are appended after device accounts in
   each batch.

2. SID collision: when base node_segment_idx values were assigned
   outside the SegmentRoutingIds allocator (e.g. via the activator),
   the bitmap doesn't know about them. Backfill now pre-collects all
   base SIDs in use across the device list and skips any allocated
   ID that conflicts, so flex-algo SIDs never duplicate a base SID.
@ben-malbeclabs ben-malbeclabs self-assigned this Apr 24, 2026
- rustfmt: collapse flat_map closure to match nightly formatting
- sdk/rs: remove unused payer variable from topology create test; update
  backfill mock expectation to match new account layout (payer removed
  from fixed accounts, appended by client infrastructure)
- changelog: add entries for account ordering and SID collision fixes
@ben-malbeclabs ben-malbeclabs marked this pull request as ready for review April 24, 2026 05:24
@elitegreg elitegreg enabled auto-merge (squash) April 24, 2026 16:49
@elitegreg elitegreg merged commit 4659ab3 into main Apr 24, 2026
36 checks passed
@elitegreg elitegreg deleted the bc/rfc18-backfill-fix branch April 24, 2026 17:09
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.

2 participants