Skip to content

Commit

Permalink
instruction-padding: Remove solana-program dependency (#7436)
Browse files Browse the repository at this point in the history
* instruction-padding: Remove solana-program dependency

#### Problem

The instruction-padding program still has an explicit dependency on
solana-program, but it isn't needed.

#### Summary of changes

Use the component crates instead. Some of the syscall consts aren't
available yet outside of solana-program, but it was easy to add a static
assertion for those.

* Add re-exports
  • Loading branch information
joncinque authored Nov 1, 2024
1 parent 8f550c5 commit 9b3076f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 19 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion instruction-padding/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ test-sbf = []

[dependencies]
num_enum = "0.7.3"
solana-program = "2.1.0"
solana-account-info = "2.1.0"
solana-cpi = "2.1.0"
solana-instruction = { version = "2.1.0", features = ["std"] }
solana-program-entrypoint = "2.1.0"
solana-program-error = "2.1.0"
solana-pubkey = "2.1.0"

[dev-dependencies]
solana-program = "2.1.0"
solana-program-test = "2.1.0"
solana-sdk = "2.1.0"
static_assertions = "1.1.0"

[lib]
crate-type = ["cdylib", "lib"]
Expand Down
6 changes: 4 additions & 2 deletions instruction-padding/program/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#![cfg(not(feature = "no-entrypoint"))]

use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};
use {
solana_account_info::AccountInfo, solana_program_error::ProgramResult, solana_pubkey::Pubkey,
};

solana_program::entrypoint!(process_instruction);
solana_program_entrypoint::entrypoint!(process_instruction);
fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
Expand Down
23 changes: 17 additions & 6 deletions instruction-padding/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

use {
num_enum::{IntoPrimitive, TryFromPrimitive},
solana_program::{
instruction::{AccountMeta, Instruction},
program_error::ProgramError,
pubkey::Pubkey,
syscalls::{MAX_CPI_ACCOUNT_INFOS, MAX_CPI_INSTRUCTION_DATA_LEN},
},
solana_instruction::{AccountMeta, Instruction},
solana_program_error::ProgramError,
solana_pubkey::Pubkey,
std::{convert::TryInto, mem::size_of},
};

const MAX_CPI_ACCOUNT_INFOS: usize = 128;
const MAX_CPI_INSTRUCTION_DATA_LEN: u64 = 10 * 1024;

#[cfg(test)]
static_assertions::const_assert_eq!(
MAX_CPI_ACCOUNT_INFOS,
solana_program::syscalls::MAX_CPI_ACCOUNT_INFOS
);
#[cfg(test)]
static_assertions::const_assert_eq!(
MAX_CPI_INSTRUCTION_DATA_LEN,
solana_program::syscalls::MAX_CPI_INSTRUCTION_DATA_LEN
);

/// Instructions supported by the padding program, which takes in additional
/// account data or accounts and does nothing with them. It's meant for testing
/// larger transactions with bench-tps.
Expand Down
7 changes: 5 additions & 2 deletions instruction-padding/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ mod entrypoint;
pub mod instruction;
pub mod processor;

pub use solana_program;
solana_program::declare_id!("iXpADd6AW1k5FaaXum5qHbSqyd7TtoN6AD7suVa83MF");
pub use {
solana_account_info, solana_cpi, solana_instruction, solana_program_entrypoint,
solana_program_error, solana_pubkey,
};
solana_pubkey::declare_id!("iXpADd6AW1k5FaaXum5qHbSqyd7TtoN6AD7suVa83MF");
13 changes: 5 additions & 8 deletions instruction-padding/program/src/processor.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use {
crate::instruction::{PadInstruction, WrapData},
solana_program::{
account_info::AccountInfo,
entrypoint::ProgramResult,
instruction::{AccountMeta, Instruction},
program::invoke,
program_error::ProgramError,
pubkey::Pubkey,
},
solana_account_info::AccountInfo,
solana_cpi::invoke,
solana_instruction::{AccountMeta, Instruction},
solana_program_error::{ProgramError, ProgramResult},
solana_pubkey::Pubkey,
std::convert::TryInto,
};

Expand Down

0 comments on commit 9b3076f

Please sign in to comment.