Ejemplo n.º 1
0
def mk_header_chain(base_header, length):
    previous_header = base_header
    for _ in range(length):
        next_header = BlockHeader.from_parent(
            parent=previous_header,
            timestamp=previous_header.timestamp + 1,
            gas_limit=previous_header.gas_limit,
            difficulty=previous_header.difficulty,
            extra_data=keccak(random.randint(0, 1e18)),
        )
        yield next_header
        previous_header = next_header
Ejemplo n.º 2
0
def make_next_header(previous_header,
                     signer_private_key,
                     coinbase=ZERO_ADDRESS,
                     nonce=NONCE_DROP,
                     difficulty=2):
    next_header = sign_block_header(
        BlockHeader.from_parent(
            coinbase=coinbase,
            nonce=nonce,
            parent=previous_header,
            timestamp=previous_header.timestamp + 1,
            gas_limit=previous_header.gas_limit,
            difficulty=difficulty,
            # FIXME: I think our sign_block_header is wrong
            extra_data=VANITY_LENGTH * b'0' + SIGNATURE_LENGTH * b'0',
        ),
        signer_private_key)
    return next_header
Ejemplo n.º 3
0
def create_fhe_header_from_parent(parent_header, **header_params):
    if 'difficulty' not in header_params:
        # Use setdefault to ensure the new header has the same timestamp we use to calculate its
        # difficulty.
        header_params.setdefault('timestamp', parent_header.timestamp + 1)
        header_params['difficulty'] = compute_fhe_difficulty(
            parent_header,
            header_params['timestamp'],
        )
    if 'gas_limit' not in header_params:
        header_params['gas_limit'] = compute_gas_limit(
            parent_header,
            gas_limit_floor=GENESIS_GAS_LIMIT,
        )

    header = BlockHeader.from_parent(parent=parent_header, **header_params)

    return header