Преглед на файлове

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
Jon C преди 1 месец
родител
ревизия
3c62576c28
променени са 9 файла, в които са добавени 419 реда и са изтрити 238 реда
  1. 367 180
      Cargo.lock
  2. 9 9
      Cargo.toml
  3. 12 12
      pinocchio/program/Cargo.toml
  4. 7 5
      pinocchio/program/tests/batch.rs
  5. 15 16
      program/Cargo.toml
  6. 2 5
      program/src/entrypoint.rs
  7. 0 1
      program/src/lib.rs
  8. 6 9
      program/src/processor.rs
  9. 1 1
      program/tests/processor.rs

Файловите разлики са ограничени, защото са твърде много
+ 367 - 180
Cargo.lock


+ 9 - 9
Cargo.toml

@@ -16,7 +16,7 @@ check-cfg = [
 ]
 
 [workspace.metadata.cli]
-solana = "2.3.4"
+solana = "3.0.0"
 
 # Specify Rust toolchains for rustfmt, clippy, and build.
 # Any unprovided toolchains default to stable.
@@ -33,13 +33,13 @@ tag-message = "Publish {{crate_name}} v{{version}}"
 consolidate-commits = false
 
 [workspace.dependencies]
-mollusk-svm = "0.4.0"
-mollusk-svm-fuzz-fixture = "0.4.0"
+mollusk-svm = "0.6.3"
+mollusk-svm-fuzz-fixture = "0.6.3"
 num-traits = "0.2"
 pinocchio = "0.9.2"
-solana-instruction = "2.3.0"
-solana-program-error = "2.2.2"
-solana-program-option = "2.2.1"
-solana-program-pack = "2.2.1"
-solana-pubkey = "2.4.0"
-solana-system-interface = { version="1.0", features=["bincode"] }
+solana-instruction = "3.0.0"
+solana-program-error = "3.0.0"
+solana-program-option = "3.0.0"
+solana-program-pack = "3.0.0"
+solana-pubkey = "3.0.0"
+solana-system-interface = { version = "2.0", features=["bincode"] }

+ 12 - 12
pinocchio/program/Cargo.toml

@@ -20,28 +20,28 @@ pinocchio-log = { version = "0.5.1", default-features = false }
 pinocchio-token-interface = { version = "^0", path = "../interface" }
 
 [dev-dependencies]
-agave-feature-set = "2.2.20"
+agave-feature-set = "3.0.0"
 assert_matches = "1.5.0"
 mollusk-svm = { workspace = true }
 mollusk-svm-fuzz-fixture = { workspace = true }
 num-traits = { workspace = true }
-solana-account = "2.2.1"
+solana-account = "3.0.0"
 solana-instruction = { workspace = true }
-solana-keypair = "2.2.3"
+solana-keypair = "3.0.0"
 solana-program-error = { workspace = true }
 solana-program-option = { workspace = true }
 solana-program-pack = { workspace = true }
-solana-program-test = "2.3.4"
+solana-program-test = "3.0.0"
 solana-pubkey = { workspace = true }
-solana-rent = "2.2.1"
-solana-sdk-ids = "2.2.1"
-solana-signature = "2.3.0"
-solana-signer = "2.2.1"
-solana-transaction = "2.2.3"
-solana-transaction-error = "2.2.1"
+solana-rent = "3.0.0"
+solana-sdk-ids = "3.0.0"
+solana-signature = "3.0.0"
+solana-signer = "3.0.0"
+solana-transaction = "3.0.0"
+solana-transaction-error = "3.0.0"
 solana-system-interface = { workspace = true }
-spl-token-interface = "1"
-spl-token-2022-interface = "1"
+spl-token-interface = "2"
+spl-token-2022-interface = "2"
 
 [lints]
 workspace = true

+ 7 - 5
pinocchio/program/tests/batch.rs

@@ -300,13 +300,15 @@ fn create_token_account(
 }
 
 /// Creates a Mollusk instance with the default feature set, excluding the
-/// `bpf_account_data_direct_mapping` feature.
+/// `account_data_direct_mapping` feature.
 fn mollusk() -> Mollusk {
     let feature_set = {
-        let mut fs = FeatureSet::all_enabled();
-        fs.active_mut()
-            .remove(&agave_feature_set::bpf_account_data_direct_mapping::id());
-        fs
+        // When upgrading to v3.1, add this back in
+        //let fs = FeatureSet::all_enabled();
+        //fs.active_mut()
+        //    .remove(&agave_feature_set::account_data_direct_mapping::id());
+        //fs
+        FeatureSet::all_enabled()
     };
     let mut mollusk = Mollusk {
         feature_set,

+ 15 - 16
program/Cargo.toml

@@ -17,20 +17,20 @@ bytemuck = "1.20.0"
 num-derive = "0.4"
 num-traits = { workspace = true }
 num_enum = "0.7.3"
-solana-account-info = "2.3.0"
-solana-cpi = "2.2.1"
+solana-account-info = "3.0.0"
+solana-cpi = "3.0.0"
 solana-instruction = { workspace = true }
-solana-msg = "2.2.1"
-solana-program-entrypoint = "2.3.0"
+solana-msg = "3.0.0"
+solana-program-entrypoint = "3.0.0"
 solana-program-error = { workspace = true }
-solana-program-memory = "2.3.1"
+solana-program-memory = "3.0.0"
 solana-program-option = { workspace = true }
 solana-program-pack = { workspace = true }
 solana-pubkey = { workspace = true, features = ["bytemuck"] }
-solana-rent = "2.2.1"
-solana-sdk-ids = "2.2.1"
-solana-sysvar = { version = "2.2.2", features = ["bincode"] }
-spl-token-interface = { version = "1.0" }
+solana-rent = "3.0.0"
+solana-sdk-ids = "3.0.0"
+solana-sysvar = { version = "3.0.0", features = ["bincode"] }
+spl-token-interface = { version = "2.0" }
 thiserror = "2.0"
 
 [dev-dependencies]
@@ -39,13 +39,12 @@ mollusk-svm = { workspace = true }
 mollusk-svm-fuzz-fixture = { workspace = true }
 proptest = "1.5"
 serial_test = "3.2.0"
-solana-account = "2.2.1"
-solana-account-info = "2.3.0"
-solana-clock = "2.2.2"
-solana-native-token = "2.2.1"
-solana-program-entrypoint = "2.3.0"
-solana-rent = { version = "2.2.1", features = ["sysvar"] }
-solana-system-interface = { version="1.0", features=["bincode"] }
+solana-account = "3.0.0"
+solana-account-info = "3.0.0"
+solana-clock = "3.0.0"
+solana-native-token = "3.0.0"
+solana-rent = { version = "3.0.0", features = ["sysvar"] }
+solana-system-interface = { version = "2.0", features=["bincode"] }
 strum = "0.24"
 strum_macros = "0.24"
 

+ 2 - 5
program/src/entrypoint.rs

@@ -1,11 +1,8 @@
 //! Program entrypoint
 
 use {
-    crate::processor::Processor,
-    solana_account_info::AccountInfo,
-    solana_msg::msg,
-    solana_program_error::{ProgramResult, ToStr},
-    solana_pubkey::Pubkey,
+    crate::processor::Processor, solana_account_info::AccountInfo, solana_msg::msg,
+    solana_program_error::ProgramResult, solana_pubkey::Pubkey,
     spl_token_interface::error::TokenError,
 };
 

+ 0 - 1
program/src/lib.rs

@@ -1,6 +1,5 @@
 #![allow(clippy::arithmetic_side_effects)]
 #![deny(missing_docs)]
-#![cfg_attr(not(test), forbid(unsafe_code))]
 
 //! An ERC20-like Token program for the Solana blockchain
 

+ 6 - 9
program/src/processor.rs

@@ -18,7 +18,7 @@ use {
     solana_pubkey::{Pubkey, PUBKEY_BYTES},
     solana_rent::Rent,
     solana_sdk_ids::system_program,
-    solana_sysvar::Sysvar,
+    solana_sysvar::{Sysvar, SysvarSerialize},
 };
 
 /// Program state handler.
@@ -976,7 +976,7 @@ impl Processor {
     /// Checks two pubkeys for equality in a computationally cheap way using
     /// `sol_memcmp`
     pub fn cmp_pubkeys(a: &Pubkey, b: &Pubkey) -> bool {
-        sol_memcmp(a.as_ref(), b.as_ref(), PUBKEY_BYTES) == 0
+        unsafe { sol_memcmp(a.as_ref(), b.as_ref(), PUBKEY_BYTES) == 0 }
     }
 
     /// Validates owner(s) are present
@@ -1025,7 +1025,9 @@ fn delete_account(account_info: &AccountInfo) -> Result<(), ProgramError> {
     account_info.assign(&system_program::id());
     let mut account_data = account_info.data.borrow_mut();
     let data_len = account_data.len();
-    solana_program_memory::sol_memset(*account_data, 0, data_len);
+    unsafe {
+        solana_program_memory::sol_memset(*account_data, 0, data_len);
+    }
     Ok(())
 }
 
@@ -1033,15 +1035,13 @@ fn delete_account(account_info: &AccountInfo) -> Result<(), ProgramError> {
 #[cfg(target_os = "solana")]
 fn delete_account(account_info: &AccountInfo) -> Result<(), ProgramError> {
     account_info.assign(&system_program::id());
-    account_info.realloc(0, false)
+    account_info.resize(0)
 }
 
 #[cfg(test)]
 mod tests {
     use {
         super::*,
-        solana_clock::Epoch,
-        solana_program_error::ToStr,
         std::sync::{Arc, RwLock},
     };
 
@@ -1201,7 +1201,6 @@ mod tests {
                 &mut signer_data,
                 &program_id,
                 false,
-                Epoch::default(),
             );
             MAX_SIGNERS + 1
         ];
@@ -1224,7 +1223,6 @@ mod tests {
             &mut data,
             &program_id,
             false,
-            Epoch::default(),
         );
 
         // full 11 of 11
@@ -1326,7 +1324,6 @@ mod tests {
                     &mut signer_data,
                     &program_id,
                     false,
-                    Epoch::default(),
                 );
                 MAX_SIGNERS + 1
             ];

+ 1 - 1
program/tests/processor.rs

@@ -75,7 +75,7 @@ fn do_process_instruction_dups(
                 data: account_info.try_borrow_data().unwrap().to_vec(),
                 owner: *account_info.owner,
                 executable: account_info.executable,
-                rent_epoch: account_info.rent_epoch,
+                rent_epoch: u64::MAX,
             };
             dedup_accounts.push((*account_info.key, account));
             cached_accounts.insert(account_info.key, account_info);

Някои файлове не бяха показани, защото твърде много файлове са промени