Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 71 additions & 62 deletions ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ use {
verifier::RequisiteVerifier,
},
solana_sdk_ids::{bpf_loader_upgradeable, sysvar},
solana_transaction_context::{IndexOfAccount, InstructionAccount},
solana_transaction_context::{
IndexOfAccount, InstructionAccountView, InstructionAccountViewVector,
},
std::{
collections::HashMap,
fmt::{self, Debug, Formatter},
Expand Down Expand Up @@ -398,7 +400,7 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
let bank = load_blockstore(&ledger_path, matches);
let loader_id = bpf_loader_upgradeable::id();
let mut transaction_accounts = Vec::new();
let mut instruction_accounts = Vec::new();
let mut instruction_accounts = InstructionAccountViewVector::new();
let mut program_id = Pubkey::new_unique();
let mut cached_account_keys = vec![];

Expand All @@ -409,7 +411,13 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
pubkey,
AccountSharedData::new(0, allocation_size, &Pubkey::new_unique()),
));
instruction_accounts.push(InstructionAccount::new(0, 0, 0, false, true));
instruction_accounts.push(InstructionAccountView {
index_in_transaction: 0,
index_in_caller: 0,
index_in_callee: 0,
is_signer: false,
is_writable: true,
});
vec![]
}
Err(_) => {
Expand All @@ -424,71 +432,72 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
// Maps a public key to the transaction account index
let mut txn_acct_indices =
HashMap::<Pubkey, usize>::with_capacity(input.accounts.len());
instruction_accounts = input
.accounts
.into_iter()
.map(|account_info| {
let pubkey = account_info.key.parse::<Pubkey>().unwrap_or_else(|err| {
eprintln!("Invalid key in input {}, error {}", account_info.key, err);
exit(1);
});
let data = account_info.data.unwrap_or_default();
let space = data.len();
let account = if let Some(account) = bank.get_account_with_fixed_root(&pubkey) {
let owner = *account.owner();
if bpf_loader_upgradeable::check_id(&owner) {
if let Ok(UpgradeableLoaderState::Program {
programdata_address,
}) = account.state()
let mut new_instr_accs = InstructionAccountViewVector::new();
for account_info in input.accounts.into_iter() {
let pubkey = account_info.key.parse::<Pubkey>().unwrap_or_else(|err| {
eprintln!("Invalid key in input {}, error {}", account_info.key, err);
exit(1);
});
let data = account_info.data.unwrap_or_default();
let space = data.len();
let account = if let Some(account) = bank.get_account_with_fixed_root(&pubkey) {
let owner = *account.owner();
if bpf_loader_upgradeable::check_id(&owner) {
if let Ok(UpgradeableLoaderState::Program {
programdata_address,
}) = account.state()
{
debug!("Program data address {}", programdata_address);
if bank
.get_account_with_fixed_root(&programdata_address)
.is_some()
{
debug!("Program data address {programdata_address}");
if bank
.get_account_with_fixed_root(&programdata_address)
.is_some()
{
cached_account_keys.push(pubkey);
}
cached_account_keys.push(pubkey);
}
}
// Override account data and lamports from input file if provided
if space > 0 {
let lamports = account_info.lamports.unwrap_or(account.lamports());
let mut account = AccountSharedData::new(lamports, space, &owner);
account.set_data_from_slice(&data);
account
} else {
account
}
} else {
let owner = account_info
.owner
.unwrap_or(Pubkey::new_unique().to_string());
let owner = owner.parse::<Pubkey>().unwrap_or_else(|err| {
eprintln!("Invalid owner key in input {owner}, error {err}");
Pubkey::new_unique()
});
let lamports = account_info.lamports.unwrap_or(0);
}
// Override account data and lamports from input file if provided
if space > 0 {
let lamports = account_info.lamports.unwrap_or(account.lamports());
let mut account = AccountSharedData::new(lamports, space, &owner);
account.set_data_from_slice(&data);
account
};
let txn_acct_index = if let Some(idx) = txn_acct_indices.get(&pubkey) {
*idx
} else {
let idx = transaction_accounts.len();
txn_acct_indices.insert(pubkey, idx);
transaction_accounts.push((pubkey, account));
idx
};
InstructionAccount::new(
txn_acct_index as IndexOfAccount,
txn_acct_index as IndexOfAccount,
txn_acct_index as IndexOfAccount,
account_info.is_signer.unwrap_or(false),
account_info.is_writable.unwrap_or(false),
)
})
.collect();
account
}
} else {
let owner = account_info
.owner
.unwrap_or(Pubkey::new_unique().to_string());
let owner = owner.parse::<Pubkey>().unwrap_or_else(|err| {
eprintln!("Invalid owner key in input {owner}, error {err}");
Pubkey::new_unique()
});
let lamports = account_info.lamports.unwrap_or(0);
let mut account = AccountSharedData::new(lamports, space, &owner);
account.set_data_from_slice(&data);
account
};
let txn_acct_index = if let Some(idx) = txn_acct_indices.get(&pubkey) {
*idx
} else {
let idx = transaction_accounts.len();
txn_acct_indices.insert(pubkey, idx);
transaction_accounts.push((pubkey, account));
idx
};

let instr_acc = InstructionAccountView {
index_in_transaction: txn_acct_index as IndexOfAccount,
index_in_caller: txn_acct_index as IndexOfAccount,
index_in_callee: txn_acct_index as IndexOfAccount,
is_signer: account_info.is_signer.unwrap_or(false),
is_writable: account_info.is_writable.unwrap_or(false),
};
new_instr_accs.push(instr_acc);
}
instruction_accounts = std::mem::take(&mut new_instr_accs);

input.instruction_data
}
};
Expand Down Expand Up @@ -527,7 +536,7 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
.unwrap()
.configure(
&[program_index, program_index.saturating_add(1)],
&instruction_accounts,
instruction_accounts,
&instruction_data,
);
invoke_context.push().unwrap();
Expand Down
Loading
Loading