From 034fa50007536362c1227f2de735d30fcc7b9be9 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Tue, 1 Feb 2022 22:57:12 +0800 Subject: [PATCH] wip: pushing to save progress --- cli/src/cluster_query.rs | 1 + cli/src/wallet.rs | 1 + client-test/tests/client.rs | 12 +- client/src/mock_sender.rs | 6 +- client/src/rpc_config.rs | 3 + client/src/rpc_custom_error.rs | 10 +- client/src/rpc_deprecated_config.rs | 2 + client/src/rpc_response.rs | 4 +- ledger-tool/src/bigtable.rs | 19 +- rpc/src/rpc.rs | 66 +++-- rpc/src/rpc_pubsub.rs | 1 + rpc/src/rpc_subscription_tracker.rs | 1 + rpc/src/rpc_subscriptions.rs | 48 +++- sdk/program/src/message/sanitized.rs | 18 +- sdk/program/src/message/versions/v0/loaded.rs | 68 +++-- sdk/program/src/message/versions/v0/mod.rs | 4 + sdk/src/transaction/sanitized.rs | 13 +- sdk/src/transaction/versioned.rs | 15 + transaction-status/src/lib.rs | 272 ++++++++++++++---- transaction-status/src/parse_accounts.rs | 18 +- 20 files changed, 437 insertions(+), 145 deletions(-) diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index 3d828046c689ce..fff8679bac3833 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -2004,6 +2004,7 @@ pub fn process_transaction_history( RpcTransactionConfig { encoding: Some(UiTransactionEncoding::Base64), commitment: Some(CommitmentConfig::confirmed()), + max_supported_transaction_version: None, }, ) { Ok(confirmed_transaction) => { diff --git a/cli/src/wallet.rs b/cli/src/wallet.rs index fbab92c5dbff0b..e1efd2d1b2fe57 100644 --- a/cli/src/wallet.rs +++ b/cli/src/wallet.rs @@ -556,6 +556,7 @@ pub fn process_confirm( RpcTransactionConfig { encoding: Some(UiTransactionEncoding::Base64), commitment: Some(CommitmentConfig::confirmed()), + max_supported_transaction_version: None, }, ) { Ok(confirmed_transaction) => { diff --git a/client-test/tests/client.rs b/client-test/tests/client.rs index d64af28f0d1469..a0959dd57fc3c0 100644 --- a/client-test/tests/client.rs +++ b/client-test/tests/client.rs @@ -36,7 +36,9 @@ use { }, solana_streamer::socket::SocketAddrSpace, solana_test_validator::TestValidator, - solana_transaction_status::{ConfirmedBlock, TransactionDetails, UiTransactionEncoding}, + solana_transaction_status::{ + BlockEncodingOptions, ConfirmedBlock, TransactionDetails, UiTransactionEncoding, + }, std::{ collections::HashSet, net::{IpAddr, SocketAddr}, @@ -270,6 +272,7 @@ fn test_block_subscription() { encoding: Some(UiTransactionEncoding::Json), transaction_details: Some(TransactionDetails::Signatures), show_rewards: None, + max_supported_transaction_version: None, }), ) .unwrap(); @@ -285,8 +288,11 @@ fn test_block_subscription() { let block = confirmed_block .encode_with_options( UiTransactionEncoding::Json, - TransactionDetails::Signatures, - false, + BlockEncodingOptions { + transaction_details: TransactionDetails::Signatures, + show_rewards: false, + max_supported_transaction_version: None, + }, ) .unwrap(); assert_eq!(actual.value.slot, slot); diff --git a/client/src/mock_sender.rs b/client/src/mock_sender.rs index aa301bc4265170..a4cde6e1e83e6a 100644 --- a/client/src/mock_sender.rs +++ b/client/src/mock_sender.rs @@ -28,7 +28,7 @@ use { pubkey::Pubkey, signature::Signature, sysvar::epoch_schedule::EpochSchedule, - transaction::{self, Transaction, TransactionError}, + transaction::{self, Transaction, TransactionError, TransactionVersion}, }, solana_transaction_status::{ EncodedConfirmedBlock, EncodedConfirmedTransactionWithStatusMeta, EncodedTransaction, @@ -192,6 +192,7 @@ impl RpcSender for MockSender { "getTransaction" => serde_json::to_value(EncodedConfirmedTransactionWithStatusMeta { slot: 2, transaction: EncodedTransactionWithStatusMeta { + version: Some(TransactionVersion::Legacy), transaction: EncodedTransaction::Json( UiTransaction { signatures: vec!["3AsdoALgZFuq2oUVWrDYhg2pNeaLJKPLf8hU2mQ6U8qJxeJ6hsrPVpMn9ma39DtfYCrDQSvngWRP8NnTpEhezJpE".to_string()], @@ -213,6 +214,7 @@ impl RpcSender for MockSender { accounts: vec![0, 1], data: "3Bxs49DitAvXtoDR".to_string(), }], + address_table_lookups: None, }) }), meta: Some(UiTransactionStatusMeta { @@ -226,6 +228,7 @@ impl RpcSender for MockSender { pre_token_balances: None, post_token_balances: None, rewards: None, + loaded_addresses: None, }), }, block_time: Some(1628633791), @@ -381,6 +384,7 @@ impl RpcSender for MockSender { UiTransactionEncoding::Base58, ), meta: None, + version: Some(TransactionVersion::Legacy), }], rewards: Rewards::new(), block_time: None, diff --git a/client/src/rpc_config.rs b/client/src/rpc_config.rs index edf3dc819877d8..380d180a5af37a 100644 --- a/client/src/rpc_config.rs +++ b/client/src/rpc_config.rs @@ -197,6 +197,7 @@ pub struct RpcBlockSubscribeConfig { pub encoding: Option, pub transaction_details: Option, pub show_rewards: Option, + pub max_supported_transaction_version: Option, } #[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)] @@ -248,6 +249,7 @@ pub struct RpcBlockConfig { pub rewards: Option, #[serde(flatten)] pub commitment: Option, + pub max_supported_transaction_version: Option, } impl EncodingConfig for RpcBlockConfig { @@ -288,6 +290,7 @@ pub struct RpcTransactionConfig { pub encoding: Option, #[serde(flatten)] pub commitment: Option, + pub max_supported_transaction_version: Option, } impl EncodingConfig for RpcTransactionConfig { diff --git a/client/src/rpc_custom_error.rs b/client/src/rpc_custom_error.rs index d443a294236ffb..ae8fc545c55069 100644 --- a/client/src/rpc_custom_error.rs +++ b/client/src/rpc_custom_error.rs @@ -60,7 +60,7 @@ pub enum RpcCustomError { #[error("BlockStatusNotAvailableYet")] BlockStatusNotAvailableYet { slot: Slot }, #[error("UnsupportedTransactionVersion")] - UnsupportedTransactionVersion, + UnsupportedTransactionVersion(u8), } #[derive(Debug, Serialize, Deserialize)] @@ -72,7 +72,9 @@ pub struct NodeUnhealthyErrorData { impl From for RpcCustomError { fn from(err: EncodeError) -> Self { match err { - EncodeError::UnsupportedTransactionVersion => Self::UnsupportedTransactionVersion, + EncodeError::UnsupportedTransactionVersion(version) => { + Self::UnsupportedTransactionVersion(version) + } } } } @@ -181,9 +183,9 @@ impl From for Error { message: format!("Block status not yet available for slot {}", slot), data: None, }, - RpcCustomError::UnsupportedTransactionVersion => Self { + RpcCustomError::UnsupportedTransactionVersion(version) => Self { code: ErrorCode::ServerError(JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION), - message: "Versioned transactions are not supported".to_string(), + message: format!("Transaction version ({}) is not supported", version), data: None, }, } diff --git a/client/src/rpc_deprecated_config.rs b/client/src/rpc_deprecated_config.rs index 9062513ba55d79..eb4fbaea8c323d 100644 --- a/client/src/rpc_deprecated_config.rs +++ b/client/src/rpc_deprecated_config.rs @@ -71,6 +71,7 @@ impl From for RpcBlockConfig { transaction_details: config.transaction_details, rewards: config.rewards, commitment: config.commitment, + max_supported_transaction_version: None, } } } @@ -98,6 +99,7 @@ impl From for RpcTransactionConfig { Self { encoding: config.encoding, commitment: config.commitment, + max_supported_transaction_version: None, } } } diff --git a/client/src/rpc_response.rs b/client/src/rpc_response.rs index a625072ebb06cd..169b52e4e2f5ea 100644 --- a/client/src/rpc_response.rs +++ b/client/src/rpc_response.rs @@ -432,8 +432,8 @@ pub enum RpcBlockUpdateError { #[error("block store error")] BlockStoreError, - #[error("unsupported transaction version")] - UnsupportedTransactionVersion, + #[error("unsupported transaction version ({0})")] + UnsupportedTransactionVersion(u8), } #[derive(Serialize, Deserialize, Debug)] diff --git a/ledger-tool/src/bigtable.rs b/ledger-tool/src/bigtable.rs index 9c599a2af41e05..f8a7bcebf7422b 100644 --- a/ledger-tool/src/bigtable.rs +++ b/ledger-tool/src/bigtable.rs @@ -17,8 +17,8 @@ use { solana_ledger::{blockstore::Blockstore, blockstore_db::AccessType}, solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Signature}, solana_transaction_status::{ - ConfirmedBlock, Encodable, EncodeError, LegacyTransactionWithStatusMeta, - UiTransactionEncoding, + BlockEncodingOptions, ConfirmedBlock, Encodable, EncodeError, + LegacyTransactionWithStatusMeta, UiTransactionEncoding, }, std::{ collections::HashSet, @@ -76,10 +76,19 @@ async fn block(slot: Slot, output_format: OutputFormat) -> Result<(), Box { - "Failed to process unsupported transaction version in block".to_string() + EncodeError::UnsupportedTransactionVersion(version) => { + format!( + "Failed to process unsupported transaction version ({}) in block", + version + ) } })?; diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 793a6be40d10a9..7e76e09ae70f98 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -69,8 +69,7 @@ use { system_instruction, sysvar::stake_history, transaction::{ - self, DisabledAddressLoader, SanitizedTransaction, TransactionError, - VersionedTransaction, + self, AddressLoader, SanitizedTransaction, TransactionError, VersionedTransaction, }, }, solana_send_transaction_service::{ @@ -80,7 +79,7 @@ use { solana_storage_bigtable::Error as StorageError, solana_streamer::socket::SocketAddrSpace, solana_transaction_status::{ - ConfirmedBlock, ConfirmedTransactionStatusWithSignature, + BlockEncodingOptions, ConfirmedBlock, ConfirmedTransactionStatusWithSignature, ConfirmedTransactionWithStatusMeta, EncodedConfirmedTransactionWithStatusMeta, Reward, RewardType, TransactionConfirmationStatus, TransactionStatus, UiConfirmedBlock, UiTransactionEncoding, @@ -983,10 +982,13 @@ impl JsonRpcRequestProcessor { let config = config .map(|config| config.convert_to_current()) .unwrap_or_default(); - let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Json); - let transaction_details = config.transaction_details.unwrap_or_default(); - let show_rewards = config.rewards.unwrap_or(true); let commitment = config.commitment.unwrap_or_default(); + let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Json); + let encoding_options = BlockEncodingOptions { + transaction_details: config.transaction_details.unwrap_or_default(), + show_rewards: config.rewards.unwrap_or(true), + max_supported_transaction_version: config.max_supported_transaction_version, + }; check_is_at_least_confirmed(commitment)?; // Block is old enough to be finalized @@ -1007,7 +1009,7 @@ impl JsonRpcRequestProcessor { confirmed_block.block_height = Some(0); } Ok(confirmed_block - .encode_with_options(encoding, transaction_details, show_rewards) + .encode_with_options(encoding, encoding_options) .map_err(RpcCustomError::from)?) }; if result.is_err() { @@ -1051,7 +1053,7 @@ impl JsonRpcRequestProcessor { } Ok(confirmed_block - .encode_with_options(encoding, transaction_details, show_rewards) + .encode_with_options(encoding, encoding_options) .map_err(RpcCustomError::from)?) }) .transpose(); @@ -1373,8 +1375,9 @@ impl JsonRpcRequestProcessor { let config = config .map(|config| config.convert_to_current()) .unwrap_or_default(); - let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Json); let commitment = config.commitment.unwrap_or_default(); + let encoding = config.encoding.unwrap_or(UiTransactionEncoding::Json); + let max_supported_transaction_version = config.max_supported_transaction_version; check_is_at_least_confirmed(commitment)?; if self.config.enable_rpc_transaction_history { @@ -1389,7 +1392,7 @@ impl JsonRpcRequestProcessor { let encode_transaction = |confirmed_tx: ConfirmedTransactionWithStatusMeta| -> Result { - Ok(confirmed_tx.encode(encoding).map_err(RpcCustomError::from)?) + Ok(confirmed_tx.encode(encoding, max_supported_transaction_version).map_err(RpcCustomError::from)?) }; match confirmed_transaction.unwrap_or(None) { @@ -3459,7 +3462,8 @@ pub mod rpc_full { .preflight_commitment .map(|commitment| CommitmentConfig { commitment }); let preflight_bank = &*meta.bank(preflight_commitment); - let transaction = sanitize_transaction(unsanitized_tx)?; + let finalized_bank = &*meta.bank(Some(CommitmentConfig::finalized())); + let transaction = sanitize_transaction(unsanitized_tx, finalized_bank)?; let signature = *transaction.signature(); let mut last_valid_block_height = preflight_bank @@ -3567,7 +3571,8 @@ pub mod rpc_full { .set_recent_blockhash(bank.last_blockhash()); } - let transaction = sanitize_transaction(unsanitized_tx)?; + let finalized_bank = &*meta.bank(Some(CommitmentConfig::finalized())); + let transaction = sanitize_transaction(unsanitized_tx, finalized_bank)?; if config.sig_verify { verify_transaction(&transaction, &bank.feature_set)?; } @@ -4252,9 +4257,12 @@ where .map(|output| (wire_output, output)) } -fn sanitize_transaction(transaction: VersionedTransaction) -> Result { +fn sanitize_transaction( + transaction: VersionedTransaction, + address_loader: &impl AddressLoader, +) -> Result { let message_hash = transaction.message.hash(); - SanitizedTransaction::try_create(transaction, message_hash, None, &DisabledAddressLoader) + SanitizedTransaction::try_create(transaction, message_hash, None, address_loader) .map_err(|err| Error::invalid_params(format!("invalid transaction: {}", err))) } @@ -4379,7 +4387,7 @@ pub mod tests { signature::{Keypair, Signer}, system_program, system_transaction, timing::slot_duration_from_slots_per_year, - transaction::{self, Transaction, TransactionError}, + transaction::{self, DisabledAddressLoader, Transaction, TransactionError}, }, solana_transaction_status::{ EncodedConfirmedBlock, EncodedTransaction, EncodedTransactionWithStatusMeta, @@ -6579,9 +6587,16 @@ pub mod tests { assert_eq!(confirmed_block.transactions.len(), 2); assert_eq!(confirmed_block.rewards, vec![]); - for EncodedTransactionWithStatusMeta { transaction, meta } in - confirmed_block.transactions.into_iter() + for EncodedTransactionWithStatusMeta { + transaction, + meta, + version, + } in confirmed_block.transactions.into_iter() { + assert_eq!( + version, None, + "requests which don't enable versioned transactions should not receive a version" + ); if let EncodedTransaction::Json(transaction) = transaction { if transaction.signatures[0] == confirmed_block_signatures[0].to_string() { let meta = meta.unwrap(); @@ -6624,9 +6639,16 @@ pub mod tests { assert_eq!(confirmed_block.transactions.len(), 2); assert_eq!(confirmed_block.rewards, vec![]); - for EncodedTransactionWithStatusMeta { transaction, meta } in - confirmed_block.transactions.into_iter() + for EncodedTransactionWithStatusMeta { + transaction, + meta, + version, + } in confirmed_block.transactions.into_iter() { + assert_eq!( + version, None, + "requests which don't enable versioned transactions should not receive a version" + ); if let EncodedTransaction::LegacyBinary(transaction) = transaction { let decoded_transaction: Transaction = deserialize(&bs58::decode(&transaction).into_vec().unwrap()).unwrap(); @@ -6686,6 +6708,7 @@ pub mod tests { transaction_details: Some(TransactionDetails::Signatures), rewards: Some(false), commitment: None, + max_supported_transaction_version: None, }) ); let res = io.handle_request_sync(&req, meta.clone()); @@ -6707,6 +6730,7 @@ pub mod tests { transaction_details: Some(TransactionDetails::None), rewards: Some(true), commitment: None, + max_supported_transaction_version: None, }) ); let res = io.handle_request_sync(&req, meta); @@ -8064,7 +8088,7 @@ pub mod tests { .to_string(), ); assert_eq!( - sanitize_transaction(unsanitary_versioned_tx).unwrap_err(), + sanitize_transaction(unsanitary_versioned_tx, &DisabledAddressLoader).unwrap_err(), expect58 ); } @@ -8084,7 +8108,7 @@ pub mod tests { }; assert_eq!( - sanitize_transaction(versioned_tx).unwrap_err(), + sanitize_transaction(versioned_tx, &DisabledAddressLoader).unwrap_err(), Error::invalid_params( "invalid transaction: Transaction version is unsupported".to_string(), ) diff --git a/rpc/src/rpc_pubsub.rs b/rpc/src/rpc_pubsub.rs index e0144017acffa2..db2b9623246192 100644 --- a/rpc/src/rpc_pubsub.rs +++ b/rpc/src/rpc_pubsub.rs @@ -538,6 +538,7 @@ impl RpcSolPubSubInternal for RpcSolPubSubImpl { }, transaction_details: config.transaction_details.unwrap_or_default(), show_rewards: config.show_rewards.unwrap_or_default(), + max_supported_transaction_version: config.max_supported_transaction_version, }; self.subscribe(SubscriptionParams::Block(params)) } diff --git a/rpc/src/rpc_subscription_tracker.rs b/rpc/src/rpc_subscription_tracker.rs index c49ff6fd942a24..ffeffcb7b679ea 100644 --- a/rpc/src/rpc_subscription_tracker.rs +++ b/rpc/src/rpc_subscription_tracker.rs @@ -140,6 +140,7 @@ pub struct BlockSubscriptionParams { pub kind: BlockSubscriptionKind, pub transaction_details: TransactionDetails, pub show_rewards: bool, + pub max_supported_transaction_version: Option, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/rpc/src/rpc_subscriptions.rs b/rpc/src/rpc_subscriptions.rs index 2ec139aae122b9..e8a09266df7c37 100644 --- a/rpc/src/rpc_subscriptions.rs +++ b/rpc/src/rpc_subscriptions.rs @@ -40,7 +40,9 @@ use { timing::timestamp, transaction, }, - solana_transaction_status::{ConfirmedBlock, EncodeError, VersionedConfirmedBlock}, + solana_transaction_status::{ + BlockEncodingOptions, ConfirmedBlock, EncodeError, VersionedConfirmedBlock, + }, std::{ cell::RefCell, collections::{HashMap, VecDeque}, @@ -300,12 +302,15 @@ fn filter_block_result_txs( let block = ConfirmedBlock::from(block) .encode_with_options( params.encoding, - params.transaction_details, - params.show_rewards, + BlockEncodingOptions { + transaction_details: params.transaction_details, + show_rewards: params.show_rewards, + max_supported_transaction_version: params.max_supported_transaction_version, + }, ) .map_err(|err| match err { - EncodeError::UnsupportedTransactionVersion => { - RpcBlockUpdateError::UnsupportedTransactionVersion + EncodeError::UnsupportedTransactionVersion(version) => { + RpcBlockUpdateError::UnsupportedTransactionVersion(version) } })?; @@ -1380,6 +1385,7 @@ pub(crate) mod tests { encoding: Some(UiTransactionEncoding::Json), transaction_details: Some(TransactionDetails::Signatures), show_rewards: None, + max_supported_transaction_version: None, }; let params = BlockSubscriptionParams { kind: BlockSubscriptionKind::All, @@ -1387,6 +1393,7 @@ pub(crate) mod tests { encoding: config.encoding.unwrap(), transaction_details: config.transaction_details.unwrap(), show_rewards: config.show_rewards.unwrap_or_default(), + max_supported_transaction_version: config.max_supported_transaction_version, }; let sub_id = rpc.block_subscribe(filter, Some(config)).unwrap(); @@ -1417,7 +1424,14 @@ pub(crate) mod tests { let confirmed_block = ConfirmedBlock::from(blockstore.get_complete_block(slot, false).unwrap()); let block = confirmed_block - .encode_with_options(params.encoding, params.transaction_details, false) + .encode_with_options( + params.encoding, + BlockEncodingOptions { + transaction_details: params.transaction_details, + show_rewards: false, + max_supported_transaction_version: None, + }, + ) .unwrap(); let expected_resp = RpcBlockUpdate { slot, @@ -1488,6 +1502,7 @@ pub(crate) mod tests { encoding: Some(UiTransactionEncoding::Json), transaction_details: Some(TransactionDetails::Signatures), show_rewards: None, + max_supported_transaction_version: None, }; let params = BlockSubscriptionParams { kind: BlockSubscriptionKind::MentionsAccountOrProgram(keypair1.pubkey()), @@ -1495,6 +1510,7 @@ pub(crate) mod tests { encoding: config.encoding.unwrap(), transaction_details: config.transaction_details.unwrap(), show_rewards: config.show_rewards.unwrap_or_default(), + max_supported_transaction_version: config.max_supported_transaction_version, }; let sub_id = rpc.block_subscribe(filter, Some(config)).unwrap(); @@ -1531,7 +1547,14 @@ pub(crate) mod tests { .any(|key| key == &keypair1.pubkey()) }); let block = confirmed_block - .encode_with_options(params.encoding, params.transaction_details, false) + .encode_with_options( + params.encoding, + BlockEncodingOptions { + transaction_details: params.transaction_details, + show_rewards: false, + max_supported_transaction_version: None, + }, + ) .unwrap(); let expected_resp = RpcBlockUpdate { slot, @@ -1590,6 +1613,7 @@ pub(crate) mod tests { encoding: Some(UiTransactionEncoding::Json), transaction_details: Some(TransactionDetails::Signatures), show_rewards: None, + max_supported_transaction_version: None, }; let params = BlockSubscriptionParams { kind: BlockSubscriptionKind::All, @@ -1597,6 +1621,7 @@ pub(crate) mod tests { encoding: config.encoding.unwrap(), transaction_details: config.transaction_details.unwrap(), show_rewards: config.show_rewards.unwrap_or_default(), + max_supported_transaction_version: config.max_supported_transaction_version, }; let sub_id = rpc.block_subscribe(filter, Some(config)).unwrap(); subscriptions @@ -1631,7 +1656,14 @@ pub(crate) mod tests { let confirmed_block = ConfirmedBlock::from(blockstore.get_complete_block(slot, false).unwrap()); let block = confirmed_block - .encode_with_options(params.encoding, params.transaction_details, false) + .encode_with_options( + params.encoding, + BlockEncodingOptions { + transaction_details: params.transaction_details, + show_rewards: false, + max_supported_transaction_version: None, + }, + ) .unwrap(); let expected_resp = RpcBlockUpdate { slot, diff --git a/sdk/program/src/message/sanitized.rs b/sdk/program/src/message/sanitized.rs index 41e8a7d4953cb8..5b402596cddff8 100644 --- a/sdk/program/src/message/sanitized.rs +++ b/sdk/program/src/message/sanitized.rs @@ -25,7 +25,7 @@ pub enum SanitizedMessage { /// Sanitized legacy message Legacy(LegacyMessage), /// Sanitized version #0 message with dynamically loaded addresses - V0(v0::LoadedMessage), + V0(v0::LoadedMessage<'static>), } #[derive(PartialEq, Debug, Error, Eq, Clone)] @@ -348,8 +348,8 @@ mod tests { assert_eq!(legacy_message.num_readonly_accounts(), 2); - let v0_message = SanitizedMessage::V0(v0::LoadedMessage { - message: v0::Message { + let v0_message = SanitizedMessage::V0(v0::LoadedMessage::new( + v0::Message { header: MessageHeader { num_required_signatures: 2, num_readonly_signed_accounts: 1, @@ -358,11 +358,11 @@ mod tests { account_keys: vec![key0, key1, key2, key3], ..v0::Message::default() }, - loaded_addresses: LoadedAddresses { + LoadedAddresses { writable: vec![key4], readonly: vec![key5], }, - }); + )); assert_eq!(v0_message.num_readonly_accounts(), 3); } @@ -415,8 +415,8 @@ mod tests { }) .unwrap(); - let v0_message = SanitizedMessage::V0(v0::LoadedMessage { - message: v0::Message { + let v0_message = SanitizedMessage::V0(v0::LoadedMessage::new( + v0::Message { header: MessageHeader { num_required_signatures: 1, num_readonly_signed_accounts: 0, @@ -425,11 +425,11 @@ mod tests { account_keys: vec![key0, key1], ..v0::Message::default() }, - loaded_addresses: LoadedAddresses { + LoadedAddresses { writable: vec![key2], readonly: vec![program_id], }, - }); + )); for message in vec![legacy_message, v0_message] { assert_eq!( diff --git a/sdk/program/src/message/versions/v0/loaded.rs b/sdk/program/src/message/versions/v0/loaded.rs index 4684f17eb1b043..240d0ccb63a66c 100644 --- a/sdk/program/src/message/versions/v0/loaded.rs +++ b/sdk/program/src/message/versions/v0/loaded.rs @@ -5,19 +5,19 @@ use { pubkey::Pubkey, sysvar, }, - std::{collections::HashSet, ops::Deref}, + std::{borrow::Cow, collections::HashSet, ops::Deref}, }; /// Combination of a version #0 message and its loaded addresses #[derive(Debug, Clone)] -pub struct LoadedMessage { +pub struct LoadedMessage<'a> { /// Message which loaded a collection of lookup table addresses - pub message: v0::Message, + pub message: Cow<'a, v0::Message>, /// Addresses loaded with on-chain address lookup tables - pub loaded_addresses: LoadedAddresses, + pub loaded_addresses: Cow<'a, LoadedAddresses>, } -impl Deref for LoadedMessage { +impl Deref for LoadedMessage<'_> { type Target = v0::Message; fn deref(&self) -> &Self::Target { &self.message @@ -59,7 +59,21 @@ impl LoadedAddresses { } } -impl LoadedMessage { +impl<'a> LoadedMessage<'a> { + pub fn new(message: v0::Message, loaded_addresses: LoadedAddresses) -> Self { + Self { + message: Cow::Owned(message), + loaded_addresses: Cow::Owned(loaded_addresses), + } + } + + pub fn new_borrowed(message: &'a v0::Message, loaded_addresses: &'a LoadedAddresses) -> Self { + Self { + message: Cow::Borrowed(message), + loaded_addresses: Cow::Borrowed(loaded_addresses), + } + } + /// Returns the list of account keys that are loaded for this message. pub fn account_keys(&self) -> AccountKeys { AccountKeys::new(&self.account_keys, Some(&self.loaded_addresses)) @@ -135,7 +149,7 @@ mod tests { itertools::Itertools, }; - fn check_test_loaded_message() -> (LoadedMessage, [Pubkey; 6]) { + fn check_test_loaded_message() -> (LoadedMessage<'static>, [Pubkey; 6]) { let key0 = Pubkey::new_unique(); let key1 = Pubkey::new_unique(); let key2 = Pubkey::new_unique(); @@ -143,8 +157,8 @@ mod tests { let key4 = Pubkey::new_unique(); let key5 = Pubkey::new_unique(); - let message = LoadedMessage { - message: v0::Message { + let message = LoadedMessage::new( + v0::Message { header: MessageHeader { num_required_signatures: 2, num_readonly_signed_accounts: 1, @@ -153,11 +167,11 @@ mod tests { account_keys: vec![key0, key1, key2, key3], ..v0::Message::default() }, - loaded_addresses: LoadedAddresses { + LoadedAddresses { writable: vec![key4], readonly: vec![key5], }, - }; + ); (message, [key0, key1, key2, key3, key4, key5]) } @@ -171,15 +185,17 @@ mod tests { #[test] fn test_has_duplicates_with_dupe_keys() { - let create_message_with_dupe_keys = |mut keys: Vec| LoadedMessage { - message: v0::Message { - account_keys: keys.split_off(2), - ..v0::Message::default() - }, - loaded_addresses: LoadedAddresses { - writable: keys.split_off(2), - readonly: keys, - }, + let create_message_with_dupe_keys = |mut keys: Vec| { + LoadedMessage::new( + v0::Message { + account_keys: keys.split_off(2), + ..v0::Message::default() + }, + LoadedAddresses { + writable: keys.split_off(2), + readonly: keys, + }, + ) }; let key0 = Pubkey::new_unique(); @@ -212,11 +228,11 @@ mod tests { fn test_is_writable() { let mut message = check_test_loaded_message().0; - message.message.account_keys[0] = sysvar::clock::id(); + message.message.to_mut().account_keys[0] = sysvar::clock::id(); assert!(message.is_writable_index(0)); assert!(!message.is_writable(0)); - message.message.account_keys[0] = system_program::id(); + message.message.to_mut().account_keys[0] = system_program::id(); assert!(message.is_writable_index(0)); assert!(!message.is_writable(0)); } @@ -226,8 +242,8 @@ mod tests { let key0 = Pubkey::new_unique(); let key1 = Pubkey::new_unique(); let key2 = Pubkey::new_unique(); - let message = LoadedMessage { - message: v0::Message { + let message = LoadedMessage::new( + v0::Message { header: MessageHeader { num_required_signatures: 1, num_readonly_signed_accounts: 0, @@ -241,11 +257,11 @@ mod tests { }], ..v0::Message::default() }, - loaded_addresses: LoadedAddresses { + LoadedAddresses { writable: vec![key1, key2], readonly: vec![], }, - }; + ); assert!(message.is_writable_index(2)); assert!(!message.is_writable(2)); diff --git a/sdk/program/src/message/versions/v0/mod.rs b/sdk/program/src/message/versions/v0/mod.rs index 1e98d5c3d60a8c..cc8643b2ad4d97 100644 --- a/sdk/program/src/message/versions/v0/mod.rs +++ b/sdk/program/src/message/versions/v0/mod.rs @@ -117,6 +117,10 @@ impl Sanitize for Message { } impl Message { + pub fn is_signer(&self, i: usize) -> bool { + i < self.header.num_required_signatures as usize + } + /// Serialize this message with a version #0 prefix using bincode encoding. pub fn serialize(&self) -> Vec { bincode::serialize(&(MESSAGE_VERSION_PREFIX, self)).unwrap() diff --git a/sdk/src/transaction/sanitized.rs b/sdk/src/transaction/sanitized.rs index 8b7cb2994bb2d0..9e3fb7287a0a41 100644 --- a/sdk/src/transaction/sanitized.rs +++ b/sdk/src/transaction/sanitized.rs @@ -65,10 +65,11 @@ impl SanitizedTransaction { let signatures = tx.signatures; let message = match tx.message { VersionedMessage::Legacy(message) => SanitizedMessage::Legacy(message), - VersionedMessage::V0(message) => SanitizedMessage::V0(v0::LoadedMessage { - loaded_addresses: address_loader.load_addresses(&message.address_table_lookups)?, - message, - }), + VersionedMessage::V0(message) => { + let loaded_addresses = + address_loader.load_addresses(&message.address_table_lookups)?; + SanitizedMessage::V0(v0::LoadedMessage::new(message, loaded_addresses)) + } }; let is_simple_vote_tx = is_simple_vote_tx.unwrap_or_else(|| { @@ -139,7 +140,7 @@ impl SanitizedTransaction { match &self.message { SanitizedMessage::V0(sanitized_msg) => VersionedTransaction { signatures, - message: VersionedMessage::V0(sanitized_msg.message.clone()), + message: VersionedMessage::V0(v0::Message::clone(&sanitized_msg.message)), }, SanitizedMessage::Legacy(message) => VersionedTransaction { signatures, @@ -191,7 +192,7 @@ impl SanitizedTransaction { pub fn get_loaded_addresses(&self) -> LoadedAddresses { match &self.message { SanitizedMessage::Legacy(_) => LoadedAddresses::default(), - SanitizedMessage::V0(message) => message.loaded_addresses.clone(), + SanitizedMessage::V0(message) => LoadedAddresses::clone(&message.loaded_addresses), } } diff --git a/sdk/src/transaction/versioned.rs b/sdk/src/transaction/versioned.rs index 2e36f21dd1caca..122de5ede872d2 100644 --- a/sdk/src/transaction/versioned.rs +++ b/sdk/src/transaction/versioned.rs @@ -17,6 +17,13 @@ use { std::cmp::Ordering, }; +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase", untagged)] +pub enum TransactionVersion { + Legacy, + Number(u8), +} + // NOTE: Serialization-related changes must be paired with the direct read at sigverify. /// An atomic transaction #[derive(Debug, PartialEq, Default, Eq, Clone, Serialize, Deserialize, AbiExample)] @@ -93,6 +100,14 @@ impl VersionedTransaction { }) } + /// Returns the version of the transaction + pub fn version(&self) -> TransactionVersion { + match self.message { + VersionedMessage::Legacy(_) => TransactionVersion::Legacy, + VersionedMessage::V0(_) => TransactionVersion::Number(0), + } + } + /// Returns a legacy transaction if the transaction message is legacy. pub fn into_legacy_transaction(self) -> Option { match self.message { diff --git a/transaction-status/src/lib.rs b/transaction-status/src/lib.rs index aac0f261cb29ce..52b7ad58822ea2 100644 --- a/transaction-status/src/lib.rs +++ b/transaction-status/src/lib.rs @@ -18,7 +18,9 @@ pub mod token_balances; pub use {crate::extract_memos::extract_and_fmt_memos, solana_runtime::bank::RewardType}; use { crate::{ - parse_accounts::{parse_accounts, ParsedAccount}, + parse_accounts::{ + parse_legacy_message_accounts, parse_loaded_message_accounts, ParsedAccount, + }, parse_instruction::{parse, ParsedInstruction}, }, solana_account_decoder::parse_token::UiTokenAmount, @@ -26,21 +28,42 @@ use { clock::{Slot, UnixTimestamp}, commitment_config::CommitmentConfig, instruction::CompiledInstruction, - message::{v0::LoadedAddresses, AccountKeys, Message, MessageHeader}, + message::{ + v0::{self, LoadedAddresses, LoadedMessage, MessageAddressTableLookup}, + AccountKeys, Message, MessageHeader, VersionedMessage, + }, + pubkey::Pubkey, sanitize::Sanitize, signature::Signature, transaction::{ - Result as TransactionResult, Transaction, TransactionError, VersionedTransaction, + Result as TransactionResult, Transaction, TransactionError, TransactionVersion, + VersionedTransaction, }, }, std::fmt, thiserror::Error, }; +pub struct BlockEncodingOptions { + pub transaction_details: TransactionDetails, + pub show_rewards: bool, + pub max_supported_transaction_version: Option, +} + +impl Default for BlockEncodingOptions { + fn default() -> Self { + Self { + transaction_details: TransactionDetails::Full, + show_rewards: true, + max_supported_transaction_version: Some(0u8), + } + } +} + #[derive(Error, Debug, PartialEq, Eq, Clone)] pub enum EncodeError { - #[error("Failed to encode unsupported transaction version")] - UnsupportedTransactionVersion, + #[error("Encoding does not support transaction version {0}")] + UnsupportedTransactionVersion(u8), } /// Represents types that can be encoded into one of several encoding formats @@ -49,6 +72,16 @@ pub trait Encodable { fn encode(&self, encoding: UiTransactionEncoding) -> Self::Encoded; } +/// Represents types that can be encoded into one of several encoding formats +pub trait EncodableWithMeta { + type Encoded; + fn encode_with_meta( + &self, + encoding: UiTransactionEncoding, + meta: &TransactionStatusMeta, + ) -> Self::Encoded; +} + #[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, Hash, PartialEq)] #[serde(rename_all = "camelCase")] pub enum UiTransactionEncoding { @@ -169,14 +202,13 @@ pub struct UiInnerInstructions { } impl UiInnerInstructions { - fn parse(inner_instructions: InnerInstructions, message: &Message) -> Self { - let account_keys = AccountKeys::new(&message.account_keys, None); + fn parse(inner_instructions: InnerInstructions, account_keys: &AccountKeys) -> Self { Self { index: inner_instructions.index, instructions: inner_instructions .instructions .iter() - .map(|ix| UiInstruction::parse(ix, &account_keys)) + .map(|ix| UiInstruction::parse(ix, account_keys)) .collect(), } } @@ -273,10 +305,38 @@ pub struct UiTransactionStatusMeta { pub pre_token_balances: Option>, pub post_token_balances: Option>, pub rewards: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub loaded_addresses: Option, +} + +/// A duplicate representation of LoadedAddresses +#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct UiLoadedAddresses { + pub writable: Vec, + pub readonly: Vec, +} + +impl From<&LoadedAddresses> for UiLoadedAddresses { + fn from(loaded_addresses: &LoadedAddresses) -> Self { + Self { + writable: loaded_addresses + .writable + .iter() + .map(ToString::to_string) + .collect(), + readonly: loaded_addresses + .readonly + .iter() + .map(ToString::to_string) + .collect(), + } + } } impl UiTransactionStatusMeta { - fn parse(meta: TransactionStatusMeta, message: &Message) -> Self { + fn parse(meta: TransactionStatusMeta, static_keys: &[Pubkey]) -> Self { + let account_keys = AccountKeys::new(static_keys, Some(&meta.loaded_addresses)); Self { err: meta.status.clone().err(), status: meta.status, @@ -285,7 +345,7 @@ impl UiTransactionStatusMeta { post_balances: meta.post_balances, inner_instructions: meta.inner_instructions.map(|ixs| { ixs.into_iter() - .map(|ix| UiInnerInstructions::parse(ix, message)) + .map(|ix| UiInnerInstructions::parse(ix, &account_keys)) .collect() }), log_messages: meta.log_messages, @@ -296,6 +356,7 @@ impl UiTransactionStatusMeta { .post_token_balances .map(|balance| balance.into_iter().map(Into::into).collect()), rewards: meta.rewards, + loaded_addresses: Some(UiLoadedAddresses::from(&meta.loaded_addresses)), } } } @@ -319,6 +380,7 @@ impl From for UiTransactionStatusMeta { .post_token_balances .map(|balance| balance.into_iter().map(Into::into).collect()), rewards: meta.rewards, + loaded_addresses: Some(UiLoadedAddresses::from(&meta.loaded_addresses)), } } } @@ -440,22 +502,19 @@ impl From for ConfirmedBlock { } impl ConfirmedBlock { - pub fn encode(self, encoding: UiTransactionEncoding) -> Result { - self.encode_with_options(encoding, TransactionDetails::Full, true) - } - pub fn encode_with_options( self, encoding: UiTransactionEncoding, - transaction_details: TransactionDetails, - show_rewards: bool, + options: BlockEncodingOptions, ) -> Result { - let (transactions, signatures) = match transaction_details { + let (transactions, signatures) = match options.transaction_details { TransactionDetails::Full => ( Some( self.transactions .into_iter() - .map(|tx_with_meta| tx_with_meta.encode(encoding)) + .map(|tx_with_meta| { + tx_with_meta.encode(encoding, options.max_supported_transaction_version) + }) .collect::, _>>()?, ), None, @@ -477,7 +536,7 @@ impl ConfirmedBlock { parent_slot: self.parent_slot, transactions, signatures, - rewards: if show_rewards { + rewards: if options.show_rewards { Some(self.rewards) } else { None @@ -530,21 +589,6 @@ pub struct UiConfirmedBlock { pub block_height: Option, } -impl From for UiConfirmedBlock { - fn from(block: EncodedConfirmedBlock) -> Self { - Self { - previous_blockhash: block.previous_blockhash, - blockhash: block.blockhash, - parent_slot: block.parent_slot, - transactions: Some(block.transactions), - signatures: None, - rewards: Some(block.rewards), - block_time: block.block_time, - block_height: block.block_height, - } - } -} - #[derive(Clone, Debug, PartialEq)] #[allow(clippy::large_enum_variant)] pub enum TransactionWithStatusMeta { @@ -563,13 +607,17 @@ impl TransactionWithStatusMeta { pub fn encode( self, encoding: UiTransactionEncoding, + max_supported_transaction_version: Option, ) -> Result { match self { - Self::MissingMetadata(transaction) => Ok(EncodedTransactionWithStatusMeta { + Self::MissingMetadata(ref transaction) => Ok(EncodedTransactionWithStatusMeta { + version: None, transaction: transaction.encode(encoding), meta: None, }), - Self::Ok(tx_with_meta) => tx_with_meta.encode(encoding), + Self::Ok(tx_with_meta) => { + tx_with_meta.encode(encoding, max_supported_transaction_version) + } } } @@ -581,9 +629,10 @@ impl TransactionWithStatusMeta { meta: None, }) } - TransactionWithStatusMeta::Ok(tx_with_meta) => { - tx_with_meta.into_legacy_transaction_with_meta() - } + TransactionWithStatusMeta::Ok(tx_with_meta) => Some(LegacyTransactionWithStatusMeta { + transaction: tx_with_meta.transaction.into_legacy_transaction()?, + meta: Some(tx_with_meta.meta), + }), } } @@ -614,18 +663,37 @@ impl VersionedTransactionWithStatusMeta { pub fn encode( self, encoding: UiTransactionEncoding, + max_supported_transaction_version: Option, ) -> Result { - let LegacyTransactionWithStatusMeta { transaction, meta } = self - .into_legacy_transaction_with_meta() - .ok_or(EncodeError::UnsupportedTransactionVersion)?; - Ok(EncodedTransactionWithStatusMeta { - transaction: transaction.encode(encoding), - meta: meta.map(|meta| match encoding { - UiTransactionEncoding::JsonParsed => { - UiTransactionStatusMeta::parse(meta, &transaction.message) + let version = match ( + max_supported_transaction_version, + self.transaction.version(), + ) { + // Set to none because old clients can't handle this field + (None, TransactionVersion::Legacy) => Ok(None), + (None, TransactionVersion::Number(version)) => { + Err(EncodeError::UnsupportedTransactionVersion(version)) + } + (Some(_), TransactionVersion::Legacy) => Ok(Some(TransactionVersion::Legacy)), + (Some(max_version), TransactionVersion::Number(version)) => { + if version <= max_version { + Ok(Some(TransactionVersion::Number(version))) + } else { + Err(EncodeError::UnsupportedTransactionVersion(version)) } - _ => UiTransactionStatusMeta::from(meta), + } + }?; + + Ok(EncodedTransactionWithStatusMeta { + transaction: self.transaction.encode_with_meta(encoding, &self.meta), + meta: Some(match encoding { + UiTransactionEncoding::JsonParsed => UiTransactionStatusMeta::parse( + self.meta, + self.transaction.message.static_account_keys(), + ), + _ => UiTransactionStatusMeta::from(self.meta), }), + version, }) } @@ -635,13 +703,6 @@ impl VersionedTransactionWithStatusMeta { Some(&self.meta.loaded_addresses), ) } - - pub fn into_legacy_transaction_with_meta(self) -> Option { - Some(LegacyTransactionWithStatusMeta { - transaction: self.transaction.into_legacy_transaction()?, - meta: Some(self.meta), - }) - } } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -649,6 +710,8 @@ impl VersionedTransactionWithStatusMeta { pub struct EncodedTransactionWithStatusMeta { pub transaction: EncodedTransaction, pub meta: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub version: Option, } #[derive(Debug, PartialEq)] @@ -662,10 +725,13 @@ impl ConfirmedTransactionWithStatusMeta { pub fn encode( self, encoding: UiTransactionEncoding, + max_supported_transaction_version: Option, ) -> Result { Ok(EncodedConfirmedTransactionWithStatusMeta { slot: self.slot, - transaction: self.tx_with_meta.encode(encoding)?, + transaction: self + .tx_with_meta + .encode(encoding, max_supported_transaction_version)?, block_time: self.block_time, }) } @@ -688,6 +754,38 @@ pub enum EncodedTransaction { Json(UiTransaction), } +impl EncodableWithMeta for VersionedTransaction { + type Encoded = EncodedTransaction; + fn encode_with_meta( + &self, + encoding: UiTransactionEncoding, + meta: &TransactionStatusMeta, + ) -> Self::Encoded { + match encoding { + UiTransactionEncoding::Binary => EncodedTransaction::LegacyBinary( + bs58::encode(bincode::serialize(self).unwrap()).into_string(), + ), + UiTransactionEncoding::Base58 => EncodedTransaction::Binary( + bs58::encode(bincode::serialize(self).unwrap()).into_string(), + encoding, + ), + UiTransactionEncoding::Base64 => EncodedTransaction::Binary( + base64::encode(bincode::serialize(self).unwrap()), + encoding, + ), + UiTransactionEncoding::Json | UiTransactionEncoding::JsonParsed => { + EncodedTransaction::Json(UiTransaction { + signatures: self.signatures.iter().map(ToString::to_string).collect(), + message: match &self.message { + VersionedMessage::Legacy(message) => message.encode(encoding), + VersionedMessage::V0(message) => message.encode_with_meta(encoding, meta), + }, + }) + } + } + } +} + impl Encodable for Transaction { type Encoded = EncodedTransaction; fn encode(&self, encoding: UiTransactionEncoding) -> Self::Encoded { @@ -759,13 +857,48 @@ impl Encodable for Message { if encoding == UiTransactionEncoding::JsonParsed { let account_keys = AccountKeys::new(&self.account_keys, None); UiMessage::Parsed(UiParsedMessage { - account_keys: parse_accounts(self), + account_keys: parse_legacy_message_accounts(self), + recent_blockhash: self.recent_blockhash.to_string(), + instructions: self + .instructions + .iter() + .map(|instruction| UiInstruction::parse(instruction, &account_keys)) + .collect(), + address_table_lookups: None, + }) + } else { + UiMessage::Raw(UiRawMessage { + header: self.header, + account_keys: self.account_keys.iter().map(ToString::to_string).collect(), + recent_blockhash: self.recent_blockhash.to_string(), + instructions: self.instructions.iter().map(Into::into).collect(), + address_table_lookups: None, + }) + } + } +} + +impl EncodableWithMeta for v0::Message { + type Encoded = UiMessage; + fn encode_with_meta( + &self, + encoding: UiTransactionEncoding, + meta: &TransactionStatusMeta, + ) -> Self::Encoded { + if encoding == UiTransactionEncoding::JsonParsed { + let account_keys = AccountKeys::new(&self.account_keys, Some(&meta.loaded_addresses)); + let loaded_message = LoadedMessage::new_borrowed(self, &meta.loaded_addresses); + UiMessage::Parsed(UiParsedMessage { + account_keys: parse_loaded_message_accounts(&loaded_message), recent_blockhash: self.recent_blockhash.to_string(), instructions: self .instructions .iter() .map(|instruction| UiInstruction::parse(instruction, &account_keys)) .collect(), + address_table_lookups: Some( + self.address_table_lookups.iter().map(Into::into).collect(), + ), }) } else { UiMessage::Raw(UiRawMessage { @@ -773,6 +906,9 @@ impl Encodable for Message { account_keys: self.account_keys.iter().map(ToString::to_string).collect(), recent_blockhash: self.recent_blockhash.to_string(), instructions: self.instructions.iter().map(Into::into).collect(), + address_table_lookups: Some( + self.address_table_lookups.iter().map(Into::into).collect(), + ), }) } } @@ -786,6 +922,27 @@ pub struct UiRawMessage { pub account_keys: Vec, pub recent_blockhash: String, pub instructions: Vec, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub address_table_lookups: Option>, +} + +/// A duplicate representation of a MessageAddressTableLookup, in raw format, for pretty JSON serialization +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct UiAddressTableLookup { + pub account_key: String, + pub writable_indexes: Vec, + pub readonly_indexes: Vec, +} + +impl From<&MessageAddressTableLookup> for UiAddressTableLookup { + fn from(lookup: &MessageAddressTableLookup) -> Self { + Self { + account_key: lookup.account_key.to_string(), + writable_indexes: lookup.writable_indexes.clone(), + readonly_indexes: lookup.readonly_indexes.clone(), + } + } } /// A duplicate representation of a Message, in parsed format, for pretty JSON serialization @@ -795,6 +952,7 @@ pub struct UiParsedMessage { pub account_keys: Vec, pub recent_blockhash: String, pub instructions: Vec, + pub address_table_lookups: Option>, } // A serialized `Vec` is stored in the `tx-by-addr` table. The row keys are diff --git a/transaction-status/src/parse_accounts.rs b/transaction-status/src/parse_accounts.rs index 35d8d4c9e6ea7b..513dd45c4c9e22 100644 --- a/transaction-status/src/parse_accounts.rs +++ b/transaction-status/src/parse_accounts.rs @@ -1,4 +1,4 @@ -use solana_sdk::message::Message; +use solana_sdk::message::{v0::LoadedMessage, Message}; #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] @@ -8,7 +8,7 @@ pub struct ParsedAccount { pub signer: bool, } -pub fn parse_accounts(message: &Message) -> Vec { +pub fn parse_legacy_message_accounts(message: &Message) -> Vec { let mut accounts: Vec = vec![]; for (i, account_key) in message.account_keys.iter().enumerate() { accounts.push(ParsedAccount { @@ -20,6 +20,18 @@ pub fn parse_accounts(message: &Message) -> Vec { accounts } +pub fn parse_loaded_message_accounts(message: &LoadedMessage) -> Vec { + let mut accounts: Vec = vec![]; + for (i, account_key) in message.account_keys().iter().enumerate() { + accounts.push(ParsedAccount { + pubkey: account_key.to_string(), + writable: message.is_writable(i), + signer: message.is_signer(i), + }); + } + accounts +} + #[cfg(test)] mod test { use {super::*, solana_sdk::message::MessageHeader}; @@ -41,7 +53,7 @@ mod test { }; assert_eq!( - parse_accounts(&message), + parse_legacy_message_accounts(&message), vec![ ParsedAccount { pubkey: pubkey0.to_string(),