Exemplo n.º 1
0
 def apply_consensus_engine(self, vms: VMConfiguration) -> VMConfiguration:
     if self.mining_method == MiningMethod.Clique:
         return CliqueApplier().amend_vm_configuration(vms)
     elif self.mining_method == MiningMethod.NoProof:
         return ConsensusApplier(NoProofConsensus).amend_vm_configuration(vms)
     elif self.mining_method == MiningMethod.Ethash:
         return ConsensusApplier(PowConsensus).amend_vm_configuration(vms)
     else:
         raise NotImplementedError(f"{self.mining_method} is not supported")
Exemplo n.º 2
0
def setup_tester_chain(genesis_params=None,
                       genesis_state=None,
                       num_accounts=None,
                       vm_configuration=None,
                       mnemonic=None):

    from eth.chains.base import MiningChain
    from eth.consensus import (
        NoProofConsensus,
        ConsensusApplier,
    )
    from eth.db import get_db_backend

    if vm_configuration is None:
        from eth.vm.forks import LondonVM
        no_proof_vms = ((0, LondonVM.configure(
            consensus_class=NoProofConsensus)), )
    else:
        consensus_applier = ConsensusApplier(NoProofConsensus)
        no_proof_vms = consensus_applier.amend_vm_configuration(
            vm_configuration)

    class MainnetTesterNoProofChain(MiningChain):
        chain_id = 131277322940537
        vm_configuration = no_proof_vms

        def create_header_from_parent(self, parent_header, **header_params):
            # Keep the gas limit constant
            return super().create_header_from_parent(
                parent_header,
                **assoc(header_params, 'gas_limit', parent_header.gas_limit))

        def get_transaction_builder(self):
            return super().get_vm().get_transaction_builder()

    if genesis_params is None:
        genesis_params = get_default_genesis_params()

    if genesis_state:
        num_accounts = len(genesis_state)

    if mnemonic:
        account_keys = get_account_keys_from_mnemonic(mnemonic,
                                                      quantity=num_accounts)
    else:
        account_keys = get_default_account_keys(quantity=num_accounts)

    if genesis_state is None:
        genesis_state = generate_genesis_state_for_keys(account_keys)

    base_db = get_db_backend()

    chain = MainnetTesterNoProofChain.from_genesis(base_db, genesis_params,
                                                   genesis_state)
    return account_keys, chain
Exemplo n.º 3
0
def setup_tester_chain(genesis_params=None,
                       genesis_state=None,
                       num_accounts=None,
                       vm_configuration=None):

    from eth.chains.base import MiningChain
    from eth.consensus import (
        NoProofConsensus,
        ConsensusApplier,
    )
    from eth.db import get_db_backend

    if vm_configuration is None:
        from eth.vm.forks.muir_glacier import MuirGlacierVM
        no_proof_vms = ((0,
                         MuirGlacierVM.configure(
                             consensus_class=NoProofConsensus)), )
    else:
        consensus_applier = ConsensusApplier(NoProofConsensus)
        no_proof_vms = consensus_applier.amend_vm_configuration(
            vm_configuration)

    class MainnetTesterNoProofChain(MiningChain):
        vm_configuration = no_proof_vms

        def create_header_from_parent(self, parent_header, **header_params):
            # Keep the gas limit constant
            return super().create_header_from_parent(
                parent_header,
                **assoc(header_params, 'gas_limit', parent_header.gas_limit))

    if genesis_params is None:
        genesis_params = get_default_genesis_params()

    if genesis_state:
        num_accounts = len(genesis_state)

    account_keys = get_default_account_keys(quantity=num_accounts)

    if genesis_state is None:
        genesis_state = generate_genesis_state_for_keys(account_keys)

    base_db = get_db_backend()

    chain = MainnetTesterNoProofChain.from_genesis(base_db, genesis_params,
                                                   genesis_state)
    return account_keys, chain