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

Basic light client CLI #15187

Merged
merged 21 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ yarn-error.log*
# misc
*.key
.env
checkpoints_dir/*
light_client.yaml
52 changes: 52 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ members = [
"crates/sui-json-rpc-types",
"crates/sui-keys",
"crates/sui-kvstore",
"crates/sui-light-client",
"crates/sui-macros",
"crates/sui-metric-checker",
"crates/sui-move",
Expand Down
56 changes: 56 additions & 0 deletions crates/sui-light-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[package]
name = "sui-light-client"
version = "0.0.0"
authors = ["Mysten Labs <build@mystenlabs.com>"]
license = "Apache-2.0"
publish = false
edition = "2021"

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
axum.workspace = true
bcs.workspace = true
byteorder.workspace = true
bytes.workspace = true
chrono.workspace = true
clap.workspace = true
csv.workspace = true
move-core-types.workspace = true
object_store.workspace = true
num_enum.workspace = true
prometheus.workspace = true
serde.workspace = true
thiserror.workspace = true
tracing.workspace = true
tokio = { workspace = true, features = ["full"] }
tokio-stream.workspace = true
url.workspace = true
strum.workspace = true
strum_macros.workspace = true
parquet.workspace = true
arrow-array.workspace = true
fastcrypto = { workspace = true, features = ["copy_key"] }
mysten-metrics.workspace = true
sui-analytics-indexer-derive.workspace = true
sui-indexer.workspace = true
serde_yaml.workspace = true
serde_json.workspace = true
eyre.workspace = true
rocksdb.workspace = true
gdanezis marked this conversation as resolved.
Show resolved Hide resolved
tempfile.workspace = true
sui-types.workspace = true
telemetry-subscribers.workspace = true
sui-config.workspace = true
sui-rest-api.workspace = true
sui-json.workspace = true
sui-storage.workspace = true
sui-sdk.workspace = true
typed-store-derive.workspace = true
typed-store.workspace = true
move-binary-format.workspace = true
move-bytecode-utils.workspace = true
sui-json-rpc-types.workspace = true
sui-package-resolver.workspace = true
workspace-hack.workspace = true

62 changes: 62 additions & 0 deletions crates/sui-light-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
This crate contains a Command Line Interface light client for Sui.

# What is a light client?

A light client allows checking the authenticity and validity of on-chain state, such as transactions, their effects including events and object contents, without the cost of running a full node.

Running a *full node* requires downloading the full sequence of all transaction and re-executing them. Any reads against the full node are guaranteed to be correct since the full state of the blockchain was recreated an in the process checked. It is however an expensive process in terms of network bandwidth needed to download the full sequence of transactions, as well as CPU to re-execute it, and storage to store the full state of the blockchain.

Alternatively, a *light client* only needs to download minimal information to authenticate blockchain state. Specifically in Sui, the light client needs to *sync* all end-of-epoch checkpoints that contain information about the committee in the next epoch. Sync involves downloading the checkpoints and checking their validity by checking their certificate.

Once all end-of-epoch checkpoints are downloaded and checked, any event or current object can be checked for its validity. To do that the light client downloads the checkpoint in which the transaction was executed, and the effects structure that summarizes its effects on the system, including events emitted and objects created. The chain of validity from the checkpoint to the effects and its contents is checked via the certificate on the checkpoint and the hashes of all structures.

## Ensuring valid data display

A light client can ensure the correctness of the event and object data using the techniques defined above. However, the light client CLI utility also needs to pretty-print the structures in JSON, which requires knowledge of the correct type for each event or object. Types themselves are defined in modules that have been uploaded by past transactions. Therefore to ensure correct display the light client authenticates that all modules needed to display sought items are also correct.

# Usage

The light client requires a config file and a directory to cache checkpoints, and then can be used to check the validity of transaction and their events or of objects.

## Setup

The config file for the light client takes a URL for a full node, a directory (that must exist) and within the directory to name of the genesis blob for the Sui network.

```
full_node_url: "http://ord-mnt-rpcbig-06.mainnet.sui.io:9000/rest"
checkpoint_summary_dir: "checkpoints_dir"
genesis_filename: "genesis.blob"
```

The genesis blob for the Sui mainnet can be found here: https://github.com/MystenLabs/sui-genesis/blob/main/mainnet/genesis.blob

## Sync

Every day there is a need to download new checkpoints through sync by doing:
```
$ sui-light-client --config light_client.yaml sync
```

Where `light_client.yaml` is the config file above.

This command will download all end-of-epoch checkpoints, and check them for validity. They will be cached within the checkpoint summary directory for use by future invocations.

## Check Transaction

To check a transaction was executed, as well as the events it emitted do:
```
$ sui-light-client --config light_client.yaml transaction -t 8RiKBwuAbtu8zNCtz8SrcfHyEUzto6zi6cMVA9t4WhWk
```

Where the base58 encoding of the transaction ID is specified. If the transaction has been executed the transaction ID the effects digest are displayed and all the events are printed in JSON. If not an error is printed.

## Check Object

To check an object provide its ID in the following way:

```
$ sui-light-client --config light_client.yaml object -o 0xc646887891adfc0540ec271fd0203603fb4c841a119ec1e00c469441
abfc7078
```

The object ID is represented in Hex as displayed in explorers. If the object exists in the latest state it is printed out in JSON, otherwise an error is printed.
Binary file not shown.
Binary file not shown.
Loading
Loading