Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Aug 4, 2021
1 parent 989ca44 commit 41a9d05
Show file tree
Hide file tree
Showing 53 changed files with 1,608 additions and 612 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
65 changes: 36 additions & 29 deletions cli-output/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ 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, native_token::lamports_to_sol,
program_utils::limited_deserialize, pubkey::Pubkey, sanitized_message::SanitizedMessage,
sanitized_transaction::SanitizedTransaction, stake, transaction::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 +133,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 +148,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,7 +160,7 @@ 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]>,
Expand All @@ -177,7 +178,8 @@ 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
Expand All @@ -200,7 +202,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 +220,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 +241,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 +369,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 +394,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
33 changes: 22 additions & 11 deletions cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use solana_sdk::{
pubkey::{self, Pubkey},
rent::Rent,
rpc_port::DEFAULT_RPC_PORT_STR,
sanitized_transaction::SanitizedTransaction,
signature::Signature,
slot_history,
stake::{self, state::StakeState},
Expand All @@ -62,6 +63,7 @@ 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 +2024,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
2 changes: 1 addition & 1 deletion core/benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ fn simulate_process_entries(
hash: next_hash(&bank.last_blockhash(), 1, &tx_vector),
transactions: tx_vector,
};
process_entries(&bank, &mut [entry], randomize_txs, None, None).unwrap();
process_entries(&bank, vec![entry], randomize_txs, None, None).unwrap();
}

#[allow(clippy::same_item_push)]
Expand Down
Loading

0 comments on commit 41a9d05

Please sign in to comment.