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

Commit da9ff33

Browse files
author
Jan Xie
committed
fix load snapshot
1 parent 764372f commit da9ff33

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

ethereum/chain.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ def add_block(self, block):
306306
self.parent_queue[block.header.prevhash].append(block)
307307
log.info('No parent found. Delaying for now')
308308
return False
309-
blk_txhashes = {tx.hash: True for tx in block.transactions}
310309
self.add_child(block)
311310
self.db.put('head_hash', self.head_hash)
312311
self.db.put(block.header.hash, rlp.encode(block))

ethereum/ethpow_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections import OrderedDict
66
from ethereum import ethash, ethash_utils, utils
77
from ethereum.block import Block, BlockHeader
8-
from ethereum.utils import sha3
8+
from ethereum.utils import sha3, encode_hex
99
from ethereum.slogging import get_logger
1010
from ethereum.ethpow import check_pow
1111
from ethereum.state_transition import calc_difficulty, check_gaslimit, initialize, \

ethereum/snapshot.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import rlp
22
from ethereum.block import BlockHeader, Block
33
from ethereum.utils import is_numeric, is_string, encode_hex, decode_hex, zpad, scan_bin, big_endian_to_int
4+
from ethereum import state_transition
45
from ethereum.state import State, Account
56
from ethereum.securetrie import SecureTrie
67
from ethereum.trie import BLANK_NODE, BLANK_ROOT
@@ -104,41 +105,32 @@ def load_snapshot(chain, snapshot):
104105
head_block_rlp = scan_bin(snapshot['blocks'][limit-1])
105106
head_header_data = rlp.decode(head_block_rlp)[0]
106107

107-
state = load_state(chain.env, snapshot['alloc'])
108-
assert state.root_hash == base_header.state_root
109-
110-
#_get_block_header = blocks.get_block_header
111-
#def get_block_header(db, blockhash):
112-
#if blockhash == first_header_data[0]: # first block's prevhash
113-
#return base_header
114-
#return _get_block_header(db, blockhash)
115-
#blocks.get_block_header = get_block_header
116-
117-
#_get_block = blocks.get_block
118-
#def get_block(env, blockhash):
119-
#if blockhash == first_header_data[0]:
120-
#return FakeBlock(env, get_block_header(env.db, blockhash), int(snapshot['chainDifficulty']))
121-
#return _get_block(env, blockhash)
122-
#blocks.get_block = get_block
123-
124-
def validate_uncles():
125-
return True
108+
trie = load_state(chain.env, snapshot['alloc'])
109+
assert trie.root_hash == base_header.state_root
110+
chain.state.trie = trie
126111

127112
print "Start loading recent blocks from snapshot"
128-
first_block = rlp.decode(first_block_rlp, Block, env=chain.env)
129-
chain.index.add_block(first_block)
130-
chain._store_block(first_block)
131-
chain.blockchain.put('HEAD', first_block.hash)
132-
chain.blockchain.put(chain.index._block_by_number_key(first_block.number), first_block.hash)
133-
chain.blockchain.commit()
134-
chain._update_head_candidate()
113+
vbh = state_transition.validate_block_header
114+
vus = state_transition.validate_uncles
115+
def _vbh(state, header):
116+
return True
117+
def _vus(state, block):
118+
return True
119+
state_transition.validate_block_header = _vbh
120+
state_transition.validate_uncles = _vus
121+
# add the first block
122+
first_block = rlp.decode(first_block_rlp, sedes=Block)
123+
chain.head_hash = first_block.header.prevhash
124+
chain.add_block(first_block)
125+
assert chain.head_hash == first_block.header.hash
126+
state_transition.validate_block_header = vbh
135127

136128
count = 0
137129
for block_rlp in snapshot['blocks'][1:]:
138130
block_rlp = scan_bin(block_rlp)
139-
block = rlp.decode(block_rlp, Block, env=chain.env)
140-
if count < chain.env.config['MAX_UNCLE_DEPTH']+2:
141-
block.__setattr__('validate_uncles', validate_uncles)
131+
block = rlp.decode(block_rlp, Block)
132+
if count == chain.state.config['MAX_UNCLE_DEPTH']+2:
133+
state_transition.validate_uncles = vus
142134
if not chain.add_block(block):
143135
print "Failed to load block #%d (%s), abort." % (block.number, encode_hex(block.hash)[:8])
144136
else:

0 commit comments

Comments
 (0)