Example #1
0
 def prepare_fn(configs_path: str) -> str:
     # Apply changes to presets, this affects some of the vector types.
     config_util.prepare_config(configs_path, config_name)
     reload(spec_phase0)
     reload(spec_phase1)
     reload(spec_altair)
     return config_name
def write_beacon_state(path):
    """
    This method outlines how we build beacon state for unit tests.
    """
    from eth2spec.config.config_util import prepare_config
    prepare_config('tests/config', 'minimal')

    from eth2spec.phase0.spec import initialize_beacon_state_from_eth1
    from eth2spec.test.helpers.deposits import prepare_genesis_deposits

    import eth2fastspec as spec

    print('preparing genesis deposits')
    deposits, deposit_root, _ = prepare_genesis_deposits(
        spec,
        spec.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT,
        spec.MAX_EFFECTIVE_BALANCE,
        signed=True)

    print('initializing beacon state')
    eth1_block_hash = b'\x12' * 32
    eth1_timestamp = spec.MIN_GENESIS_TIME
    state = initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp,
                                              deposits)

    print('writing beacon state')
    os.makedirs(os.path.dirname(path), exist_ok=True)
    with open(path, 'wb') as w:
        state.serialize(w)

    return state
Example #3
0
def default_builder():
    from eth2spec.config.config_util import prepare_config
    prepare_config('config', 'minimal')

    from eth2spec.phase0.spec import initialize_beacon_state_from_eth1
    from eth2spec.test.helpers.deposits import prepare_genesis_deposits

    import eth2fastspec as spec

    deposits, deposit_root, _ = prepare_genesis_deposits(
        spec,
        spec.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT,
        spec.MAX_EFFECTIVE_BALANCE,
        signed=True)

    eth1_block_hash = b'\x12' * 32
    eth1_timestamp = spec.MIN_GENESIS_TIME
    state = initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp,
                                              deposits)

    return state
Example #4
0
import importlib
import os
import types
import nest_asyncio
nest_asyncio.apply()
from eth2spec.config.config_util import prepare_config
from eth2spec.utils.ssz.ssz_impl import hash_tree_root

import os, sys
sys.path.insert(1, os.path.realpath(os.path.pardir))

print("auxiliary imports loaded!")

import beaconrunner as br

prepare_config(".", "fast")
br.reload_package(br)

print("beaconrunner loaded!")
# We then create our observers, to allow us to record interesting metrics at each simulation step.


current_slot = lambda s: s["network"].validators[0].data.slot

def average_balance_prudent(state):
    validators = state["network"].validators
    validator = validators[0]
    head = br.specs.get_head(validator.store)
    current_state = validator.store.block_states[head]
    current_epoch = br.specs.get_current_epoch(current_state)
    prudent_indices = [i for i, v in enumerate(validators) if v.validator_behaviour == "prudent"]
Example #5
0
 def prepare_fn(configs_path: str) -> str:
     config_util.prepare_config(configs_path, config_name)
     reload(spec_phase0)
     reload(spec_phase1)
     return config_name
Example #6
0
def config(request):
    config_name = request.config.getoption("--config")
    config_util.prepare_config('../../../configs/', config_name)
    # now that the presets are loaded, reload the specs to apply them
    context.reload_specs()
Example #7
0
 def prepare_fn(configs_path: str) -> str:
     config_util.prepare_config(configs_path, config_name)
     for spec in specs:
         reload(spec)
     bls.use_milagro()
     return config_name
Example #8
0
import io
import os

from eth2spec.config.config_util import prepare_config
# Apply lighthouse config to spec (instead of reloading spec, we can prepare the config before the spec is loaded)
prepare_config("./lighthouse", "config")

import fast_spec as spec

# Turn off sig verification
spec.bls.bls_active = False


def load_state(filepath: str) -> spec.BeaconState:
    state_size = os.stat(filepath).st_size
    with io.open(filepath, 'br') as f:
        return spec.BeaconState.deserialize(f, state_size)


def load_block(filepath: str) -> spec.SignedBeaconBlock:
    block_size = os.stat(filepath).st_size
    with io.open(filepath, 'br') as f:
        return spec.SignedBeaconBlock.deserialize(f, block_size)

print("loading inputs")
state = load_state('pre.ssz')
block = load_block('block.ssz')

print("loading transition context")
epochs_ctx = spec.EpochsContext()
epochs_ctx.load_state(state)