Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Aug 11, 2021
1 parent 679e7a2 commit a02be00
Show file tree
Hide file tree
Showing 36 changed files with 855 additions and 174 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ members = [
"poh",
"poh-bench",
"program-test",
"programs/address_map",
"programs/bpf_loader",
"programs/compute-budget",
"programs/config",
Expand Down
4 changes: 2 additions & 2 deletions cli-output/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@ impl fmt::Display for CliBlock {
writeln!(f, "Transaction {}:", index)?;
writeln_transaction(
f,
&transaction_with_meta.transaction.decode().unwrap(),
transaction_with_meta.transaction.decode().unwrap(),
&transaction_with_meta.meta,
" ",
None,
Expand Down Expand Up @@ -2296,7 +2296,7 @@ impl fmt::Display for CliTransaction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln_transaction(
f,
&self.decoded_transaction,
self.decoded_transaction.clone(),
&self.meta,
&self.prefix,
if !self.sigverify_status.is_empty() {
Expand Down
76 changes: 44 additions & 32 deletions cli-output/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ use {
console::style,
indicatif::{ProgressBar, ProgressStyle},
solana_sdk::{
clock::UnixTimestamp, hash::Hash, message::Message, native_token::lamports_to_sol,
program_utils::limited_deserialize, pubkey::Pubkey, stake, transaction::Transaction,
clock::UnixTimestamp,
hash::Hash,
message::SanitizedMessage,
native_token::lamports_to_sol,
program_utils::limited_deserialize,
pubkey::Pubkey,
stake,
transaction::{SanitizedTransaction, Transaction},
},
solana_transaction_status::UiTransactionStatusMeta,
spl_memo::id as spl_memo_id,
spl_memo::v1::id as spl_memo_v1_id,
std::{collections::HashMap, fmt, io},
std::{collections::HashMap, convert::TryFrom, fmt, io},
};

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -132,7 +138,7 @@ pub fn println_signers(
println!();
}

fn format_account_mode(message: &Message, index: usize) -> String {
fn format_account_mode(message: &SanitizedMessage, index: usize) -> String {
format!(
"{}r{}{}", // accounts are always readable...
if message.is_signer(index) {
Expand All @@ -147,7 +153,7 @@ fn format_account_mode(message: &Message, index: usize) -> String {
},
// account may be executable on-chain while not being
// designated as a program-id in the message
if message.maybe_executable(index) {
if message.is_invoked(index) {
"x"
} else {
// programs to be executed via CPI cannot be identified as
Expand All @@ -159,13 +165,13 @@ fn format_account_mode(message: &Message, index: usize) -> String {

pub fn write_transaction<W: io::Write>(
w: &mut W,
transaction: &Transaction,
transaction: &SanitizedTransaction,
transaction_status: &Option<UiTransactionStatusMeta>,
prefix: &str,
sigverify_status: Option<&[CliSignatureVerificationStatus]>,
block_time: Option<UnixTimestamp>,
) -> io::Result<()> {
let message = &transaction.message;
let message = transaction.message();
if let Some(block_time) = block_time {
writeln!(
w,
Expand All @@ -177,18 +183,19 @@ pub fn write_transaction<W: io::Write>(
writeln!(
w,
"{}Recent Blockhash: {:?}",
prefix, message.recent_blockhash
prefix,
message.recent_blockhash()
)?;
let sigverify_statuses = if let Some(sigverify_status) = sigverify_status {
sigverify_status
.iter()
.map(|s| format!(" ({})", s))
.collect()
} else {
vec!["".to_string(); transaction.signatures.len()]
vec!["".to_string(); transaction.signatures().len()]
};
for (signature_index, (signature, sigverify_status)) in transaction
.signatures
.signatures()
.iter()
.zip(&sigverify_statuses)
.enumerate()
Expand All @@ -200,7 +207,7 @@ pub fn write_transaction<W: io::Write>(
)?;
}
let mut fee_payer_index = None;
for (account_index, account) in message.account_keys.iter().enumerate() {
for (account_index, account) in message.account_keys_iter().enumerate() {
if fee_payer_index.is_none() && message.is_non_loader_key(account_index) {
fee_payer_index = Some(account_index)
}
Expand All @@ -218,16 +225,19 @@ pub fn write_transaction<W: io::Write>(
},
)?;
}
for (instruction_index, instruction) in message.instructions.iter().enumerate() {
let program_pubkey = message.account_keys[instruction.program_id_index as usize];
for (instruction_index, (program_pubkey, instruction)) in
message.program_instructions_iter().enumerate()
{
writeln!(w, "{}Instruction {}", prefix, instruction_index)?;
writeln!(
w,
"{} Program: {} ({})",
prefix, program_pubkey, instruction.program_id_index
)?;
for (account_index, account) in instruction.accounts.iter().enumerate() {
let account_pubkey = message.account_keys[*account as usize];
let account_pubkey = message
.get_account_key(*account as usize)
.expect("account index is sanitized");
writeln!(
w,
"{} Account {}: {} ({})",
Expand All @@ -236,30 +246,30 @@ pub fn write_transaction<W: io::Write>(
}

let mut raw = true;
if program_pubkey == solana_vote_program::id() {
if program_pubkey == &solana_vote_program::id() {
if let Ok(vote_instruction) = limited_deserialize::<
solana_vote_program::vote_instruction::VoteInstruction,
>(&instruction.data)
{
writeln!(w, "{} {:?}", prefix, vote_instruction)?;
raw = false;
}
} else if program_pubkey == stake::program::id() {
} else if program_pubkey == &stake::program::id() {
if let Ok(stake_instruction) =
limited_deserialize::<stake::instruction::StakeInstruction>(&instruction.data)
{
writeln!(w, "{} {:?}", prefix, stake_instruction)?;
raw = false;
}
} else if program_pubkey == solana_sdk::system_program::id() {
} else if program_pubkey == &solana_sdk::system_program::id() {
if let Ok(system_instruction) = limited_deserialize::<
solana_sdk::system_instruction::SystemInstruction,
>(&instruction.data)
{
writeln!(w, "{} {:?}", prefix, system_instruction)?;
raw = false;
}
} else if is_memo_program(&program_pubkey) {
} else if is_memo_program(program_pubkey) {
if let Ok(s) = std::str::from_utf8(&instruction.data) {
writeln!(w, "{} Data: \"{}\"", prefix, s)?;
raw = false;
Expand Down Expand Up @@ -364,7 +374,7 @@ pub fn write_transaction<W: io::Write>(
}

pub fn println_transaction(
transaction: &Transaction,
transaction: &SanitizedTransaction,
transaction_status: &Option<UiTransactionStatusMeta>,
prefix: &str,
sigverify_status: Option<&[CliSignatureVerificationStatus]>,
Expand All @@ -389,25 +399,27 @@ pub fn println_transaction(

pub fn writeln_transaction(
f: &mut dyn fmt::Write,
transaction: &Transaction,
transaction: Transaction,
transaction_status: &Option<UiTransactionStatusMeta>,
prefix: &str,
sigverify_status: Option<&[CliSignatureVerificationStatus]>,
block_time: Option<UnixTimestamp>,
) -> fmt::Result {
let mut w = Vec::new();
if write_transaction(
&mut w,
transaction,
transaction_status,
prefix,
sigverify_status,
block_time,
)
.is_ok()
{
if let Ok(s) = String::from_utf8(w) {
write!(f, "{}", s)?;
if let Ok(transaction) = SanitizedTransaction::try_from(transaction) {
if write_transaction(
&mut w,
&transaction,
transaction_status,
prefix,
sigverify_status,
block_time,
)
.is_ok()
{
if let Ok(s) = String::from_utf8(w) {
write!(f, "{}", s)?;
}
}
}
Ok(())
Expand Down
34 changes: 22 additions & 12 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ use solana_sdk::{
stake_history::{self},
},
timing,
transaction::Transaction,
transaction::{SanitizedTransaction, Transaction},
};
use solana_transaction_status::UiTransactionEncoding;
use solana_vote_program::vote_state::VoteState;
use std::{
collections::{BTreeMap, HashMap, VecDeque},
convert::TryFrom,
fmt,
str::FromStr,
sync::{
Expand Down Expand Up @@ -2022,17 +2023,26 @@ pub fn process_transaction_history(
},
) {
Ok(confirmed_transaction) => {
println_transaction(
&confirmed_transaction
.transaction
.transaction
.decode()
.expect("Successful decode"),
&confirmed_transaction.transaction.meta,
" ",
None,
None,
);
let transaction = confirmed_transaction
.transaction
.transaction
.decode()
.expect("Successful decode");

match SanitizedTransaction::try_from(transaction) {
Ok(transaction) => {
println_transaction(
&transaction,
&confirmed_transaction.transaction.meta,
" ",
None,
None,
);
}
Err(err) => {
println!(" Unable to construct sanitized transaction: {}", err)
}
}
}
Err(err) => println!(" Unable to get confirmed transaction details: {}", err),
}
Expand Down
13 changes: 8 additions & 5 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,23 +1043,26 @@ impl BankingStage {
// Also returned is packet indexes for transaction should be retried due to cost limits.
#[allow(clippy::needless_collect)]
fn transactions_from_packets(
bank: &Arc<Bank>,
msgs: &Packets,
transaction_indexes: &[usize],
libsecp256k1_0_5_upgrade_enabled: bool,
cost_tracker: &Arc<RwLock<CostTracker>>,
banking_stage_stats: &BankingStageStats,
) -> (Vec<SanitizedTransaction>, Vec<usize>, Vec<usize>) {
let mut retryable_transaction_packet_indexes: Vec<usize> = vec![];

let libsecp256k1_0_5_upgrade_enabled = bank.libsecp256k1_0_5_upgrade_enabled();
let verified_transactions_with_packet_indexes: Vec<_> = transaction_indexes
.iter()
.filter_map(|tx_index| {
let p = &msgs.packets[*tx_index];
let tx: VersionedTransaction = limited_deserialize(&p.data[0..p.meta.size]).ok()?;
let message_bytes = Self::packet_message(p)?;
let message_hash = Message::hash_raw_message(message_bytes);
let tx = SanitizedTransaction::try_create(tx, message_hash, |_| {
Err(TransactionError::UnsupportedVersion)
let tx = SanitizedTransaction::try_create(tx, message_hash, |message| {
bank.address_map_cache()
.map_message_addresses(message)
.ok_or(TransactionError::AccountNotFound)
})
.ok()?;
tx.verify_precompiles(libsecp256k1_0_5_upgrade_enabled)
Expand Down Expand Up @@ -1155,9 +1158,9 @@ impl BankingStage {
let mut packet_conversion_time = Measure::start("packet_conversion");
let (transactions, transaction_to_packet_indexes, retryable_packet_indexes) =
Self::transactions_from_packets(
bank,
msgs,
&packet_indexes,
bank.libsecp256k1_0_5_upgrade_enabled(),
cost_tracker,
banking_stage_stats,
);
Expand Down Expand Up @@ -1257,9 +1260,9 @@ impl BankingStage {
Measure::start("unprocessed_packet_conversion");
let (transactions, transaction_to_packet_indexes, retry_packet_indexes) =
Self::transactions_from_packets(
bank,
msgs,
transaction_indexes,
bank.libsecp256k1_0_5_upgrade_enabled(),
cost_tracker,
banking_stage_stats,
);
Expand Down
25 changes: 17 additions & 8 deletions ledger-tool/src/bigtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ use solana_cli_output::{
OutputFormat,
};
use solana_ledger::{blockstore::Blockstore, blockstore_db::AccessType};
use solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Signature};
use solana_sdk::{
clock::Slot, pubkey::Pubkey, signature::Signature, transaction::SanitizedTransaction,
};
use solana_transaction_status::{ConfirmedBlock, EncodedTransaction, UiTransactionEncoding};
use std::{
convert::TryFrom,
path::Path,
process::exit,
result::Result,
Expand Down Expand Up @@ -183,13 +186,19 @@ pub async fn transaction_history(
);
}
Some(transaction_with_meta) => {
println_transaction(
&transaction_with_meta.transaction,
&transaction_with_meta.meta.clone().map(|m| m.into()),
" ",
None,
None,
);
let transaction = transaction_with_meta.transaction.clone();
match SanitizedTransaction::try_from(transaction) {
Ok(transaction) => println_transaction(
&transaction,
&transaction_with_meta.meta.clone().map(|m| m.into()),
" ",
None,
None,
),
Err(err) => {
println!(" Unable to construct sanitized transaction for {}: {}", result.signature, err)
}
}
}
}
break;
Expand Down
Loading

0 comments on commit a02be00

Please sign in to comment.