mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-22 20:51:16 +00:00
seal_reentrant_count returns contract reentrant count (#12695)
* Add logic, test, broken benchmark * account_entrance_count * Addressing comments * Address @agryaznov's comments * Add test for account_entrance_count, fix ci * Cargo fmt * Fix tests * Fix tests * Remove delegated call from test, address comments * Minor fixes and indentation in wat files * Update test for account_entrance_count * Update reentrant_count_call test * Delegate call test * Cargo +nightly fmt * Address comments * Update reentrant_count_works test * Apply weights diff * Add fixture descriptions * Update comments as suggested * Update reentrant_count_call test to use seal_address * add missing code * cargo fmt * account_entrance_count -> account_reentrance_count * fix tests * fmt * normalize signatures Co-authored-by: yarikbratashchuk <yarik.bratashchuk@gmail.com>
This commit is contained in:
@@ -296,6 +296,15 @@ pub trait Ext: sealing::Sealed {
|
||||
|
||||
/// Sets new code hash for existing contract.
|
||||
fn set_code_hash(&mut self, hash: CodeHash<Self::T>) -> Result<(), DispatchError>;
|
||||
|
||||
/// Returns the number of times the currently executing contract exists on the call stack in
|
||||
/// addition to the calling instance. A value of 0 means no reentrancy.
|
||||
fn reentrant_count(&self) -> u32;
|
||||
|
||||
/// Returns the number of times the specified contract exists on the call stack. Delegated calls
|
||||
/// are not calculated as separate entrance.
|
||||
/// A value of 0 means it does not exist on the call stack.
|
||||
fn account_reentrance_count(&self, account_id: &AccountIdOf<Self::T>) -> u32;
|
||||
}
|
||||
|
||||
/// Describes the different functions that can be exported by an [`Executable`].
|
||||
@@ -1374,6 +1383,17 @@ where
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn reentrant_count(&self) -> u32 {
|
||||
let id: &AccountIdOf<Self::T> = &self.top_frame().account_id;
|
||||
self.account_reentrance_count(id).saturating_sub(1)
|
||||
}
|
||||
|
||||
fn account_reentrance_count(&self, account_id: &AccountIdOf<Self::T>) -> u32 {
|
||||
self.frames()
|
||||
.filter(|f| f.delegate_caller.is_none() && &f.account_id == account_id)
|
||||
.count() as u32
|
||||
}
|
||||
}
|
||||
|
||||
mod sealing {
|
||||
|
||||
Reference in New Issue
Block a user