From 0239a4f88f5a4ca3402ff978f765fb6fbf093c23 Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Sat, 27 Apr 2019 23:02:59 +0300 Subject: [PATCH] Include private testnet generic genesis json deploy file, localize chain init to dev-only processes --- deploy/testnet_genesis.json | 20 ++++++++++++++++++++ nucypher/blockchain/eth/clients.py | 26 ++++++++++++++------------ nucypher/config/constants.py | 1 + 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 deploy/testnet_genesis.json diff --git a/deploy/testnet_genesis.json b/deploy/testnet_genesis.json new file mode 100644 index 000000000..00ac36a7c --- /dev/null +++ b/deploy/testnet_genesis.json @@ -0,0 +1,20 @@ +{ + "coinbase" : "0xA87722643685B38D37ecc7637ACA9C1E09c8C5e1", + "difficulty" : "10000", + "extraData" : "0x", + "gasLimit" : "8000000", + "nonce" : "0x0112358132134550", + "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "timestamp" : "0x00", + "alloc": { + "0xA87722643685B38D37ecc7637ACA9C1E09c8C5e1": {"balance": "100000000000000000000000"} + }, + "config": { + "chainId": 112358, + "homesteadBlock": 0, + "eip155Block": 0, + "eip158Block": 0, + "byzantiumBlock": 0 + } +} diff --git a/nucypher/blockchain/eth/clients.py b/nucypher/blockchain/eth/clients.py index e483fc4b0..40cd02816 100644 --- a/nucypher/blockchain/eth/clients.py +++ b/nucypher/blockchain/eth/clients.py @@ -13,7 +13,7 @@ from geth.chain import ( from geth.process import BaseGethProcess from twisted.logger import Logger -from nucypher.config.constants import DEFAULT_CONFIG_ROOT +from nucypher.config.constants import DEFAULT_CONFIG_ROOT, BASE_DIR, DEPLOY_DIR NUCYPHER_CHAIN_IDS = { 'devnet': 112358, @@ -22,8 +22,6 @@ NUCYPHER_CHAIN_IDS = { class NuCypherGethProcess(BaseGethProcess, LoggingMixin): - GENESIS_FILENAME = 'genesis.json' - GENESIS_SOURCE_FILEPATH = os.path.join('deploy', 'geth', GENESIS_FILENAME) IPC_PROTOCOL = 'ipc' IPC_FILENAME = 'geth.ipc' VERBOSITY = 5 @@ -46,15 +44,6 @@ class NuCypherGethProcess(BaseGethProcess, LoggingMixin): super().start() self.wait_for_ipc(timeout=timeout) - def initialize_blockchain(self, geth_kwargs: dict) -> None: - log = Logger('nucypher-geth-init') - with open(self.GENESIS_SOURCE_FILEPATH) as file: - genesis_data = json.loads(file.read()) - log.info(f"Read genesis file '{self.GENESIS_SOURCE_FILEPATH}'") - - log.info(f'Initializing new blockchain database and genesis block.') - initialize_chain(genesis_data, **geth_kwargs) - class NuCypherGethDevProcess(NuCypherGethProcess): @@ -76,6 +65,9 @@ class NuCypherGethDevProcess(NuCypherGethProcess): class NuCypherGethDevnetProcess(NuCypherGethProcess): + GENESIS_FILENAME = 'testnet_genesis.json' + GENESIS_SOURCE_FILEPATH = os.path.join(DEPLOY_DIR, GENESIS_FILENAME) + P2P_PORT = 30303 _CHAIN_NAME = 'devnet' __CHAIN_ID = NUCYPHER_CHAIN_IDS[_CHAIN_NAME] @@ -127,6 +119,16 @@ class NuCypherGethDevnetProcess(NuCypherGethProcess): super().__init__(geth_kwargs) + @classmethod + def initialize_blockchain(cls, geth_kwargs: dict) -> None: + log = Logger('nucypher-geth-init') + with open(cls.GENESIS_SOURCE_FILEPATH) as file: + genesis_data = json.loads(file.read()) + log.info(f"Read genesis file '{cls.GENESIS_SOURCE_FILEPATH}'") + + log.info(f'Initializing new blockchain database and genesis block.') + initialize_chain(genesis_data, **geth_kwargs) + @classmethod def ensure_account_exists(cls, password: str, data_dir: str): geth_kwargs = {'network_id': str(cls.__CHAIN_ID), diff --git a/nucypher/config/constants.py b/nucypher/config/constants.py index 4adb03ea0..a6e2b4570 100644 --- a/nucypher/config/constants.py +++ b/nucypher/config/constants.py @@ -29,6 +29,7 @@ from nucypher.blockchain.eth import sol # Base Filepaths BASE_DIR = abspath(dirname(dirname(nucypher.__file__))) +DEPLOY_DIR = os.path.join(BASE_DIR, 'deploy') PROJECT_ROOT = abspath(dirname(nucypher.__file__)) CONTRACT_ROOT = os.path.join(abspath(dirname(sol.__file__)), 'source', 'contracts')