Move cap_accounts_data_len feature gate only around new error (#23048) (#23057)

(cherry picked from commit 0a1ab945bc)

Co-authored-by: Brooks Prumo <brooks@solana.com>
This commit is contained in:
mergify[bot]
2022-02-10 20:41:15 +00:00
committed by GitHub
parent 70f76b450e
commit 4698fbc036
3 changed files with 20 additions and 14 deletions

View File

@@ -75,14 +75,20 @@ impl AccountsDataMeter {
/// Consume accounts data space, in bytes. If `amount` is positive, we are *increasing* the
/// amount of accounts data space used. If `amount` is negative, we are *decreasing* the
/// amount of accounts data space used.
/// amount of accounts data space used. If `amount` is greater than the remaining space,
/// return an error and *do not* consume more accounts data space.
pub fn consume(&mut self, amount: i64) -> Result<(), InstructionError> {
if amount > self.remaining() as i64 {
return Err(InstructionError::AccountsDataBudgetExceeded);
}
self.delta = self.delta.saturating_add(amount);
self.consume_unchecked(amount);
Ok(())
}
/// Unconditionally consume accounts data space. Refer to `consume()` for more documentation.
pub fn consume_unchecked(&mut self, amount: i64) {
self.delta = self.delta.saturating_add(amount);
}
}
#[cfg(test)]