Fix BPF program static linking (#5992)
This commit is contained in:
		@@ -179,8 +179,9 @@ impl Accounts {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // add loader to chain
 | 
					            // add loader to chain
 | 
				
			||||||
            program_id = program.owner;
 | 
					            let program_owner = program.owner;
 | 
				
			||||||
            accounts.insert(0, (program_id, program));
 | 
					            accounts.insert(0, (program_id, program));
 | 
				
			||||||
 | 
					            program_id = program_owner;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Ok(accounts)
 | 
					        Ok(accounts)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -1035,7 +1036,6 @@ mod tests {
 | 
				
			|||||||
        let key0 = keypair.pubkey();
 | 
					        let key0 = keypair.pubkey();
 | 
				
			||||||
        let key1 = Pubkey::new(&[5u8; 32]);
 | 
					        let key1 = Pubkey::new(&[5u8; 32]);
 | 
				
			||||||
        let key2 = Pubkey::new(&[6u8; 32]);
 | 
					        let key2 = Pubkey::new(&[6u8; 32]);
 | 
				
			||||||
        let key3 = Pubkey::new(&[7u8; 32]);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let mut account = Account::new(1, 1, &Pubkey::default());
 | 
					        let mut account = Account::new(1, 1, &Pubkey::default());
 | 
				
			||||||
        account.rent_epoch = 1;
 | 
					        account.rent_epoch = 1;
 | 
				
			||||||
@@ -1053,12 +1053,6 @@ mod tests {
 | 
				
			|||||||
        account.owner = key1;
 | 
					        account.owner = key1;
 | 
				
			||||||
        accounts.push((key2, account));
 | 
					        accounts.push((key2, account));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let mut account = Account::new(42, 1, &Pubkey::default());
 | 
					 | 
				
			||||||
        account.executable = true;
 | 
					 | 
				
			||||||
        account.rent_epoch = 1;
 | 
					 | 
				
			||||||
        account.owner = key2;
 | 
					 | 
				
			||||||
        accounts.push((key3, account));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let instructions = vec![
 | 
					        let instructions = vec![
 | 
				
			||||||
            CompiledInstruction::new(1, &(), vec![0]),
 | 
					            CompiledInstruction::new(1, &(), vec![0]),
 | 
				
			||||||
            CompiledInstruction::new(2, &(), vec![0]),
 | 
					            CompiledInstruction::new(2, &(), vec![0]),
 | 
				
			||||||
@@ -1092,7 +1086,7 @@ mod tests {
 | 
				
			|||||||
                for loaders in transaction_loaders.iter() {
 | 
					                for loaders in transaction_loaders.iter() {
 | 
				
			||||||
                    for (i, accounts_subset) in loaders.iter().enumerate() {
 | 
					                    for (i, accounts_subset) in loaders.iter().enumerate() {
 | 
				
			||||||
                        // +1 to skip first not loader account
 | 
					                        // +1 to skip first not loader account
 | 
				
			||||||
                        assert_eq![accounts_subset.1, accounts[i + 1].1];
 | 
					                        assert_eq!(*accounts_subset, accounts[i + 1]);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -209,17 +209,18 @@ impl MessageProcessor {
 | 
				
			|||||||
            .collect();
 | 
					            .collect();
 | 
				
			||||||
        keyed_accounts.append(&mut keyed_accounts2);
 | 
					        keyed_accounts.append(&mut keyed_accounts2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (id, process_instruction) in &self.instruction_processors {
 | 
					 | 
				
			||||||
            if id == program_id {
 | 
					 | 
				
			||||||
                return process_instruction(&program_id, &mut keyed_accounts[1..], &ix_data);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        assert!(
 | 
					        assert!(
 | 
				
			||||||
            keyed_accounts[0].account.executable,
 | 
					            keyed_accounts[0].account.executable,
 | 
				
			||||||
            "loader not executable"
 | 
					            "loader not executable"
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let loader_id = keyed_accounts[0].unsigned_key();
 | 
				
			||||||
 | 
					        for (id, process_instruction) in &self.instruction_processors {
 | 
				
			||||||
 | 
					            if id == loader_id {
 | 
				
			||||||
 | 
					                return process_instruction(&program_id, &mut keyed_accounts[1..], &ix_data);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        native_loader::invoke_entrypoint(
 | 
					        native_loader::invoke_entrypoint(
 | 
				
			||||||
            &program_id,
 | 
					            &program_id,
 | 
				
			||||||
            &mut keyed_accounts,
 | 
					            &mut keyed_accounts,
 | 
				
			||||||
@@ -324,7 +325,7 @@ mod tests {
 | 
				
			|||||||
    use super::*;
 | 
					    use super::*;
 | 
				
			||||||
    use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
 | 
					    use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
 | 
				
			||||||
    use solana_sdk::message::Message;
 | 
					    use solana_sdk::message::Message;
 | 
				
			||||||
    use solana_sdk::native_loader::{create_loadable_account, id};
 | 
					    use solana_sdk::native_loader::create_loadable_account;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn test_has_duplicates() {
 | 
					    fn test_has_duplicates() {
 | 
				
			||||||
@@ -585,7 +586,7 @@ mod tests {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        let mut loaders: Vec<Vec<(Pubkey, Account)>> = Vec::new();
 | 
					        let mut loaders: Vec<Vec<(Pubkey, Account)>> = Vec::new();
 | 
				
			||||||
        let account = create_loadable_account("mock_system_program");
 | 
					        let account = create_loadable_account("mock_system_program");
 | 
				
			||||||
        loaders.push(vec![(id(), account)]);
 | 
					        loaders.push(vec![(mock_system_program_id, account)]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let from_pubkey = Pubkey::new_rand();
 | 
					        let from_pubkey = Pubkey::new_rand();
 | 
				
			||||||
        let to_pubkey = Pubkey::new_rand();
 | 
					        let to_pubkey = Pubkey::new_rand();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user