account.data -> data() (#15778)

This commit is contained in:
Jeff Washington (jwash)
2021-03-09 16:31:33 -06:00
committed by GitHub
parent 8a3135d17b
commit 52e54e1100
30 changed files with 220 additions and 174 deletions

View File

@@ -24,6 +24,7 @@ use solana_rbpf::{
};
use solana_runtime::message_processor::MessageProcessor;
use solana_sdk::{
account::ReadableAccount,
account_utils::State,
bpf_loader, bpf_loader_deprecated,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
@@ -243,7 +244,7 @@ fn process_instruction_common(
Some(executor) => executor,
None => create_and_cache_executor(
program_id,
&program.try_account_ref()?.data[offset..],
&program.try_account_ref()?.data()[offset..],
invoke_context,
use_jit,
)?,
@@ -445,7 +446,7 @@ fn process_loader_upgradeable_instruction(
// Load and verify the program bits
let _ = create_and_cache_executor(
program_id,
&buffer.try_account_ref()?.data[buffer_data_offset..],
&buffer.try_account_ref()?.data()[buffer_data_offset..],
invoke_context,
use_jit,
)?;
@@ -457,7 +458,7 @@ fn process_loader_upgradeable_instruction(
})?;
programdata.try_account_ref_mut()?.data
[programdata_data_offset..programdata_data_offset + buffer_data_len]
.copy_from_slice(&buffer.try_account_ref()?.data[buffer_data_offset..]);
.copy_from_slice(&buffer.try_account_ref()?.data()[buffer_data_offset..]);
// Update the Program account
program.set_state(&UpgradeableLoaderState::Program {
@@ -573,7 +574,7 @@ fn process_loader_upgradeable_instruction(
let _ = create_and_cache_executor(
program.unsigned_key(),
&buffer.try_account_ref()?.data[buffer_data_offset..],
&buffer.try_account_ref()?.data()[buffer_data_offset..],
invoke_context,
use_jit,
)?;
@@ -587,7 +588,7 @@ fn process_loader_upgradeable_instruction(
})?;
programdata.try_account_ref_mut()?.data
[programdata_data_offset..programdata_data_offset + buffer_data_len]
.copy_from_slice(&buffer.try_account_ref()?.data[buffer_data_offset..]);
.copy_from_slice(&buffer.try_account_ref()?.data()[buffer_data_offset..]);
for i in &mut programdata.try_account_ref_mut()?.data
[programdata_data_offset + buffer_data_len..]
{
@@ -707,7 +708,7 @@ fn process_loader_instruction(
let _ = create_and_cache_executor(
program.unsigned_key(),
&program.try_account_ref()?.data,
&program.try_account_ref()?.data(),
invoke_context,
use_jit,
)?;
@@ -977,8 +978,8 @@ mod tests {
)
);
assert_eq!(
vec![0, 0, 0, 1, 2, 3],
keyed_accounts[0].account.borrow().data
&vec![0, 0, 0, 1, 2, 3],
keyed_accounts[0].account.borrow().data()
);
// Case: Overflow
@@ -1363,7 +1364,8 @@ mod tests {
}
);
assert_eq!(
&buffer_account.borrow().data[UpgradeableLoaderState::buffer_data_offset().unwrap()..],
&buffer_account.borrow().data()
[UpgradeableLoaderState::buffer_data_offset().unwrap()..],
&[42; 9]
);
@@ -1404,7 +1406,8 @@ mod tests {
}
);
assert_eq!(
&buffer_account.borrow().data[UpgradeableLoaderState::buffer_data_offset().unwrap()..],
&buffer_account.borrow().data()
[UpgradeableLoaderState::buffer_data_offset().unwrap()..],
&[0, 0, 0, 42, 42, 42, 42, 42, 42]
);
@@ -1622,7 +1625,7 @@ mod tests {
assert_eq!(post_program_account.lamports, min_program_balance);
assert_eq!(post_program_account.owner, bpf_loader_upgradeable::id());
assert_eq!(
post_program_account.data.len(),
post_program_account.data().len(),
UpgradeableLoaderState::program_len().unwrap()
);
let state: UpgradeableLoaderState = post_program_account.state().unwrap();
@@ -1643,7 +1646,7 @@ mod tests {
upgrade_authority_address: Some(upgrade_authority_keypair.pubkey())
}
);
for (i, byte) in post_programdata_account.data
for (i, byte) in post_programdata_account.data()
[UpgradeableLoaderState::programdata_data_offset().unwrap()..]
.iter()
.enumerate()
@@ -2315,7 +2318,7 @@ mod tests {
upgrade_authority_address: Some(upgrade_authority_address)
}
);
for (i, byte) in programdata_account.borrow().data
for (i, byte) in programdata_account.borrow().data()
[UpgradeableLoaderState::programdata_data_offset().unwrap()
..UpgradeableLoaderState::programdata_data_offset().unwrap() + elf_new.len()]
.iter()

View File

@@ -1,7 +1,7 @@
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
use solana_sdk::{
bpf_loader_deprecated, entrypoint::MAX_PERMITTED_DATA_INCREASE, instruction::InstructionError,
keyed_account::KeyedAccount, pubkey::Pubkey,
account::ReadableAccount, bpf_loader_deprecated, entrypoint::MAX_PERMITTED_DATA_INCREASE,
instruction::InstructionError, keyed_account::KeyedAccount, pubkey::Pubkey,
};
use std::{
io::prelude::*,
@@ -86,7 +86,8 @@ pub fn serialize_parameters_unaligned(
.unwrap();
v.write_u64::<LittleEndian>(keyed_account.data_len()? as u64)
.unwrap();
v.write_all(&keyed_account.try_account_ref()?.data).unwrap();
v.write_all(&keyed_account.try_account_ref()?.data())
.unwrap();
v.write_all(keyed_account.owner()?.as_ref()).unwrap();
v.write_u8(keyed_account.executable()? as u8).unwrap();
v.write_u64::<LittleEndian>(keyed_account.rent_epoch()? as u64)
@@ -181,7 +182,8 @@ pub fn serialize_parameters_aligned(
.unwrap();
v.write_u64::<LittleEndian>(keyed_account.data_len()? as u64)
.unwrap();
v.write_all(&keyed_account.try_account_ref()?.data).unwrap();
v.write_all(&keyed_account.try_account_ref()?.data())
.unwrap();
v.resize(
v.len()
+ MAX_PERMITTED_DATA_INCREASE
@@ -323,7 +325,7 @@ mod tests {
assert_eq!(key, *account_info.key);
let account = account.borrow();
assert_eq!(account.lamports, account_info.lamports());
assert_eq!(&account.data[..], &account_info.data.borrow()[..]);
assert_eq!(&account.data()[..], &account_info.data.borrow()[..]);
assert_eq!(&account.owner, account_info.owner);
assert_eq!(account.executable, account_info.executable);
assert_eq!(account.rent_epoch, account_info.rent_epoch);
@@ -360,7 +362,7 @@ mod tests {
assert_eq!(key, *account_info.key);
let account = account.borrow();
assert_eq!(account.lamports, account_info.lamports());
assert_eq!(&account.data[..], &account_info.data.borrow()[..]);
assert_eq!(&account.data()[..], &account_info.data.borrow()[..]);
assert_eq!(&account.owner, account_info.owner);
assert_eq!(account.executable, account_info.executable);
assert_eq!(account.rent_epoch, account_info.rent_epoch);

View File

@@ -10,7 +10,7 @@ use solana_rbpf::{
};
use solana_runtime::message_processor::MessageProcessor;
use solana_sdk::{
account::AccountSharedData,
account::{AccountSharedData, ReadableAccount},
account_info::AccountInfo,
account_utils::StateMut,
bpf_loader, bpf_loader_deprecated,
@@ -1665,7 +1665,7 @@ fn call<'a>(
if message.is_writable(i) && !account.executable {
*account_ref.lamports = account.lamports;
*account_ref.owner = account.owner;
if account_ref.data.len() != account.data.len() {
if account_ref.data.len() != account.data().len() {
if !account_ref.data.is_empty() {
// Only support for `CreateAccount` at this time.
// Need a way to limit total realloc size across multiple CPI calls
@@ -1678,7 +1678,8 @@ fn call<'a>(
)
.into());
}
if account.data.len() > account_ref.data.len() + MAX_PERMITTED_DATA_INCREASE
if account.data().len()
> account_ref.data.len() + MAX_PERMITTED_DATA_INCREASE
{
ic_msg!(
invoke_context,
@@ -1694,14 +1695,14 @@ fn call<'a>(
memory_mapping,
AccessType::Store,
account_ref.vm_data_addr,
account.data.len() as u64,
account.data().len() as u64,
)?;
*account_ref.ref_to_len_in_vm = account.data.len() as u64;
*account_ref.serialized_len_ptr = account.data.len() as u64;
*account_ref.ref_to_len_in_vm = account.data().len() as u64;
*account_ref.serialized_len_ptr = account.data().len() as u64;
}
account_ref
.data
.clone_from_slice(&account.data[0..account_ref.data.len()]);
.clone_from_slice(&account.data()[0..account_ref.data.len()]);
}
}
}