Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Feb 12, 2022
1 parent 0855cef commit 24ea904
Show file tree
Hide file tree
Showing 21 changed files with 592 additions and 250 deletions.
5 changes: 3 additions & 2 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2019,16 +2019,17 @@ pub fn process_transaction_history(
RpcTransactionConfig {
encoding: Some(UiTransactionEncoding::Base64),
commitment: Some(CommitmentConfig::confirmed()),
max_supported_transaction_version: None,
},
) {
Ok(confirmed_transaction) => {
println_transaction(
&confirmed_transaction
.transaction
.tx_with_meta
.transaction
.decode()
.expect("Successful decode"),
&confirmed_transaction.transaction.meta,
&confirmed_transaction.tx_with_meta.meta,
" ",
None,
None,
Expand Down
5 changes: 3 additions & 2 deletions cli/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,12 @@ pub fn process_confirm(
RpcTransactionConfig {
encoding: Some(UiTransactionEncoding::Base64),
commitment: Some(CommitmentConfig::confirmed()),
max_supported_transaction_version: None,
},
) {
Ok(confirmed_transaction) => {
let decoded_transaction = confirmed_transaction
.transaction
.tx_with_meta
.transaction
.decode()
.expect("Successful decode");
Expand All @@ -569,7 +570,7 @@ pub fn process_confirm(

transaction = Some(CliTransaction {
transaction: json_transaction,
meta: confirmed_transaction.transaction.meta,
meta: confirmed_transaction.tx_with_meta.meta,
block_time: confirmed_transaction.block_time,
slot: Some(confirmed_transaction.slot),
decoded_transaction,
Expand Down
22 changes: 14 additions & 8 deletions client-test/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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();
Expand All @@ -281,14 +284,17 @@ fn test_block_subscription() {
match maybe_actual {
Ok(actual) => {
let versioned_block = blockstore.get_complete_block(slot, false).unwrap();
let legacy_block = ConfirmedBlock::from(versioned_block)
.into_legacy_block()
let confirmed_block = ConfirmedBlock::from(versioned_block);
let block = confirmed_block
.encode_with_options(
UiTransactionEncoding::Json,
BlockEncodingOptions {
transaction_details: TransactionDetails::Signatures,
show_rewards: false,
max_supported_transaction_version: None,
},
)
.unwrap();
let block = legacy_block.configure(
UiTransactionEncoding::Json,
TransactionDetails::Signatures,
false,
);
assert_eq!(actual.value.slot, slot);
assert!(block.eq(&actual.value.block.unwrap()));
}
Expand Down
8 changes: 6 additions & 2 deletions client/src/mock_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -191,7 +191,8 @@ impl RpcSender for MockSender {
}
"getTransaction" => serde_json::to_value(EncodedConfirmedTransactionWithStatusMeta {
slot: 2,
transaction: EncodedTransactionWithStatusMeta {
tx_with_meta: EncodedTransactionWithStatusMeta {
version: Some(TransactionVersion::Legacy),
transaction: EncodedTransaction::Json(
UiTransaction {
signatures: vec!["3AsdoALgZFuq2oUVWrDYhg2pNeaLJKPLf8hU2mQ6U8qJxeJ6hsrPVpMn9ma39DtfYCrDQSvngWRP8NnTpEhezJpE".to_string()],
Expand All @@ -213,6 +214,7 @@ impl RpcSender for MockSender {
accounts: vec![0, 1],
data: "3Bxs49DitAvXtoDR".to_string(),
}],
address_table_lookups: None,
})
}),
meta: Some(UiTransactionStatusMeta {
Expand All @@ -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),
Expand Down Expand Up @@ -381,6 +384,7 @@ impl RpcSender for MockSender {
UiTransactionEncoding::Base58,
),
meta: None,
version: Some(TransactionVersion::Legacy),
}],
rewards: Rewards::new(),
block_time: None,
Expand Down
3 changes: 3 additions & 0 deletions client/src/rpc_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ pub struct RpcBlockSubscribeConfig {
pub encoding: Option<UiTransactionEncoding>,
pub transaction_details: Option<TransactionDetails>,
pub show_rewards: Option<bool>,
pub max_supported_transaction_version: Option<u8>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -248,6 +249,7 @@ pub struct RpcBlockConfig {
pub rewards: Option<bool>,
#[serde(flatten)]
pub commitment: Option<CommitmentConfig>,
pub max_supported_transaction_version: Option<u8>,
}

impl EncodingConfig for RpcBlockConfig {
Expand Down Expand Up @@ -288,6 +290,7 @@ pub struct RpcTransactionConfig {
pub encoding: Option<UiTransactionEncoding>,
#[serde(flatten)]
pub commitment: Option<CommitmentConfig>,
pub max_supported_transaction_version: Option<u8>,
}

impl EncodingConfig for RpcTransactionConfig {
Expand Down
17 changes: 14 additions & 3 deletions client/src/rpc_custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
crate::rpc_response::RpcSimulateTransactionResult,
jsonrpc_core::{Error, ErrorCode},
solana_sdk::clock::Slot,
solana_transaction_status::EncodeError,
thiserror::Error,
};

Expand Down Expand Up @@ -59,7 +60,7 @@ pub enum RpcCustomError {
#[error("BlockStatusNotAvailableYet")]
BlockStatusNotAvailableYet { slot: Slot },
#[error("UnsupportedTransactionVersion")]
UnsupportedTransactionVersion,
UnsupportedTransactionVersion(u8),
}

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -68,6 +69,16 @@ pub struct NodeUnhealthyErrorData {
pub num_slots_behind: Option<Slot>,
}

impl From<EncodeError> for RpcCustomError {
fn from(err: EncodeError) -> Self {
match err {
EncodeError::UnsupportedTransactionVersion(version) => {
Self::UnsupportedTransactionVersion(version)
}
}
}
}

impl From<RpcCustomError> for Error {
fn from(e: RpcCustomError) -> Self {
match e {
Expand Down Expand Up @@ -172,9 +183,9 @@ impl From<RpcCustomError> 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,
},
}
Expand Down
2 changes: 2 additions & 0 deletions client/src/rpc_deprecated_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl From<RpcConfirmedBlockConfig> for RpcBlockConfig {
transaction_details: config.transaction_details,
rewards: config.rewards,
commitment: config.commitment,
max_supported_transaction_version: None,
}
}
}
Expand Down Expand Up @@ -98,6 +99,7 @@ impl From<RpcConfirmedTransactionConfig> for RpcTransactionConfig {
Self {
encoding: config.encoding,
commitment: config.commitment,
max_supported_transaction_version: None,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/rpc_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
25 changes: 20 additions & 5 deletions ledger-tool/src/bigtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use {
},
solana_ledger::{blockstore::Blockstore, blockstore_db::AccessType},
solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Signature},
solana_transaction_status::{Encodable, LegacyConfirmedBlock, UiTransactionEncoding},
solana_transaction_status::{
BlockEncodingOptions, Encodable, EncodeError, LegacyConfirmedBlock, UiTransactionEncoding,
},
std::{
collections::HashSet,
path::Path,
Expand Down Expand Up @@ -72,12 +74,25 @@ async fn block(slot: Slot, output_format: OutputFormat) -> Result<(), Box<dyn st
.map_err(|err| format!("Failed to connect to storage: {:?}", err))?;

let confirmed_block = bigtable.get_confirmed_block(slot).await?;
let legacy_block = confirmed_block
.into_legacy_block()
.ok_or_else(|| "Failed to read versioned transaction in block".to_string())?;
let encoded_block = confirmed_block
.encode_with_options(
UiTransactionEncoding::Base64,
BlockEncodingOptions {
max_supported_transaction_version: None,
..BlockEncodingOptions::default()
},
)
.map_err(|err| match err {
EncodeError::UnsupportedTransactionVersion(version) => {
format!(
"Failed to process unsupported transaction version ({}) in block",
version
)
}
})?;

let cli_block = CliBlock {
encoded_confirmed_block: legacy_block.encode(UiTransactionEncoding::Base64),
encoded_confirmed_block: encoded_block.into(),
slot,
};
println!("{}", output_format.formatted_string(&cli_block));
Expand Down
Loading

0 comments on commit 24ea904

Please sign in to comment.