Fix duplicate records of inner instructions (#13380)

* Fix duplicate records of inner instructions

* fix tests

* fix clippy

* Remove bad_inner_instructions
This commit is contained in:
Justin Starry 2020-11-05 15:23:52 +08:00 committed by GitHub
parent 66c3c6c2b3
commit c24fbb6f8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 8 deletions

View File

@ -1316,10 +1316,11 @@ fn test_fake_shreds_broadcast_leader() {
fn test_faulty_node(faulty_node_type: BroadcastStageType) {
solana_logger::setup();
let num_nodes = 2;
let validator_config = ValidatorConfig::default();
let mut error_validator_config = ValidatorConfig::default();
error_validator_config.broadcast_stage_type = faulty_node_type;
let mut validator_configs = vec![validator_config; num_nodes - 1];
let mut validator_configs = Vec::with_capacity(num_nodes - 1);
validator_configs.resize_with(num_nodes - 1, ValidatorConfig::default);
// Push a faulty_bootstrap = vec![error_validator_config];
validator_configs.insert(0, error_validator_config);
let node_stakes = vec![300, 100];

View File

@ -459,7 +459,7 @@ fn test_program_bpf_invoke() {
let mut programs = Vec::new();
#[cfg(feature = "bpf_c")]
{
programs.push((Languages::C, "invoke", "invoked"));
programs.push((Languages::C, "invoke", "invoked", "noop"));
}
#[cfg(feature = "bpf_rust")]
{
@ -467,6 +467,7 @@ fn test_program_bpf_invoke() {
Languages::Rust,
"solana_bpf_rust_invoke",
"solana_bpf_rust_invoked",
"solana_bpf_rust_noop",
));
}
for program in programs.iter() {
@ -487,6 +488,8 @@ fn test_program_bpf_invoke() {
load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program.1);
let invoked_program_id =
load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program.2);
let noop_program_id =
load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program.3);
let argument_keypair = Keypair::new();
let account = Account::new(42, 100, &invoke_program_id);
@ -529,7 +532,12 @@ fn test_program_bpf_invoke() {
&[TEST_SUCCESS, bump_seed1, bump_seed2, bump_seed3],
account_metas.clone(),
);
let message = Message::new(&[instruction], Some(&mint_pubkey));
let noop_instruction = Instruction::new(
noop_program_id,
&(),
vec![]
);
let message = Message::new(&[instruction, noop_instruction], Some(&mint_pubkey));
let tx = Transaction::new(
&[
&mint_keypair,
@ -582,6 +590,12 @@ fn test_program_bpf_invoke() {
};
assert_eq!(invoked_programs, expected_invoked_programs);
let no_invoked_programs: Vec<Pubkey> = inner_instructions[1]
.iter()
.map(|ix| message.account_keys[ix.program_id_index as usize].clone())
.collect();
assert_eq!(no_invoked_programs.len(), 0);
// failure cases
let instruction = Instruction::new(

View File

@ -2437,10 +2437,10 @@ impl Bank {
Self::accounts_to_refcells(accounts, loaders);
let instruction_recorders = if enable_cpi_recording {
Some(vec![
InstructionRecorder::default();
tx.message.instructions.len()
])
let ix_count = tx.message.instructions.len();
let mut recorders = Vec::with_capacity(ix_count);
recorders.resize_with(ix_count, InstructionRecorder::default);
Some(recorders)
} else {
None
};