-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from Squads-Protocol/release
Release - Final V4 Upgrade
- Loading branch information
Showing
70 changed files
with
6,291 additions
and
680 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
{ | ||
"private": true, | ||
"workspaces": [ | ||
"sdk/*" | ||
], | ||
"scripts": { | ||
"build": "turbo run build", | ||
"test": "turbo run build && anchor test -- --features=testing && echo \"\n⚠️ Don't forget to recompile the .so file before deployment\n\"", | ||
"pretest": "mkdir -p target/deploy && cp ./test-program-keypair.json ./target/deploy/squads_multisig_program-keypair.json", | ||
"ts": "turbo run ts && yarn tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"@solana/spl-token": "*", | ||
"@solana/spl-memo": "^0.2.3", | ||
"@types/bn.js": "5.1.0", | ||
"@types/mocha": "10.0.1", | ||
"@types/node-fetch": "2.6.2", | ||
"mocha": "10.2.0", | ||
"prettier": "2.6.2", | ||
"ts-node": "10.9.1", | ||
"turbo": "1.6.3", | ||
"typescript": "*" | ||
}, | ||
"resolutions": { | ||
"@solana/web3.js": "1.70.3", | ||
"@solana/spl-token": "0.3.6", | ||
"typescript": "4.9.4" | ||
} | ||
"private": true, | ||
"workspaces": [ | ||
"sdk/*" | ||
], | ||
"scripts": { | ||
"build": "turbo run build", | ||
"test:detached": "turbo run build && anchor test --detach -- --features=testing && echo \"\n⚠️ Don't forget to recompile the .so file before deployment\n\"", | ||
"test": "turbo run build && anchor test -- --features=testing && echo \"\n⚠️ Don't forget to recompile the .so file before deployment\n\"", | ||
"pretest": "mkdir -p target/deploy && cp ./test-program-keypair.json ./target/deploy/squads_multisig_program-keypair.json", | ||
"ts": "turbo run ts && yarn tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"@solana/spl-token": "*", | ||
"@solana/spl-memo": "^0.2.3", | ||
"@types/bn.js": "5.1.0", | ||
"@types/mocha": "10.0.1", | ||
"@types/node-fetch": "2.6.2", | ||
"mocha": "10.2.0", | ||
"prettier": "2.6.2", | ||
"ts-node": "10.9.1", | ||
"turbo": "1.6.3", | ||
"typescript": "*" | ||
}, | ||
"resolutions": { | ||
"@solana/web3.js": "1.70.3", | ||
"@solana/spl-token": "0.3.6", | ||
"typescript": "4.9.4" | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
Optimizing Bump Heap Allocation | ||
Objective: Increase available heap memory while maintaining flexibility in program invocation. | ||
1. Initial State: Default 32 KiB Heap | ||
Memory Layout: | ||
0x300000000 0x300008000 | ||
| | | ||
v v | ||
[--------------------] | ||
^ ^ | ||
| | | ||
VM Lower VM Upper | ||
Boundary Boundary | ||
Default Allocator (Allocates Backwards / Top Down) (Default 32 KiB): | ||
0x300000000 0x300008000 | ||
| | | ||
[--------------------] | ||
^ | ||
| | ||
Allocation starts here (SAFE) | ||
2. Naive Approach: Increase HEAP_LENGTH to 8 * 32 KiB + Default Allocator | ||
Memory Layout with Increased HEAP_LENGTH: | ||
0x300000000 0x300008000 0x300040000 | ||
| | | | ||
v v v | ||
[--------------------|------------------------------------|] | ||
^ ^ ^ | ||
| | | | ||
VM Lower VM Upper Allocation starts here | ||
Boundary Boundary (ACCESS VIOLATION!) | ||
Issue: Access violation occurs without requestHeapFrame, requiring it for every transaction. | ||
3. Optimized Solution: Forward Allocation with Flexible Heap Usage | ||
Memory Layout (Same as Naive Approach): | ||
0x300000000 0x300008000 0x300040000 | ||
| | | | ||
v v v | ||
[--------------------|------------------------------------|] | ||
^ ^ ^ | ||
| | | | ||
VM Lower VM Upper Allocator & VM | ||
Boundary Boundary Heap Limit | ||
Forward Allocator Behavior: | ||
a) Without requestHeapFrame: | ||
0x300000000 0x300008000 | ||
| | | ||
[--------------------] | ||
^ ^ | ||
| | | ||
VM Lower VM Upper | ||
Boundary Boundary | ||
Allocation | ||
starts here (SAFE) | ||
b) With requestHeapFrame: | ||
0x300000000 0x300008000 0x300040000 | ||
| | | | ||
[--------------------|------------------------------------|] | ||
^ ^ ^ | ||
| | | | ||
VM Lower | VM Upper | ||
Boundary Boundary | ||
Allocation Allocation continues Maximum allocation | ||
starts here with requestHeapFrame with requestHeapFrame | ||
(SAFE) | ||
Key Advantages: | ||
1. Compatibility: Functions without requestHeapFrame for allocations ≤32 KiB. | ||
2. Extensibility: Supports larger allocations when requestHeapFrame is invoked. | ||
3. Efficiency: Eliminates mandatory requestHeapFrame calls for all transactions. | ||
Conclusion: | ||
The forward allocation strategy offers a robust solution, providing both backward | ||
compatibility for smaller heap requirements and the flexibility to utilize extended | ||
heap space when necessary. | ||
The following allocator is a copy of the bump allocator found in | ||
solana_program::entrypoint and | ||
https://github.com/solana-labs/solana-program-library/blob/master/examples/rust/custom-heap/src/entrypoint.rs | ||
but with changes to its HEAP_LENGTH and its | ||
starting allocation address. | ||
*/ | ||
|
||
use solana_program::entrypoint::HEAP_START_ADDRESS; | ||
use std::{alloc::Layout, mem::size_of, ptr::null_mut}; | ||
|
||
/// Length of the memory region used for program heap. | ||
pub const HEAP_LENGTH: usize = 8 * 32 * 1024; | ||
|
||
struct BumpAllocator; | ||
|
||
unsafe impl std::alloc::GlobalAlloc for BumpAllocator { | ||
#[inline] | ||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { | ||
const POS_PTR: *mut usize = HEAP_START_ADDRESS as *mut usize; | ||
const TOP_ADDRESS: usize = HEAP_START_ADDRESS as usize + HEAP_LENGTH; | ||
const BOTTOM_ADDRESS: usize = HEAP_START_ADDRESS as usize + size_of::<*mut u8>(); | ||
let mut pos = *POS_PTR; | ||
if pos == 0 { | ||
// First time, set starting position to bottom address | ||
pos = BOTTOM_ADDRESS; | ||
} | ||
// Align the position upwards | ||
pos = (pos + layout.align() - 1) & !(layout.align() - 1); | ||
let next_pos = pos.saturating_add(layout.size()); | ||
if next_pos > TOP_ADDRESS { | ||
return null_mut(); | ||
} | ||
*POS_PTR = next_pos; | ||
pos as *mut u8 | ||
} | ||
|
||
#[inline] | ||
unsafe fn dealloc(&self, _: *mut u8, _: Layout) { | ||
// I'm a bump allocator, I don't free | ||
} | ||
} | ||
|
||
// Only use the allocator if we're not in a no-entrypoint context | ||
#[cfg(not(feature = "no-entrypoint"))] | ||
#[global_allocator] | ||
static A: BumpAllocator = BumpAllocator; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.