Use Account::owner as loader for executable accounts
This commit is contained in:
parent
3849b8ece4
commit
4a0009365e
|
@ -59,7 +59,6 @@ pub fn entrypoint(
|
|||
keyed_accounts[to].account.owner = program_id;
|
||||
keyed_accounts[to].account.userdata = vec![0; space as usize];
|
||||
keyed_accounts[to].account.executable = false;
|
||||
keyed_accounts[to].account.loader = Pubkey::default();
|
||||
}
|
||||
SystemInstruction::Assign { program_id } => {
|
||||
if !system_program::check_id(&keyed_accounts[from].account.owner) {
|
||||
|
@ -83,11 +82,10 @@ pub fn entrypoint(
|
|||
}
|
||||
SystemInstruction::Spawn => {
|
||||
if !keyed_accounts[from].account.executable
|
||||
|| keyed_accounts[from].account.loader != Pubkey::default()
|
||||
|| keyed_accounts[from].account.owner != Pubkey::default()
|
||||
{
|
||||
Err(ProgramError::AccountNotFinalized)?;
|
||||
}
|
||||
keyed_accounts[from].account.loader = keyed_accounts[from].account.owner;
|
||||
keyed_accounts[from].account.owner = *keyed_accounts[from].signer_key().unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,13 +8,10 @@ pub struct Account {
|
|||
pub tokens: u64,
|
||||
/// data held in this account
|
||||
pub userdata: Vec<u8>,
|
||||
/// the program that owns this account
|
||||
/// the program that owns this account. If executable, the program that loads this account.
|
||||
pub owner: Pubkey,
|
||||
/// this account's userdata contains a loaded program (and is now read-only)
|
||||
pub executable: bool,
|
||||
/// the loader for this account
|
||||
/// (Pubkey::default() if the account is not executable and thus was never 'loaded')
|
||||
pub loader: Pubkey,
|
||||
}
|
||||
|
||||
impl Account {
|
||||
|
@ -25,7 +22,6 @@ impl Account {
|
|||
userdata: vec![0u8; space],
|
||||
owner,
|
||||
executable: false,
|
||||
loader: Pubkey::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,5 @@ pub fn create_program_account(name: &str) -> Account {
|
|||
owner: id(),
|
||||
userdata: name.as_bytes().to_vec(),
|
||||
executable: true,
|
||||
loader: id(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ impl AccountsDB {
|
|||
return Err(BankError::AccountNotFound);
|
||||
}
|
||||
};
|
||||
if !program.executable || program.loader == Pubkey::default() {
|
||||
if !program.executable || program.owner == Pubkey::default() {
|
||||
error_counters.account_not_found += 1;
|
||||
return Err(BankError::AccountNotFound);
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ impl AccountsDB {
|
|||
// add loader to chain
|
||||
accounts.insert(0, (program_id, program.clone()));
|
||||
|
||||
program_id = program.loader;
|
||||
program_id = program.owner;
|
||||
}
|
||||
Ok(accounts)
|
||||
}
|
||||
|
@ -616,32 +616,32 @@ mod tests {
|
|||
|
||||
let mut account = Account::new(40, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = native_loader::id();
|
||||
account.owner = native_loader::id();
|
||||
accounts.push((key1, account));
|
||||
|
||||
let mut account = Account::new(41, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = key1;
|
||||
account.owner = key1;
|
||||
accounts.push((key2, account));
|
||||
|
||||
let mut account = Account::new(42, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = key2;
|
||||
account.owner = key2;
|
||||
accounts.push((key3, account));
|
||||
|
||||
let mut account = Account::new(43, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = key3;
|
||||
account.owner = key3;
|
||||
accounts.push((key4, account));
|
||||
|
||||
let mut account = Account::new(44, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = key4;
|
||||
account.owner = key4;
|
||||
accounts.push((key5, account));
|
||||
|
||||
let mut account = Account::new(45, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = key5;
|
||||
account.owner = key5;
|
||||
accounts.push((key6, account));
|
||||
|
||||
let instructions = vec![Instruction::new(0, &(), vec![0])];
|
||||
|
@ -675,7 +675,7 @@ mod tests {
|
|||
|
||||
let mut account = Account::new(40, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = Pubkey::default();
|
||||
account.owner = Pubkey::default();
|
||||
accounts.push((key1, account));
|
||||
|
||||
let instructions = vec![Instruction::new(0, &(), vec![0])];
|
||||
|
@ -708,7 +708,7 @@ mod tests {
|
|||
accounts.push((key0, account));
|
||||
|
||||
let mut account = Account::new(40, 1, Pubkey::default());
|
||||
account.loader = native_loader::id();
|
||||
account.owner = native_loader::id();
|
||||
accounts.push((key1, account));
|
||||
|
||||
let instructions = vec![Instruction::new(0, &(), vec![0])];
|
||||
|
@ -744,17 +744,17 @@ mod tests {
|
|||
|
||||
let mut account = Account::new(40, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = native_loader::id();
|
||||
account.owner = native_loader::id();
|
||||
accounts.push((key1, account));
|
||||
|
||||
let mut account = Account::new(41, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = key1;
|
||||
account.owner = key1;
|
||||
accounts.push((key2, account));
|
||||
|
||||
let mut account = Account::new(42, 1, Pubkey::default());
|
||||
account.executable = true;
|
||||
account.loader = key2;
|
||||
account.owner = key2;
|
||||
accounts.push((key3, account));
|
||||
|
||||
let instructions = vec![
|
||||
|
|
|
@ -191,7 +191,6 @@ impl Bank {
|
|||
userdata: vec![0; vote_program::get_max_size() as usize],
|
||||
owner: vote_program::id(),
|
||||
executable: false,
|
||||
loader: Pubkey::default(),
|
||||
};
|
||||
|
||||
let mut vote_state = vote_program::VoteState::new(
|
||||
|
|
|
@ -599,8 +599,7 @@ mod tests {
|
|||
"owner": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
|
||||
"tokens": 20,
|
||||
"userdata": [],
|
||||
"executable": false,
|
||||
"loader": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||
"executable": false
|
||||
},
|
||||
"id":1}
|
||||
"#;
|
||||
|
|
|
@ -507,7 +507,6 @@ mod tests {
|
|||
let contract_funds = Keypair::new();
|
||||
let contract_state = Keypair::new();
|
||||
let budget_program_id = budget_program::id();
|
||||
let loader = Pubkey::default(); // TODO
|
||||
let executable = false; // TODO
|
||||
let bank = Bank::new(&genesis_block);
|
||||
let arc_bank = Arc::new(bank);
|
||||
|
@ -565,7 +564,6 @@ mod tests {
|
|||
"tokens": 1,
|
||||
"userdata": expected_userdata,
|
||||
"executable": executable,
|
||||
"loader": loader,
|
||||
|
||||
},
|
||||
"subscription": 0,
|
||||
|
@ -605,7 +603,6 @@ mod tests {
|
|||
"tokens": 51,
|
||||
"userdata": expected_userdata,
|
||||
"executable": executable,
|
||||
"loader": loader,
|
||||
},
|
||||
"subscription": 0,
|
||||
}
|
||||
|
@ -644,7 +641,6 @@ mod tests {
|
|||
"tokens": 1,
|
||||
"userdata": expected_userdata,
|
||||
"executable": executable,
|
||||
"loader": loader,
|
||||
},
|
||||
"subscription": 0,
|
||||
}
|
||||
|
@ -736,7 +732,7 @@ mod tests {
|
|||
subscriptions.check_account(&alice.pubkey(), &account);
|
||||
let string = transport_receiver.poll();
|
||||
if let Async::Ready(Some(response)) = string.unwrap() {
|
||||
let expected = format!(r#"{{"jsonrpc":"2.0","method":"accountNotification","params":{{"result":{{"executable":false,"loader":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"owner":[129,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"subscription":0}}}}"#);
|
||||
let expected = format!(r#"{{"jsonrpc":"2.0","method":"accountNotification","params":{{"result":{{"executable":false,"owner":[129,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tokens":1,"userdata":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},"subscription":0}}}}"#);
|
||||
assert_eq!(expected, response);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue