Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Add support for private networks #22

Closed
vpulim opened this issue Aug 12, 2018 · 3 comments
Closed

Add support for private networks #22

vpulim opened this issue Aug 12, 2018 · 3 comments

Comments

@vpulim
Copy link
Contributor

vpulim commented Aug 12, 2018

In order to support private networks, we should allow an instance of Common to be created from a chain spec and/or a geth genesis file. Any of the following would be user-friendly ways to construct a Common instance from a spec file:

const common = Common.fromSpec('./genesis.json')
const common = Common.fromJson('./genesis.json')
const spec = require('./genesis.json')
const common = new Common(spec) // detect first argument is an Object instead of string

We could also consider migrating the json definition files in the chains/ folder to the chain spec format for consistency and future-proofing.

@holgerd77
Copy link
Member

I've some reservations towards the chain spec format, that's why I somewhat put that aside.

These are mainly:

  • Integrating the accounts makes the file very large especially for mainnet, which puts an unnecessary burden on loading for many use cases not needing the accounts
  • Including the hardforks like in the genesis file definitions makes things unnecessarily static, e.g. if there is another HF on the horizon and one would want to add some draft params, then one would have to wait for the official genesis files to update. This also doesn't fit (at all) to our current file structure with the parameter override mechanism on new HFs
  • I also don't think that the ever-changing bootstrap nodes belong into the chain spec and is better kept separate. This also prevents (somewhat theoretical atm) to provide a hash to prove the integrity of the static genesis parameters

So: there would be definitely some more discussion necessary if we want to move in this direction. Atm I actually wouldn't want to set a priority here. Maybe some middle ground would be to adopt naming and un-problematic structure as much as possible but e.g. leave accounts and bootstrap nodes separate (people could just copy-and-paste to separate files, which should be acceptable).

There is actually some ongoing discussion atm on Gitter about crossclient standards on genesis definition, but I somewhat dropped here since I wasn't so satisfied with the running discussion.

@vpulim
Copy link
Contributor Author

vpulim commented Aug 14, 2018

Yes, no urgency to adopt the full chain spec format. However, I do need to be able to load custom genesis settings into a Common instance in order to connect to a private test net I've set up for ethereumjs client debugging/testing. A simple short-term solution could be to modify Common.setChain() to also accept an external chain params object. This way, the genesis.json parsing can be done in the client and the resulting params object can be passed on to setChain(). Something like this:

const common = new Common()
const params = parseGenesis('genesis.json')
common.setChain(params)

with these changes to Common.setChain():

  setChain (chain) {
    if (typeof (chain) === 'number') {
        ...
    } else if (typeof (chain) === 'string') {
        ...
    } else if (typeof (chain) === 'object' && chain.genesis) {
        this._chainParams = chain
    } else {
      throw new Error('Wrong input format')
    }
  }

If this makes sense, I can create a PR

@holgerd77
Copy link
Member

Addressed with #24, will close.

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

No branches or pull requests

2 participants