Ejemplo n.º 1
0
def configure_homestead_header(vm, **header_params):
    validate_header_params_for_configuration(header_params)

    with vm.block.header.build_changeset(**header_params) as changeset:
        if 'timestamp' in header_params and changeset.block_number > 0:
            parent_header = get_parent_header(changeset.build_rlp(),
                                              vm.chaindb)
            changeset.difficulty = compute_homestead_difficulty(
                parent_header,
                header_params['timestamp'],
            )

        # In geth the modification of the state in the DAO fork block is performed
        # before any transactions are applied, so doing it here is the closest we
        # get to that. Another alternative would be to do it in Block.mine(), but
        # there we'd need to manually instantiate the State and update
        # header.state_root after we're done.
        if vm.support_dao_fork and changeset.block_number == vm.dao_fork_block_number:
            state = vm.state

            for account in dao_drain_list:
                account = decode_hex(account)
                balance = state.account_db.get_balance(account)
                state.account_db.delta_balance(dao_refund_contract, balance)
                state.account_db.set_balance(account, 0)

            # Persist the changes to the database
            state.account_db.persist()

            # Update state_root manually
            changeset.state_root = state.state_root

        header = changeset.commit()
    return header
Ejemplo n.º 2
0
def configure_frontier_header(vm: "FrontierVM", **header_params: Any) -> BlockHeader:
    validate_header_params_for_configuration(header_params)

    with vm.get_header().build_changeset(**header_params) as changeset:
        if 'timestamp' in header_params and vm.get_header().block_number > 0:
            parent_header = get_parent_header(changeset.build_rlp(), vm.chaindb)
            changeset.difficulty = compute_frontier_difficulty(
                parent_header,
                header_params['timestamp'],
            )

        header = changeset.commit()
    return header
Ejemplo n.º 3
0
def configure_fhe_header(vm, **header_params):
    validate_header_params_for_configuration(header_params)

    with vm.block.header.build_changeset(**header_params) as changeset:
        if 'timestamp' in header_params and vm.block.header.block_number > 0:
            parent_header = get_parent_header(changeset.build_rlp(),
                                              vm.chaindb)
            changeset.difficulty = compute_fhe_difficulty(
                parent_header,
                header_params['timestamp'],
            )

        header = changeset.commit()
    return header
Ejemplo n.º 4
0
def configure_header(difficulty_fn: Callable[[BlockHeader, int], int],
                     vm: BaseVM, **header_params: Any) -> BlockHeader:
    validate_header_params_for_configuration(header_params)

    with vm.block.header.build_changeset(**header_params) as changeset:
        if 'timestamp' in header_params and changeset.block_number > 0:
            parent_header = get_parent_header(changeset.build_rlp(),
                                              vm.chaindb)
            changeset.difficulty = difficulty_fn(
                parent_header,
                header_params['timestamp'],
            )

        header = changeset.commit()
    return header