|
1 | 1 | import rlp
|
2 | 2 | from ethereum.block import BlockHeader, Block
|
3 | 3 | 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 |
4 | 5 | from ethereum.state import State, Account
|
5 | 6 | from ethereum.securetrie import SecureTrie
|
6 | 7 | from ethereum.trie import BLANK_NODE, BLANK_ROOT
|
@@ -104,41 +105,32 @@ def load_snapshot(chain, snapshot):
|
104 | 105 | head_block_rlp = scan_bin(snapshot['blocks'][limit-1])
|
105 | 106 | head_header_data = rlp.decode(head_block_rlp)[0]
|
106 | 107 |
|
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 |
126 | 111 |
|
127 | 112 | 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 |
135 | 127 |
|
136 | 128 | count = 0
|
137 | 129 | for block_rlp in snapshot['blocks'][1:]:
|
138 | 130 | 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 |
142 | 134 | if not chain.add_block(block):
|
143 | 135 | print "Failed to load block #%d (%s), abort." % (block.number, encode_hex(block.hash)[:8])
|
144 | 136 | else:
|
|
0 commit comments