smartcontract,sdk: fix user update tenant reassignment for initial assignment#3707
Merged
Conversation
elitegreg
approved these changes
May 15, 2026
Contributor
|
I approve, but did you consider checking in the program if the old tenant account is Pubkey::default() before checking the ownership? Seems a little simpler. |
Allows initial tenant assignment: when the user has no prior tenant (tenant_pk == Pubkey::default()), the SDK passes the placeholder readonly and the processor skips old tenant validation, ownership, writability and reference count decrement. The new tenant is always processed. Adds integration tests for both initial assignment and reassignment paths.
f3c1609 to
b3f5256
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
user updatefailing withInvalid Old Tenant Account Ownerwhen the user being reassigned has no current tenant (user.tenant_pk == Pubkey::default()). The SDK was pushingPubkey::default()(the System Program ID) as the old tenant account, and the program asserted that account was owned by the serviceability program, which fails because the System Program account is owned byNativeLoader1111111111111111111111111111111.AccountMetawhen the user has no current tenant; it still pushes the new tenant.process_update_useraccepts three remaining-account layouts ([payer, system],[new_tenant, payer, system],[old_tenant, new_tenant, payer, system]), increments the new tenant's reference count whenevertenant_pkis set, and decrements the old tenant's reference count only when the user currently has one. Existing tenant-reassignment behavior is unchanged.Diff Breakdown
Net diff is dominated by new SDK unit tests covering the initial-assignment and reassignment paths; the actual behavior change is small.
Key files (click to expand)
smartcontract/sdk/rs/src/commands/user/update.rs- gate theold_tenantAccountMetapush onuser.tenant_pk != Pubkey::default(); addtest_commands_user_update_tenant_initial_assignment_omits_old_tenantandtest_commands_user_update_tenant_reassignment_includes_old_and_new.smartcontract/programs/doublezero-serviceability/src/processors/user/update.rs- replace the binary "tenants present / absent" branch with a 3-way layout match (2/3/4 remaining accounts); restructure theif let Some(new_tenant_pk)block to mandate the new-tenant account and conditionally validate/decrement the old tenant only whenuser.tenant_pk != Pubkey::default(); reusevalidate_program_account!for owner+writability checks.CHANGELOG.md- add Unreleased entry describing the fix.Testing Verification
cargo test -p doublezero_sdk --lib commands::user::update- 5/5 tests pass, including the two new tenant-update tests.cargo test -p doublezero-serviceability --tests- all serviceability integration test suites pass (user, tenant, accesspass, onchain-allocation, etc.).update.rs:354withleft: NativeLoader1111111111111111111111111111111). End-to-end verification on testnet requires redeploying the serviceability program with this fix.