Skip to content
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

Closed
wants to merge 21 commits into from

Conversation

cpurta
Copy link

@cpurta cpurta commented Sep 3, 2018

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.

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.
@cpurta cpurta changed the title Use private genesis cofig for private network WIP: Use private genesis config for private network Sep 3, 2018
Copy link
Member

@pipermerriam pipermerriam left a 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.

@@ -56,6 +65,50 @@
)


def validate_genesis(chain_config: ChainConfig) -> (BlockHeader, int):
Copy link
Member

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.

Checks the genesis configuration file provided and ensures that it is valid.
"""
if not os.path.exists(chain_config.genesis):
raise MissingPath(
Copy link
Member

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.


with open(chain_config.genesis, 'r') as genesis_config:
raw_genesis = genesis_config.read()
genesis = json.load(raw_genesis)
Copy link
Member

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.

raw_genesis = genesis_config.read()
genesis = json.load(raw_genesis)

if not 'chainId' in genesis.keys():
Copy link
Member

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.

if not 'extraData' in genesis.keys():
raise ValidationError("genesis config missing required 'extraData'")

return BlockHeader(
Copy link
Member

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.

  1. load the JSON
  2. validate the JSON
  3. extraction (block header, chain configuration, etc)

@pipermerriam
Copy link
Member

@cpurta let me know when you'd like me to take another look.

@cpurta
Copy link
Author

cpurta commented Sep 4, 2018

@pipermerriam feel free to take another look. Most recent commits have been just trying to get tests to pass.

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • the ChainConfig.genesis and ChainConfig.genesis_header properties will be None 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.

if 'extraData' not in genesis.keys():
raise ValidationError("genesis config missing required 'extraData'")

return True
Copy link
Member

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.

vm_configuration = () # type: Tuple[Tuple[int, Type[BaseVM]], ...]


class PrivateChain(BasePrivateChain, Chain):
Copy link
Member

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.

"""
Return the path of the genesis configuration file.
"""
return self.genesis
Copy link
Member

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

"""
Return the genesis block header parsed from the genesis configuration file.
"""
return self.genesis_header
Copy link
Member

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

@@ -56,6 +70,49 @@
)


def is_valid_genesis_header(genesis: Dict) -> bool:
Copy link
Member

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

Chris Purta added 4 commits September 6, 2018 08:16
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.
@cpurta
Copy link
Author

cpurta commented Sep 6, 2018

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.

@cpurta
Copy link
Author

cpurta commented Sep 6, 2018

@pipermerriam I believe that this could use another review before I address the issues in CI.

@pipermerriam
Copy link
Member

@cpurta 👀

@cpurta
Copy link
Author

cpurta commented Sep 17, 2018

@pipermerriam any comments on the changes? Going to try and tackle the CI issues today.

@pipermerriam
Copy link
Member

@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.

@cpurta
Copy link
Author

cpurta commented Sep 17, 2018

@pipermerriam appreciate the response. I know too well how that goes 😄. I will be addressing the CI issues in the meantime.

@@ -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
Copy link
Member

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.

Copy link
Member

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.

Chris Purta added 3 commits September 17, 2018 12:09
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.
@pipermerriam
Copy link
Member

@cpurta I'm going to take this PR over to get it across the line and merged. thanks for getting it this far 😹

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make trinity conform to standard genesis.json standard from EIP-1085
2 participants