Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 14bdab4

Browse files
author
Jan Xie
committed
fix pos test
1 parent 245ce18 commit 14bdab4

File tree

4 files changed

+9
-36
lines changed

4 files changed

+9
-36
lines changed

ethereum/casper_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def get_dunkle_candidates(chain, state, scan_limit=10):
260260
if anc:
261261
descendants = chain.get_descendants(anc)
262262
else:
263-
descendants = chain.get_descendants(chain.db.get('GENESIS_HASH'))
263+
descendants = chain.get_descendants(chain.get_block(chain.db.get('GENESIS_HASH')))
264264
potential_uncles = [x for x in descendants if x not in chain and isinstance(x, Block)]
265265
uncles = [x.header for x in potential_uncles if not call_casper(chain.state, 'isDunkleIncluded', [x.header.hash])]
266266
dunkle_txs = []

ethereum/chain.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import rlp
66

77
from ethereum import parse_genesis_declaration
8-
from ethereum.block import Block, BlockHeader, FakeHeader, BLANK_UNCLES_HASH
8+
from ethereum.block import Block, BlockHeader, BLANK_UNCLES_HASH
99
from ethereum.config import Env
1010
from ethereum.slogging import get_logger
11-
from ethereum.state import State, dict_to_prev_header
11+
from ethereum.state import State
1212
from ethereum.state_transition import apply_block, initialize, \
1313
update_block_env_variables
1414
from ethereum.utils import encode_hex, parse_as_bin, big_endian_to_int
@@ -127,7 +127,7 @@ def mk_poststate_of_blockhash(self, blockhash, convert=False):
127127
if state.db.get(b.header.prevhash) == 'GENESIS':
128128
jsondata = json.loads(state.db.get('GENESIS_STATE'))
129129
for h in jsondata["prev_headers"][:header_depth - i]:
130-
state.prev_headers.append(dict_to_prev_header(h))
130+
state.prev_headers.append(rlp.decode(parse_as_bin(h), BlockHeader))
131131
for blknum, uncles in jsondata["recent_uncles"].items():
132132
if blknum >= state.block_number - state.config['MAX_UNCLE_DEPTH']:
133133
state.recent_uncles[blknum] = [parse_as_bin(u) for u in uncles]
@@ -190,7 +190,7 @@ def get_child_hashes(self, blockhash):
190190
def get_children(self, block):
191191
if isinstance(block, Block):
192192
block = block.header.hash
193-
if isinstance(block, (BlockHeader, FakeHeader)):
193+
if isinstance(block, BlockHeader):
194194
block = block.hash
195195
return [self.get_block(h) for h in self.get_child_hashes(block)]
196196

@@ -378,13 +378,6 @@ def get_descendants(self, block):
378378
def db(self):
379379
return self.env.db
380380

381-
def get_descendants(self, block, count=1):
382-
log.debug("get_descendants", block_hash=block)
383-
assert block.hash in self
384-
block_numbers = list(range(block.number + 1, min(self.head.number + 1,
385-
block.number + count + 1)))
386-
return [self.get(self.index.get_block_by_number(n)) for n in block_numbers]
387-
388381
def get_blockhashes_from_hash(self, hash, max):
389382
try:
390383
header = blocks.get_block_header(self.db, hash)

ethereum/parse_genesis_declaration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ethereum.state import State
2-
from ethereum.block import Block, BlockHeader, FakeHeader, BLANK_UNCLES_HASH
2+
from ethereum.block import Block, BlockHeader, BLANK_UNCLES_HASH
33
from ethereum.utils import decode_hex, big_endian_to_int, encode_hex, \
44
parse_as_bin, parse_as_int, normalize_address
55
from ethereum.state_transition import initialize

ethereum/state.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from ethereum import utils
88
from ethereum import trie
99
from ethereum.trie import Trie
10+
from ethereum.block import BlockHeader
1011
from ethereum.securetrie import SecureTrie
1112
from ethereum.config import default_config, Env
12-
from ethereum.block import FakeHeader
1313
from ethereum.db import BaseDB, EphemDB, OverlayDB
1414
import copy
1515
import sys
@@ -383,7 +383,7 @@ def from_snapshot(cls, snapshot_data, env):
383383
setattr(state, k, parse_as_bin(v) if k in snapshot_data else default)
384384
elif k == 'prev_headers':
385385
if k in snapshot_data:
386-
headers = [dict_to_prev_header(h) for h in v]
386+
headers = [rlp.decode(parse_as_bin(h), BlockHeader) for h in v]
387387
else:
388388
headers = default
389389
setattr(state, k, headers)
@@ -419,7 +419,7 @@ def to_snapshot(self, root_only=False, no_prevblocks=False):
419419
elif isinstance(default, (str, bytes)):
420420
snapshot[k] = '0x'+encode_hex(v)
421421
elif k == 'prev_headers' and not no_prevblocks:
422-
snapshot[k] = [prev_header_to_dict(h) for h in v[:self.config['PREV_HEADER_DEPTH']]]
422+
snapshot[k] = ['0x' + encode_hex(rlp.encode(h)) for h in v[:self.config['PREV_HEADER_DEPTH']]]
423423
elif k == 'recent_uncles' and not no_prevblocks:
424424
snapshot[k] = {str(n): ['0x'+encode_hex(h) for h in headers] for n, headers in v.items()}
425425
return snapshot
@@ -466,28 +466,8 @@ def is_DAO(self, at_fork_height=False):
466466
return self._is_X_fork('DAO', at_fork_height)
467467

468468

469-
def prev_header_to_dict(h):
470-
return {
471-
"hash": '0x'+encode_hex(h.hash),
472-
"number": str(h.number),
473-
"timestamp": str(h.timestamp),
474-
"difficulty": str(h.difficulty),
475-
"gas_used": str(h.gas_used),
476-
"gas_limit": str(h.gas_limit),
477-
"uncles_hash": '0x'+encode_hex(h.uncles_hash)
478-
}
479-
480-
481469
BLANK_UNCLES_HASH = sha3(rlp.encode([]))
482470

483-
def dict_to_prev_header(h):
484-
return FakeHeader(hash=parse_as_bin(h['hash']),
485-
number=parse_as_int(h['number']),
486-
timestamp=parse_as_int(h['timestamp']),
487-
difficulty=parse_as_int(h['difficulty']),
488-
gas_used=parse_as_int(h.get('gas_used', '0')),
489-
gas_limit=parse_as_int(h['gas_limit']),
490-
uncles_hash=parse_as_bin(h.get('uncles_hash', '0x'+encode_hex(BLANK_UNCLES_HASH))))
491471

492472
class Account(rlp.Serializable):
493473

0 commit comments

Comments
 (0)