Bank gets accounts data len delta from MessageProcessor::process_message()
This commit is contained in:
parent
46e5350d8c
commit
635337d2ff
|
@ -148,7 +148,7 @@ use {
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{
|
atomic::{
|
||||||
AtomicBool, AtomicU64,
|
AtomicBool, AtomicU64,
|
||||||
Ordering::{Acquire, Relaxed, Release},
|
Ordering::{AcqRel, Acquire, Relaxed, Release},
|
||||||
},
|
},
|
||||||
Arc, LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard,
|
Arc, LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard,
|
||||||
},
|
},
|
||||||
|
@ -3626,7 +3626,12 @@ impl Bank {
|
||||||
&*self.sysvar_cache.read().unwrap(),
|
&*self.sysvar_cache.read().unwrap(),
|
||||||
blockhash,
|
blockhash,
|
||||||
lamports_per_signature,
|
lamports_per_signature,
|
||||||
);
|
)
|
||||||
|
.map(|process_result| {
|
||||||
|
self.update_accounts_data_len(
|
||||||
|
process_result.accounts_data_len_delta,
|
||||||
|
)
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// TODO: support versioned messages
|
// TODO: support versioned messages
|
||||||
process_result = Err(TransactionError::UnsupportedVersion);
|
process_result = Err(TransactionError::UnsupportedVersion);
|
||||||
|
@ -3787,6 +3792,18 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Calculate fee for `SanitizedMessage`
|
/// Calculate fee for `SanitizedMessage`
|
||||||
pub fn calculate_fee(message: &SanitizedMessage, lamports_per_signature: u64) -> u64 {
|
pub fn calculate_fee(message: &SanitizedMessage, lamports_per_signature: u64) -> u64 {
|
||||||
let mut num_signatures = u64::from(message.header().num_required_signatures);
|
let mut num_signatures = u64::from(message.header().num_required_signatures);
|
||||||
|
|
|
@ -34,6 +34,13 @@ 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,
|
||||||
|
}
|
||||||
|
|
||||||
impl MessageProcessor {
|
impl MessageProcessor {
|
||||||
/// Process a message.
|
/// Process a message.
|
||||||
/// This method calls each instruction in the message over the set of loaded accounts.
|
/// This method calls each instruction in the message over the set of loaded accounts.
|
||||||
|
@ -56,7 +63,7 @@ impl MessageProcessor {
|
||||||
sysvars: &[(Pubkey, Vec<u8>)],
|
sysvars: &[(Pubkey, Vec<u8>)],
|
||||||
blockhash: Hash,
|
blockhash: Hash,
|
||||||
lamports_per_signature: u64,
|
lamports_per_signature: u64,
|
||||||
) -> Result<(), TransactionError> {
|
) -> Result<ProcessedMessageInfo, TransactionError> {
|
||||||
let mut invoke_context = InvokeContext::new(
|
let mut invoke_context = InvokeContext::new(
|
||||||
rent,
|
rent,
|
||||||
accounts,
|
accounts,
|
||||||
|
@ -118,7 +125,7 @@ impl MessageProcessor {
|
||||||
);
|
);
|
||||||
timings.accumulate(&invoke_context.timings);
|
timings.accumulate(&invoke_context.timings);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(ProcessedMessageInfo::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +251,7 @@ mod tests {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
assert_eq!(result, Ok(()));
|
assert!(result.is_ok());
|
||||||
assert_eq!(accounts[0].1.borrow().lamports(), 100);
|
assert_eq!(accounts[0].1.borrow().lamports(), 100);
|
||||||
assert_eq!(accounts[1].1.borrow().lamports(), 0);
|
assert_eq!(accounts[1].1.borrow().lamports(), 0);
|
||||||
|
|
||||||
|
@ -483,7 +490,7 @@ mod tests {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
assert_eq!(result, Ok(()));
|
assert!(result.is_ok());
|
||||||
|
|
||||||
// Do work on the same account but at different location in keyed_accounts[]
|
// Do work on the same account but at different location in keyed_accounts[]
|
||||||
let message = Message::new(
|
let message = Message::new(
|
||||||
|
@ -513,7 +520,7 @@ mod tests {
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
assert_eq!(result, Ok(()));
|
assert!(result.is_ok());
|
||||||
assert_eq!(accounts[0].1.borrow().lamports(), 80);
|
assert_eq!(accounts[0].1.borrow().lamports(), 80);
|
||||||
assert_eq!(accounts[1].1.borrow().lamports(), 20);
|
assert_eq!(accounts[1].1.borrow().lamports(), 20);
|
||||||
assert_eq!(accounts[0].1.borrow().data(), &vec![42]);
|
assert_eq!(accounts[0].1.borrow().data(), &vec![42]);
|
||||||
|
|
Loading…
Reference in New Issue