@lodestar/light-client 1.13.0-dev.faa4514532 → 1.13.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +109 -6
  2. package/package.json +8 -8
package/README.md CHANGED
@@ -1,26 +1,129 @@
1
- # Lodestar Light-client
1
+ # Lodestar Light Client
2
+
3
+ Ethereum light clients provide a pathway for users to interact with the Ethereum blockchain in a trust-minimized manner, comparable to the level of trust required when engaging with a third-party provider like Infura or EtherScan. Not that those platforms are bad, but trust in any centralized provider goes against the ethos of blockchain. Light clients are a way that low-power devices, like cell phones, can do self validation of transactions and dApp state.
4
+
5
+ Unlike full nodes, light clients do not download and store the entire blockchain. Instead, they download only the headers of each block and employ Merkle proofs to verify transactions. This enables a quick synchronization with the network and access the latest information without using significant system resources​. This streamlined approach to accessing Ethereum is crucial, especially in scenarios where full-scale network participation is infeasible or undesired.
6
+
7
+ The evolution of light clients is emblematic of the broader trajectory of Ethereum towards becoming more accessible and resource-efficient, making blockchain technology more inclusive and adaptable to a wide array of use cases and environments. The Altair hard fork introduced sync committees to allow light-clients to synchronize to the network.
8
+
9
+ ## Prerequisites
2
10
 
3
11
  [![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)](https://discord.gg/aMxzVcr)
4
12
  [![Eth Consensus Spec v1.1.10](https://img.shields.io/badge/ETH%20consensus--spec-1.1.10-blue)](https://github.com/ethereum/consensus-specs/releases/tag/v1.1.10)
5
13
  ![ES Version](https://img.shields.io/badge/ES-2021-yellow)
6
14
  ![Node Version](https://img.shields.io/badge/node-16.x-green)
15
+ [Yarn](https://yarnpkg.com/)
7
16
 
8
17
  > This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
9
18
 
10
- ## Prerequisites
19
+ ## Requirements for Running a Light-Client
20
+
21
+ Access to an beacon node that supports the light client specification is necessary. The client must support the following routes from the [consensus API spec](https://github.com/ethereum/consensus-specs/tree/dev):
11
22
 
12
- - [NodeJS](https://nodejs.org/) (LTS)
13
- - [Yarn](https://yarnpkg.com/)
23
+ - `/eth/v1/beacon/light_client/updates`
24
+ - `/eth/v1/beacon/light_client/optimistic_update`
25
+ - `/eth/v1/beacon/light_client/finality_update`
26
+ - `/eth/v1/beacon/light_client/bootstrap/{block_root}`
27
+ - `/eth/v0/beacon/light_client/committee_root`
14
28
 
15
- ## What you need
29
+ System requirements are quite low so its possible to run a light client in the browser as part of a website. There are a few examples of this on github that you can use as reference, our [prover](https://chainsafe.github.io/lodestar/lightclient-prover/prover.md) being one of them.
16
30
 
17
- You will need to go over the [specification](https://github.com/ethereum/consensus-specs).
31
+ You can find more information about the light-client protocol in the [specification](https://github.com/ethereum/consensus-specs).
18
32
 
19
33
  ## Getting started
20
34
 
21
35
  - Follow the [installation guide](https://chainsafe.github.io/lodestar/) to install Lodestar.
22
36
  - Quickly try out the whole stack by [starting a local testnet](https://chainsafe.github.io/lodestar/usage/local).
23
37
 
38
+ ## Light-Client CLI Example
39
+
40
+ It is possible to start up the light-client as a standalone process.
41
+
42
+ ```bash
43
+ lodestar lightclient \
44
+ --network mainnet \
45
+ --beacon-api-url https://beacon-node.your-domain.com \
46
+ --checkpoint-root "0xccaff4b99986a7b05e06738f1828a32e40799b277fd9f9ff069be55341fe0229"
47
+ ```
48
+
49
+ ## Light-Client Programmatic Example
50
+
51
+ For this example we will assume there is a running beacon node at `https://beacon-node.your-domain.com`
52
+
53
+ ```ts
54
+ import {Api} from "@lodestar/api/beacon";
55
+ import {ApiError} from "@lodestar/api";
56
+ import {Bytes32} from "@lodestar/types";
57
+ import {createChainForkConfig} from "@lodestar/config";
58
+ import {networksChainConfig} from "@lodestar/config/networks";
59
+ import {
60
+ GenesisData,
61
+ Lightclient,
62
+ LightclientEvent,
63
+ RunStatusCode,
64
+ getLcLoggerConsole
65
+ } from `@lodestar/lightclient`;
66
+
67
+ async function getGenesisData(api: Pick<Api, "beacon">): Promise<GenesisData> {
68
+ const res = await api.beacon.getGenesis();
69
+ ApiError.assert(res);
70
+
71
+ return {
72
+ genesisTime: Number(res.response.data.genesisTime),
73
+ genesisValidatorsRoot: res.response.data.genesisValidatorsRoot,
74
+ };
75
+ }
76
+
77
+ async function getSyncCheckpoint(api: Pick<Api, "beacon">): Promise<Bytes32> {
78
+ const res = await api.beacon.getStateFinalityCheckpoints("head");
79
+ ApiError.assert(res);
80
+ return res.response.data.finalized.root;
81
+ }
82
+
83
+ const config = createChainForkConfig(networksChainConfig.mainnet);
84
+
85
+ const logger = getLcLoggerConsole({logDebug: Boolean(process.env.DEBUG)});
86
+
87
+ const api = getClient({urls: ["https://beacon-node.your-domain.com"]}, {config});
88
+
89
+ const transport = new LightClientRestTransport(api);
90
+
91
+ const lightclient = await Lightclient.initializeFromCheckpointRoot({
92
+ config,
93
+ logger,
94
+ transport,
95
+ genesisData: await getGenesisData(api),
96
+ checkpointRoot: await getSyncCheckpoint(api),
97
+ opts: {
98
+ allowForcedUpdates: true,
99
+ updateHeadersOnForcedUpdate: true,
100
+ }
101
+ });
102
+
103
+ // Wait for the lightclient to start
104
+ await new Promise<void>((resolve) => {
105
+ const lightclientStarted = (status: RunStatusCode): void => {
106
+ if (status === RunStatusCode.started) {
107
+ this.lightclient?.emitter.off(LightclientEvent.statusChange, lightclientStarted);
108
+ resolve();
109
+ }
110
+ };
111
+ lightclient?.emitter.on(LightclientEvent.statusChange, lightclientStarted);
112
+ logger.info("Initiating lightclient");
113
+ lightclient?.start();
114
+ });
115
+
116
+ logger.info("Lightclient synced");
117
+
118
+ lightclient.emitter.on(LightclientEvent.lightClientFinalityHeader, async (finalityUpdate) => {
119
+ console.log(finalityUpdate);
120
+ });
121
+
122
+ lightclient.emitter.on(LightclientEvent.lightClientOptimisticHeader, async (optimisticUpdate) => {
123
+ console.log(optimisticUpdate);
124
+ });
125
+ ```
126
+
24
127
  ## Contributors
25
128
 
26
129
  Read our [contributors document](/CONTRIBUTING.md), [submit an issue](https://github.com/ChainSafe/lodestar/issues/new/choose) or talk to us on our [discord](https://discord.gg/yjyvFRP)!
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.13.0-dev.faa4514532",
14
+ "version": "1.13.0-rc.0",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -67,12 +67,12 @@
67
67
  "@chainsafe/bls": "7.1.1",
68
68
  "@chainsafe/persistent-merkle-tree": "^0.6.1",
69
69
  "@chainsafe/ssz": "^0.14.0",
70
- "@lodestar/api": "1.13.0-dev.faa4514532",
71
- "@lodestar/config": "1.13.0-dev.faa4514532",
72
- "@lodestar/params": "1.13.0-dev.faa4514532",
73
- "@lodestar/state-transition": "1.13.0-dev.faa4514532",
74
- "@lodestar/types": "1.13.0-dev.faa4514532",
75
- "@lodestar/utils": "1.13.0-dev.faa4514532",
70
+ "@lodestar/api": "1.13.0-rc.0",
71
+ "@lodestar/config": "1.13.0-rc.0",
72
+ "@lodestar/params": "1.13.0-rc.0",
73
+ "@lodestar/state-transition": "1.13.0-rc.0",
74
+ "@lodestar/types": "1.13.0-rc.0",
75
+ "@lodestar/utils": "1.13.0-rc.0",
76
76
  "mitt": "^3.0.0",
77
77
  "strict-event-emitter-types": "^2.0.0"
78
78
  },
@@ -89,5 +89,5 @@
89
89
  "light-client",
90
90
  "blockchain"
91
91
  ],
92
- "gitHead": "b06bf05b1e36d78c78978a523496f8521bff5f38"
92
+ "gitHead": "85272e1c2061251617465232f9173ddd171c1d6b"
93
93
  }