smartcontract: add Index account and standalone instructions#3256
smartcontract: add Index account and standalone instructions#3256martinsander00 merged 2 commits intomainfrom
Conversation
9ba8974 to
a67cb86
Compare
a67cb86 to
41ae161
Compare
41ae161 to
db89dd2
Compare
How the Index Account WorksCreate: A counter increments to get a new PDA address that doesn't repeat. We get the pubkey of that PDA and point to it in a new associated Index account (derived from the code). The multicast group PDA is derived from the counter; the Index PDA is derived from the code. Delete: Both the group and the Index are closed. Rename: The multicast group pubkey doesn't change on rename (it's still derived from the counter, which was set at creation). So:
The Index PDA changes (because the code in its seeds changed), but it still points to the same multicast group account. The group's PDA never moves — only the "DNS record" pointing to it gets swapped. Lookup: Since the Index PDA seeds are deterministic ( Before this, looking up by code meant fetching every multicast group account and scanning through them to find the one with a matching code — O(n). |
7bde2d2 to
dd81d51
Compare
dd81d51 to
f95f302
Compare
f95f302 to
a3008ee
Compare
Introduce an Index account (PDA derived from entity type + lowercased code) for O(1) code-to-pubkey lookup. Add standalone CreateIndex and DeleteIndex instructions (variants 104/105) for migration backfill. Add Index PDA derivation and Rust SDK command wrappers.
a3008ee to
4a51bc6
Compare
elitegreg
left a comment
There was a problem hiding this comment.
I assume the ultimate plan is to not use CreateIndex, but rather, create the index account when something like CreateMulticastGroup occurs? If that's the case, I'd suggest splitting out the account verification/creation logic and having that be called by the process_* routines here and then you can use the functions later when you modify process_create_multicastgroup.
Also, I'd consider changing the name of code to something else, perhaps key or field. The index can be used for any string we want to be unique, not just codes.
Resolves: #3408
Summary
get_index_pda) and Rust SDK command wrappersSplit PR (1/2). Integration into multicast group lifecycle follows in #3415.
New derivation workflow: #3256 (comment)
Diff Breakdown
~50% tests, ~41% onchain program, ~9% Rust SDK
Key files (click to expand)
smartcontract/programs/doublezero-serviceability/src/state/index.rs— new Index account struct (account_type + pubkey + bump_seed) with Borsh serializationsmartcontract/programs/doublezero-serviceability/src/processors/index/create.rs— standalone CreateIndex processorsmartcontract/programs/doublezero-serviceability/src/processors/index/delete.rs— standalone DeleteIndex processorsmartcontract/programs/doublezero-serviceability/src/pda.rs—get_index_pda()with case-insensitive seed derivationsmartcontract/sdk/rs/src/commands/index/create.rs— CreateIndex SDK command wrappersmartcontract/sdk/rs/src/commands/index/delete.rs— DeleteIndex SDK command wrapperTesting Verification
index_test.rswith 5 tests: create, duplicate rejection, unauthorized create, delete, unauthorized delete