Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract instruction crate #2405

Merged
merged 46 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
03f7de0
extract instruction crate
kevinheavey Aug 2, 2024
269af1f
remove thiserror
kevinheavey Aug 2, 2024
022bc50
make bincode optional in solana-instruction
kevinheavey Aug 2, 2024
ed76f8d
make serde optional in solana-instruction
kevinheavey Aug 2, 2024
8c0e5ef
fix doc tests
kevinheavey Aug 2, 2024
cbe3cc2
fmt
kevinheavey Aug 2, 2024
fc9e019
harmonize features
kevinheavey Aug 2, 2024
50cd0f3
fmt Cargo.toml
kevinheavey Aug 2, 2024
d9f5335
clippy
kevinheavey Aug 2, 2024
55dca67
fix syscalls.rs imports
kevinheavey Aug 2, 2024
629bfdb
update digests
kevinheavey Aug 2, 2024
afd03a0
update digest
kevinheavey Aug 2, 2024
cf3212b
unused imports
kevinheavey Aug 3, 2024
12f9a7a
post-rebase fmt
kevinheavey Aug 9, 2024
7dcfbf4
fix doc links
kevinheavey Sep 5, 2024
066ceb3
use workspace lints
kevinheavey Sep 6, 2024
e28ba93
fmt
kevinheavey Sep 7, 2024
aef2a2b
make rustc_version dep optional
kevinheavey Sep 9, 2024
67f2dc9
update digest
kevinheavey Sep 9, 2024
e023cc4
update digest
kevinheavey Sep 10, 2024
7cf608c
update import
kevinheavey Sep 10, 2024
7ac2fdd
fmt
kevinheavey Sep 10, 2024
be32fad
fix dup import
kevinheavey Sep 10, 2024
1da7102
remove dev-context-only-utils (no longer needed)
kevinheavey Sep 10, 2024
87e991b
fmt
kevinheavey Sep 10, 2024
c6141bd
remove unnecessary allow()
kevinheavey Sep 10, 2024
6bcdf3d
fix overwriting instruction syscall stubs
kevinheavey Sep 11, 2024
f6373c8
fmt
kevinheavey Sep 11, 2024
7bc0fae
move get_processed_sibling_instruction and get_stack_height back to s…
kevinheavey Sep 11, 2024
f8acbfb
fix path
kevinheavey Sep 11, 2024
bf9a4a4
fix typo
kevinheavey Sep 12, 2024
cdb0a48
move the checked_add utility function back to solana-program
kevinheavey Sep 12, 2024
0c43f15
move AccountMeta to its own file
kevinheavey Sep 12, 2024
1127181
fix bad import
kevinheavey Sep 12, 2024
9ed5c74
move ProcessedSiblingInstruction to syscalls.rs
kevinheavey Sep 12, 2024
e7db89a
move CompiledInstruction back to solana-program
kevinheavey Sep 12, 2024
0504374
move ProcessedSiblingInstruction back into lib.rs
kevinheavey Sep 12, 2024
5d62dff
make std optional in solana-instruction
kevinheavey Sep 12, 2024
10f1c82
fix required features for frozen-abi
kevinheavey Sep 12, 2024
3d77935
update digest
kevinheavey Sep 12, 2024
edfd466
update digest
kevinheavey Sep 12, 2024
0d4dd64
missing import
kevinheavey Sep 12, 2024
d2564f3
update digest
kevinheavey Sep 12, 2024
c0e6ca0
don't assume std is imported in frozen-abi macros
kevinheavey Sep 12, 2024
4b20996
fix import warnings
kevinheavey Sep 12, 2024
5727e9f
simplify cfg usage
kevinheavey Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ members = [
"sdk/feature-set",
"sdk/gen-headers",
"sdk/hash",
"sdk/instruction",
"sdk/macro",
"sdk/msg",
"sdk/package-metadata-macro",
Expand Down Expand Up @@ -403,6 +404,7 @@ solana-geyser-plugin-manager = { path = "geyser-plugin-manager", version = "=2.1
solana-gossip = { path = "gossip", version = "=2.1.0" }
solana-hash = { path = "sdk/hash", version = "=2.1.0" }
solana-inline-spl = { path = "inline-spl", version = "=2.1.0" }
solana-instruction = { path = "sdk/instruction", version = "=2.1.0", default-features = false }
solana-lattice-hash = { path = "lattice-hash", version = "=2.1.0" }
solana-ledger = { path = "ledger", version = "=2.1.0" }
solana-loader-v4-program = { path = "programs/loader-v4", version = "=2.1.0" }
Expand Down
4 changes: 2 additions & 2 deletions frozen-abi/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn do_derive_abi_enum_visitor(input: ItemEnum) -> TokenStream {
let enum_name = #type_str;
use ::serde::ser::Serialize;
use ::solana_frozen_abi::abi_example::AbiExample;
digester.update_with_string(format!("enum {} (variants = {})", enum_name, #variant_count));
digester.update_with_string(::std::format!("enum {} (variants = {})", enum_name, #variant_count));
#serialized_variants
digester.create_child()
}
Expand Down Expand Up @@ -303,7 +303,7 @@ fn quote_for_test(
::solana_frozen_abi::__private::log::error!("digest error: {:#?}", result);
}
result.unwrap();
let actual_digest = format!("{}", hash);
let actual_digest = ::std::format!("{}", hash);
if ::std::env::var("SOLANA_ABI_BULK_UPDATE").is_ok() {
if #expected_digest != actual_digest {
#p!("sed -i -e 's/{}/{}/g' $(git grep --files-with-matches frozen_abi)", #expected_digest, hash);
Expand Down
1 change: 1 addition & 0 deletions program-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ solana-bpf-loader-program = { workspace = true }
solana-compute-budget = { workspace = true }
solana-feature-set = { workspace = true }
solana-inline-spl = { workspace = true }
solana-instruction = { workspace = true }
solana-log-collector = { workspace = true }
solana-logger = { workspace = true }
solana-program-runtime = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use {
solana_bpf_loader_program::serialization::serialize_parameters,
solana_compute_budget::compute_budget::ComputeBudget,
solana_feature_set::FEATURE_NAMES,
solana_instruction::{error::InstructionError, Instruction},
solana_log_collector::ic_msg,
solana_program_runtime::{
invoke_context::BuiltinFunctionWithContext, loaded_programs::ProgramCacheEntry, stable_log,
Expand All @@ -37,7 +38,6 @@ use {
fee_calculator::{FeeRateGovernor, DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE},
genesis_config::{ClusterType, GenesisConfig},
hash::Hash,
instruction::{Instruction, InstructionError},
native_token::sol_to_lamports,
poh_config::PohConfig,
program_error::{ProgramError, UNSUPPORTED_SYSVAR},
Expand Down
18 changes: 18 additions & 0 deletions programs/sbf/Cargo.lock

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

2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ struct RentMetrics {
pub type BankStatusCache = StatusCache<Result<()>>;
#[cfg_attr(
feature = "frozen-abi",
frozen_abi(digest = "EQwW6Ym6ECKaAREnAgkhXYisBQovuraBKSALdJ8koZzq")
frozen_abi(digest = "BswQL6n7kKwgHFKcwMCQcrWjt8h59Vh6KkNb75iaqG2B")
)]
pub type BankSlotDelta = SlotDelta<Result<()>>;

Expand Down
58 changes: 58 additions & 0 deletions sdk/instruction/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[package]
name = "solana-instruction"
description = "Types for directing the execution of Solana programs."
documentation = "https://docs.rs/solana-instruction"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
bincode = { workspace = true, optional = true }
borsh = { workspace = true, optional = true }
num-traits = { workspace = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-frozen-abi = { workspace = true, optional = true }
solana-frozen-abi-macro = { workspace = true, optional = true }
solana-pubkey = { workspace = true, default-features = false }

[target.'cfg(target_os = "solana")'.dependencies]
solana-define-syscall = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { workspace = true, features = ["js", "wasm-bindgen"] }
js-sys = { workspace = true }
wasm-bindgen = { workspace = true }

[dev-dependencies]
solana-instruction = { path = ".", features = ["borsh"] }

[build-dependencies]
rustc_version = { workspace = true, optional = true }

[features]
bincode = ["dep:bincode", "dep:serde"]
borsh = ["dep:borsh"]
joncinque marked this conversation as resolved.
Show resolved Hide resolved
default = ["std"]
frozen-abi = [
"dep:rustc_version",
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
"serde",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I noticed this was needed while testing, thanks for fixing!

"std",
]
serde = [
"dep:serde",
"dep:serde_derive",
"solana-pubkey/serde",
]
std = []

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[lints]
workspace = true
1 change: 1 addition & 0 deletions sdk/instruction/build.rs
105 changes: 105 additions & 0 deletions sdk/instruction/src/account_meta.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#[cfg(any(feature = "std", target_arch = "wasm32"))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something -- why is this gated on the std feature / wasm32 arch? It should be usable regardless of features and all that, no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I took another look and realised this can be much simpler, had been assuming the wasm32 code needed std because we have other places where that's the case but it's not the case here

use solana_pubkey::Pubkey;

/// Describes a single account read or written by a program during instruction
/// execution.
///
/// When constructing an [`Instruction`], a list of all accounts that may be
/// read or written during the execution of that instruction must be supplied.
/// Any account that may be mutated by the program during execution, either its
/// data or metadata such as held lamports, must be writable.
///
/// Note that because the Solana runtime schedules parallel transaction
/// execution around which accounts are writable, care should be taken that only
/// accounts which actually may be mutated are specified as writable. As the
/// default [`AccountMeta::new`] constructor creates writable accounts, this is
/// a minor hazard: use [`AccountMeta::new_readonly`] to specify that an account
/// is not writable.
#[cfg(any(feature = "std", target_arch = "wasm32"))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this, is the featurization / arch cfg needed?

#[repr(C)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[derive(Debug, Default, PartialEq, Eq, Clone)]
pub struct AccountMeta {
/// An account's public key.
pub pubkey: Pubkey,
/// True if an `Instruction` requires a `Transaction` signature matching `pubkey`.
pub is_signer: bool,
/// True if the account data or metadata may be mutated during program execution.
pub is_writable: bool,
}

#[cfg(any(feature = "std", target_arch = "wasm32"))]
impl AccountMeta {
/// Construct metadata for a writable account.
///
/// # Examples
///
/// ```
/// # use solana_pubkey::Pubkey;
/// # use solana_instruction::{AccountMeta, Instruction};
/// # use borsh::{BorshSerialize, BorshDeserialize};
/// #
/// # #[derive(BorshSerialize, BorshDeserialize)]
/// # #[borsh(crate = "borsh")]
/// # pub struct MyInstruction;
/// #
/// # let instruction = MyInstruction;
/// # let from = Pubkey::new_unique();
/// # let to = Pubkey::new_unique();
/// # let program_id = Pubkey::new_unique();
/// let instr = Instruction::new_with_borsh(
/// program_id,
/// &instruction,
/// vec![
/// AccountMeta::new(from, true),
/// AccountMeta::new(to, false),
/// ],
/// );
/// ```
pub fn new(pubkey: Pubkey, is_signer: bool) -> Self {
Self {
pubkey,
is_signer,
is_writable: true,
}
}

/// Construct metadata for a read-only account.
///
/// # Examples
///
/// ```
/// # use solana_pubkey::Pubkey;
/// # use solana_instruction::{AccountMeta, Instruction};
/// # use borsh::{BorshSerialize, BorshDeserialize};
/// #
/// # #[derive(BorshSerialize, BorshDeserialize)]
/// # #[borsh(crate = "borsh")]
/// # pub struct MyInstruction;
/// #
/// # let instruction = MyInstruction;
/// # let from = Pubkey::new_unique();
/// # let to = Pubkey::new_unique();
/// # let from_account_storage = Pubkey::new_unique();
/// # let program_id = Pubkey::new_unique();
/// let instr = Instruction::new_with_borsh(
/// program_id,
/// &instruction,
/// vec![
/// AccountMeta::new(from, true),
/// AccountMeta::new(to, false),
/// AccountMeta::new_readonly(from_account_storage, false),
/// ],
/// );
/// ```
pub fn new_readonly(pubkey: Pubkey, is_signer: bool) -> Self {
Self {
pubkey,
is_signer,
is_writable: false,
}
}
}
Loading
Loading