Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Does not start if genesis is specified #166

Open
hackable opened this issue Feb 8, 2019 · 6 comments
Open

Does not start if genesis is specified #166

hackable opened this issue Feb 8, 2019 · 6 comments

Comments

@hackable
Copy link

hackable commented Feb 8, 2019

It wouldn't start if genesisPath and GCI is specified.

Node v11.8.0

Lotion 0.4.8

lotion({ initialState: { blockNo: 0, txCount: 0 }, ports: { abci: 58354, p2p: 58355, rpc: 58356 }, GCI: '08a5972afaf42e5751cd7f1af542c4e5e259e07dd0d45d31ffba3eaced632549', genesisPath: '/Users/admin/.lotion/networks/806f53597c1bfb8fdd9d128aca662a19/config/genesis.json' })

@mappum
Copy link
Contributor

mappum commented Feb 9, 2019

Hey @hackable,

You might want to try enabling the Tendermint logs to debug (run with TM_LOG=true environment variable). A possible issue could be that the node isn't using the validator private key and can't sign blocks.

@hackable
Copy link
Author

hackable commented Feb 9, 2019

The set home method has bug when genesisPath & keyPath as specified it hashes them and looks for node_keys etc in a different directory

private setHome() {
    /**
     * if genesis and key paths are provided,
     * home path is hash(genesisPath + keyPath)
     *
     * otherwise a random id is generated.
     */
    if (this.config.genesisPath && this.config.keyPath) {
      this.home = join(
        this.lotionHome,
        createHash('sha256')
          .update(fs.readFileSync(this.config.genesisPath))
          .update(fs.readFileSync(this.config.keyPath))
          .digest('hex')
      )
    } else {
      this.home = join(this.lotionHome, randomBytes(16).toString('hex'))
    }
  }
`

@hackable
Copy link
Author

Will this be fixed anytime soon?

@keppel
Copy link
Owner

keppel commented Mar 13, 2019

Hey @hackable, are you specifying a path to your private key on your validator? (opts.keyPath)

Also it looks like a few of the options you provided aren't valid, double check this section to make sure you're using the correct options.

@emizzle
Copy link

emizzle commented May 16, 2019

I'm having the same issue. An easy way to reproduce is as follows:

WORKING

const lotion = require('lotion');
const path = require('path');
const { inspect } = require('util');

const networkConfigPath = "./network/config";

async function go() {
  const config = {
    initialState: {
      count: 0,
      accounts: []
    },
    // keyPath: path.join(networkConfigPath, 'node_key_1.json'),       // path to privkey.json. generates own keys if not specified.
    // genesisPath: path.join(networkConfigPath, 'genesis.json'),      // path to genesis.json. generates new one if not specified.
    // peers: [],                                                      // array of '<host>:<p2pport>' of initial tendermint nodes to connect to. does automatic peer discovery if not specified.
    // logTendermint: false,                                           // if true, shows all output from the underlying tendermint process
    // p2pPort: 26658,                                                 // port to use for tendermint peer connections
    // rpcPort: 26657                                                  // port to use for tendermint rpc
  };

  let app = lotion(config);

  app.use(function (state, tx) {
    if (state.count === tx.nonce) {
      state.count++
    }
  });
  console.log("Starting network...");
  const appParams = await app.start();
  console.log(inspect(appParams));
}
go();

Outputs:

Starting network...
{ ports: { abci: 64019, p2p: 64020, rpc: 64021 },
  GCI:
   '25988419385b0e910c5a90ff82eea3c96833c71ec79491998b20d61be70998f4',
  genesisPath:
   '/Users/emizzle/.lotion/networks/ab2af737331159011607eed7a0b13ccf/config/genesis.json',
  home:
   '/Users/emizzle/.lotion/networks/ab2af737331159011607eed7a0b13ccf' }

NOT WORKING:

const lotion = require('lotion');
const path = require('path');
const { inspect } = require('util');

const networkConfigPath = "./network/config";

async function go() {
  const config = {
    initialState: {
      count: 0,
      accounts: []
    },
    // keyPath: path.join(networkConfigPath, 'node_key_1.json'),       // path to privkey.json. generates own keys if not specified.
    genesisPath: path.join(networkConfigPath, 'genesis.json'),      // path to genesis.json. generates new one if not specified.
    // peers: [],                                                      // array of '<host>:<p2pport>' of initial tendermint nodes to connect to. does automatic peer discovery if not specified.
    // logTendermint: false,                                           // if true, shows all output from the underlying tendermint process
    // p2pPort: 26658,                                                 // port to use for tendermint peer connections
    // rpcPort: 26657                                                  // port to use for tendermint rpc
  };

  let app = lotion(config);

  app.use(function (state, tx) {
    if (state.count === tx.nonce) {
      state.count++
    }
  });
  console.log("Starting network...");
  const appParams = await app.start();
  console.log(inspect(appParams));
}
go();

Outputs:

Starting network...

And essentially hangs.

@keppel
Copy link
Owner

keppel commented May 16, 2019

The application is hanging because it's waiting for the validators specified in the genesis to come online and start creating blocks.

The genesis says who has the authority to create blocks at the beginning of the chain. So by specifying a genesis, you've said exactly which validators can participate in consensus; they're just not online. When you don't specify a genesis or validator key, Tendermint just generates a new validator key and then makes a genesis where that key has all the authority.

If you provide a path to your validator key in opts.keyPath, the application will start as you expect. Or if you provide a running validator's address in opts.peers.

Perhaps a message explaining this would make sense when an application starts with a genesis but no validator key. (PR's welcome!)

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

No branches or pull requests

4 participants