Optimize account copies and use RefCell to handle duplicate accounts in BPF programs (#7958)
This commit is contained in:
@ -12,32 +12,32 @@ fn process_instruction(_program_id: &Pubkey, accounts: &mut [AccountInfo], data:
|
||||
match data[0] {
|
||||
1 => {
|
||||
info!("modify first account data");
|
||||
accounts[2].data[0] = 1;
|
||||
accounts[2].m.borrow_mut().data[0] = 1;
|
||||
}
|
||||
2 => {
|
||||
info!("modify first account data");
|
||||
accounts[3].data[0] = 2;
|
||||
accounts[3].m.borrow_mut().data[0] = 2;
|
||||
}
|
||||
3 => {
|
||||
info!("modify both account data, should fail");
|
||||
accounts[2].data[0] = 1;
|
||||
accounts[3].data[0] = 2;
|
||||
info!("modify both account data");
|
||||
accounts[2].m.borrow_mut().data[0] += 1;
|
||||
accounts[3].m.borrow_mut().data[0] += 2;
|
||||
}
|
||||
4 => {
|
||||
info!("modify first account lamports");
|
||||
*accounts[1].lamports -= 1;
|
||||
*accounts[2].lamports += 1;
|
||||
*accounts[1].m.borrow_mut().lamports -= 1;
|
||||
*accounts[2].m.borrow_mut().lamports += 1;
|
||||
}
|
||||
5 => {
|
||||
info!("modify first account lamports");
|
||||
*accounts[1].lamports -= 2;
|
||||
*accounts[3].lamports += 2;
|
||||
*accounts[1].m.borrow_mut().lamports -= 2;
|
||||
*accounts[3].m.borrow_mut().lamports += 2;
|
||||
}
|
||||
6 => {
|
||||
info!("modify both account lamports, should fail");
|
||||
*accounts[1].lamports -= 1;
|
||||
*accounts[2].lamports += 1;
|
||||
*accounts[3].lamports += 2;
|
||||
info!("modify both account lamports");
|
||||
*accounts[1].m.borrow_mut().lamports -= 3;
|
||||
*accounts[2].m.borrow_mut().lamports += 1;
|
||||
*accounts[3].m.borrow_mut().lamports += 2;
|
||||
}
|
||||
_ => {
|
||||
info!("Unrecognized command");
|
||||
|
Reference in New Issue
Block a user