Skip to content

Commit

Permalink
Use private genesis cofig for private network
Browse files Browse the repository at this point in the history
Allow trinity to use a custom genesis configuration to allow for private
networks to be specified. The changes specify that a genesis flag be
supplied with a valid filepath to the genesis config. It will also
require that a datadir flag is provided.

If using the custom genesis config if it does not contain the required
parameters trinity will not continue to try and create a new network.
Testing is still yet to be implemented.
  • Loading branch information
Chris Purta authored and pipermerriam committed Oct 2, 2018
1 parent 2aa9d2e commit c5be5cc
Show file tree
Hide file tree
Showing 46 changed files with 1,534 additions and 533 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ include requirements.txt

recursive-exclude * __pycache__
recursive-exclude * *.py[co]

include trinity/assets/*
3 changes: 3 additions & 0 deletions docs/api/eth/tools/api.tools.builders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ The following utilities are provided to assist with constructing a chain class.
.. autofunction:: eth.tools.builder.chain.name


.. autofunction:: eth.tools.builder.chain.chain_id


Initializing Chains
~~~~~~~~~~~~~~~~~~~

Expand Down
17 changes: 8 additions & 9 deletions eth/chains/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@

import logging

from cytoolz import (
assoc,
compose,
groupby,
iterate,
take,
)

from eth_typing import (
Address,
BlockNumber,
Expand All @@ -41,6 +33,13 @@
to_set,
ValidationError,
)
from eth_utils.toolz import (
assoc,
compose,
groupby,
iterate,
take,
)

from eth.db.backends.base import BaseAtomicDB
from eth.db.chain import (
Expand Down Expand Up @@ -120,7 +119,7 @@ class BaseChain(Configurable, ABC):
chaindb = None # type: BaseChainDB
chaindb_class = None # type: Type[BaseChainDB]
vm_configuration = None # type: Tuple[Tuple[int, Type[BaseVM]], ...]
network_id = None # type: int
chain_id = None # type: int

@abstractmethod
def __init__(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion eth/chains/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BaseHeaderChain(Configurable, ABC):
_headerdb = None # type: BaseHeaderDB

header = None # type: BlockHeader
network_id = None # type: int
chain_id = None # type: int
vm_configuration = None # type: Tuple[Tuple[int, Type[BaseVM]], ...]

@abstractmethod
Expand Down
5 changes: 3 additions & 2 deletions eth/chains/mainnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ class MainnetHomesteadVM(MainnetDAOValidatorVM, HomesteadVM):

MAINNET_VM_CONFIGURATION = tuple(zip(MAINNET_FORK_BLOCKS, MAINNET_VMS))

MAINNET_NETWORK_ID = 1

MAINNET_CHAIN_ID = 1


class BaseMainnetChain:
chain_id = MAINNET_CHAIN_ID
vm_configuration = MAINNET_VM_CONFIGURATION # type: Tuple[Tuple[int, Type[BaseVM]], ...]
network_id = MAINNET_NETWORK_ID # type: int


class MainnetChain(BaseMainnetChain, Chain):
Expand Down
4 changes: 2 additions & 2 deletions eth/chains/ropsten/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
)


ROPSTEN_NETWORK_ID = 3
ROPSTEN_CHAIN_ID = 3


class BaseRopstenChain:
vm_configuration = ROPSTEN_VM_CONFIGURATION # type: Tuple[Tuple[int, Type[BaseVM]], ...] # noqa: E501
network_id = ROPSTEN_NETWORK_ID # type: int
chain_id = ROPSTEN_CHAIN_ID # type: int


class RopstenChain(BaseRopstenChain, Chain):
Expand Down
3 changes: 3 additions & 0 deletions eth/rlp/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def hash(self) -> bytes:


class BaseTransaction(BaseTransactionFields, BaseTransactionMethods):
supports_chain_id = False

@classmethod
def from_base_transaction(cls, transaction: 'BaseTransaction') -> 'BaseTransaction':
Expand Down Expand Up @@ -159,6 +160,8 @@ def create_unsigned_transaction(self, *args: Any, **kwargs: Any) -> 'BaseTransac


class BaseUnsignedTransaction(rlp.Serializable, BaseTransactionMethods, ABC):
supports_chain_id = False

fields = [
('nonce', big_endian_int),
('gas_price', big_endian_int),
Expand Down
8 changes: 7 additions & 1 deletion eth/tools/builder/chain/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .builders import ( # noqa: F401
at_block_number,
build,
chain_id,
chain_split,
copy,
dao_fork_at,
Expand Down Expand Up @@ -46,6 +47,12 @@ class API:
# Configure chain vm_configuration
fork_at = staticmethod(fork_at)

# Configure chain name
name = staticmethod(name)

# Configure chain chain_id
chain_id = staticmethod(chain_id)

# Mainnet Forks
frontier_at = staticmethod(frontier_at)
homestead_at = staticmethod(homestead_at)
Expand All @@ -68,7 +75,6 @@ class API:
#
# Chain Instance Initialization
#
name = staticmethod(name)
genesis = staticmethod(genesis)

#
Expand Down
8 changes: 8 additions & 0 deletions eth/tools/builder/chain/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def name(class_name, chain_class):
return chain_class.configure(__name__=class_name)


@curry
def chain_id(chain_id, chain_class):
"""
Set the ``chain_id`` for the chain class.
"""
return chain_class.configure(chain_id=chain_id)


@curry
def fork_at(vm_class, at_block, chain_class):
"""
Expand Down
2 changes: 1 addition & 1 deletion eth/vm/forks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
ByzantiumVM,
)
from .constantinople import ( # noqa: F401
ConstantinopleVM
ConstantinopleVM,
)
4 changes: 4 additions & 0 deletions eth/vm/forks/spurious_dragon/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@


class SpuriousDragonTransaction(HomesteadTransaction):
supports_chain_id = True

def get_message_for_signing(self):
if is_eip_155_signed_transaction(self):
txn_parts = rlp.decode(rlp.encode(self))
Expand Down Expand Up @@ -58,6 +60,8 @@ def v_max(self):


class SpuriousDragonUnsignedTransaction(HomesteadUnsignedTransaction):
supports_chain_id = True

def as_signed_transaction(self, private_key, chain_id=None):
v, r, s = create_transaction_signature(self, private_key, chain_id=chain_id)
return SpuriousDragonTransaction(
Expand Down
19 changes: 14 additions & 5 deletions tests/core/builder-tools/test_chain_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
from eth.consensus.pow import check_pow
from eth.tools.builder.chain import (
build,
enable_pow_mining,
byzantium_at,
chain_id,
constantinople_at,
disable_pow_check,
name,
enable_pow_mining,
fork_at,
byzantium_at,
frontier_at,
genesis,
homestead_at,
name,
spurious_dragon_at,
tangerine_whistle_at,
constantinople_at,
genesis,
)
from eth.vm.forks import (
FrontierVM,
Expand Down Expand Up @@ -141,3 +142,11 @@ def test_chain_builder_disable_pow_check():
block.header.nonce,
block.header.difficulty,
)


def test_chain_builder_chain_id():
chain = build(
MiningChain,
chain_id(1234),
)
assert chain.chain_id == 1234
70 changes: 70 additions & 0 deletions tests/core/chain-object/test_create_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest

from eth_keys import keys

from eth.chains.base import MiningChain
from eth.chains.mainnet import MAINNET_VMS
from eth.tools.builder.chain import api


@pytest.fixture(params=MAINNET_VMS)
def chain(request):
return api.build(
MiningChain,
api.fork_at(request.param, 0),
api.disable_pow_check(),
api.genesis(),
)


@pytest.fixture
def sender():
return keys.PrivateKey(b'unicornsrainbows' * 2)


TO_ADDRESS = b'\0' * 20


@pytest.fixture
def basic_transaction(chain, sender):
unsigned_txn = chain.create_unsigned_transaction(
nonce=0,
gas_price=1234,
gas=21001, # non-default for testing purposes
to=TO_ADDRESS,
value=4321,
data=b'test',
)
return unsigned_txn.as_signed_transaction(sender)


def test_basic_create_transaction(chain, basic_transaction):
transaction = chain.create_transaction(
nonce=basic_transaction.nonce,
gas_price=basic_transaction.gas_price,
gas=basic_transaction.gas,
to=basic_transaction.to,
value=basic_transaction.value,
data=basic_transaction.data,
v=basic_transaction.v,
r=basic_transaction.r,
s=basic_transaction.s,
)
assert transaction == basic_transaction


def test_basic_create_unsigned_transaction(chain):
transaction = chain.create_unsigned_transaction(
nonce=0,
gas_price=1234,
gas=21001,
to=TO_ADDRESS,
value=4321,
data=b'test',
)
assert transaction.nonce == 0
assert transaction.gas_price == 1234
assert transaction.gas == 21001
assert transaction.to == TO_ADDRESS
assert transaction.value == 4321
assert transaction.data == b'test'
92 changes: 0 additions & 92 deletions tests/trinity/core/config/test_trinity_config_object.py

This file was deleted.

Loading

0 comments on commit c5be5cc

Please sign in to comment.