Skip to content

Commit c37e4b5

Browse files
committed
rust: Bump Solana crates to v2.1
#### Problem Version 2.1 of the Solana crates is out, but all of the Rust programs are still on v2.0. #### Summary of changes Bump crates to v2.1, Rust to 1.81, and use component crates wherever possible. The CPI program has a higher CU usage also, so update the README to reflect that.
1 parent 7d00568 commit c37e4b5

File tree

13 files changed

+1365
-775
lines changed

13 files changed

+1365
-775
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ members = [
88
]
99
resolver = "2"
1010

11+
[workspace.lints.rust.unexpected_cfgs]
12+
level = "warn"
13+
check-cfg = [
14+
'cfg(target_os, values("solana"))',
15+
'cfg(feature, values("frozen-abi", "no-entrypoint"))',
16+
]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ the address and `invoke_signed` to CPI to the system program.
179179

180180
| Language | CU Usage | CU Usage (minus syscalls) |
181181
| --- | --- | --- |
182-
| Rust | 3662 | 1162 |
182+
| Rust | 3698 | 1198 |
183183
| Zig | 2825 | 325 |
184184
| C | 3122 | 622 |
185185
| Rust (pinocchio) | 2816 | 316 |

cpi/Cargo.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ edition = "2021"
77
test-sbf = []
88

99
[dependencies]
10-
solana-program = "2.0.3"
10+
solana-account-info = "2.1.0"
11+
solana-cpi = "2.1.0"
12+
solana-program = "2.1.0"
13+
solana-program-entrypoint = "2.1.0"
14+
solana-program-error = "2.1.0"
15+
solana-pubkey = "2.1.0"
1116

1217
[dev-dependencies]
13-
solana-program-test = "2.0.3"
14-
solana-sdk = "2.0.3"
18+
solana-program-test = "2.1.0"
19+
solana-sdk = "2.1.0"
1520

1621
[lib]
1722
crate-type = ["cdylib", "lib"]
23+
24+
[lints]
25+
workspace = true

cpi/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
#![deny(missing_docs)]
33
#![forbid(unsafe_code)]
44

5-
use solana_program::{
6-
account_info::{next_account_info, AccountInfo},
7-
entrypoint::ProgramResult,
8-
program::invoke_signed,
9-
program_error::ProgramError,
10-
pubkey::Pubkey,
11-
system_instruction,
5+
use {
6+
solana_account_info::{next_account_info, AccountInfo},
7+
solana_cpi::invoke_signed,
8+
solana_program::system_instruction, // replace with solana_system_interface
9+
solana_program_entrypoint::ProgramResult,
10+
solana_program_error::ProgramError,
11+
solana_pubkey::Pubkey,
1212
};
1313

14-
solana_program::entrypoint!(process_instruction);
14+
solana_program_entrypoint::entrypoint!(process_instruction);
1515

1616
/// Amount of bytes of account data to allocate
1717
pub const SIZE: usize = 42;

cpi/tests/functional.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async fn test_cross_program_invocation() {
3131
},
3232
);
3333

34-
let (mut banks_client, payer, recent_blockhash) = program_test.start().await;
34+
let (banks_client, payer, recent_blockhash) = program_test.start().await;
3535

3636
let mut transaction = Transaction::new_with_payer(
3737
&[Instruction::new_with_bincode(

helloworld/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
solana-program = "2"
7+
solana-msg = "2.1"
8+
solana-program-entrypoint = "2.1"
89

910
[dev-dependencies]
10-
solana-program-test = "2"
11-
solana-sdk = "2"
11+
solana-instruction = "2.1"
12+
solana-program-test = "2.1"
13+
solana-pubkey = "2.1"
14+
solana-sdk = "2.1"
1215

1316
[lib]
1417
crate-type = ["cdylib", "lib"]
18+
19+
[lints]
20+
workspace = true

helloworld/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use solana_program::msg;
1+
use solana_msg::msg;
22

33
#[no_mangle]
44
pub extern "C" fn entrypoint(_: *mut u8) -> u64 {
@@ -7,5 +7,5 @@ pub extern "C" fn entrypoint(_: *mut u8) -> u64 {
77
}
88
#[cfg(target_os = "solana")]
99
#[no_mangle]
10-
fn custom_panic(info: &core::panic::PanicInfo<'_>) {}
11-
solana_program::custom_heap_default!();
10+
fn custom_panic(_info: &core::panic::PanicInfo<'_>) {}
11+
solana_program_entrypoint::custom_heap_default!();

helloworld/tests/functional.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use {
2-
solana_program::instruction::Instruction,
2+
solana_instruction::Instruction,
33
solana_program_test::{tokio, ProgramTest},
44
solana_sdk::{signature::Signer, transaction::Transaction},
55
};
66
mod program {
7-
solana_program::declare_id!("1og1111111111111111111111111111111111111111");
7+
solana_pubkey::declare_id!("1og1111111111111111111111111111111111111111");
88
}
99
fn program_test() -> ProgramTest {
1010
ProgramTest::new("solana_program_rosetta_helloworld", program::id(), None)
1111
}
1212
#[tokio::test]
1313
async fn call() {
1414
let pt = program_test();
15-
let mut context = pt.start_with_context().await;
15+
let context = pt.start_with_context().await;
1616
let blockhash = context.banks_client.get_latest_blockhash().await.unwrap();
1717
let transaction = Transaction::new_signed_with_payer(
1818
&[Instruction {

transfer-lamports/Cargo.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ version = "1.0.0"
44
edition = "2021"
55

66
[features]
7-
no-entrypoint = []
87
test-sbf = []
98

109
[dependencies]
11-
solana-program = "2.0.3"
10+
solana-account-info = "2.1.0"
11+
solana-program-entrypoint = "2.1.0"
12+
solana-program-error = "2.1.0"
13+
solana-pubkey = "2.1.0"
1214

1315
[dev-dependencies]
14-
solana-program-test = "2.0.3"
15-
solana-sdk = "2.0.3"
16+
solana-instruction = "2.1.0"
17+
solana-program-test = "2.1.0"
18+
solana-sdk = "2.1.0"
1619

1720
[lib]
1821
crate-type = ["cdylib", "lib"]
22+
23+
[lints]
24+
workspace = true

0 commit comments

Comments
 (0)