mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +00:00
keep track storage bytes (#2154)
* refactor * fix accountinfo creation + impl mem_stored * add comment * improve syntax Co-Authored-By: thiolliere <gui.thiolliere@gmail.com> * rename current_mem_stored -> storage_size * more explaination + more readable code * bump impl version of node + builds * delete builds
This commit is contained in:
@@ -14,15 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{CodeHash, Config, ContractAddressFor, Event, RawEvent, Trait, TrieId, BalanceOf};
|
||||
use crate::account_db::{AccountDb, DirectAccountDb, OverlayAccountDb, AccountTrieIdMapping};
|
||||
use super::{CodeHash, Config, ContractAddressFor, Event, RawEvent, Trait, TrieId, BalanceOf, AccountInfoOf};
|
||||
use crate::account_db::{AccountDb, DirectAccountDb, OverlayAccountDb};
|
||||
use crate::gas::{GasMeter, Token, approx_gas_for_balance};
|
||||
|
||||
use rstd::prelude::*;
|
||||
use rstd::cell::RefCell;
|
||||
use rstd::rc::Rc;
|
||||
use runtime_primitives::traits::{CheckedAdd, CheckedSub, Zero};
|
||||
use srml_support::traits::{WithdrawReason, Currency};
|
||||
use srml_support::{StorageMap, traits::{WithdrawReason, Currency}};
|
||||
use timestamp;
|
||||
|
||||
pub type AccountIdOf<T> = <T as system::Trait>::AccountId;
|
||||
@@ -226,7 +224,7 @@ impl<T: Trait> Token<T> for ExecFeeToken {
|
||||
|
||||
pub struct ExecutionContext<'a, T: Trait + 'a, V, L> {
|
||||
pub self_account: T::AccountId,
|
||||
pub self_trieid: TrieId,
|
||||
pub self_trie_id: Option<TrieId>,
|
||||
pub overlay: OverlayAccountDb<'a, T>,
|
||||
pub depth: usize,
|
||||
pub events: Vec<Event<T>>,
|
||||
@@ -246,13 +244,11 @@ where
|
||||
///
|
||||
/// The specified `origin` address will be used as `sender` for
|
||||
pub fn top_level(origin: T::AccountId, cfg: &'a Config<T>, vm: &'a V, loader: &'a L) -> Self {
|
||||
let overlay = OverlayAccountDb::<T>::new(&DirectAccountDb, Rc::new(RefCell::new(AccountTrieIdMapping::new())), true);
|
||||
let self_trieid = overlay.get_or_create_trieid(&origin);
|
||||
ExecutionContext {
|
||||
self_trie_id: <AccountInfoOf<T>>::get(&origin).map(|s| s.trie_id),
|
||||
self_account: origin,
|
||||
self_trieid,
|
||||
overlay: OverlayAccountDb::<T>::new(&DirectAccountDb),
|
||||
depth: 0,
|
||||
overlay,
|
||||
events: Vec::new(),
|
||||
calls: Vec::new(),
|
||||
config: &cfg,
|
||||
@@ -262,11 +258,10 @@ where
|
||||
}
|
||||
|
||||
fn nested(&self, overlay: OverlayAccountDb<'a, T>, dest: T::AccountId) -> Self {
|
||||
let self_trieid = overlay.get_or_create_trieid(&dest);
|
||||
ExecutionContext {
|
||||
overlay,
|
||||
self_trie_id: <AccountInfoOf<T>>::get(&dest).map(|s| s.trie_id),
|
||||
self_account: dest,
|
||||
self_trieid,
|
||||
overlay,
|
||||
depth: self.depth + 1,
|
||||
events: Vec::new(),
|
||||
calls: Vec::new(),
|
||||
@@ -301,7 +296,7 @@ where
|
||||
|
||||
let (change_set, events, calls) = {
|
||||
let mut nested = self.nested(
|
||||
OverlayAccountDb::new(&self.overlay, self.overlay.reg_cache_new_rc(), false),
|
||||
OverlayAccountDb::new(&self.overlay),
|
||||
dest.clone()
|
||||
);
|
||||
|
||||
@@ -376,7 +371,7 @@ where
|
||||
}
|
||||
|
||||
let (change_set, events, calls) = {
|
||||
let mut overlay = OverlayAccountDb::new(&self.overlay, self.overlay.reg_cache_new_rc(), false);
|
||||
let mut overlay = OverlayAccountDb::new(&self.overlay);
|
||||
|
||||
overlay.set_code(&dest, Some(code_hash.clone()));
|
||||
let mut nested = self.nested(overlay, dest.clone());
|
||||
@@ -561,7 +556,7 @@ where
|
||||
type T = T;
|
||||
|
||||
fn get_storage(&self, key: &[u8]) -> Option<Vec<u8>> {
|
||||
self.ctx.overlay.get_storage(&self.ctx.self_trieid, key)
|
||||
self.ctx.overlay.get_storage(&self.ctx.self_account, self.ctx.self_trie_id.as_ref(), key)
|
||||
}
|
||||
|
||||
fn set_storage(&mut self, key: &[u8], value: Option<Vec<u8>>) {
|
||||
|
||||
Reference in New Issue
Block a user