Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Program Upgradability #2610

Draft
wants to merge 49 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a99a40f
Introduce V2 variant of program owner
d0cd Jan 23, 2025
d65e636
Clippy
d0cd Jan 23, 2025
d2044f2
Add deploy_with_authority
d0cd Jan 23, 2025
740fdc9
Clippy
d0cd Jan 23, 2025
9bae55b
Add skeleton for finalizing updates
d0cd Jan 23, 2025
5eefdcf
Use editions to track versions of the program
d0cd Jan 23, 2025
73c2db7
Checkpointing design
d0cd Jan 24, 2025
66c7143
Add editions to process stacks
d0cd Jan 25, 2025
aff18e8
Checkpoint
d0cd Jan 27, 2025
6b7286e
Lookup stacks in Process, remove external stacks
d0cd Jan 31, 2025
bc7855c
Clippy
d0cd Jan 31, 2025
3825922
Add to deployment DB
d0cd Jan 31, 2025
9b5c716
Rename DeploymentMap::ID to IDV1
d0cd Feb 4, 2025
35cac79
Resolve some TODOs, API cleanup
d0cd Feb 4, 2025
417e373
Clean up check_update
d0cd Feb 5, 2025
812a210
Remove caching of finalize costs as they are invalid on an update to …
d0cd Feb 5, 2025
b3a6ced
Add runtime checks for program costs and and number of calls
d0cd Feb 5, 2025
704098b
Implement global.get edition ...
d0cd Feb 5, 2025
9828994
Add test
d0cd Feb 5, 2025
965e9e1
Place stacks under a RwLock for interior mutability
d0cd Feb 5, 2025
97cee48
global.get test case passes
d0cd Feb 6, 2025
6d9060e
Verify edition is only valid global
d0cd Feb 6, 2025
95f5c87
Merge branch 'staging' into feat/program-upgradability
d0cd Feb 6, 2025
c0f489b
Test template for (in)validity checks
d0cd Feb 6, 2025
e9ddc88
Valid update tests
d0cd Feb 7, 2025
8b0daba
Add negative update tests
d0cd Feb 7, 2025
ef44d05
Add safety check against self imports on update
d0cd Feb 7, 2025
d6df694
Refactor tests
d0cd Feb 7, 2025
7bda11a
Clippy
d0cd Feb 7, 2025
ef54427
Basic upgrade passes
d0cd Feb 7, 2025
432b4a3
Add some VM tests
d0cd Feb 11, 2025
c4c6a69
Clippy
d0cd Feb 11, 2025
06b4a90
Test effect of updates on dependents
d0cd Feb 12, 2025
45caf01
Add test with cycle, currently mutual recursion fails to deploy, howe…
d0cd Feb 12, 2025
ec32aad
Add some protections against infinite recursion
d0cd Feb 12, 2025
2811d7e
Defend against recursion in get_number_of_calls and costs
d0cd Feb 12, 2025
13e3692
Rename global.get to metadata.get
d0cd Feb 12, 2025
2c94a02
Add test for record consumption
d0cd Feb 13, 2025
bcac67f
Fix impl
d0cd Feb 14, 2025
7c61ac4
Fix failing test, move original vm tests back for reviewability
d0cd Feb 14, 2025
0d8e040
Fix and move unrelated test to different branch
d0cd Feb 14, 2025
0ea9bc4
Add debugs
d0cd Feb 14, 2025
415c620
Use weak references back to global stacks
d0cd Feb 15, 2025
c637563
Adjust test
d0cd Feb 15, 2025
b3ada76
Cleanup
d0cd Feb 15, 2025
b0ba2f4
Adjust test
d0cd Feb 15, 2025
e4ffd4a
Clippy
d0cd Feb 15, 2025
634fa71
Merge branch 'staging' into feat/program-upgradability
d0cd Feb 15, 2025
1225f49
Merge branch 'staging' into feat/program-upgradability
d0cd Feb 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions console/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub trait Network:
const MAX_OUTPUTS: usize = 16;

/// The maximum program depth.
/// Note. This is unused.
const MAX_PROGRAM_DEPTH: usize = 64;
/// The maximum number of imports.
const MAX_IMPORTS: usize = 64;
Expand Down
76 changes: 59 additions & 17 deletions console/program/src/owner/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,59 @@ impl<N: Network> FromBytes for ProgramOwner<N> {
// Read the version.
let version = u8::read_le(&mut reader)?;
// Ensure the version is valid.
if version != 1 {
return Err(error("Invalid program owner version"));
}
match version {
1 => {
// Read the address.
let address = Address::read_le(&mut reader)?;
// Read the signature.
let signature = Signature::read_le(&mut reader)?;

// Read the address.
let address = Address::read_le(&mut reader)?;
// Read the signature.
let signature = Signature::read_le(&mut reader)?;
// Return the program owner.
Ok(Self::V1(ProgramOwnerV1::from(address, signature)))
}
2 => {
// Read the address.
let address = Address::read_le(&mut reader)?;
// Read the authority.
let authority = Address::read_le(&mut reader)?;
// Read the edition.
let edition = U16::read_le(&mut reader)?;
// Read the signature.
let signature = Signature::read_le(&mut reader)?;

// Return the program owner.
Ok(Self::from(address, signature))
// Return the program owner.
Ok(Self::V2(ProgramOwnerV2::from(address, authority, edition, signature)))
}
_ => Err(error("Invalid program owner version")),
}
}
}

impl<N: Network> ToBytes for ProgramOwner<N> {
/// Writes the program owner to a buffer.
fn write_le<W: Write>(&self, mut writer: W) -> IoResult<()> {
// Write the version.
1u8.write_le(&mut writer)?;
// Write the address.
self.address.write_le(&mut writer)?;
// Write the signature.
self.signature.write_le(&mut writer)
match &self {
Self::V1(owner) => {
// Write the version.
1u8.write_le(&mut writer)?;
// Write the address.
owner.address.write_le(&mut writer)?;
// Write the signature.
owner.signature.write_le(&mut writer)
}
Self::V2(owner) => {
// Write the version.
2u8.write_le(&mut writer)?;
// Write the address.
owner.address.write_le(&mut writer)?;
// Write the authority.
owner.authority.write_le(&mut writer)?;
// Write the edition.
owner.edition.write_le(&mut writer)?;
// Write the signature.
owner.signature.write_le(&mut writer)
}
}
}
}

Expand All @@ -55,9 +85,21 @@ mod tests {
type CurrentNetwork = MainnetV0;

#[test]
fn test_bytes() -> Result<()> {
fn test_bytes_v1() -> Result<()> {
// Construct a new program owner.
let expected = test_helpers::sample_program_owner_v1();

// Check the byte representation.
let expected_bytes = expected.to_bytes_le()?;
assert_eq!(expected, ProgramOwner::read_le(&expected_bytes[..])?);
assert!(ProgramOwner::<CurrentNetwork>::read_le(&expected_bytes[1..]).is_err());
Ok(())
}

#[test]
fn test_bytes_v2() -> Result<()> {
// Construct a new program owner.
let expected = test_helpers::sample_program_owner();
let expected = test_helpers::sample_program_owner_v2();

// Check the byte representation.
let expected_bytes = expected.to_bytes_le()?;
Expand Down
Loading