(cherry picked from commit 800472ddf5)
Co-authored-by: Brooks Prumo <brooks@solana.com>
This commit is contained in:
@@ -151,7 +151,7 @@ use {
|
||||
sync::{
|
||||
atomic::{
|
||||
AtomicBool, AtomicU64,
|
||||
Ordering::{AcqRel, Acquire, Relaxed, Release},
|
||||
Ordering::{Acquire, Relaxed, Release},
|
||||
},
|
||||
Arc, LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard,
|
||||
},
|
||||
@@ -243,7 +243,7 @@ impl ExecuteTimings {
|
||||
}
|
||||
|
||||
type BankStatusCache = StatusCache<Result<()>>;
|
||||
#[frozen_abi(digest = "HvKCvCAizDb2sEGnqVKbSoZT2iCs7iMpqB6ErgU5uzS")]
|
||||
#[frozen_abi(digest = "6XG6H1FChrDdY39K62KFWj5XfDao4dd24WZgcJkdMu1E")]
|
||||
pub type BankSlotDelta = SlotDelta<Result<()>>;
|
||||
|
||||
// Eager rent collection repeats in cyclic manner.
|
||||
@@ -1276,8 +1276,7 @@ impl Bank {
|
||||
};
|
||||
|
||||
let total_accounts_stats = bank.get_total_accounts_stats().unwrap();
|
||||
bank.accounts_data_len
|
||||
.store(total_accounts_stats.data_len as u64, Release);
|
||||
bank.store_accounts_data_len(total_accounts_stats.data_len as u64);
|
||||
|
||||
bank
|
||||
}
|
||||
@@ -1525,7 +1524,7 @@ impl Bank {
|
||||
freeze_started: AtomicBool::new(false),
|
||||
cost_tracker: RwLock::new(CostTracker::default()),
|
||||
sysvar_cache: RwLock::new(Vec::new()),
|
||||
accounts_data_len: AtomicU64::new(parent.accounts_data_len.load(Acquire)),
|
||||
accounts_data_len: AtomicU64::new(parent.load_accounts_data_len()),
|
||||
};
|
||||
|
||||
let mut ancestors = Vec::with_capacity(1 + new.parents().len());
|
||||
@@ -3646,6 +3645,7 @@ impl Bank {
|
||||
&*self.sysvar_cache.read().unwrap(),
|
||||
blockhash,
|
||||
lamports_per_signature,
|
||||
self.load_accounts_data_len(),
|
||||
);
|
||||
|
||||
let log_messages: Option<TransactionLogMessages> =
|
||||
@@ -3672,7 +3672,7 @@ impl Bank {
|
||||
|
||||
let status = process_result
|
||||
.map(|info| {
|
||||
self.update_accounts_data_len(info.accounts_data_len_delta);
|
||||
self.store_accounts_data_len(info.accounts_data_len);
|
||||
self.update_executors(executors);
|
||||
})
|
||||
.map_err(|err| {
|
||||
@@ -3897,16 +3897,14 @@ impl Bank {
|
||||
)
|
||||
}
|
||||
|
||||
/// Update the bank's accounts_data_len field based on the `delta`.
|
||||
fn update_accounts_data_len(&self, delta: i64) {
|
||||
if delta == 0 {
|
||||
return;
|
||||
}
|
||||
if delta > 0 {
|
||||
self.accounts_data_len.fetch_add(delta as u64, AcqRel);
|
||||
} else {
|
||||
self.accounts_data_len.fetch_sub(delta.abs() as u64, AcqRel);
|
||||
}
|
||||
/// Load the accounts data len
|
||||
fn load_accounts_data_len(&self) -> u64 {
|
||||
self.accounts_data_len.load(Acquire)
|
||||
}
|
||||
|
||||
/// Store a new value to the accounts data len
|
||||
fn store_accounts_data_len(&self, accounts_data_len: u64) {
|
||||
self.accounts_data_len.store(accounts_data_len, Release)
|
||||
}
|
||||
|
||||
/// Calculate fee for `SanitizedMessage`
|
||||
|
||||
@@ -40,8 +40,8 @@ impl ::solana_frozen_abi::abi_example::AbiExample for MessageProcessor {
|
||||
/// Resultant information gathered from calling process_message()
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct ProcessedMessageInfo {
|
||||
/// The amount that the accounts data len has changed
|
||||
pub accounts_data_len_delta: i64,
|
||||
/// The new accounts data len
|
||||
pub accounts_data_len: u64,
|
||||
}
|
||||
|
||||
impl MessageProcessor {
|
||||
@@ -66,6 +66,7 @@ impl MessageProcessor {
|
||||
sysvars: &[(Pubkey, Vec<u8>)],
|
||||
blockhash: Hash,
|
||||
lamports_per_signature: u64,
|
||||
current_accounts_data_len: u64,
|
||||
) -> Result<ProcessedMessageInfo, TransactionError> {
|
||||
let mut invoke_context = InvokeContext::new(
|
||||
rent,
|
||||
@@ -78,6 +79,7 @@ impl MessageProcessor {
|
||||
feature_set,
|
||||
blockhash,
|
||||
lamports_per_signature,
|
||||
current_accounts_data_len,
|
||||
);
|
||||
|
||||
debug_assert_eq!(program_indices.len(), message.instructions.len());
|
||||
@@ -130,7 +132,9 @@ impl MessageProcessor {
|
||||
result
|
||||
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
|
||||
}
|
||||
Ok(ProcessedMessageInfo::default())
|
||||
Ok(ProcessedMessageInfo {
|
||||
accounts_data_len: invoke_context.get_accounts_data_meter().current(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,6 +259,7 @@ mod tests {
|
||||
&[],
|
||||
Hash::default(),
|
||||
0,
|
||||
0,
|
||||
);
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(accounts[0].1.borrow().lamports(), 100);
|
||||
@@ -284,6 +289,7 @@ mod tests {
|
||||
&[],
|
||||
Hash::default(),
|
||||
0,
|
||||
0,
|
||||
);
|
||||
assert_eq!(
|
||||
result,
|
||||
@@ -317,6 +323,7 @@ mod tests {
|
||||
&[],
|
||||
Hash::default(),
|
||||
0,
|
||||
0,
|
||||
);
|
||||
assert_eq!(
|
||||
result,
|
||||
@@ -461,6 +468,7 @@ mod tests {
|
||||
&[],
|
||||
Hash::default(),
|
||||
0,
|
||||
0,
|
||||
);
|
||||
assert_eq!(
|
||||
result,
|
||||
@@ -494,6 +502,7 @@ mod tests {
|
||||
&[],
|
||||
Hash::default(),
|
||||
0,
|
||||
0,
|
||||
);
|
||||
assert!(result.is_ok());
|
||||
|
||||
@@ -524,6 +533,7 @@ mod tests {
|
||||
&[],
|
||||
Hash::default(),
|
||||
0,
|
||||
0,
|
||||
);
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(accounts[0].1.borrow().lamports(), 80);
|
||||
@@ -581,6 +591,7 @@ mod tests {
|
||||
&[],
|
||||
Hash::default(),
|
||||
0,
|
||||
0,
|
||||
);
|
||||
assert_eq!(
|
||||
result,
|
||||
|
||||
Reference in New Issue
Block a user