def mk_poststate_of_blockhash(self, blockhash, convert=False): if blockhash not in self.db: raise Exception("Block hash %s not found" % encode_hex(blockhash)) block_rlp = self.db.get(blockhash) if block_rlp == b'GENESIS': return State.from_snapshot( json.loads(self.db.get(b'GENESIS_STATE')), self.env) block = rlp.decode(block_rlp, Block) state = State(env=self.env) state.trie.root_hash = block.header.state_root if convert else self.db.get( b'state:' + blockhash) update_block_env_variables(state, block) state.gas_used = block.header.gas_used state.txindex = len(block.transactions) state.recent_uncles = {} state.prev_headers = [] b = block header_depth = state.config['PREV_HEADER_DEPTH'] for i in range(header_depth + 1): state.prev_headers.append(b.header) if i < 6: state.recent_uncles[state.block_number - i] = [] for u in b.uncles: state.recent_uncles[state.block_number - i].append(u.hash) try: b = rlp.decode(state.db.get(b.header.prevhash), Block) except: break if i < header_depth: if state.db.get(b.header.prevhash) == b'GENESIS': jsondata = json.loads(state.db.get(b'GENESIS_STATE')) for h in jsondata["prev_headers"][:header_depth - i]: state.prev_headers.append(dict_to_prev_header(h)) for blknum, uncles in jsondata["recent_uncles"].items(): if int(blknum) >= state.block_number - int( state.config['MAX_UNCLE_DEPTH']): state.recent_uncles[blknum] = [ parse_as_bin(u) for u in uncles ] else: raise Exception("Dangling prevhash") assert len(state.journal) == 0, state.journal return state
def mk_poststate_of_collation_hash(self, collation_hash): """Return the post-state of the collation """ if collation_hash not in self.db: raise Exception("Collation hash %s not found" % encode_hex(collation_hash)) collation_rlp = self.db.get(collation_hash) if collation_rlp == 'GENESIS': return State.from_snapshot( json.loads(self.db.get('GENESIS_STATE')), self.env) collation = rlp.decode(collation_rlp, Collation) state = State(env=self.env) state.trie.root_hash = collation.header.post_state_root update_collation_env_variables(state, collation) state.gas_used = 0 state.txindex = len(collation.transactions) state.recent_uncles = {} state.prev_headers = [] assert len(state.journal) == 0, state.journal return state