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 message crate #3704

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1239f72
minimize solana_program usage in message module
kevinheavey Nov 18, 2024
7898abd
move CompiledInstruction to message module
kevinheavey Nov 18, 2024
f251f8b
move AddressLookupTableAccount to message module
kevinheavey Nov 18, 2024
f87472b
update AddressLookupTableAccount import
kevinheavey Nov 18, 2024
83e2b8b
start extracting message crate
kevinheavey Nov 19, 2024
e01ac23
copy ALL_IDS from sysvar module to avoid dependency
kevinheavey Nov 19, 2024
901ab43
update comment
kevinheavey Nov 19, 2024
6d34c5a
use system-interface crate
kevinheavey Nov 19, 2024
4e1ea29
re-export message crate in solana-program
kevinheavey Nov 19, 2024
8207faa
fix tests
kevinheavey Nov 19, 2024
7f50ca3
fix doc links
kevinheavey Nov 19, 2024
29d8a0f
add doc_auto_cfg
kevinheavey Nov 19, 2024
2fedc6b
make serde and bincode optional
kevinheavey Nov 19, 2024
8333558
inline const from solana_nonce
kevinheavey Nov 19, 2024
4caf30c
update lock file
kevinheavey Nov 19, 2024
d6d09d6
remove thiserror
kevinheavey Nov 19, 2024
21f295e
frozen-abi support
kevinheavey Nov 19, 2024
7500c81
missing feature activation
kevinheavey Nov 19, 2024
b5bc693
unused import
kevinheavey Nov 19, 2024
b9e6bde
fix frozen-abi support
kevinheavey Nov 19, 2024
fd64946
missing dep
kevinheavey Nov 19, 2024
74393ef
sort deps
kevinheavey Nov 19, 2024
ddef457
update digest
kevinheavey Nov 19, 2024
906c1cb
update system-interface feature activation
kevinheavey Nov 21, 2024
43ba89b
update rev
kevinheavey Nov 21, 2024
9e6616a
fmt
kevinheavey Nov 21, 2024
3142c99
use published system-interface crate
kevinheavey Nov 21, 2024
74e9c96
add test for inlined ALL_IDS
kevinheavey Nov 22, 2024
5bbf835
Patch extra crates needed to unify build
joncinque Nov 25, 2024
ae767c7
missing wasm-bindgen dep
kevinheavey Nov 26, 2024
842f24f
reduce example_mocks usage
kevinheavey Nov 28, 2024
d1ba18e
make blake3 optional
kevinheavey Nov 28, 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
52 changes: 52 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ members = [
"sdk/keypair",
"sdk/logger",
"sdk/macro",
"sdk/message",
"sdk/msg",
"sdk/native-token",
"sdk/nonce",
Expand Down Expand Up @@ -488,6 +489,7 @@ solana-log-collector = { path = "log-collector", version = "=2.2.0" }
solana-logger = { path = "sdk/logger", version = "=2.2.0" }
solana-measure = { path = "measure", version = "=2.2.0" }
solana-merkle-tree = { path = "merkle-tree", version = "=2.2.0" }
solana-message = { path = "sdk/message", version = "=2.2.0" }
solana-metrics = { path = "metrics", version = "=2.2.0" }
solana-msg = { path = "sdk/msg", version = "=2.2.0" }
solana-native-token = { path = "sdk/native-token", version = "=2.2.0" }
Expand Down Expand Up @@ -533,6 +535,7 @@ solana-signature = { path = "sdk/signature", version = "=2.2.0", default-feature
solana-signer = { path = "sdk/signer", version = "=2.2.0" }
solana-slot-hashes = { path = "sdk/slot-hashes", version = "=2.2.0" }
solana-slot-history = { path = "sdk/slot-history", version = "=2.2.0" }
solana-system-interface = "1.0.0"
solana-time-utils = { path = "sdk/time-utils", version = "=2.2.0" }
solana-timings = { path = "timings", version = "=2.2.0" }
solana-unified-scheduler-logic = { path = "unified-scheduler-logic", version = "=2.2.0" }
Expand Down
2 changes: 1 addition & 1 deletion gossip/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) const PULL_RESPONSE_MIN_SERIALIZED_SIZE: usize = 161;
#[cfg_attr(
feature = "frozen-abi",
derive(AbiExample, AbiEnumVisitor),
frozen_abi(digest = "D8HvpYCkdo6JweUW61WQ9ZQH2AFvzh3G1qthicnvz4E8")
frozen_abi(digest = "ESDND6D3FcRyA6UTUpDVDcS4AkESc5E6UtZWSbT7G8e8")
)]
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::large_enum_variant)]
Expand Down
38 changes: 38 additions & 0 deletions programs/sbf/Cargo.lock

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

5 changes: 5 additions & 0 deletions sdk/cargo-build-sbf/tests/crates/fail/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ solana-program = { path = "../../../../program", version = "=2.2.0" }
[lib]
crate-type = ["cdylib"]

[patch.crates-io]
solana-decode-error = { path = "../../../../decode-error" }
solana-instruction = { path = "../../../../instruction" }
solana-pubkey = { path = "../../../../pubkey" }

[workspace]
5 changes: 5 additions & 0 deletions sdk/cargo-build-sbf/tests/crates/noop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ solana-program = { path = "../../../../program", version = "=2.2.0" }
[lib]
crate-type = ["cdylib"]

[patch.crates-io]
solana-decode-error = { path = "../../../../decode-error" }
solana-instruction = { path = "../../../../instruction" }
solana-pubkey = { path = "../../../../pubkey" }

[workspace]
5 changes: 5 additions & 0 deletions sdk/cargo-build-sbf/tests/crates/package-metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ solana-program = { path = "../../../../program", version = "=2.2.0" }
[lib]
crate-type = ["cdylib"]

[patch.crates-io]
solana-decode-error = { path = "../../../../decode-error" }
solana-instruction = { path = "../../../../instruction" }
solana-pubkey = { path = "../../../../pubkey" }

[workspace]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ solana-program = { path = "../../../../program", version = "=2.2.0" }
[lib]
crate-type = ["cdylib"]

[patch.crates-io]
solana-decode-error = { path = "../../../../decode-error" }
solana-instruction = { path = "../../../../instruction" }
solana-pubkey = { path = "../../../../pubkey" }

[workspace]

[workspace.metadata.solana]
Expand Down
79 changes: 79 additions & 0 deletions sdk/message/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[package]
name = "solana-message"
description = "Solana transaction message types."
documentation = "https://docs.rs/solana-message"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
bincode = { workspace = true, optional = true }
blake3 = { workspace = true, features = ["traits-preview"], optional = true }
lazy_static = { workspace = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
solana-bincode = { workspace = true, optional = true }
solana-frozen-abi = { workspace = true, optional = true }
solana-frozen-abi-macro = { workspace = true, optional = true }
solana-hash = { workspace = true }
solana-instruction = { workspace = true, features = ["std"] }
solana-logger = { workspace = true, optional = true }
solana-pubkey = { workspace = true }
solana-sanitize = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-short-vec = { workspace = true, optional = true }
solana-system-interface = { workspace = true, optional = true, features = [
"bincode",
] }
solana-transaction-error = { workspace = true }

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

[dev-dependencies]
anyhow = { workspace = true }
bitflags = { workspace = true }
borsh = { workspace = true }
itertools = { workspace = true }
serde_json = { workspace = true }
solana-message = { path = ".", features = ["dev-context-only-utils"] }
solana-nonce = { workspace = true }
solana-program = { path = "../program" }
solana-sha256-hasher = { workspace = true }
solana-sysvar = { workspace = true }
static_assertions = { workspace = true }

[features]
bincode = [
"dep:bincode",
"dep:solana-bincode",
"dep:solana-system-interface",
"serde",
]
blake3 = ["dep:blake3"]
dev-context-only-utils = ["bincode", "blake3"]
frozen-abi = [
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
"dep:solana-logger",
"solana-hash/frozen-abi",
"solana-pubkey/frozen-abi",
]
serde = [
"dep:serde",
"dep:serde_derive",
"dep:solana-short-vec",
"solana-hash/serde",
"solana-pubkey/serde",
]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]

[lints]
workspace = true
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use {
crate::{
instruction::{CompiledInstruction, Instruction},
message::{v0::LoadedAddresses, CompileError},
pubkey::Pubkey,
},
crate::{compiled_instruction::CompiledInstruction, v0::LoadedAddresses, CompileError},
solana_instruction::Instruction,
solana_pubkey::Pubkey,
std::{collections::BTreeMap, iter::zip, ops::Index},
};

Expand Down Expand Up @@ -152,7 +150,7 @@ impl PartialEq for AccountKeys<'_> {

#[cfg(test)]
mod tests {
use {super::*, crate::instruction::AccountMeta};
use {super::*, solana_instruction::AccountMeta};

fn test_account_keys() -> [Pubkey; 6] {
let key0 = Pubkey::new_unique();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::v0::{LoadedAddresses, MessageAddressTableLookup};
use crate::v0::{LoadedAddresses, MessageAddressTableLookup};
#[deprecated(
since = "2.1.0",
note = "Use solana_transaction_error::AddressLoaderError instead"
Expand Down
56 changes: 56 additions & 0 deletions sdk/message/src/compiled_instruction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#[cfg(feature = "serde")]
use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::AbiExample;
use {solana_pubkey::Pubkey, solana_sanitize::Sanitize};

/// A compact encoding of an instruction.
///
/// A `CompiledInstruction` is a component of a multi-instruction [`Message`],
/// which is the core of a Solana transaction. It is created during the
/// construction of `Message`. Most users will not interact with it directly.
///
/// [`Message`]: crate::Message
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
#[cfg_attr(
feature = "serde",
derive(Deserialize, Serialize),
serde(rename_all = "camelCase")
)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct CompiledInstruction {
/// Index into the transaction keys array indicating the program account that executes this instruction.
pub program_id_index: u8,
/// Ordered indices into the transaction keys array indicating which accounts to pass to the program.
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
pub accounts: Vec<u8>,
/// The program input data.
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
pub data: Vec<u8>,
}

impl Sanitize for CompiledInstruction {}

impl CompiledInstruction {
#[cfg(feature = "bincode")]
pub fn new<T: serde::Serialize>(program_ids_index: u8, data: &T, accounts: Vec<u8>) -> Self {
let data = bincode::serialize(data).unwrap();
Self {
program_id_index: program_ids_index,
accounts,
data,
}
}

pub fn new_from_raw_parts(program_id_index: u8, data: Vec<u8>, accounts: Vec<u8>) -> Self {
Self {
program_id_index,
accounts,
data,
}
}

pub fn program_id<'a>(&self, program_ids: &'a [Pubkey]) -> &'a Pubkey {
&program_ids[self.program_id_index as usize]
}
}
Loading
Loading