Skip to content

Commit

Permalink
wip: pushing to save progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Feb 5, 2022
1 parent 32df5a5 commit 2744901
Show file tree
Hide file tree
Showing 20 changed files with 435 additions and 145 deletions.
1 change: 1 addition & 0 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions cli/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
12 changes: 9 additions & 3 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 @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion 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 @@ -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()],
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
10 changes: 6 additions & 4 deletions client/src/rpc_custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum RpcCustomError {
#[error("BlockStatusNotAvailableYet")]
BlockStatusNotAvailableYet { slot: Slot },
#[error("UnsupportedTransactionVersion")]
UnsupportedTransactionVersion,
UnsupportedTransactionVersion(u8),
}

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -72,7 +72,9 @@ pub struct NodeUnhealthyErrorData {
impl From<EncodeError> for RpcCustomError {
fn from(err: EncodeError) -> Self {
match err {
EncodeError::UnsupportedTransactionVersion => Self::UnsupportedTransactionVersion,
EncodeError::UnsupportedTransactionVersion(version) => {
Self::UnsupportedTransactionVersion(version)
}
}
}
}
Expand Down Expand Up @@ -181,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
19 changes: 14 additions & 5 deletions ledger-tool/src/bigtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -76,10 +76,19 @@ async fn block(slot: Slot, output_format: OutputFormat) -> Result<(), Box<dyn st

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

Expand Down
66 changes: 45 additions & 21 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand All @@ -1389,7 +1392,7 @@ impl JsonRpcRequestProcessor {

let encode_transaction =
|confirmed_tx: ConfirmedTransactionWithStatusMeta| -> Result<EncodedConfirmedTransactionWithStatusMeta> {
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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)?;
}
Expand Down Expand Up @@ -4252,9 +4257,12 @@ where
.map(|output| (wire_output, output))
}

fn sanitize_transaction(transaction: VersionedTransaction) -> Result<SanitizedTransaction> {
fn sanitize_transaction(
transaction: VersionedTransaction,
address_loader: &impl AddressLoader,
) -> Result<SanitizedTransaction> {
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)))
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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
);
}
Expand All @@ -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(),
)
Expand Down
Loading

0 comments on commit 2744901

Please sign in to comment.