Skip to content

Commit 3c62576

Browse files
authored
program: Upgrade to v3 crates (#102)
* program: Upgrade to v3 crates #### Problem The interface crate has been on v3 for some time, but the program and tests have been lagging behind. #### Summary of changes Upgrade everything to new CLI, crates, etc, and fix everything that comes up. The biggest change is that it isn't possible to disable direct mapping, because it was removed from the feature set in v3.0. * Cargo fmt * Fix program build errors * Cleanup imports
1 parent 41d5722 commit 3c62576

File tree

9 files changed

+1445
-1466
lines changed

9 files changed

+1445
-1466
lines changed

Cargo.lock

Lines changed: 1393 additions & 1408 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ check-cfg = [
1616
]
1717

1818
[workspace.metadata.cli]
19-
solana = "2.3.4"
19+
solana = "3.0.0"
2020

2121
# Specify Rust toolchains for rustfmt, clippy, and build.
2222
# Any unprovided toolchains default to stable.
@@ -33,13 +33,13 @@ tag-message = "Publish {{crate_name}} v{{version}}"
3333
consolidate-commits = false
3434

3535
[workspace.dependencies]
36-
mollusk-svm = "0.4.0"
37-
mollusk-svm-fuzz-fixture = "0.4.0"
36+
mollusk-svm = "0.6.3"
37+
mollusk-svm-fuzz-fixture = "0.6.3"
3838
num-traits = "0.2"
3939
pinocchio = "0.9.2"
40-
solana-instruction = "2.3.0"
41-
solana-program-error = "2.2.2"
42-
solana-program-option = "2.2.1"
43-
solana-program-pack = "2.2.1"
44-
solana-pubkey = "2.4.0"
45-
solana-system-interface = { version="1.0", features=["bincode"] }
40+
solana-instruction = "3.0.0"
41+
solana-program-error = "3.0.0"
42+
solana-program-option = "3.0.0"
43+
solana-program-pack = "3.0.0"
44+
solana-pubkey = "3.0.0"
45+
solana-system-interface = { version = "2.0", features=["bincode"] }

pinocchio/program/Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,28 @@ pinocchio-log = { version = "0.5.1", default-features = false }
2020
pinocchio-token-interface = { version = "^0", path = "../interface" }
2121

2222
[dev-dependencies]
23-
agave-feature-set = "2.2.20"
23+
agave-feature-set = "3.0.0"
2424
assert_matches = "1.5.0"
2525
mollusk-svm = { workspace = true }
2626
mollusk-svm-fuzz-fixture = { workspace = true }
2727
num-traits = { workspace = true }
28-
solana-account = "2.2.1"
28+
solana-account = "3.0.0"
2929
solana-instruction = { workspace = true }
30-
solana-keypair = "2.2.3"
30+
solana-keypair = "3.0.0"
3131
solana-program-error = { workspace = true }
3232
solana-program-option = { workspace = true }
3333
solana-program-pack = { workspace = true }
34-
solana-program-test = "2.3.4"
34+
solana-program-test = "3.0.0"
3535
solana-pubkey = { workspace = true }
36-
solana-rent = "2.2.1"
37-
solana-sdk-ids = "2.2.1"
38-
solana-signature = "2.3.0"
39-
solana-signer = "2.2.1"
40-
solana-transaction = "2.2.3"
41-
solana-transaction-error = "2.2.1"
36+
solana-rent = "3.0.0"
37+
solana-sdk-ids = "3.0.0"
38+
solana-signature = "3.0.0"
39+
solana-signer = "3.0.0"
40+
solana-transaction = "3.0.0"
41+
solana-transaction-error = "3.0.0"
4242
solana-system-interface = { workspace = true }
43-
spl-token-interface = "1"
44-
spl-token-2022-interface = "1"
43+
spl-token-interface = "2"
44+
spl-token-2022-interface = "2"
4545

4646
[lints]
4747
workspace = true

pinocchio/program/tests/batch.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,15 @@ fn create_token_account(
300300
}
301301

302302
/// Creates a Mollusk instance with the default feature set, excluding the
303-
/// `bpf_account_data_direct_mapping` feature.
303+
/// `account_data_direct_mapping` feature.
304304
fn mollusk() -> Mollusk {
305305
let feature_set = {
306-
let mut fs = FeatureSet::all_enabled();
307-
fs.active_mut()
308-
.remove(&agave_feature_set::bpf_account_data_direct_mapping::id());
309-
fs
306+
// When upgrading to v3.1, add this back in
307+
//let fs = FeatureSet::all_enabled();
308+
//fs.active_mut()
309+
// .remove(&agave_feature_set::account_data_direct_mapping::id());
310+
//fs
311+
FeatureSet::all_enabled()
310312
};
311313
let mut mollusk = Mollusk {
312314
feature_set,

program/Cargo.toml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ bytemuck = "1.20.0"
1717
num-derive = "0.4"
1818
num-traits = { workspace = true }
1919
num_enum = "0.7.3"
20-
solana-account-info = "2.3.0"
21-
solana-cpi = "2.2.1"
20+
solana-account-info = "3.0.0"
21+
solana-cpi = "3.0.0"
2222
solana-instruction = { workspace = true }
23-
solana-msg = "2.2.1"
24-
solana-program-entrypoint = "2.3.0"
23+
solana-msg = "3.0.0"
24+
solana-program-entrypoint = "3.0.0"
2525
solana-program-error = { workspace = true }
26-
solana-program-memory = "2.3.1"
26+
solana-program-memory = "3.0.0"
2727
solana-program-option = { workspace = true }
2828
solana-program-pack = { workspace = true }
2929
solana-pubkey = { workspace = true, features = ["bytemuck"] }
30-
solana-rent = "2.2.1"
31-
solana-sdk-ids = "2.2.1"
32-
solana-sysvar = { version = "2.2.2", features = ["bincode"] }
33-
spl-token-interface = { version = "1.0" }
30+
solana-rent = "3.0.0"
31+
solana-sdk-ids = "3.0.0"
32+
solana-sysvar = { version = "3.0.0", features = ["bincode"] }
33+
spl-token-interface = { version = "2.0" }
3434
thiserror = "2.0"
3535

3636
[dev-dependencies]
@@ -39,13 +39,12 @@ mollusk-svm = { workspace = true }
3939
mollusk-svm-fuzz-fixture = { workspace = true }
4040
proptest = "1.5"
4141
serial_test = "3.2.0"
42-
solana-account = "2.2.1"
43-
solana-account-info = "2.3.0"
44-
solana-clock = "2.2.2"
45-
solana-native-token = "2.2.1"
46-
solana-program-entrypoint = "2.3.0"
47-
solana-rent = { version = "2.2.1", features = ["sysvar"] }
48-
solana-system-interface = { version="1.0", features=["bincode"] }
42+
solana-account = "3.0.0"
43+
solana-account-info = "3.0.0"
44+
solana-clock = "3.0.0"
45+
solana-native-token = "3.0.0"
46+
solana-rent = { version = "3.0.0", features = ["sysvar"] }
47+
solana-system-interface = { version = "2.0", features=["bincode"] }
4948
strum = "0.24"
5049
strum_macros = "0.24"
5150

program/src/entrypoint.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
//! Program entrypoint
22
33
use {
4-
crate::processor::Processor,
5-
solana_account_info::AccountInfo,
6-
solana_msg::msg,
7-
solana_program_error::{ProgramResult, ToStr},
8-
solana_pubkey::Pubkey,
4+
crate::processor::Processor, solana_account_info::AccountInfo, solana_msg::msg,
5+
solana_program_error::ProgramResult, solana_pubkey::Pubkey,
96
spl_token_interface::error::TokenError,
107
};
118

program/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![allow(clippy::arithmetic_side_effects)]
22
#![deny(missing_docs)]
3-
#![cfg_attr(not(test), forbid(unsafe_code))]
43

54
//! An ERC20-like Token program for the Solana blockchain
65

program/src/processor.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use {
1818
solana_pubkey::{Pubkey, PUBKEY_BYTES},
1919
solana_rent::Rent,
2020
solana_sdk_ids::system_program,
21-
solana_sysvar::Sysvar,
21+
solana_sysvar::{Sysvar, SysvarSerialize},
2222
};
2323

2424
/// Program state handler.
@@ -976,7 +976,7 @@ impl Processor {
976976
/// Checks two pubkeys for equality in a computationally cheap way using
977977
/// `sol_memcmp`
978978
pub fn cmp_pubkeys(a: &Pubkey, b: &Pubkey) -> bool {
979-
sol_memcmp(a.as_ref(), b.as_ref(), PUBKEY_BYTES) == 0
979+
unsafe { sol_memcmp(a.as_ref(), b.as_ref(), PUBKEY_BYTES) == 0 }
980980
}
981981

982982
/// Validates owner(s) are present
@@ -1025,23 +1025,23 @@ fn delete_account(account_info: &AccountInfo) -> Result<(), ProgramError> {
10251025
account_info.assign(&system_program::id());
10261026
let mut account_data = account_info.data.borrow_mut();
10271027
let data_len = account_data.len();
1028-
solana_program_memory::sol_memset(*account_data, 0, data_len);
1028+
unsafe {
1029+
solana_program_memory::sol_memset(*account_data, 0, data_len);
1030+
}
10291031
Ok(())
10301032
}
10311033

10321034
/// Helper function to totally delete an account on-chain
10331035
#[cfg(target_os = "solana")]
10341036
fn delete_account(account_info: &AccountInfo) -> Result<(), ProgramError> {
10351037
account_info.assign(&system_program::id());
1036-
account_info.realloc(0, false)
1038+
account_info.resize(0)
10371039
}
10381040

10391041
#[cfg(test)]
10401042
mod tests {
10411043
use {
10421044
super::*,
1043-
solana_clock::Epoch,
1044-
solana_program_error::ToStr,
10451045
std::sync::{Arc, RwLock},
10461046
};
10471047

@@ -1201,7 +1201,6 @@ mod tests {
12011201
&mut signer_data,
12021202
&program_id,
12031203
false,
1204-
Epoch::default(),
12051204
);
12061205
MAX_SIGNERS + 1
12071206
];
@@ -1224,7 +1223,6 @@ mod tests {
12241223
&mut data,
12251224
&program_id,
12261225
false,
1227-
Epoch::default(),
12281226
);
12291227

12301228
// full 11 of 11
@@ -1326,7 +1324,6 @@ mod tests {
13261324
&mut signer_data,
13271325
&program_id,
13281326
false,
1329-
Epoch::default(),
13301327
);
13311328
MAX_SIGNERS + 1
13321329
];

program/tests/processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn do_process_instruction_dups(
7575
data: account_info.try_borrow_data().unwrap().to_vec(),
7676
owner: *account_info.owner,
7777
executable: account_info.executable,
78-
rent_epoch: account_info.rent_epoch,
78+
rent_epoch: u64::MAX,
7979
};
8080
dedup_accounts.push((*account_info.key, account));
8181
cached_accounts.insert(account_info.key, account_info);

0 commit comments

Comments
 (0)