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

Merged
merged 32 commits into from
Dec 2, 2024
Merged
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
2111b31
minimize solana_program usage in message module
kevinheavey Nov 18, 2024
7ed1013
move CompiledInstruction to message module
kevinheavey Nov 18, 2024
b63bd2e
move AddressLookupTableAccount to message module
kevinheavey Nov 18, 2024
2589199
update AddressLookupTableAccount import
kevinheavey Nov 18, 2024
dd959b7
start extracting message crate
kevinheavey Nov 19, 2024
753d473
copy ALL_IDS from sysvar module to avoid dependency
kevinheavey Nov 19, 2024
9ae4db5
update comment
kevinheavey Nov 19, 2024
1932228
use system-interface crate
kevinheavey Nov 19, 2024
e45a289
re-export message crate in solana-program
kevinheavey Nov 19, 2024
424a21b
fix tests
kevinheavey Nov 19, 2024
163a93d
fix doc links
kevinheavey Nov 19, 2024
a8c54c7
add doc_auto_cfg
kevinheavey Nov 19, 2024
7e3460d
make serde and bincode optional
kevinheavey Nov 19, 2024
8ed22d7
inline const from solana_nonce
kevinheavey Nov 19, 2024
cb4af8b
update lock file
kevinheavey Nov 19, 2024
058bce3
remove thiserror
kevinheavey Nov 19, 2024
b31ad82
frozen-abi support
kevinheavey Nov 19, 2024
73a2256
missing feature activation
kevinheavey Nov 19, 2024
ecf0331
unused import
kevinheavey Nov 19, 2024
aa5a7db
fix frozen-abi support
kevinheavey Nov 19, 2024
a8a1a9b
missing dep
kevinheavey Nov 19, 2024
af1fd6a
sort deps
kevinheavey Nov 19, 2024
aa09716
update digest
kevinheavey Nov 19, 2024
1e2f0de
update system-interface feature activation
kevinheavey Nov 21, 2024
86da791
update rev
kevinheavey Nov 21, 2024
b64d4bc
fmt
kevinheavey Nov 21, 2024
f51937b
use published system-interface crate
kevinheavey Nov 21, 2024
1bfcb1a
add test for inlined ALL_IDS
kevinheavey Nov 22, 2024
289461f
missing wasm-bindgen dep
kevinheavey Nov 26, 2024
705d2d7
reduce example_mocks usage
kevinheavey Nov 28, 2024
b89ead6
make blake3 optional
kevinheavey Nov 28, 2024
6dd02ce
post-rebase fix
kevinheavey Dec 2, 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
36 changes: 36 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 @@ -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
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
22 changes: 22 additions & 0 deletions programs/sbf/Cargo.lock

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

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]
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#[cfg(not(target_os = "solana"))]
use crate::{
address_lookup_table::AddressLookupTableAccount,
message::v0::{LoadedAddresses, MessageAddressTableLookup},
v0::{LoadedAddresses, MessageAddressTableLookup},
AddressLookupTableAccount,
};
use {
crate::{instruction::Instruction, message::MessageHeader, pubkey::Pubkey},
crate::MessageHeader, core::fmt, solana_instruction::Instruction, solana_pubkey::Pubkey,
std::collections::BTreeMap,
thiserror::Error,
};

/// A helper struct to collect pubkeys compiled for a set of instructions
Expand All @@ -17,16 +16,32 @@ pub(crate) struct CompiledKeys {
}

#[cfg_attr(target_os = "solana", allow(dead_code))]
#[derive(PartialEq, Debug, Error, Eq, Clone)]
#[derive(PartialEq, Debug, Eq, Clone)]
pub enum CompileError {
#[error("account index overflowed during compilation")]
AccountIndexOverflow,
#[error("address lookup table index overflowed during compilation")]
AddressTableLookupIndexOverflow,
#[error("encountered unknown account key `{0}` during instruction compilation")]
UnknownInstructionKey(Pubkey),
}

impl std::error::Error for CompileError {}

impl fmt::Display for CompileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CompileError::AccountIndexOverflow => {
f.write_str("account index overflowed during compilation")
}
CompileError::AddressTableLookupIndexOverflow => {
f.write_str("address lookup table index overflowed during compilation")
}
CompileError::UnknownInstructionKey(key) => f.write_fmt(format_args!(
"encountered unknown account key `{0}` during instruction compilation",
key,
)),
}
}
}

#[derive(Default, Debug, Clone, PartialEq, Eq)]
struct CompiledKeyMeta {
is_signer: bool,
Expand Down Expand Up @@ -184,7 +199,7 @@ impl CompiledKeys {

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

bitflags! {
#[derive(Clone, Copy)]
Expand Down
Loading
Loading