-
-
Notifications
You must be signed in to change notification settings - Fork 325
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
Connect to network discv5 boot enrs on start up #3672
Changes from 3 commits
0e26ca5
d100709
a8efda7
6e79bc5
dcacf7f
38c0b02
034b8ba
ad28754
9c5362f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,76 @@ | ||
# Local testnet | ||
|
||
To quickly test and run Lodestar we recommend to start a local testnet. We recommend a simple configuration of two beacon nodes with multiple validators | ||
To quickly test and run Lodestar we recommend starting a local testnet. We recommend a simple configuration of two beacon nodes with multiple validators | ||
|
||
**Terminal 1** | ||
|
||
Run a beacon node with 8 validators and default settings. State will be written to .tmp/state.ssz | ||
Run a beacon node, with 8 validators with the following command. | ||
|
||
```bash | ||
./lodestar dev --genesisValidators 8 --reset | ||
./lodestar dev --genesisValidators 8 --genesisTime 1578787200 --network prater --rootDir </path/to/node1> --reset | ||
``` | ||
|
||
`--genesisValidators` and `--genesisTime` define the genesis state of the beacon chain. `--rootDir` defines a path where lodestar should store the beacon state | ||
while the `--reset` flag ensures the state is cleared on each restart - which is useful when testing locally. | ||
|
||
Once the node has started, make a request to `curl http://localhost:9596/eth/v1/node/identity` and copy the `enr` value. | ||
|
||
This would be used to connect from the second node. | ||
|
||
> enr stands for ethereum node records, which is a format for conveying p2p connectivity information for ethereum nodes. | ||
> For more info see [eip-778](https://eips.ethereum.org/EIPS/eip-778) | ||
|
||
**Terminal 2** | ||
|
||
Connect to bootnode (node 1 default multiaddrs) but without starting validators. | ||
Start the second node without starting any validators and connect to the first node by supplying the copied `enr` value: | ||
|
||
```bash | ||
./lodestar dev --startValidators 0:0 \ | ||
--genesisStateFile ./dev/genesis.ssz \ | ||
--network.localMultiaddrs /ip4/127.0.0.1/tcp/30607 \ | ||
--sync.minPeers 1 | ||
--genesisValidators 8 --genesisTime 1578787200 \ | ||
--network prater \ | ||
--rootDir /path/to/node2 \ | ||
--port 9001 \ | ||
--api.rest.port 9597 \ | ||
--network.discv5.bootEnrs <enr value> | ||
--reset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may be this will now need connectToDiscv5Bootnodes arg as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Updated. |
||
``` | ||
|
||
--- | ||
By default, lodestar starts as many validators as the number supplied by `--genesisValidators`. In other to not start any validator, this is overridden by | ||
the `--startValidators` option. Passing a value of `0:0` means no validators should be started. | ||
|
||
Once both instances are running you should see an output similar to this | ||
Also, take note that the values of `--genesisValidators` and `--genesisTime` must be the same as the ones passed to the first node in other for the two nodes | ||
to have the same beacon chain. | ||
|
||
**Terminal 1** | ||
Finally `port` and `api.rest.port` are supplied since the default values will already be in use by the first node. | ||
|
||
Once the second node starts, you should see an output similar to the following in either of the terminals: | ||
|
||
```bash | ||
2020-06-21 16:42:40 [SYNC] warn: Current peerCount=0, required = 2 | ||
2020-06-21 16:42:43 [SYNC] warn: Current peerCount=0, required = 2 | ||
2020-06-21 16:42:43 [VALIDATOR 7] info: Validator is proposer at slot 9 | ||
2020-06-21 16:42:43 [CHAIN] info: Processed new chain head newChainHeadRoot=0x3223a51b51fa4f42ea2281e8580806907a8e69f490cfe12a380b8e8b41b21d27, slot=9, epoch=1 | ||
2020-06-21 16:42:43 [VALIDATOR 7] info: Proposed block with hash 0x3223a51b51fa4f42ea2281e8580806907a8e69f490cfe12a380b8e8b41b21d27 and slot 9 | ||
2020-06-21 16:42:46 [SYNC] warn: Current peerCount=1, required = 2 | ||
2020-06-21 16:42:49 [SYNC] warn: Current peerCount=1, required = 2 | ||
2020-06-21 16:42:49 [VALIDATOR 6] info: Validator is proposer at slot 10 | ||
2020-06-21 16:42:49 [CHAIN] info: Processed new chain head newChainHeadRoot=0x7c3a77ad892ca631b750b988277a6caca9cc011461e326537fb607c94359b95f, slot=10, epoch=1 | ||
2020-06-21 16:42:49 [VALIDATOR 6] info: Proposed block with hash 0x7c3a77ad892ca631b750b988277a6caca9cc011461e326537fb607c94359b95f and slot 10 | ||
2020-06-21 16:42:52 [SYNC] warn: Current peerCount=1, required = 2 | ||
2020-06-21 16:42:55 [SYNC] warn: Current peerCount=1, required = 2 | ||
2020-06-21 16:42:55 [VALIDATOR 2] info: Validator is proposer at slot 11 | ||
2020-06-21 16:42:55 [CHAIN] info: Processed new chain head newChainHeadRoot=0x74e96be4058e0edec26028c2f727b30dbc05e12c3f29f364e487916e16777f4a, slot=11, epoch=1 | ||
2020-06-21 16:42:55 [VALIDATOR 2] info: Proposed block with hash 0x74e96be4058e0edec26028c2f727b30dbc05e12c3f29f364e487916e16777f4a and slot 11 | ||
``` | ||
Eph 167991/6 6.007 [] info: Searching peers - peers: 1 - slot: 5375718 (skipped 5375718) - head: 0 0xcc67…3345 - finalized: 0x0000…0000:0 | ||
``` | ||
|
||
**Terminal 2** | ||
For further confirmation that both nodes are connected as peers, make a request to the `/eth/v1/node/peers` endpoint. | ||
|
||
For example, making the request on the first node via the following command: | ||
|
||
`curl http://localhost:9596/eth/v1/node/peers | jq` | ||
|
||
will give a result similar to the following: | ||
|
||
```bash | ||
2020-06-21 16:42:49 [SYNC] info: Sync caught up to latest slot 9 | ||
2020-06-21 16:42:49 [CHAIN] info: Processed new chain head newChainHeadRoot=0x7c3a77ad892ca631b750b988277a6caca9cc011461e326537fb607c94359b95f, slot=10, epoch=1 | ||
2020-06-21 16:42:56 [CHAIN] info: Processed new chain head newChainHeadRoot=0x74e96be4058e0edec26028c2f727b30dbc05e12c3f29f364e487916e16777f4a, slot=11, epoch=1 | ||
2020-06-21 16:43:01 [CHAIN] info: Processed new chain head newChainHeadRoot=0x75ff1e7143acead878913a516c87f620022e178298e7a7f4a9485fd731bc7128, slot=12, epoch=1 | ||
2020-06-21 16:43:07 [CHAIN] info: Processed new chain head newChainHeadRoot=0x250da6f5ebad021894eb07824b535c3442fe0f7a67949f266d46ffa6b5a18b76, slot=13, epoch=1 | ||
2020-06-21 16:43:13 [CHAIN] info: Processed new chain head newChainHeadRoot=0x2e90c4a2cea722cb8bfccdfe3b73a4211e7a21d07075d11307626d8b048b9074, slot=14, epoch=1 | ||
2020-06-21 16:43:19 [CHAIN] info: Processed new chain head newChainHeadRoot=0x03fcff4f23de519c1e294f6b1256d194199c107c56b4466efed6bfab8d6e7e92, slot=15, epoch=1 | ||
``` | ||
|
||
{ | ||
"data": [ | ||
{ | ||
"peer_id": "...", | ||
"enr": "", | ||
"last_seen_p2p_address": "....", | ||
"direction": "inbound", | ||
"state": "connected" | ||
} | ||
], | ||
"meta": { | ||
"count": 1 | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,8 @@ export class PeerDiscovery { | |
await this.discv5.start(); | ||
this.discv5StartMs = Date.now(); | ||
this.discv5.on("discovered", this.onDiscovered); | ||
// on start, dial the discv5.bootEnrs that has been added to the routing table | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we have two choices here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not supposed to connect to the Mainnet bootnodes, this has to be behind a cli flag and used only for local devnets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added it behind the |
||
this.discv5.kadValues().forEach((enr) => this.onDiscovered(enr)); | ||
} | ||
|
||
async stop(): Promise<void> { | ||
|
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.
maybe remove
--network prater
here and belowI think this is a little confusing as an example in the docs, folks may think they are actually connecting to the prater testnet
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.
may be
network
option can be removed from the dev cli options, so that it will throw error if someone even tries to specifyThere 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.
Good tip. I'll see to that
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.
@g11tech so I looked into your suggestion. The
network
option is a global option and hence the changes that will be required to make it not applicable when the dev cli option is used feels a bit out of scope to this PR. So I created a separate issue: #3695 for the suggestion to be implemented separately.