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 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
82a1aad
minimize solana_program usage in message module
kevinheavey Nov 18, 2024
879edc9
move CompiledInstruction to message module
kevinheavey Nov 18, 2024
8796525
move AddressLookupTableAccount to message module
kevinheavey Nov 18, 2024
6e22c78
update AddressLookupTableAccount import
kevinheavey Nov 18, 2024
51a2f36
start extracting message crate
kevinheavey Nov 19, 2024
6151a0c
copy ALL_IDS from sysvar module to avoid dependency
kevinheavey Nov 19, 2024
357b2ea
update comment
kevinheavey Nov 19, 2024
b5de46f
use system-interface crate
kevinheavey Nov 19, 2024
886cc7c
re-export message crate in solana-program
kevinheavey Nov 19, 2024
90fa81d
fix tests
kevinheavey Nov 19, 2024
f1d621b
fix doc links
kevinheavey Nov 19, 2024
06e683f
add doc_auto_cfg
kevinheavey Nov 19, 2024
79d972e
make serde and bincode optional
kevinheavey Nov 19, 2024
9e4ae97
inline const from solana_nonce
kevinheavey Nov 19, 2024
773d2be
update lock file
kevinheavey Nov 19, 2024
6d8e18a
remove thiserror
kevinheavey Nov 19, 2024
214b21d
frozen-abi support
kevinheavey Nov 19, 2024
bc4ac3f
missing feature activation
kevinheavey Nov 19, 2024
5122ef6
unused import
kevinheavey Nov 19, 2024
63e3481
fix frozen-abi support
kevinheavey Nov 19, 2024
be70471
missing dep
kevinheavey Nov 19, 2024
bcc66eb
sort deps
kevinheavey Nov 19, 2024
0c5cd7d
update digest
kevinheavey Nov 19, 2024
0100f18
update system-interface feature activation
kevinheavey Nov 21, 2024
a097b01
update rev
kevinheavey Nov 21, 2024
f36ff63
fmt
kevinheavey Nov 21, 2024
dcf0688
use published system-interface crate
kevinheavey Nov 21, 2024
ace0bf6
add test for inlined ALL_IDS
kevinheavey Nov 22, 2024
c58c2f3
Patch extra crates needed to unify build
joncinque Nov 25, 2024
daf43fb
missing wasm-bindgen dep
kevinheavey Nov 26, 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
51 changes: 51 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 @@ -487,6 +488,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 @@ -532,6 +534,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
37 changes: 37 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
75 changes: 75 additions & 0 deletions sdk/message/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[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"] }
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 }

[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",
]
dev-context-only-utils = ["bincode"]
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