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

light-node: cli #430

Merged
merged 34 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ea07bd2
Add an `initialize` subcommand and update some of the existing config…
liamsi Jul 9, 2020
98f2a4d
delete a bunch of legacy code and update config
liamsi Jul 9, 2020
4e3e3e8
Almost working init command
liamsi Jul 9, 2020
a487820
Working init command
liamsi Jul 9, 2020
ae33f13
use header hash for subjective init instead of validators' hash
liamsi Jul 9, 2020
ffe55f0
add From impl to translate between abscissa config and `light_client:…
liamsi Jul 9, 2020
de13191
capture all rpc rel. things in RpcConfig and add example config (toml)
liamsi Jul 9, 2020
1ae8ffa
Fix example config and minor cleanup
liamsi Jul 9, 2020
a14d1a8
make rpc server addr overridable via cli argument
liamsi Jul 9, 2020
fae8fcb
Check if store was initialized
liamsi Jul 9, 2020
996c550
Start command almost working
liamsi Jul 9, 2020
590b6d1
add todo
liamsi Jul 9, 2020
d66feb0
Delete example (thanks @xla that was very useful :+1:)
liamsi Jul 10, 2020
ca4979e
remove broken absicca acceptance tests
liamsi Jul 10, 2020
5e59191
add todo
liamsi Jul 10, 2020
ea07d67
Merge remote-tracking branch 'remotes/origin/master' into ismail/ligh…
liamsi Jul 10, 2020
544fe75
catch up with latest changes from master
liamsi Jul 10, 2020
8c88d7e
Update Readme with instructions
liamsi Jul 10, 2020
8a8e3ae
Improve README.md
liamsi Jul 10, 2020
d810443
Add documentation for JSONRPC endpoint
liamsi Jul 10, 2020
59ec2a6
Add link to tendermint repo
liamsi Jul 10, 2020
0dfba5e
Minor improvement
liamsi Jul 10, 2020
abf5f84
language
liamsi Jul 10, 2020
ae3a55b
Minor changes
liamsi Jul 10, 2020
953dbcf
Add explanatory comments in the example config
liamsi Jul 10, 2020
6fed6ce
Reference explanatory comments in example conf in README.md
liamsi Jul 10, 2020
08ce5cc
refactor run to be more readable
liamsi Jul 10, 2020
f0a4fb1
add 2 todos ...
liamsi Jul 10, 2020
f2f1d5c
Minor fix in README.md
liamsi Jul 10, 2020
5350960
rename binary from ligth_node to light-node and minor improvement to …
liamsi Jul 10, 2020
36f64d1
unindent example config to please the @xla
liamsi Jul 11, 2020
11c3ed9
disambiguate cl flag
liamsi Jul 11, 2020
08d11b1
use abscissa cargo-like status logging instead of println!
liamsi Jul 11, 2020
3d82818
use latest_trusted_or_verified instead
liamsi Jul 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions light-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jsonrpc-http-server = "14.2"
jsonrpc-derive = "14.2"
serde = { version = "1", features = ["serde_derive"] }
serde_json = "1.0"
sled = "0.31.0"
xla marked this conversation as resolved.
Show resolved Hide resolved
tendermint = { version = "0.14.0", path = "../tendermint" }
tendermint-light-client = { version = "0.14.0", path = "../light-client" }
tendermint-rpc = { version = "0.14.0", path = "../rpc", features = [ "client" ] }
Expand Down
209 changes: 202 additions & 7 deletions light-node/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,209 @@
# LightNode
# Light-Node

Tendermint light client node.
The [Tendermint] light-node wraps the [light-client] crate into a command-line interface tool.
It can be used as a standalone light client daemon and exposes a JSONRPC endpoint
from which you can query the current state of the light node.

## Getting Started

This application is authored using [Abscissa], a Rust application framework.
### Prerequisites

For more information, see:
This short tutorial assumes that you are familiar with how to run a Tendermint fullnode on your machine. To learn how to do this, you can consult the [quick start] section of the tendermint documentation.

[Documentation]
This tutorial further assumes you have `git` and the latest stable rust tool-chain installed (see https://rustup.rs/).
Additionally, the `jq` tool will make your life easier when dealing with JSON output.

[Abscissa]: https://github.com/iqlusioninc/abscissa
[Documentation]: https://docs.rs/abscissa_core/
#### Cloning the repository

To run the light node from source you have to clone this repository first:
```
$ git clone https://github.com/informalsystems/tendermint-rs.git
```

Then navigate to the light node crate:
```
$ cd tendermint-rs/light-node
```

### Configuration

You can configure all aspects of light node via a configuration file.
An example cofigartion can be found under [light_node.toml.example](light_node.toml.example).

If you are running a Tendermint fullnode on your machine, you can simply copy and use it to get started:
```
$ cp light_node.toml.example light_node.toml
```
Please, take a look into the config file and edit it according to your needs.
The provided example configuration file comes with a lot of explanatory comments
which hopefully provide enough guidance to configure your light node.

### Subjective initialization
Assuming that you are running a Tendermint fullnode that exposes an RPC endpoint on your loopback interface, you can intialize the light-node subjectively following th following steps:

First, you have to obtain a header hash and height you want to trust (subjectively). For our purposes you can obtain one via querying the Tendermint fullnode you are running.
Here we are obtaining the header hash of height 2:
```
$ curl -X GET "http://localhost:26657/block?height=2" -H "accept: application/json" | jq .result.block_id.hash 1515:15:26
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2155 0 2155 0 0 161k 0 --:--:-- --:--:-- --:--:-- 161k
"76F85BEF1133114482FC8F78C5E78D2B1C1875DD8422A0394B175DD694A7FBA1"
```

You can now use this header hash to subjectively initialize your light node via:
```
$ cargo run -- initialize 2 76F85BEF1133114482FC8F78C5E78D2B1C1875DD8422A0394B175DD694A7FBA1
```

Note that calling `cargo run` for the first time might take a while as this command will also compile the light node and all its dependencies.

### Running the light node daemon

Now you can start your light node by simply running:
```
$ cargo run -- start
```

If everything worked the output will look sth like:
```
cargo run -- start 17:56:31
Finished dev [unoptimized + debuginfo] target(s) in 0.42s
Running `/redacted/tendermint-rs/target/debug/light_node start`
[info] synced to block 20041
[info] synced to block 20042
[info] synced to block 20044
[info] synced to block 20046
[info] synced to block 20048
[info] synced to block 20049
[info] synced to block 20051
[info] synced to block 20053
[info] synced to block 20054
[...]
```

You can stop the light node by pressing Ctrl+c.

### Help

You will notice that some config parameters can be overwritten via command line arguments.

To get a full overview and commandline parameters and available sub-commands, run:

```
$ cargo run -- help
```
Or on a specific sub-command, e.g.:
```shell script
$ cargo run -- help start
```

### JSONRPC Endpoint(s)

When you have a light-node running you can query its current state via:
```
$ curl localhost:8888 -X POST -H 'Content-Type: application/json' \
-d '{"jsonrpc": "2.0", "method": "state", "id": 1}' | jq
```

<details>
<summary><b>Click here</b> to see an example for expected output:</summary>

Command:
```
$ curl localhost:8888 -X POST -H 'Content-Type: application/json' \
-d '{"jsonrpc": "2.0", "method": "state", "id": 1}' | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1902 100 1856 100 46 164k 4181 --:--:-- --:--:-- --:--:-- 168k
```
Example output:
```json
{
"jsonrpc": "2.0",
"result": {
"next_validator_set": {
"validators": [
{
"address": "AD358F20C8CE80889E0F0248FDDC454595D632AE",
"proposer_priority": "0",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "uo9rbgR5J0kuED0C529bTa6mcHZ4uXDjJRdg1k8proY="
},
"voting_power": "10"
}
]
},
"provider": "BADFADAD0BEFEEDC0C0ADEADBEEFC0FFEEFACADE",
"signed_header": {
"commit": {
"block_id": {
"hash": "76F85BEF1133114482FC8F78C5E78D2B1C1875DD8422A0394B175DD694A7FBA1",
"parts": {
"hash": "568F279E3F59FBE3CABEACE7A3C028C15CA6A902F9D77DDEBA3BFCB9514E2881",
"total": "1"
}
},
"height": "2",
"round": "0",
"signatures": [
{
"block_id_flag": 2,
"signature": "sN3e6bzKLeIFNRptQ4SytBDLZJA53e92D6FWTll5Lq8Wdg4fVzxya6qx3SHFU82ukuj8jKmBMkwTTJsb8xThCQ==",
"timestamp": "2020-07-10T12:39:06.977628900Z",
"validator_address": "AD358F20C8CE80889E0F0248FDDC454595D632AE"
}
]
},
"header": {
"app_hash": "0000000000000000",
"chain_id": "dockerchain",
"consensus_hash": "048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F",
"data_hash": null,
"evidence_hash": null,
"height": "2",
"last_block_id": {
"hash": "F008EACA817CF6A3918CF7A6FD44F1F2464BB24D25A7EDB45A03E8783E9AB438",
"parts": {
"hash": "BF5130E879A02AC4BB83E392732ED4A37BE2F01304A615467EE7960858774E57",
"total": "1"
}
},
"last_commit_hash": "474496740A2EAA967EED02B239DA302BAF696AE36AEA78F7FEFCE4A77CCA5B33",
"last_results_hash": null,
"next_validators_hash": "74F2AC2B6622504D08DD2509E28CE731985CFE4D133C9DB0CB85763EDCA95AA3",
"proposer_address": "AD358F20C8CE80889E0F0248FDDC454595D632AE",
"time": "2020-07-10T12:39:05.977628900Z",
"validators_hash": "74F2AC2B6622504D08DD2509E28CE731985CFE4D133C9DB0CB85763EDCA95AA3",
"version": {
"app": "1",
"block": "10"
}
}
},
"validator_set": {
"validators": [
{
"address": "AD358F20C8CE80889E0F0248FDDC454595D632AE",
"proposer_priority": "0",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "uo9rbgR5J0kuED0C529bTa6mcHZ4uXDjJRdg1k8proY="
},
"voting_power": "10"
}
]
}
},
"id": 1
}

```

</details>


[quick start]: https://github.com/tendermint/tendermint/blob/master/docs/introduction/quick-start.md
[Tendermint]: https://github.com/tendermint/tendermint
[light-client]: https://github.com/informalsystems/tendermint-rs/tree/master/light-client
146 changes: 0 additions & 146 deletions light-node/examples/rpc.rs

This file was deleted.

Loading