def build_uncle_chain_to_existing_db(write_db, existing_db, fork_at, num_blocks=20): # 1000pow_headers fixture uses byzantium and we don't want to upgrade the fixture to not bloat # the git repository too much (see discussion: https://github.com/ethereum/trinity/pull/1777) base_chain = load_mining_chain(existing_db, byzantium_at(0)) uncle_chain = load_mining_chain(write_db, byzantium_at(0)) assert uncle_chain.get_canonical_head( ) == base_chain.get_canonical_block_header_by_number(0) for block_number in range(1, fork_at): uncle_chain.import_block( base_chain.get_canonical_block_by_number(block_number)) assert uncle_chain.get_canonical_head().block_number == fork_at - 1 for _ in range(num_blocks): uncle_chain.mine_block() # If `fork_at` is 500 it means that up to block 499 is shared history and 500 is the first uncle tip_number = fork_at - 1 + num_blocks assert uncle_chain.get_canonical_head().block_number == tip_number assert uncle_chain.get_canonical_head( ) != base_chain.get_canonical_block_by_number(tip_number)
def load_mining_chain(db): GENESIS_PARAMS = { 'coinbase': constants.ZERO_ADDRESS, 'difficulty': 5, 'gas_limit': 3141592, 'timestamp': 1514764800, } GENESIS_STATE = { FUNDED_ACCT.public_key.to_canonical_address(): { "balance": 100000000000000000, } } return build( FakeAsyncChain, byzantium_at(0), enable_pow_mining(), genesis(db=db, params=GENESIS_PARAMS, state=GENESIS_STATE), )