Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
  • Loading branch information
pipermerriam committed Sep 18, 2018
1 parent 17254fd commit 9b45f9b
Show file tree
Hide file tree
Showing 17 changed files with 322 additions and 154 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/*
8 changes: 5 additions & 3 deletions tests/trinity/core/configuration/test_chain_config_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
ROPSTEN_GENESIS_HEADER,
)

from trinity.chains.mainnet import MAINNET_NETWORK_ID
from trinity.chains.ropsten import ROPSTEN_NETWORK_ID
from trinity.config import (
ChainConfig,
)
from trinity.constants import (
MAINNET_NETWORK_ID,
ROPSTEN_NETWORK_ID,
)
from trinity.utils.eip1085 import validate_eip1085_genesis_config


Expand Down Expand Up @@ -73,7 +75,7 @@ def test_chain_config_from_preconfigured_network(network_id):
"EIP158ForkBlock": "0x00",
"byzantiumForkBlock": "0x00",
"constantinopleForkBlock": "0x00",
"chainID": "0x04d2",
"chainId": "0x04d2",
},
"genesis": {
"nonce": "0x0000000000000042",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from trinity.db.chain import ChainDBProxy
from trinity.db.base import DBProxy
from trinity.nodes.constants import ROPSTEN_NETWORK_ID
from trinity.constants import ROPSTEN_NETWORK_ID
from trinity.utils.ipc import (
wait_for_ipc,
kill_process_gracefully,
Expand Down
2 changes: 1 addition & 1 deletion tests/trinity/integration/test_lightchain_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from p2p.kademlia import Node
from p2p.peer import BasePeerContext

from trinity.nodes.constants import ROPSTEN_NETWORK_ID
from trinity.constants import ROPSTEN_NETWORK_ID
from trinity.protocol.les.peer import LESPeerPool
from trinity.sync.light.chain import LightChainSyncer
from trinity.sync.light.service import LightPeerChain
Expand Down
153 changes: 153 additions & 0 deletions trinity/assets/eip1085.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"title": "EIP1085 standard genesis schema",
"type": "object",
"required": [
"version",
"params",
"genesis"
],
"version": "2",
"properties": {
"version": {
"type": "string",
"title": "Genesis schema version",
"default": "1",
"enum": ["1"]
},
"params": {
"$ref": "#/definitions/Params"
},
"genesis": {
"$ref": "#/definitions/Genesis"
},
"accounts": {
"$ref": "#/definitions/Accounts"
}
},
"definitions": {
"Params": {
"title": "Chain parameters",
"type": "object",
"required": [
"chainId"
],
"properties": {
"frontierForkBlock": {
"title": "Block number for the Frontier fork",
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"homesteadForkBlock": {
"title": "Block number for the Homestead fork",
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"EIP150ForkBlock": {
"title": "Block number for the TangerineWhistle fork",
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"EIP158ForkBlock": {
"title": "Block number for the SpuriousDragon fork",
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"byzantiumForkBlock": {
"title": "Block number for the Byzantium fork",
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"constantinopleForkBlock": {
"title": "Block number for the Constantinople fork",
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"chainId": {
"title": "The chain ID",
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
}
}
},
"Genesis": {
"title": "Genesis block parameters",
"type": "object",
"required": [
"nonce",
"difficulty",
"author",
"timestamp",
"extraData",
"gasLimit"
],
"properties": {
"nonce": {
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2}){8}$"
},
"difficulty": {
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"author": {
"title": "Corresponds to coinbase",
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2}){20}$"
},
"timestamp": {
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"extraData": {
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2}){32}$"
},
"gasLimit": {
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
}
}
},
"Accounts": {
"title": "Genesis block parameters",
"type": "object",
"patternProperties": {
"^0x([0-9a-fA-F]{2}){20}$": {
"$ref": "#/definitions/Account"
}
}
},
"Account": {
"title": "Genesis block parameters",
"type": "object",
"required": [
"balance",
"code",
"nonce",
"storage"
],
"properties": {
"balance": {
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"code": {
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"nonce": {
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
},
"storage": {
"patternProperties": {
"^0x([0-9a-fA-F]{2})+$": {
"type": "string",
"pattern": "^0x([0-9a-fA-F]{2})+$"
}
}
}
}
}
}
}
3 changes: 2 additions & 1 deletion trinity/cli_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SYNC_FULL,
SYNC_LIGHT,
)
from trinity.nodes.constants import (
from trinity.constants import (
MAINNET_NETWORK_ID,
ROPSTEN_NETWORK_ID,
)
Expand Down Expand Up @@ -265,6 +265,7 @@ def __call__(self,
namespace: argparse.Namespace,
value: Any,
option_string: str=None) -> None:
pass
# TODO: load raw json or file....


Expand Down
33 changes: 22 additions & 11 deletions trinity/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
)

from trinity.constants import (
SYNC_FULL,
SYNC_LIGHT,
)
from trinity.nodes.constants import (
DEFAULT_PREFERRED_NODES,
MAINNET_NETWORK_ID,
ROPSTEN_NETWORK_ID,
SYNC_FULL,
SYNC_LIGHT,
)
from trinity.protocol.common.constants import DEFAULT_PREFERRED_NODES
from trinity.utils.chains import (
construct_trinity_config_params,
get_data_dir_for_network_id,
Expand Down Expand Up @@ -94,13 +92,13 @@ def __init__(self,
genesis_header: BlockHeader = None,
) -> None:
# Validate mutual exclusivity of initialization parameters.
if genesis_params and genesis_header:
if genesis_params is not None and genesis_header is not None:
raise TypeError(
"Invalid configuration: `genesis_params` and "
"`genesis_header` are mutually exclusive but were both "
"provided."
)
elif not genesis_params and not genesis_header:
elif genesis_params is None and genesis_header is None:
raise TypeError(
"Invalid configuration: One of `genesis_params` or "
"`genesis_header` must be provided."
Expand All @@ -125,6 +123,7 @@ def from_eip1085_genesis_config(cls,
genesis_params = get_genesis_params(genesis_config)
chain_id = get_chain_id(genesis_config)
return cls(
is_preconfigured_chain=False,
vm_configuration=vm_configuration,
genesis_params=genesis_params,
chain_id=chain_id,
Expand All @@ -144,16 +143,23 @@ def from_preconfigured_network(cls, network_id: int) -> 'ChainConfig':
raise TypeError(f"Unknown `network_id`: {network_id}")

return cls(
is_preconfigured_chain=True,
genesis_header=genesis_header,
vm_configuration=vm_configuration,
chain_id=chain_id,
)

@property
def chain_id(self) -> int:
if self._chain_id is None:
raise AttributeError("The `_chain_id` must be explicitely set")
return self._chain_id

@property
def is_preconfigured_chain(self) -> bool:
if self._is_preconfigured_chain is None:
raise AttributeError("The `_is_preconfigured_chain` must be explicitely set to True or False")
return self.is_preconfigured_chain
raise AttributeError("The `_is_preconfigured_chain` must be explicitely set")
return self._is_preconfigured_chain

@is_preconfigured_chain.setter
def is_preconfigured_chain(self, value: bool) -> None:
Expand All @@ -174,6 +180,11 @@ def genesis_header(self, value: BlockHeader) -> None:
"mutually exclusive. `genesis_params` already set to "
f"{self._genesis_params}"
)
elif not self.is_preconfigured_chain:
raise AttributeError(
"The `genesis_header` configuration is only valid for "
"preconfigured chains."
)
self._genesis_header = value

@property
Expand All @@ -191,7 +202,7 @@ def genesis_params(self, value: T_GENESIS_PARAMS) -> None:
"mutually exclusive. `genesis_header` already set to "
f"{self._genesis_header}"
)
elif not self.is_preconfigured_chain:
elif self.is_preconfigured_chain:
raise AttributeError(
"The `genesis_params` configuration is only valid for "
"non-preconfigured chains."
Expand Down Expand Up @@ -227,7 +238,7 @@ class TrinityConfig:

def __init__(self,
network_id: int,
genesis_config: Dict[str, Any],
genesis_config: Dict[str, Any]=None,
max_peers: int=25,
trinity_root_dir: str=None,
data_dir: str=None,
Expand Down
60 changes: 59 additions & 1 deletion trinity/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,65 @@
from typing import Dict, Tuple

from eth_utils import (
decode_hex,
)

from eth_keys import (
keys,
)

from p2p.kademlia import Address, Node


# sync modes
SYNC_FULL = 'full'
SYNC_LIGHT = 'light'

# lahja endpoint names
MAIN_EVENTBUS_ENDPOINT = 'main'
NETWORKING_EVENTBUS_ENDPOINT = 'networking'

MAXIMUM_OBJECT_MEMORY_BYTES = 10000000
# Network IDs: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
MAINNET_NETWORK_ID = 1
ROPSTEN_NETWORK_ID = 3


# Default preferred enodes
DEFAULT_PREFERRED_NODES: Dict[int, Tuple[Node, ...]] = {
MAINNET_NETWORK_ID: (
Node(keys.PublicKey(decode_hex("1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082")), # noqa: E501
Address("52.74.57.123", 30303, 30303)),
Node(keys.PublicKey(decode_hex("78de8a0916848093c73790ead81d1928bec737d565119932b98c6b100d944b7a95e94f847f689fc723399d2e31129d182f7ef3863f2b4c820abbf3ab2722344d")), # noqa: E501
Address("191.235.84.50", 30303, 30303)),
Node(keys.PublicKey(decode_hex("ddd81193df80128880232fc1deb45f72746019839589eeb642d3d44efbb8b2dda2c1a46a348349964a6066f8afb016eb2a8c0f3c66f32fadf4370a236a4b5286")), # noqa: E501
Address("52.231.202.145", 30303, 30303)),
Node(keys.PublicKey(decode_hex("3f1d12044546b76342d59d4a05532c14b85aa669704bfe1f864fe079415aa2c02d743e03218e57a33fb94523adb54032871a6c51b2cc5514cb7c7e35b3ed0a99")), # noqa: E501
Address("13.93.211.84", 30303, 30303)),
),
ROPSTEN_NETWORK_ID: (
Node(keys.PublicKey(decode_hex("053d2f57829e5785d10697fa6c5333e4d98cc564dbadd87805fd4fedeb09cbcb642306e3a73bd4191b27f821fb442fcf964317d6a520b29651e7dd09d1beb0ec")), # noqa: E501
Address("79.98.29.154", 30303, 30303)),
Node(keys.PublicKey(decode_hex("94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09")), # noqa: E501
Address("192.81.208.223", 30303, 30303)),
Node(keys.PublicKey(decode_hex("a147a3adde1daddc0d86f44f1a76404914e44cee018c26d49248142d4dc8a9fb0e7dd14b5153df7e60f23b037922ae1f33b8f318844ef8d2b0453b9ab614d70d")), # noqa: E501
Address("72.36.89.11", 30303, 30303)),
Node(keys.PublicKey(decode_hex("d8714127db3c10560a2463c557bbe509c99969078159c69f9ce4f71c2cd1837bcd33db3b9c3c3e88c971b4604bbffa390a0a7f53fc37f122e2e6e0022c059dfd")), # noqa: E501
Address("51.15.217.106", 30303, 30303)),
Node(keys.PublicKey(decode_hex("efc75f109d91cdebc62f33be992ca86fce2637044d49a954a8bdceb439b1239afda32e642456e9dfd759af5b440ef4d8761b9bda887e2200001c5f3ab2614043")), # noqa: E501
Address("34.228.166.142", 30303, 30303)),
Node(keys.PublicKey(decode_hex("c8b9ec645cd7fe570bc73740579064c528771338c31610f44d160d2ae63fd00699caa163f84359ab268d4a0aed8ead66d7295be5e9c08b0ec85b0198273bae1f")), # noqa: E501
Address("178.62.246.6", 30303, 30303)),
Node(keys.PublicKey(decode_hex("7a34c02d5ef9de43475580cbb88fb492afb2858cfc45f58cf5c7088ceeded5f58e65be769b79c31c5ae1f012c99b3e9f2ea9ef11764d553544171237a691493b")), # noqa: E501
Address("35.227.38.243", 30303, 30303)),
Node(keys.PublicKey(decode_hex("bbb3ad8be9684fa1d67ac057d18f7357dd236dc01a806fef6977ac9a259b352c00169d092c50475b80aed9e28eff12d2038e97971e0be3b934b366e86b59a723")), # noqa: E501
Address("81.169.153.213", 30303, 30303)),
Node(keys.PublicKey(decode_hex("30b7ab30a01c124a6cceca36863ece12c4f5fa68e3ba9b0b51407ccc002eeed3b3102d20a88f1c1d3c3154e2449317b8ef95090e77b312d5cc39354f86d5d606")), # noqa: E501
Address("52.176.7.10", 30303, 30303)),
Node(keys.PublicKey(decode_hex("02508da84b37a1b7f19f77268e5b69acc9e9ab6989f8e5f2f8440e025e633e4277019b91884e46821414724e790994a502892144fc1333487ceb5a6ce7866a46")), # noqa: E501
Address("54.175.255.230", 30303, 30303)),
Node(keys.PublicKey(decode_hex("0eec3472a46f0b637045e41f923ce1d4a585cd83c1c7418b183c46443a0df7405d020f0a61891b2deef9de35284a0ad7d609db6d30d487dbfef72f7728d09ca9")), # noqa: E501
Address("181.168.193.197", 30303, 30303)),
Node(keys.PublicKey(decode_hex("643c31104d497e3d4cd2460ff0dbb1fb9a6140c8bb0fca66159bbf177d41aefd477091c866494efd3f1f59a0652c93ab2f7bb09034ed5ab9f2c5c6841aef8d94")), # noqa: E501
Address("34.198.237.7", 30303, 30303)),
),
}
Loading

0 comments on commit 9b45f9b

Please sign in to comment.