Skip to content

smartcontract: add Index account for multicast group code uniqueness#3256

Draft
martinsander00 wants to merge 1 commit intomainfrom
ms/pda-derivation
Draft

smartcontract: add Index account for multicast group code uniqueness#3256
martinsander00 wants to merge 1 commit intomainfrom
ms/pda-derivation

Conversation

@martinsander00
Copy link
Contributor

Summary of Changes

  • Introduce an Index account (PDA derived from entity type + lowercased code) that enforces unique multicast group codes onchain and enables O(1) code-to-pubkey lookup
  • Integrate Index lifecycle into existing multicast group instructions: create (atomically creates Index), update (renames Index on code change), delete/close (closes Index)
  • Add standalone CreateIndex/DeleteIndex instructions (variants 104/105) for migration backfill of existing accounts
  • Update Rust SDK with Index PDA derivation in create/update/get commands

Diff Breakdown

Category Files Lines (+/-) Net
Core logic 16 +430 / -12 +418
Scaffolding 7 +97 / -0 +97
Tests 13 +522 / -84 +438

~45% tests, ~45% core logic, ~10% scaffolding (module wiring, SDK command wrappers)

Key files (click to expand)
  • smartcontract/programs/doublezero-serviceability/src/state/index.rs — new Index account struct (34 bytes: account_type + pubkey + bump_seed) with Borsh serialization
  • smartcontract/programs/doublezero-serviceability/src/processors/index/create.rs — standalone CreateIndex processor for migration backfill
  • smartcontract/programs/doublezero-serviceability/src/processors/multicastgroup/update.rs — atomic Index rename when multicast group code changes (close old, create new)
  • smartcontract/programs/doublezero-serviceability/src/processors/multicastgroup/create.rs — creates Index account alongside multicast group
  • smartcontract/programs/doublezero-serviceability/src/processors/index/delete.rs — standalone DeleteIndex processor for cleanup
  • smartcontract/programs/doublezero-serviceability/src/pda.rsget_index_pda() with case-insensitive seed derivation
  • smartcontract/sdk/rs/src/commands/multicastgroup/get.rs — O(1) Index PDA lookup with fallback scan for pre-migration accounts
  • smartcontract/sdk/rs/src/commands/multicastgroup/update.rs — derives old/new Index PDAs when code changes

Testing Verification

  • All existing integration tests updated to pass Index accounts to CreateMulticastGroup
  • New test cases for Index creation, rename on update, and onchain allocation + Index interaction
  • SDK mock tests updated for O(1) Index lookup path and fallback scan
  • make rust-build, make rust-lint, and make rust-test all pass

Introduce an Index account pattern that enforces unique multicast group
codes onchain and enables O(1) code-to-pubkey lookup. The Index PDA is
derived from the entity type seed and lowercased code, providing
case-insensitive uniqueness.

Integrated into existing instructions:
- CreateMulticastGroup: creates Index alongside the group
- UpdateMulticastGroup: atomically renames Index on code change
- DeleteMulticastGroup/CloseAccount: closes Index if provided

Standalone CreateIndex/DeleteIndex instructions (variants 104/105)
added for migration backfill of existing accounts.

SDK updated with Index PDA derivation in create/update/get commands
and new CreateIndex/DeleteIndex command wrappers.
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