Skip to content

Commit c97feef

Browse files
authored
Add custom testnet chainspec inputs (#1424)
* Move TssPublicKeys type to entropy-shared so it can be accessed by the chain node * Make it possible to give custom testnet configuration * Rm tdx testnet config as this can now be configured by the standard testnet config * Taplo * Read input as json * Handle file in testnet.rs * Add test for JSON input chainspec parsing * Fix imports * Fix imports * Fix maping measurement values * Clippy * Fix feature flags * Fix feature flags * Fix following changing account id type * Take accepted measurement values as hex * Add hex crate * Use example chainspec inputs in CI checks * Use example chainspec inputs in CI checks * Correct filename in CI script * Correct filename in CI script * Add endowed accounts * Clippy * Clone endowed accounts * Add schemars - to derive JSON schema for input struct * Ditch schemars - it would need to be implemented on a bunch of foreign types - so probably it makes sense to implement JsonSchema manually - which i would do in a followup * Error handling * Error handling * Error handling * Error handling * Error handling * Error handling * Error handling * Error handling * Error handling * Clippy * Rm unused import * Changelog * Doccomments * Fix comment following review comments * Suggestions from code review * Add docs * Improve docs * Readme
1 parent b161f05 commit c97feef

File tree

16 files changed

+243
-241
lines changed

16 files changed

+243
-241
lines changed

.github/workflows/check-chainspecs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
run: |
1515
cargo run -p entropy -- build-spec --raw --chain dev > chainspec-dev-raw.json
1616
cargo run -p entropy -- build-spec --raw --chain integration-tests > chainspec-integration-raw.json
17-
cargo run -p entropy -- build-spec --raw --chain testnet > chainspec-testnet-raw.json
17+
cargo run -p entropy -- build-spec --raw --chain ./node/cli/test-chainspec-inputs/example-chainspec-inputs.json > chainspec-testnet-raw.json

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ runtime
6666
and the network key will be lost.
6767
- In [#1377](https://github.com/entropyxyz/entropy-core/pull/1377) all endpoints except for the
6868
healthz in the TSS had a /v1 added to them.
69+
- In [#1424](https://github.com/entropyxyz/entropy-core/pull/1424) the `testnet` chainspec (given by
70+
`--chain testnet` when starting `entropy`) was removed and replaced with a custom build function.
71+
If `--chain some-filename-ending-with-chainspec-inputs.json` is passed, the testnet chainspec will
72+
be built from special parameters given in that json file.
6973

7074
### Added
7175
- In [#1128](https://github.com/entropyxyz/entropy-core/pull/1128) an `/info` route was added to `entropy-tss`

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ To speed up running tests, some tests use pre-generated keyshares rather than ru
172172
173173
from the project root. For an explanation of how the test keyshare sets are structured, see [`create-test-keyshares`](./scripts/create-test-keyshares).
174174
175+
## Chain specification (chainspec)
176+
177+
For documentation of the chainspec for a deployment of the Entropy network see: [./node/cli/Chainspec-README.md](./node/cli/Chainspec-README.md).
178+
175179
## Support
176180
177181
Need help with something not necessarily related to `entropy-core`?

crates/shared/src/types.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::constants::VERIFICATION_KEY_LENGTH;
1717
use codec::alloc::vec::Vec;
1818
use codec::{Decode, Encode};
1919
use scale_info::TypeInfo;
20-
#[cfg(any(feature = "std", feature = "wasm"))]
20+
#[cfg(any(feature = "std", feature = "wasm", feature = "user-native"))]
2121
use serde::{Deserialize, Serialize};
2222
#[cfg(feature = "std")]
2323
use strum_macros::EnumIter;
@@ -103,3 +103,18 @@ pub type EncodedVerifyingKey = [u8; VERIFICATION_KEY_LENGTH as usize];
103103
#[cfg(not(feature = "wasm"))]
104104
pub type BoundedVecEncodedVerifyingKey =
105105
sp_runtime::BoundedVec<u8, sp_runtime::traits::ConstU32<VERIFICATION_KEY_LENGTH>>;
106+
107+
/// Public signing and encryption keys associated with a TS server
108+
/// This is the output from the TSS `/info` HTTP route
109+
#[cfg(feature = "wasm-no-std")]
110+
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Eq, PartialEq)]
111+
pub struct TssPublicKeys {
112+
/// Indicates that all prerequisite checks have passed
113+
pub ready: bool,
114+
/// The TSS account ID
115+
pub tss_account: sp_runtime::AccountId32,
116+
/// The public encryption key
117+
pub x25519_public_key: X25519PublicKey,
118+
/// The Provisioning Certification Key used in TDX quotes
119+
pub provisioning_certification_key: BoundedVecEncodedVerifyingKey,
120+
}

crates/threshold-signature-server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ sp-core ={ version="34.0.0", default-features=false }
4343
sp-keyring ="39.0.0"
4444

4545
# Entropy
46-
entropy-shared={ version="0.4.0-rc.1", path="../shared" }
46+
entropy-shared={ version="0.4.0-rc.1", path="../shared", features=["wasm-no-std"] }
4747
entropy-kvdb={ version="0.4.0-rc.1", path="../kvdb", default-features=false }
4848
entropy-protocol={ version="0.4.0-rc.1", path="../protocol", features=["server"] }
4949
entropy-client={ version="0.4.0-rc.1", path="../client", default-features=false, features=[

crates/threshold-signature-server/src/node_info/api.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1515
use crate::{attestation::api::get_pck, node_info::errors::GetInfoError, AppState};
1616
use axum::{extract::State, Json};
17-
use entropy_shared::{types::HashingAlgorithm, BoundedVecEncodedVerifyingKey, X25519PublicKey};
17+
use entropy_shared::types::{HashingAlgorithm, TssPublicKeys};
1818
use serde::{Deserialize, Serialize};
1919
use strum::IntoEnumIterator;
20-
use subxt::utils::AccountId32;
2120

2221
/// Version information - the output of the `/version` HTTP endpoint
2322
#[derive(Serialize, Deserialize, PartialEq, Debug)]
@@ -75,26 +74,13 @@ pub async fn hashes() -> Json<Vec<HashingAlgorithm>> {
7574
Json(hashing_algos)
7675
}
7776

78-
/// Public signing and encryption keys associated with a TS server
79-
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
80-
pub struct TssPublicKeys {
81-
/// Indicates that all prerequisite checks have passed
82-
pub ready: bool,
83-
/// The TSS account ID
84-
pub tss_account: AccountId32,
85-
/// The public encryption key
86-
pub x25519_public_key: X25519PublicKey,
87-
/// The Provisioning Certification Key used in TDX quotes
88-
pub provisioning_certification_key: BoundedVecEncodedVerifyingKey,
89-
}
90-
9177
/// Returns the TS server's public keys and HTTP endpoint
9278
#[tracing::instrument(skip_all)]
9379
pub async fn info(State(app_state): State<AppState>) -> Result<Json<TssPublicKeys>, GetInfoError> {
9480
Ok(Json(TssPublicKeys {
9581
ready: app_state.cache.is_ready(),
9682
x25519_public_key: app_state.x25519_public_key(),
97-
tss_account: app_state.subxt_account_id(),
83+
tss_account: app_state.account_id(),
9884
provisioning_certification_key: get_pck(app_state.subxt_account_id())?,
9985
}))
10086
}

crates/threshold-signature-server/src/node_info/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
use crate::{
1717
attestation::api::get_pck,
1818
helpers::tests::{initialize_test_logger, setup_client},
19-
node_info::api::{BuildDetails, TssPublicKeys, VersionDetails},
19+
node_info::api::{BuildDetails, VersionDetails},
2020
};
2121
use entropy_kvdb::clean_tests;
22-
use entropy_shared::types::HashingAlgorithm;
22+
use entropy_shared::types::{HashingAlgorithm, TssPublicKeys};
2323
use entropy_testing_utils::constants::{TSS_ACCOUNTS, X25519_PUBLIC_KEYS};
2424
use serial_test::serial;
2525

@@ -80,7 +80,7 @@ async fn info_test() {
8080
assert_eq!(
8181
public_keys,
8282
TssPublicKeys {
83-
tss_account: TSS_ACCOUNTS[0].clone(),
83+
tss_account: TSS_ACCOUNTS[0].0.into(),
8484
x25519_public_key: X25519_PUBLIC_KEYS[0],
8585
ready: true,
8686
provisioning_certification_key: get_pck(TSS_ACCOUNTS[0].clone()).unwrap(),

node/cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pallet-im-online={ version="37.0.0" }
3131
rand ="0.8.5"
3232
serde ={ version="1.0.219", features=["derive"] }
3333
serde_json ='1.0.140'
34+
hex ={ version="0.4.3", optional=true }
3435

3536
# Substrate Client
3637

@@ -98,7 +99,6 @@ entropy-shared={ version="0.4.0-rc.1", path="../../crates/shared", default-featu
9899
] }
99100
pallet-registry={ version="0.4.0-rc.1", path="../../pallets/registry" }
100101
pallet-staking-extension={ version="0.4.0-rc.1", path="../../pallets/staking" }
101-
project-root="0.2.2"
102102

103103
[build-dependencies]
104104
clap={ version="4.5.37", optional=true }
@@ -113,7 +113,7 @@ sp-tracing={ version="17.0.1" }
113113

114114
[features]
115115
default=["cli"]
116-
cli=["clap", "frame-benchmarking-cli", "sc-cli", "sc-service/rocksdb"]
116+
cli=["clap", "frame-benchmarking-cli", "sc-cli", "sc-service/rocksdb", "hex"]
117117
runtime-benchmarks=[
118118
"entropy-runtime/runtime-benchmarks",
119119
"frame-benchmarking-cli/runtime-benchmarks",

node/cli/Chainspec-README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Entropy Chain Specification (chainspec)
2+
3+
When deploying a network, we need to define a chain specification (chainspec) containing the
4+
genesis configuration and various other parameters.
5+
6+
The chainspec can be passed when starting the chain node using the `--chain` command line argument
7+
with either the name of a pre-set chainspec, or the path to a JSON file. The possible pre-set values
8+
are [documented here](https://github.com/entropyxyz/entropy-core/blob/master/node/cli/src/command.rs#L71).
9+
10+
It is possible to give the complete chainspec configuration as a JSON object, but this may not be
11+
desirable for two reasons:
12+
13+
- It is a large data structure which contains many settings for which we can define sane defaults.
14+
- This data structure changes when the substrate crates are updated, making it hard to maintain
15+
outside of this repository - as type checking and testing becomes difficult.
16+
17+
So for deploying test networks we have a smaller set of options which are the things we want to
18+
customize for a particular deployment.
19+
20+
If you give a JSON filename ending in `-chainspec-inputs.json`, for example `entropy --chain
21+
my-testnet-chainspec-inputs.json` it will be parsed as the `TestnetChainspecInputs` struct defined here:
22+
23+
https://github.com/entropyxyz/entropy-core/blob/19f34eaaadb48ad504e264c9ec91581237583be8/node/cli/src/chain_spec/testnet.rs#L57-L79
24+
25+
For a complete example of what the JSON should look like, see the test object used in CI to check this works:
26+
27+
https://github.com/entropyxyz/entropy-core/blob/master/node/cli/test-chainspec-inputs/example-chainspec-inputs.json
28+
29+
This object includes the following fields:
30+
31+
## Threshold signature server details - `tss_details`
32+
33+
This should be given as an object mapping HTTP endpoint (hostname / IP address and port, which no
34+
scheme - meaning without the 'http://' part), given as a string, to a `TssPublicKeys` object. This
35+
object is the output of the `/info` TSS HTTP route, and has the following fields:
36+
37+
- `ready` Boolean. Describes whether the node is ready to begin protocol sessions. This not relevant
38+
in this context and is not included in the chainspec.
39+
- `tss_account` String. ss58 encoded TSS account ID.
40+
- `x25519_public_key` number array (bytes) with 32 elements.
41+
- `provisioning_certification_key` number array (bytes) with 32 elements.
42+
43+
Example:
44+
```JSON
45+
"tss_details": {
46+
"127.0.0.1:3001": {"ready":false,"tss_account":"5Dy7r8pTEoJJDGRrebQvFyWWfKCpTJiXxz7NxbKeh8zXE7Vk","x25519_public_key":[40,170,149,217,225,231,193,134,157,146,161,94,118,146,134,201,179,206,106,186,35,6,93,138,104,203,205,68,208,90,255,7],"provisioning_certification_key":[2,35,153,56,144,219,98,192,9,186,39,114,167,154,75,24,93,39,159,234,180,105,135,89,110,203,179,93,192,164,177,214,78]},
47+
"127.0.0.1:3002": {"ready":false,"tss_account":"5Dy7r8pTEoJJDGRrebQvFyWWfKCpTJiXxz7NxbKeh8zXE7Vk","x25519_public_key":[40,170,149,217,225,231,193,134,157,146,161,94,118,146,134,201,179,206,106,186,35,6,93,138,104,203,205,68,208,90,255,7],"provisioning_certification_key":[2,35,153,56,144,219,98,192,9,186,39,114,167,154,75,24,93,39,159,234,180,105,135,89,110,203,179,93,192,164,177,214,78]},
48+
"127.0.0.1:3003": {"ready":false,"tss_account":"5Dy7r8pTEoJJDGRrebQvFyWWfKCpTJiXxz7NxbKeh8zXE7Vk","x25519_public_key":[40,170,149,217,225,231,193,134,157,146,161,94,118,146,134,201,179,206,106,186,35,6,93,138,104,203,205,68,208,90,255,7],"provisioning_certification_key":[2,35,153,56,144,219,98,192,9,186,39,114,167,154,75,24,93,39,159,234,180,105,135,89,110,203,179,93,192,164,177,214,78]},
49+
"127.0.0.1:3004": {"ready":false,"tss_account":"5Dy7r8pTEoJJDGRrebQvFyWWfKCpTJiXxz7NxbKeh8zXE7Vk","x25519_public_key":[40,170,149,217,225,231,193,134,157,146,161,94,118,146,134,201,179,206,106,186,35,6,93,138,104,203,205,68,208,90,255,7],"provisioning_certification_key":[2,35,153,56,144,219,98,192,9,186,39,114,167,154,75,24,93,39,159,234,180,105,135,89,110,203,179,93,192,164,177,214,78]}
50+
},
51+
```
52+
53+
## Accepted TDX measurement values - `accepted_measurement_values` (optional)
54+
This is an array of strings. These should be hex-encoded strings (32 bytes / 64 characters).
55+
56+
The measurement value for a currently running version of the entropy-tss CVM can be
57+
obtained from the `/version` HTTP route.
58+
59+
If this field is omitted, it will be assumed this is a non-production network and mock values will be
60+
accepted.
61+
62+
```JSON
63+
"accepted_measurement_values": [
64+
"a3f9c04e19d3b6a71e6f7e4d9b2573ff9c2e476d381f8a5cb02eac4d6b0f7b9c"
65+
],
66+
```
67+
68+
## Bootnode peer IDs - `boot_nodes`
69+
70+
This is an array of strings. These are the libp2p 'multi-addresses' of the initial chain nodes. For details
71+
see [the multiaddr specification](https://github.com/libp2p/specs/blob/master/addressing/README.md#multiaddr-in-libp2p).
72+
73+
```JSON
74+
"boot_nodes": [
75+
"/dns4/example-bootnode-0.entropy.xyz/tcp/30333/p2p/12D3KooWE5XyZm8RhsCq7LkZQ8mCDZWQcMJ1FZWYoUk6ZUgKojpL",
76+
"/dns4/example-bootnode-1.entropy.xyz/tcp/30333/p2p/12D3KooWLp1KkZC6NsX2Vt3sM8j3eVr1RJCeSAvKxHvE5E6WExwR",
77+
"/dns4/example-bootnode-2.entropy.xyz/tcp/30333/p2p/12D3KooWJz3vL5JzA5RL7tZczhU3NcQ2x9smvMHyrPBZBhdR35A9",
78+
"/dns4/example-bootnode-3.entropy.xyz/tcp/30333/p2p/12D3KooWQm3X3FH5dD1FZRxkN8WzEzoA6uVpWi3mDsHDFeDdR7xz"
79+
],
80+
```
81+
82+
## Endowed accounts - `endowed_accounts`
83+
84+
This is an array of strings. This is a list of ss58-encoded account IDs which will be have funds at
85+
genesis. This does not need to include the initial TSS accounts, validator stash accounts or
86+
nominator accounts - these will all be funded even if they are not present in this list.
87+
88+
Note that accounts added to this list may be included in the governance and technical committees.
89+
90+
```JSON
91+
"endowed_accounts": [
92+
"5CtViLgvdHoLDvdsSsfEPxczsF6D7FtQ59h6B4Gey5EXE47t",
93+
"5EbyKpRWK9z7Efso1QYFcfAiHHkxzxMRSFAkJtmeUmuz1CGj",
94+
"5E2fDSRWSVjYLP8VsvTvzHBUdC2h6xtrApqkBdAb9xqPqcNK"
95+
]
96+
```

node/cli/src/chain_spec/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
3434
pub mod dev;
3535
pub mod integration_tests;
36-
pub mod tdx_testnet;
3736
pub mod testnet;
3837

3938
pub use entropy_runtime::{AccountId, Signature};

node/cli/src/chain_spec/tdx_testnet.rs

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)