-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Use private genesis config for private network #1247
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some basic comments. 👍
I believe this will be a good candidate for the integration test suite when it is done.
trinity/chains/__init__.py
Outdated
@@ -56,6 +65,50 @@ | |||
) | |||
|
|||
|
|||
def validate_genesis(chain_config: ChainConfig) -> (BlockHeader, int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this to validate_EIPXXX_genesis
(with the XXX
replaced by the EIP number), as well as maybe linking to the EIP in the docstring for easy reference.
trinity/chains/__init__.py
Outdated
Checks the genesis configuration file provided and ensures that it is valid. | ||
""" | ||
if not os.path.exists(chain_config.genesis): | ||
raise MissingPath( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the built-in FileNotFoundError
would be sufficient here.
trinity/chains/__init__.py
Outdated
|
||
with open(chain_config.genesis, 'r') as genesis_config: | ||
raw_genesis = genesis_config.read() | ||
genesis = json.load(raw_genesis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines should be replaced with genesis = json.load(genesis_config)
. No need to read()
the file object.
trinity/chains/__init__.py
Outdated
raw_genesis = genesis_config.read() | ||
genesis = json.load(raw_genesis) | ||
|
||
if not 'chainId' in genesis.keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we've parsed the JSON, we can exit the with
block above, dedenting these lines a level.
trinity/chains/__init__.py
Outdated
if not 'extraData' in genesis.keys(): | ||
raise ValidationError("genesis config missing required 'extraData'") | ||
|
||
return BlockHeader( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our general pattern is that validate_
functions don't return data, so this should likely be re-written to three independent things.
- load the JSON
- validate the JSON
- extraction (block header, chain configuration, etc)
@cpurta let me know when you'd like me to take another look. |
@pipermerriam feel free to take another look. Most recent commits have been just trying to get tests to pass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- the
ChainConfig.genesis
andChainConfig.genesis_header
properties will beNone
when running a non-private chain which is not idea. It would be good to have those properties return the correct data for pre-configured chains as well.
I assume that there is still pending work on this as I don't see anywhere that the fork configuration is being extracted from the genesis data.
trinity/chains/__init__.py
Outdated
if 'extraData' not in genesis.keys(): | ||
raise ValidationError("genesis config missing required 'extraData'") | ||
|
||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of our other validation functions don't have return values. They either implicitly return None
or raise a validation error. Take a look at eth/validation.py
for examples of this.
trinity/chains/__init__.py
Outdated
vm_configuration = () # type: Tuple[Tuple[int, Type[BaseVM]], ...] | ||
|
||
|
||
class PrivateChain(BasePrivateChain, Chain): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Private
carries meaning that I don't think applies to all use cases of this. Maybe CustomChain
? cc @carver if you have any suggestions.
trinity/config.py
Outdated
""" | ||
Return the path of the genesis configuration file. | ||
""" | ||
return self.genesis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should access self._genesis
trinity/config.py
Outdated
""" | ||
Return the genesis block header parsed from the genesis configuration file. | ||
""" | ||
return self.genesis_header |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be accessing self._genesis_header
trinity/chains/__init__.py
Outdated
@@ -56,6 +70,49 @@ | |||
) | |||
|
|||
|
|||
def is_valid_genesis_header(genesis: Dict) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the removal of the bool
return, this should be renamed something like validate_eip1085_genesis
Moved the helper functions to parse the genesis config and generate the header to the utils chains.py file. Seems like a better place for them and no longer having issues with importing the functions at runtime. Added the data-dir to be a requirement when the genesis flag is provided. Correctly build the genesis header to the correct types.
Persist all of the vm configurations from the genesis config file specified to the custom chain. Then allow for the chain to use either full or light syncing with other nodes in the network.
Got this to a state to where it is using the genesis config correctly and is now running using that config. But it seems to be wanting to connect to the discovery peers to sync with them. Also will be addresses some of the failing CI tests. |
@pipermerriam I believe that this could use another review before I address the issues in CI. |
@cpurta 👀 |
@pipermerriam any comments on the changes? Going to try and tackle the CI issues today. |
@cpurta I started looking but got pulled away last time. Going to try and close this out this week. Likely late today or tomorrow before I get to reviewing this. |
@pipermerriam appreciate the response. I know too well how that goes 😄. I will be addressing the CI issues in the meantime. |
eth/chains/base.py
Outdated
@@ -125,6 +125,10 @@ class BaseChain(Configurable, ABC): | |||
def __init__(self) -> None: | |||
raise NotImplementedError("Chain classes must implement this method") | |||
|
|||
@property | |||
def vm_configuration(self) -> Tuple[Tuple[int, Type['BaseVM']], ...]: | |||
return self.vm_configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to cause infinite recursion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I believe we already have a get_vm_configuration
method that you can use.
Remove the vm_configuration as a class level property from the BaseChain class. This is due to the potential for infinite recursion and is causing errors in CI. Also addressing some the errors from the lint test in CI.
@cpurta I'm going to take this PR over to get it across the line and merged. thanks for getting it this far 😹 |
Will resolve #722 when merged.
What was wrong?
Currently trinity does not allow for the use of a private chain by specifying a custom genesis block. Trinity only allows the use of the mainnet and ropsten test-net.
How was it fixed?
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.