ebrightfield / solana-devtools

Rust Developer Tools for Solana and Anchor
14 stars 8 forks source link

no variant named `RequestUnitsDeprecated` found for enum `ComputeBudgetInstruction` #23

Open 0xstonegm opened 2 months ago

0xstonegm commented 2 months ago

commit e08b37a9bbfa40d5789fa3d4abba61348de61da3 introduced RequestUnitsDeprecated

but it got removed in v1.18, so the solana-* = "1.17" in Cargo.toml should be solana-* = "~1.17" to restrict solana-* version to avoid compiler errors like the title above since solana-devtools no longer compatible with >=1.18 versions.

diff --git a/sdk/src/compute_budget.rs b/sdk/src/compute_budget.rs
index 84d0c37660..c903be13c2 100644
--- a/sdk/src/compute_budget.rs
+++ b/sdk/src/compute_budget.rs
@@ -23,14 +23,7 @@ crate::declare_id!("ComputeBudget111111111111111111111111111111");
     Serialize,
 )]
 pub enum ComputeBudgetInstruction {
-    /// Deprecated
-    // TODO: after feature remove_deprecated_request_unit_ix::id() is activated, replace it with 'unused'
-    RequestUnitsDeprecated {
-        /// Units to request
-        units: u32,
-        /// Additional fee to add
-        additional_fee: u32,
-    },
+    Unused, // deprecated variant, reserved value.
     /// Request a specific transaction-wide program heap region size in bytes.
     /// The value requested must be a multiple of 1024. This new heap region
     /// size applies to each program executed in the transaction, including all
@@ -63,9 +56,9 @@ impl ComputeBudgetInstruction {

     /// Serialize Instruction using borsh, this is only used in runtime::cost_model::tests but compilation
     /// can't be restricted as it's used across packages
-    // #[cfg(test)]
-    pub fn pack(self) -> Result<Vec<u8>, std::io::Error> {
-        self.try_to_vec()
+    #[cfg(feature = "dev-context-only-utils")]
+    pub fn pack(self) -> Result<Vec<u8>, borsh::io::Error> {
+        borsh::to_vec(&self)
     }
0xstonegm commented 2 months ago

another fix is check if remove_deprecated_request_unit_ix::id() is activated or not like the following:

https://github.com/pyth-network/pythnet/blob/b12cecb197240715d519b82963d30bf095e2f9c2/runtime/src/accounts.rs#L538


use solana_sdk::{
        feature_set::{
            self, remove_deprecated_request_unit_ix, use_default_units_in_fee_calculation,
            FeatureSet,
        }
}

feature_set.is_active(&remove_deprecated_request_unit_ix::id())