Exemplo n.º 1
0
def load_state(env, alloc):
    db = env.db
    state = SecureTrie(Trie(db, BLANK_ROOT))
    count = 0
    print("Start loading state from snapshot")
    for addr in alloc:
        print("[%d] loading account %s" % (count, addr))
        account = alloc[addr]
        acct = Account.blank_account(db, env.config['ACCOUNT_INITIAL_NONCE'])
        if len(account['storage']) > 0:
            t = SecureTrie(Trie(db, BLANK_ROOT))
            c = 0
            for k in account['storage']:
                v = account['storage'][k]
                enckey = zpad(decode_hex(k), 32)
                t.update(enckey, decode_hex(v))
                c += 1
                if c % 1000 and len(db.db_service.uncommitted) > 50000:
                    print("%d uncommitted. committing..." %
                          len(db.db_service.uncommitted))
                    db.commit()
            acct.storage = t.root_hash
        if account['nonce']:
            acct.nonce = int(account['nonce'])
        if account['balance']:
            acct.balance = int(account['balance'])
        if account['code']:
            acct.code = decode_hex(account['code'])
        state.update(decode_hex(addr), rlp.encode(acct))
        count += 1
    db.commit()
    return state
Exemplo n.º 2
0
 def __init__(self, root=b'', env=Env(), **kwargs):
     self.env = env
     self.trie = SecureTrie(Trie(self.db, root))
     for k, v in STATE_DEFAULTS.items():
         setattr(self, k, kwargs.get(k, copy.copy(v)))
     self.journal = []
     self.cache = {}
     self.log_listeners = []
Exemplo n.º 3
0
 def __init__(self, root=b'', env=Env(), executing_on_head=False, **kwargs):
     self.env = env
     self.trie = SecureTrie(Trie(RefcountDB(self.db), root))
     for k, v in STATE_DEFAULTS.items():
         setattr(self, k, kwargs.get(k, copy.copy(v)))
     self.journal = []
     self.cache = {}
     self.log_listeners = []
     self.deletes = []
     self.changed = {}
     self.executing_on_head = executing_on_head
Exemplo n.º 4
0
 def __init__(self, nonce, balance, storage, code_hash, db, address):
     self.db = db
     self.address = address
     super(Account, self).__init__(nonce, balance, storage, code_hash)
     self.storage_cache = {}
     self.storage_trie = SecureTrie(Trie(self.db))
     self.storage_trie.root_hash = self.storage
     self.touched = False
     self.existent_at_start = True
     self._mutable = True
     self.deleted = False
Exemplo n.º 5
0
 def __init__(self, nonce, balance, storage, code_hash, env):
     assert isinstance(env.db, BaseDB)
     self.env = env
     super(Account, self).__init__(nonce, balance, storage, code_hash)
     self.storage_cache = {}
     self.storage_trie = SecureTrie(Trie(self.env.db))
     self.storage_trie.root_hash = self.storage
     self.touched = False
     self.existent_at_start = True
     self._mutable = True
     self.deleted = False
Exemplo n.º 6
0
    def __init__(self, db, root):
        """

        :param db:
        :param root:
        """
        self.db = db
        self.trie = Trie(self.db, root)
        self.secure_trie = SecureTrie(self.trie)
        self.journal = []
        self.cache = {}
Exemplo n.º 7
0
def create_account_snapshot(env, rlpdata):
    account = get_account(env, rlpdata)
    storage_trie = SecureTrie(Trie(env.db, account.storage))
    storage = dict()
    for k, v in storage_trie.iter_branch():
        storage[encode_hex(k.lstrip(b'\x00') or b'\x00')] = encode_hex(v)
    return {
        'nonce': snapshot_form(account.nonce),
        'balance': snapshot_form(account.balance),
        'code': encode_hex(account.code),
        'storage': storage
    }
Exemplo n.º 8
0
    def __init__(self, nonce, balance, storage, code_hash, env, address):
        assert isinstance(env.db, BaseDB)
        self.env = env
        self.address = address

        acc = _Account(nonce, balance, storage, code_hash)
        self.nonce = acc.nonce
        self.balance = acc.balance
        self.storage = acc.storage
        self.code_hash = acc.code_hash

        self.storage_cache = {}
        self.storage_trie = SecureTrie(Trie(RefcountDB(self.env.db)))
        self.storage_trie.root_hash = self.storage
        self.touched = False
        self.existent_at_start = True
        self._mutable = True
        self.deleted = False
Exemplo n.º 9
0
 def __init__(self, db, root):
     self.db = db
     self.trie = Trie(self.db, root)
     self.secure_trie = SecureTrie(self.trie)
     self.journal = []
     self.cache = {}