Skip to content

Commit 3bf7ddf

Browse files
update macro to multiple address_trees
1 parent 68dc0c6 commit 3bf7ddf

File tree

9 files changed

+3107
-2203
lines changed

9 files changed

+3107
-2203
lines changed

program-tests/anchor-compressible-user-derived/README.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ await program.methods
7575
.createCompressibleConfig(
7676
100, // compression_delay
7777
rentRecipient,
78-
addressSpace
78+
[addressSpace] // Now accepts an array of address trees (1-4 allowed)
7979
)
8080
.accounts({
8181
payer: wallet.publicKey,
@@ -92,7 +92,7 @@ await program.methods
9292
.updateCompressibleConfig(
9393
200, // new_compression_delay (optional)
9494
newRentRecipient, // (optional)
95-
newAddressSpace, // (optional)
95+
[newAddressSpace1, newAddressSpace2], // (optional) - array of 1-4 address trees
9696
newUpdateAuthority // (optional)
9797
)
9898
.accounts({
@@ -159,6 +159,53 @@ await program.methods
159159
.rpc();
160160
```
161161

162+
## Address Space Configuration
163+
164+
The config now supports multiple address trees per address space (1-4 allowed):
165+
166+
```typescript
167+
// Single address tree (backward compatible)
168+
const addressSpace = [addressTree1];
169+
170+
// Multiple address trees for better scalability
171+
const addressSpace = [addressTree1, addressTree2, addressTree3];
172+
173+
// When creating config
174+
await program.methods
175+
.createCompressibleConfig(
176+
100,
177+
rentRecipient,
178+
addressSpace // Array of 1-4 unique address tree pubkeys
179+
)
180+
// ... accounts
181+
.rpc();
182+
```
183+
184+
### Address Space Validation Rules
185+
186+
**Create Config:**
187+
188+
- Must contain 1-4 unique address tree pubkeys
189+
- No duplicate pubkeys allowed
190+
- All pubkeys must be valid address trees
191+
192+
**Update Config:**
193+
194+
- Can only **add** new address trees, never remove existing ones
195+
- No duplicate pubkeys allowed in the new configuration
196+
- Must maintain all existing address trees
197+
198+
```typescript
199+
// Valid update: adding new trees
200+
const currentAddressSpace = [tree1, tree2];
201+
const newAddressSpace = [tree1, tree2, tree3]; // ✅ Valid: adds tree3
202+
203+
// Invalid update: removing existing trees
204+
const invalidAddressSpace = [tree2, tree3]; // ❌ Invalid: removes tree1
205+
```
206+
207+
The system validates that compressed accounts use address trees from the configured address space, providing flexibility while maintaining security and preventing accidental removal of active trees.
208+
162209
## What You Need to Implement
163210

164211
Since the macro only generates compression-related instructions, you need to implement:
@@ -188,13 +235,13 @@ pub fn create_user_record(
188235
name: String,
189236
) -> Result<()> {
190237
let user_record = &mut ctx.accounts.user_record;
191-
238+
192239
// Your custom initialization logic here
193240
user_record.compression_info = CompressionInfo::new()?;
194241
user_record.owner = ctx.accounts.user.key();
195242
user_record.name = name;
196243
user_record.score = 0;
197-
244+
198245
Ok(())
199246
}
200247
```

0 commit comments

Comments
 (0)