Skip to content

Conversation

@elitegreg
Copy link
Contributor

Summary of Changes

  • SetGlobalConfig instruction changed to create global resource accounts
  • ActivateDevice instruction changed to create device resource accounts
  • UpdateDevice instruction changed to create/update device resource accounts
  • CloseAccountDevice instruction changed to close device resource accounts
  • SDK updated for these instructions
  • Added a resource close cli command/instruction

Testing Verification

  • Tests updated
  • New tests for smart contract as well as sdk commands

Closes #2623
Closes #2624
Closes #2625

@elitegreg elitegreg force-pushed the gm/device_activate branch 4 times, most recently from 25baf16 to 1e80b28 Compare January 16, 2026 17:58
Manages resource account creation with the instructions:
SetGlobalConfig, ActivateDevice, UpdateDevice and CloseAccountDevice.

Closes #2623
Closes #2624
Closes #2625
@elitegreg elitegreg marked this pull request as ready for review January 16, 2026 18:28
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances resource management in the smart contract by automating the creation and removal of resource accounts during device lifecycle operations. The changes ensure that resource accounts (such as TunnelIds and DzPrefixBlock) are properly managed when devices are activated, updated, or closed.

Changes:

  • Modified SetGlobalConfig, ActivateDevice, UpdateDevice, and CloseAccountDevice instructions to automatically create/update/close associated resource accounts
  • Added a new CloseResource instruction and CLI command for manual resource cleanup
  • Updated SDK commands to handle resource account management

Reviewed changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
smartcontract/sdk/rs/src/commands/resource/mod.rs Added closeaccount module export
smartcontract/sdk/rs/src/commands/resource/closeaccount.rs New command to close resource accounts
smartcontract/sdk/rs/src/commands/globalconfig/set.rs Updated to create global resource accounts during config setup
smartcontract/sdk/rs/src/commands/device/update.rs Added resource account creation when updating device prefixes
smartcontract/sdk/rs/src/commands/device/activate.rs Modified to create resource accounts during device activation
smartcontract/sdk/rs/src/commands/device/closeaccount.rs Enhanced to close associated resource accounts when closing device
smartcontract/programs/doublezero-serviceability/src/processors/resource/mod.rs Updated resource creation logic to support optional associated accounts and account resizing
smartcontract/programs/doublezero-serviceability/src/processors/resource/closeaccount.rs New processor for closing resource accounts
smartcontract/programs/doublezero-serviceability/src/processors/globalconfig/set.rs Integrated resource account creation into global config setup
smartcontract/programs/doublezero-serviceability/src/processors/device/activate.rs Added resource account creation during device activation
smartcontract/programs/doublezero-serviceability/src/processors/device/update.rs Implemented resource account creation/update when modifying device prefixes
smartcontract/programs/doublezero-serviceability/src/processors/device/closeaccount.rs Added resource account cleanup during device closure
smartcontract/programs/doublezero-serviceability/src/instructions.rs Added CloseResource instruction variant
smartcontract/programs/doublezero-serviceability/src/error.rs Added ImmutableField error and reordered error codes
smartcontract/programs/doublezero-serviceability/src/entrypoint.rs Integrated new instruction handlers
smartcontract/cli/src/resource/close.rs New CLI command for closing resources
smartcontract/cli/src/doublezerocommand.rs Added close_resource trait method
client/doublezero/src/main.rs Integrated close resource command
Various test files Updated tests to include resource account management

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI commented Jan 16, 2026

@elitegreg I've opened a new pull request, #2655, to work on those changes. Once the pull request is ready, I'll request review from you.

elitegreg and others added 2 commits January 16, 2026 13:33
…s/resource/closeaccount.rs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
## Summary of Changes
* Restored original error code mappings (codes 2-6) in
`From<DoubleZeroError> for ProgramError` and `From<u32> for
DoubleZeroError` implementations
* The previous implementation reordered these mappings, which would
cause deployed clients to misinterpret error codes returned by the smart
contract
* Preserved the new `ImmutableField` error variant at code 68

**Corrected mappings:**
```rust
// Before (breaking)
2 => InvalidExchangePubkey
3 => InvalidDevicePubkey  
4 => InvalidLocationPubkey
5 => InvalidDeviceAPubkey
6 => InvalidDeviceZPubkey

// After (backward compatible)
2 => InvalidLocationPubkey
3 => InvalidExchangePubkey
4 => InvalidDeviceAPubkey
5 => InvalidDeviceZPubkey
6 => InvalidDevicePubkey
```

## Testing Verification
* Verified error enum round-trip conversion with
`test_error_enum_conversions`

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/malbeclabs/doublezero/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

skip-changelog

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: elitegreg <3893730+elitegreg@users.noreply.github.com>
@elitegreg elitegreg enabled auto-merge (squash) January 16, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants