Skip to content

Commit c95f783

Browse files
c-geeklibrelois
authored andcommitted
Resolve "Add RPC method to list peers" (nodes/rust/duniter-v2s!316)
* fix: Docker config + documentation * Revert "review: test code, not dead code" This reverts commit 922df964187d8aeb5ed60787247b4ff1b9dcab65. * review: test code, not dead code * review: iodiomatic usage of stream * review: add --public-endpoints option * review: spawn_handle + BoundedVec * fix: metadata.scale * fix: warnings * fix: node was no more starting * clippy (again) * clippy * feat(#97): add RPC endpoint + gossip protocol for peerings
1 parent b202881 commit c95f783

21 files changed

+2368
-1084
lines changed

Cargo.lock

+1,122-1,012
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ simple_logger = { version = "4.3.3", default-features = false }
105105
bincode = { version = "1.3.3", default-features = false }
106106
dubp-wot = { version = "0.11.1", default-features = false }
107107
flate2 = { version = "1.0.28", default-features = false }
108+
array-bytes = { version = "6.2.2", default-features = false }
109+
parking_lot = { version = "0.12.1" }
108110

109111
# Subxt
110112
subxt = { git = 'https://github.com/duniter/subxt', branch = 'subxt-v0.38.0-duniter-substrate-v1.17.0', default-features = false }
@@ -213,6 +215,9 @@ sc-telemetry = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch
213215
sc-transaction-pool = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.17.0', default-features = false }
214216
sc-basic-authorship = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.17.0', default-features = false }
215217
sc-network = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.17.0', default-features = false }
218+
sc-network-sync = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.17.0', default-features = false }
219+
sc-network-test = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.17.0', default-features = false }
220+
sc-utils = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.17.0', default-features = false }
216221
sp-keystore = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.17.0', default-features = false }
217222
sp-storage = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.17.0', default-features = false }
218223
sp-timestamp = { git = 'https://github.com/duniter/duniter-polkadot-sdk', branch = 'duniter-substrate-v1.17.0', default-features = false }

docker/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ volumes:
6868
| `DUNITER_DISABLE_PROMETHEUS` | Boolean to disable the Prometheus endpoint on port 9615. | `false` |
6969
| `DUNITER_DISABLE_TELEMETRY` | Boolean to disable connecting to the Substrate telemetry server. | `false` |
7070
| `DUNITER_PRUNING_PROFILE` | _ `default`<br> _ `archive`: keep all blocks and state blocks<br> \* `light`: keep only last 256 state blocks and last 14400 blocks (one day duration) | `default` |
71+
| `DUNITER_PUBLIC_RPC` | The public RPC endpoint to gossip on the network and make available in the apps. | None |
72+
| `DUNITER_PUBLIC_SQUID` | The public Squid graphql endpoint to gossip on the network and make available in the apps. | None |
73+
| `DUNITER_PUBLIC_ENDPOINTS` | Path to a JSON file containing public endpoints to gossip on the network. The file should use the following format:<br>```{"endpoints": [ { "protocol": "rpc", "address": "wss://gdev.example.com" }, { "protocol": "squid", "address": "gdev.example.com/graphql/v1" }]}``` | None |
7174

7275
## Other Duniter options
7376

docker/docker-entrypoint

+15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ if [ -n "$DUNITER_PUBLIC_ADDR" ]; then
5959
set -- "$@" --public-addr "$DUNITER_PUBLIC_ADDR"
6060
fi
6161

62+
# Define public RPC endpoint (gossiped on the network)
63+
if [ -n "$DUNITER_PUBLIC_RPC" ]; then
64+
set -- "$@" --public-rpc "$DUNITER_PUBLIC_RPC"
65+
fi
66+
67+
# Define public Squid endpoint (gossiped on the network)
68+
if [ -n "$DUNITER_PUBLIC_SQUID" ]; then
69+
set -- "$@" --public-squid "$DUNITER_PUBLIC_SQUID"
70+
fi
71+
72+
# Define public endpoints from JSON file (gossiped on the network)
73+
if [ -n "$DUNITER_PUBLIC_ENDPOINTS" ]; then
74+
set -- "$@" --public-endpoints "$DUNITER_PUBLIC_ENDPOINTS"
75+
fi
76+
6277
# Define listen address (inside docker)
6378
if [ -n "$DUNITER_LISTEN_ADDR" ]; then
6479
set -- "$@" --listen-addr "$DUNITER_LISTEN_ADDR"

node/Cargo.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ num-format = { workspace = true }
130130
serde = { workspace = true }
131131
serde_json = { workspace = true }
132132
serde_yaml = { workspace = true }
133+
codec = { workspace = true }
134+
array-bytes = { workspace = true }
135+
parking_lot = { workspace = true }
133136
tokio = { workspace = true, features = ["rt-multi-thread"] }
134137

135138
# Local
@@ -162,11 +165,13 @@ sc-consensus-manual-seal = { workspace = true, default-features = true }
162165
sc-executor = { workspace = true, default-features = true }
163166
sc-keystore = { workspace = true, default-features = true }
164167
sc-network = { workspace = true, default-features = true }
168+
sc-network-sync = { workspace = true, default-features = true }
165169
sc-offchain = { workspace = true, default-features = true }
166170
sc-rpc-api = { workspace = true, default-features = true }
167171
sc-telemetry = { workspace = true, default-features = true }
168172
sc-transaction-pool = { workspace = true, default-features = true }
169173
sc-transaction-pool-api = { workspace = true, default-features = true }
174+
sc-utils = { workspace = true, default-features = true }
170175
sp-api = { workspace = true, default-features = true }
171176
sp-authority-discovery = { workspace = true, default-features = true }
172177
sp-block-builder = { workspace = true, default-features = true }
@@ -190,6 +195,12 @@ sp-transaction-pool = { workspace = true, default-features = true }
190195
sp-transaction-storage-proof = { workspace = true, default-features = true }
191196
substrate-frame-rpc-system = { workspace = true, default-features = true }
192197

198+
[dev-dependencies]
199+
sc-network-test = { workspace = true, default-features = true }
200+
async-trait = { version = "0.1.79" }
201+
env_logger = "0.10.2"
202+
async-channel = "2.3.1"
203+
193204
[build-dependencies]
194205
substrate-build-script-utils = { workspace = true, default-features = true }
195206

@@ -228,4 +239,4 @@ assets = [
228239
{ source = "../resources/debian/duniter-mirror.service", dest = "/usr/lib/systemd/system/duniter-mirror.service", mode = "0644" },
229240
{ source = "../resources/debian/duniter-smith.service", dest = "/usr/lib/systemd/system/duniter-smith.service", mode = "0644" },
230241
{ source = "../resources/debian/duniter-smith.service", dest = "/usr/lib/systemd/system/distance-oracle.service", mode = "0644" },
231-
]
242+
]

node/src/cli.rs

+32
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,48 @@ pub struct Cli {
1919
#[clap(subcommand)]
2020
pub subcommand: Option<Subcommand>,
2121

22+
/// substrate base options
2223
#[clap(flatten)]
2324
pub run: sc_cli::RunCmd,
2425

26+
/// duniter specific options
27+
#[clap(flatten)]
28+
pub duniter_options: DuniterConfigExtension,
29+
2530
/// How blocks should be sealed
2631
///
2732
/// Options are "production", "instant", "manual", or timer interval in milliseconds
2833
#[clap(long, default_value = "production")]
2934
pub sealing: crate::cli::Sealing,
3035
}
3136

37+
/// add options specific to duniter client
38+
#[derive(Debug, Default, Clone, clap::Parser)]
39+
pub struct DuniterConfigExtension {
40+
/// Public RPC endpoint to gossip on the network and make available in the apps.
41+
#[arg(long)]
42+
pub public_rpc: Option<String>,
43+
44+
/// Public Squid graphql endpoint to gossip on the network and make available in the apps.
45+
#[arg(long)]
46+
pub public_squid: Option<String>,
47+
48+
/// Public endpoints from a JSON file, using following format where `protocol` and `address` are
49+
/// strings (value is free) :
50+
///
51+
/// ```json
52+
/// {
53+
/// "endpoints": [
54+
/// { "protocol": "rpc", "address": "wss://gdev.example.com" },
55+
/// { "protocol": "squid", "address": "gdev.example.com/graphql/v1" },
56+
/// { "protocol": "other", "address": "gdev.example.com/other" }
57+
/// ]
58+
/// }
59+
/// ```
60+
#[arg(long, value_name = "JSON_FILE_PATH")]
61+
pub public_endpoints: Option<String>,
62+
}
63+
3264
#[derive(Debug, clap::Subcommand)]
3365
pub enum Subcommand {
3466
/// Build a chain specification.

node/src/command.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub mod utils;
2222

2323
use crate::{
2424
chain_spec,
25-
cli::{Cli, Subcommand},
25+
cli::{Cli, DuniterConfigExtension, Subcommand},
2626
service,
2727
service::{runtime_executor::Executor, RuntimeType},
2828
};
@@ -374,6 +374,7 @@ pub fn run() -> sc_cli::Result<()> {
374374
}
375375
None => {
376376
let runner = cli.create_runner(&cli.run)?;
377+
let duniter_options: DuniterConfigExtension = cli.duniter_options;
377378
runner.run_node_until_exit(|mut config| async move {
378379
// Force offchain worker and offchain indexing if we have the role Authority
379380
if config.role.is_authority() {
@@ -386,7 +387,7 @@ pub fn run() -> sc_cli::Result<()> {
386387
service::runtime_executor::runtime::RuntimeApi,
387388
Executor,
388389
sc_network::Litep2pNetworkBackend,
389-
>(config, cli.sealing)
390+
>(config, cli.sealing, duniter_options)
390391
.map_err(sc_cli::Error::Service)
391392
}
392393
})

0 commit comments

Comments
 (0)