|
1 | 1 | import asyncio
|
2 | 2 |
|
| 3 | +from cytoolz import ( |
| 4 | + merge, |
| 5 | +) |
| 6 | + |
3 | 7 | from cancel_token import CancelToken
|
4 | 8 |
|
| 9 | +from eth_utils import ( |
| 10 | + to_tuple, |
| 11 | +) |
| 12 | + |
5 | 13 | from eth.db.atomic import AtomicDB
|
6 | 14 | from eth.beacon.db.chain import BeaconChainDB
|
7 | 15 | from eth.beacon.types.blocks import BaseBeaconBlock
|
|
12 | 20 | from trinity.protocol.bcc.context import BeaconContext
|
13 | 21 | from trinity.protocol.bcc.peer import (
|
14 | 22 | BCCPeerFactory,
|
| 23 | + BCCPeerPool, |
15 | 24 | )
|
16 | 25 |
|
17 | 26 | from p2p import ecies
|
|
21 | 30 | )
|
22 | 31 |
|
23 | 32 |
|
| 33 | +def create_test_block(parent=None, **kwargs): |
| 34 | + defaults = { |
| 35 | + "slot": 0, |
| 36 | + "randao_reveal": ZERO_HASH32, |
| 37 | + "candidate_pow_receipt_root": ZERO_HASH32, |
| 38 | + "ancestor_hashes": [ZERO_HASH32] * 32, |
| 39 | + "state_root": ZERO_HASH32, # note: not the actual genesis state root |
| 40 | + "attestations": [], |
| 41 | + "specials": [], |
| 42 | + "proposer_signature": None, |
| 43 | + } |
| 44 | + |
| 45 | + if parent is not None: |
| 46 | + kwargs["ancestor_hashes"] = [parent.hash] + [ZERO_HASH32] * 31 |
| 47 | + kwargs["slot"] = parent.slot + 1 |
| 48 | + |
| 49 | + return BaseBeaconBlock(**merge(defaults, kwargs)) |
| 50 | + |
| 51 | + |
| 52 | +@to_tuple |
| 53 | +def create_branch(length, root, **start_kwargs): |
| 54 | + if length == 0: |
| 55 | + return |
| 56 | + |
| 57 | + parent = create_test_block(parent=root, **start_kwargs) |
| 58 | + yield parent |
| 59 | + |
| 60 | + for slot in range(root.slot + 2, root.slot + length + 1): |
| 61 | + child = create_test_block(parent) |
| 62 | + yield child |
| 63 | + parent = child |
| 64 | + |
| 65 | + |
24 | 66 | def get_fresh_chain_db():
|
25 | 67 | db = AtomicDB()
|
26 |
| - genesis_block = BaseBeaconBlock( |
27 |
| - slot=0, |
28 |
| - randao_reveal=ZERO_HASH32, |
29 |
| - candidate_pow_receipt_root=ZERO_HASH32, |
30 |
| - ancestor_hashes=[ZERO_HASH32] * 32, |
31 |
| - state_root=ZERO_HASH32, # note: not the actual genesis state root |
32 |
| - attestations=[], |
33 |
| - specials=[], |
34 |
| - proposer_signature=None, |
35 |
| - ) |
| 68 | + genesis_block = create_test_block(slot=0) |
36 | 69 |
|
37 | 70 | chain_db = BeaconChainDB(db)
|
38 | 71 | chain_db.persist_block(genesis_block)
|
| 72 | + |
39 | 73 | return chain_db
|
40 | 74 |
|
41 | 75 |
|
|
0 commit comments