Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1,756 changes: 454 additions & 1,302 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/webb-tools/tangle"
[workspace]
members = [
"primitives",
"primitives/crypto",
"primitives/rpc/*",
"primitives/ext",
"client/evm-tracing",
Expand Down Expand Up @@ -277,8 +278,9 @@ pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot
sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-consensus-manual-seal = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }

# Webb dependencies
# Tangle dependencies
tangle-primitives = { path = 'primitives', default-features = false }
tangle-crypto-primitives = { path = "primitives/crypto", default-features = false }
pallet-transaction-pause = { path = 'pallets/transaction-pause', default-features = false }

# Light client dependencies
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ frame-system-rpc-runtime-api = { workspace = true }
tangle-testnet-runtime = { workspace = true, optional = true }
tangle-runtime = { workspace = true }
tangle-primitives = { workspace = true }
tangle-crypto-primitives = { workspace = true }

[features]
default = ["with-rocksdb-weights", "rocksdb", "sql"]
Expand Down
13 changes: 6 additions & 7 deletions node/src/chainspec/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ where
pub fn authority_keys_from_seed(
controller: &str,
stash: &str,
) -> (AccountId, AccountId, BabeId, GrandpaId, ImOnlineId) {
) -> (AccountId, BabeId, GrandpaId, ImOnlineId) {
(
get_account_id_from_seed::<sr25519::Public>(controller),
get_account_id_from_seed::<sr25519::Public>(stash),
get_from_seed::<BabeId>(controller),
get_from_seed::<GrandpaId>(controller),
Expand All @@ -81,11 +80,11 @@ pub fn authority_keys_from_seed(
/// The input must be a tuple of individual keys (a single arg for now since we
/// have just one key).
fn generate_session_keys(
grandpa: GrandpaId,
babe: BabeId,
grandpa: GrandpaId,
im_online: ImOnlineId,
) -> tangle_runtime::opaque::SessionKeys {
tangle_runtime::opaque::SessionKeys { grandpa, babe, im_online }
tangle_runtime::opaque::SessionKeys { babe, grandpa, im_online }
}

pub fn local_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
Expand Down Expand Up @@ -202,7 +201,7 @@ pub fn tangle_mainnet_config(chain_id: u64) -> Result<ChainSpec, String> {
#[allow(clippy::too_many_arguments)]
fn mainnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId)>,
initial_authorities: Vec<(AccountId, BabeId, GrandpaId, ImOnlineId)>,
endowed_accounts: Vec<AccountId>,
root_key: AccountId,
chain_id: u64,
Expand Down Expand Up @@ -256,9 +255,9 @@ fn mainnet_genesis(
.iter()
.map(|x| {
(
x.1.clone(),
x.0.clone(),
generate_session_keys(x.3.clone(), x.2.clone(), x.4.clone()),
x.0.clone(),
generate_session_keys(x.1.clone(), x.2.clone(), x.3.clone()),
)
})
.collect::<Vec<_>>(),
Expand Down
42 changes: 19 additions & 23 deletions node/src/chainspec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use sp_runtime::{
BoundedVec,
};
use std::collections::BTreeMap;
use tangle_crypto_primitives::crypto::AuthorityId as RoleKeyId;
use tangle_primitives::BlockNumber;
use tangle_testnet_runtime::{
AccountId, BabeConfig, Balance, BalancesConfig, ClaimsConfig, EVMChainIdConfig, EVMConfig,
Expand Down Expand Up @@ -63,28 +64,28 @@ where

/// Generate an babe authority key.
pub fn authority_keys_from_seed(
controller: &str,
stash: &str,
) -> (AccountId, AccountId, BabeId, GrandpaId, ImOnlineId) {
) -> (AccountId, BabeId, GrandpaId, ImOnlineId, RoleKeyId) {
(
get_account_id_from_seed::<sr25519::Public>(controller),
get_account_id_from_seed::<sr25519::Public>(stash),
get_from_seed::<BabeId>(controller),
get_from_seed::<GrandpaId>(controller),
get_from_seed::<BabeId>(stash),
get_from_seed::<GrandpaId>(stash),
get_from_seed::<ImOnlineId>(stash),
get_from_seed::<RoleKeyId>(stash),
)
}

/// Generate the session keys from individual elements.
///
/// The input must be a tuple of individual keys (a single arg for now since we
/// have just one key).
fn generate_sesion_keys(
grandpa: GrandpaId,
fn generate_session_keys(
babe: BabeId,
grandpa: GrandpaId,
im_online: ImOnlineId,
role: RoleKeyId,
) -> tangle_testnet_runtime::opaque::SessionKeys {
tangle_testnet_runtime::opaque::SessionKeys { grandpa, babe, im_online }
tangle_testnet_runtime::opaque::SessionKeys { babe, grandpa, im_online, role }
}

pub fn local_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
Expand All @@ -105,22 +106,17 @@ pub fn local_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
wasm_binary,
// Initial PoA authorities
vec![
authority_keys_from_seed("Alice", "Alice//stash"),
authority_keys_from_seed("Bob", "Bob//stash"),
authority_keys_from_seed("Charlie", "Charlie//stash"),
authority_keys_from_seed("Dave", "Dave//stash"),
authority_keys_from_seed("Eve", "Eve//stash"),
authority_keys_from_seed("Alice//stash"),
authority_keys_from_seed("Bob//stash"),
authority_keys_from_seed("Charlie//stash"),
authority_keys_from_seed("Dave//stash"),
authority_keys_from_seed("Eve//stash"),
],
vec![],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
Expand Down Expand Up @@ -228,7 +224,7 @@ pub fn tangle_testnet_config(chain_id: u64) -> Result<ChainSpec, String> {
#[allow(clippy::too_many_arguments)]
fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId)>,
initial_authorities: Vec<(AccountId, BabeId, GrandpaId, ImOnlineId, RoleKeyId)>,
initial_nominators: Vec<AccountId>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
Expand All @@ -244,7 +240,7 @@ fn testnet_genesis(
let mut rng = rand::thread_rng();
let stakers = initial_authorities
.iter()
.map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
.map(|x| (x.0.clone(), x.0.clone(), STASH, StakerStatus::Validator))
.chain(initial_nominators.iter().map(|x| {
use rand::{seq::SliceRandom, Rng};
let limit = (MaxNominations::get() as usize).min(initial_authorities.len());
Expand Down Expand Up @@ -298,9 +294,9 @@ fn testnet_genesis(
.iter()
.map(|x| {
(
x.1.clone(),
x.0.clone(),
generate_sesion_keys(x.3.clone(), x.2.clone(), x.4.clone()),
x.0.clone(),
generate_session_keys(x.1.clone(), x.2.clone(), x.3.clone(), x.4.clone()),
)
})
.collect::<Vec<_>>(),
Expand Down
7 changes: 1 addition & 6 deletions node/src/mainnet_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ pub fn get_bootnodes() -> Vec<MultiaddrWithPeerId> {
}

/// Standalone initial authorities
pub fn get_initial_authorities() -> Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId)> {
pub fn get_initial_authorities() -> Vec<(AccountId, BabeId, GrandpaId, ImOnlineId)> {
vec![
// standalone 1
(
hex!["d4c197403bae729fd0f219a0925c4f9274d432c7bfce5f94f2e0dae605dde407"].into(),
hex!["6c99e8e4ae3fe7e3328d7e9d85eb98e86bdc6410695797349fa536ebb9bb0a4a"].into(),
hex!["d8a00a2454cd7455c040e363e6e76f4abd9e4d3876253964d9f40a66ad79694b"]
.unchecked_into(),
Expand All @@ -65,7 +64,6 @@ pub fn get_initial_authorities() -> Vec<(AccountId, AccountId, BabeId, GrandpaId
),
// standalone 2
(
hex!["48a705897c103ddeda7e38bdadb42dc4c429e1b542287dfb07a9837982e04d14"].into(),
hex!["444dbfd0220eb1a993a7a2b9e1530aee1d17388ba3db34a0ee2b8ff971bfd073"].into(),
hex!["f02ee9baa32c490cf06eabe3580a90be704618f04636b321ee599c8912392c7a"]
.unchecked_into(),
Expand All @@ -76,7 +74,6 @@ pub fn get_initial_authorities() -> Vec<(AccountId, AccountId, BabeId, GrandpaId
),
// standalone 3
(
hex!["e2629eedccc6887f78d62d4ed15becd1b791ba0c38a5c72ccd416367097d7c3c"].into(),
hex!["2c4e648b0fbbb88ff6b92b208273eb144383b2b19edc992e91448a4371d4d97d"].into(),
hex!["a41b35f75e5509ce96e62bc27bb9a1b5587cc3d596f8afa867962b0e03230513"]
.unchecked_into(),
Expand All @@ -87,7 +84,6 @@ pub fn get_initial_authorities() -> Vec<(AccountId, AccountId, BabeId, GrandpaId
),
// standalone 4
(
hex!["3281b9311756ee35e8bd53bc05e38af78ea4211c72db0ffcd8dd317785fa1327"].into(),
hex!["c884c8eb280327221a3ae6a45fe6c8805f09bcfc11b409c8e2daa621c0d99608"].into(),
hex!["06e0a0d39503a101ca9c36f84b3ccf53015ee625a546bc570e550af963d13164"]
.unchecked_into(),
Expand All @@ -98,7 +94,6 @@ pub fn get_initial_authorities() -> Vec<(AccountId, AccountId, BabeId, GrandpaId
),
// standalone 5
(
hex!["34d06ae4117b82a936b81d5219a438fa7b4093a6b67ebb0899686fb4e3b79b55"].into(),
hex!["483e0b8d6801c51115fd4b124c91e2d5dcd642b30335f6c5a1738ea18f66c251"].into(),
hex!["ce80df4851003f6ffd4ee88d9be85966f1de8b2e494c009dbf336177485f023f"]
.unchecked_into(),
Expand Down
23 changes: 17 additions & 6 deletions node/src/testnet_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use sc_consensus_grandpa::AuthorityId as GrandpaId;
use sc_network::config::MultiaddrWithPeerId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::crypto::UncheckedInto;
use tangle_crypto_primitives::crypto::AuthorityId as RoleKeyId;
use tangle_testnet_runtime::AccountId;

/// Testnet root key
Expand Down Expand Up @@ -50,62 +51,72 @@ pub fn get_bootnodes() -> Vec<MultiaddrWithPeerId> {
}

/// Standalone initial authorities
pub fn get_initial_authorities() -> Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId)> {
pub fn get_initial_authorities() -> Vec<(AccountId, BabeId, GrandpaId, ImOnlineId, RoleKeyId)> {
vec![
// standalone 1
(
hex!["d4c197403bae729fd0f219a0925c4f9274d432c7bfce5f94f2e0dae605dde407"].into(),
// hex!["d4c197403bae729fd0f219a0925c4f9274d432c7bfce5f94f2e0dae605dde407"].into(),
hex!["6c99e8e4ae3fe7e3328d7e9d85eb98e86bdc6410695797349fa536ebb9bb0a4a"].into(),
hex!["d8a00a2454cd7455c040e363e6e76f4abd9e4d3876253964d9f40a66ad79694b"]
.unchecked_into(),
hex!["5bcf983a969f8de7628b271a5bf523924856c3935b15eb3e03f20146ced2c57f"]
.unchecked_into(),
hex!["0297bc051d94b25787482e60fa4eba19f15af30fa244240ae4439d219ee00e78"]
.unchecked_into(),
hex!["000000000000000000000000000000000000000000000000000000000000000000"]
.unchecked_into(),
),
// standalone 2
(
hex!["48a705897c103ddeda7e38bdadb42dc4c429e1b542287dfb07a9837982e04d14"].into(),
// hex!["48a705897c103ddeda7e38bdadb42dc4c429e1b542287dfb07a9837982e04d14"].into(),
hex!["444dbfd0220eb1a993a7a2b9e1530aee1d17388ba3db34a0ee2b8ff971bfd073"].into(),
hex!["f02ee9baa32c490cf06eabe3580a90be704618f04636b321ee599c8912392c7a"]
.unchecked_into(),
hex!["2d6ac10cde791863771847c035c36e13ad60e6129465e1aefad8f5fee8dff5c7"]
.unchecked_into(),
hex!["de6d5010678fd2175fe70c857d3eba80838e3735b1051f4aed98671800ec483f"]
.unchecked_into(),
hex!["000000000000000000000000000000000000000000000000000000000000000000"]
.unchecked_into(),
),
// standalone 3
(
hex!["e2629eedccc6887f78d62d4ed15becd1b791ba0c38a5c72ccd416367097d7c3c"].into(),
// hex!["e2629eedccc6887f78d62d4ed15becd1b791ba0c38a5c72ccd416367097d7c3c"].into(),
hex!["2c4e648b0fbbb88ff6b92b208273eb144383b2b19edc992e91448a4371d4d97d"].into(),
hex!["a41b35f75e5509ce96e62bc27bb9a1b5587cc3d596f8afa867962b0e03230513"]
.unchecked_into(),
hex!["340e5969c8dd40ff77184fa73fbdcda77dcc90dd9b68b8b28eef5f01ce42339c"]
.unchecked_into(),
hex!["8472336050c4e4a51ac69865a4a31c6dd0e5c2f79555d8646cafb3bd8f12d75c"]
.unchecked_into(),
hex!["000000000000000000000000000000000000000000000000000000000000000000"]
.unchecked_into(),
),
// standalone 4
(
hex!["3281b9311756ee35e8bd53bc05e38af78ea4211c72db0ffcd8dd317785fa1327"].into(),
// hex!["3281b9311756ee35e8bd53bc05e38af78ea4211c72db0ffcd8dd317785fa1327"].into(),
hex!["c884c8eb280327221a3ae6a45fe6c8805f09bcfc11b409c8e2daa621c0d99608"].into(),
hex!["06e0a0d39503a101ca9c36f84b3ccf53015ee625a546bc570e550af963d13164"]
.unchecked_into(),
hex!["57eda010788108257f4c148cf0c3112d620b9067546777dc393a65dd34732079"]
.unchecked_into(),
hex!["029cb182ddb9c5560aaa299f7b445e575007b8295bd85a80a7b2eb7baa3e2b7c"]
.unchecked_into(),
hex!["000000000000000000000000000000000000000000000000000000000000000000"]
.unchecked_into(),
),
// standalone 5
(
hex!["34d06ae4117b82a936b81d5219a438fa7b4093a6b67ebb0899686fb4e3b79b55"].into(),
// hex!["34d06ae4117b82a936b81d5219a438fa7b4093a6b67ebb0899686fb4e3b79b55"].into(),
hex!["483e0b8d6801c51115fd4b124c91e2d5dcd642b30335f6c5a1738ea18f66c251"].into(),
hex!["ce80df4851003f6ffd4ee88d9be85966f1de8b2e494c009dbf336177485f023f"]
.unchecked_into(),
hex!["9027284e6cad3f73eee950695c56f87330311331139616640c9168934dba82df"]
.unchecked_into(),
hex!["1ea007d87f91f96c31b1062548eb77c40d47a43f1c84c36caa8586fc7c359729"]
.unchecked_into(),
hex!["000000000000000000000000000000000000000000000000000000000000000000"]
.unchecked_into(),
),
]
}
4 changes: 2 additions & 2 deletions pallets/dkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
tangle-primitives = { workspace = true, default-features = false }
tangle-crypto-primitives = { workspace = true, default-features = false }

[dev-dependencies]
pallet-balances = { workspace = true }
smallvec = { workspace = true }
sp-application-crypto = { workspace = true }
sp-keystore = { workspace = true }

[features]
Expand All @@ -35,9 +35,9 @@ std = [
"sp-core/std",
"sp-std/std",
"tangle-primitives/std",
"tangle-crypto-primitives/std",
"pallet-balances/std",
"sp-io/std",
"sp-application-crypto/std",
"sp-keystore/std"
]
try-runtime = ["frame-support/try-runtime"]
21 changes: 10 additions & 11 deletions pallets/dkg/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,27 @@ use sp_core::{crypto::ByteArray, ecdsa, keccak_256, sr25519};
use sp_io::crypto::{ecdsa_generate, ecdsa_sign_prehashed, sr25519_generate, sr25519_sign};
use tangle_primitives::jobs::{DKGResult, DKGSignatureResult, DkgKeyType, JobResult};

/// Key type for DKG keys
pub const KEY_TYPE: sp_application_crypto::KeyTypeId = sp_application_crypto::KeyTypeId(*b"wdkg");

fn mock_pub_key_ecdsa() -> ecdsa::Public {
ecdsa_generate(KEY_TYPE, None)
ecdsa_generate(tangle_crypto_primitives::ROLE_KEY_TYPE, None)
}

fn mock_pub_key_sr25519() -> sr25519::Public {
sr25519_generate(KEY_TYPE, None)
sr25519_generate(tangle_crypto_primitives::ROLE_KEY_TYPE, None)
}

fn mock_signature_ecdsa(pub_key: ecdsa::Public, dkg_key: ecdsa::Public) -> Vec<u8> {
let msg = dkg_key.encode();
fn mock_signature_ecdsa(pub_key: ecdsa::Public, role_key: ecdsa::Public) -> Vec<u8> {
let msg = role_key.encode();
let hash = keccak_256(&msg);
let signature: ecdsa::Signature = ecdsa_sign_prehashed(KEY_TYPE, &pub_key, &hash).unwrap();
let signature: ecdsa::Signature =
ecdsa_sign_prehashed(tangle_crypto_primitives::ROLE_KEY_TYPE, &pub_key, &hash).unwrap();
signature.encode()
}

fn mock_signature_sr25519(pub_key: sr25519::Public, dkg_key: sr25519::Public) -> Vec<u8> {
let msg = dkg_key.to_vec().encode();
fn mock_signature_sr25519(pub_key: sr25519::Public, role_key: sr25519::Public) -> Vec<u8> {
let msg = role_key.to_vec().encode();
let hash = keccak_256(&msg);
let signature: sr25519::Signature = sr25519_sign(KEY_TYPE, &pub_key, &hash).unwrap();
let signature: sr25519::Signature =
sr25519_sign(tangle_crypto_primitives::ROLE_KEY_TYPE, &pub_key, &hash).unwrap();
// sanity check
assert!(sp_io::crypto::sr25519_verify(&signature, &hash, &pub_key));
signature.encode()
Expand Down
3 changes: 2 additions & 1 deletion pallets/jobs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
tangle-primitives = { workspace = true, default-features = false }
tangle-crypto-primitives = { workspace = true, default-features = false }

[dev-dependencies]
ethereum = { workspace = true, features = ["with-codec"] }
Expand All @@ -29,7 +30,6 @@ pallet-timestamp = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
smallvec = { workspace = true }
sp-application-crypto = { workspace = true }
sp-io = { workspace = true }
sp-keystore = { workspace = true }

Expand Down Expand Up @@ -61,6 +61,7 @@ std = [
"sp-core/std",
"sp-std/std",
"tangle-primitives/std",
"tangle-crypto-primitives/std",
"pallet-balances/std",
"pallet-timestamp/std",
"fp-account/std",
Expand Down
Loading