mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
* Fix keystore types * Use SyncCryptoStorePtr * Borrow keystore * Fix unused imports * Fix polkadot service * Fix bitfield-distribution tests * Fix indentation * Fix backing tests * Fix tests * Fix provisioner tests * Removed SyncCryptoStorePtr * Fix services * Address PR feedback * Address PR feedback - 2 * Update CryptoStorePtr imports to be from sp_keystore * Typo * Fix CryptoStore import * Document the reason behind using filesystem keystore * Remove VALIDATORS * Fix duplicate dependency * Mark sp-keystore as optional * Fix availability distribution * Fix call to sign_with * Fix keystore usage * Remove tokio and fix parachains Cargo config * Typos * Fix keystore dereferencing * Fix CryptoStore import * Fix provisioner * Fix node backing * Update services * Cleanup dependencies * Use sync_keystore * Fix node service * Fix node service - 2 * Fix node service - 3 * Rename CryptoStorePtr to SyncCryptoStorePtr * "Update Substrate" * Apply suggestions from code review * Update node/core/backing/Cargo.toml * Update primitives/src/v0.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Fix wasm build * Update Cargo.lock Co-authored-by: parity-processbot <> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
|
||||
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
|
||||
|
||||
pallet-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
@@ -40,6 +41,7 @@ rand = { version = "0.7", default-features = false }
|
||||
rand_chacha = { version = "0.2.2", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
futures = "0.3.4"
|
||||
hex-literal = "0.2.1"
|
||||
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
@@ -51,6 +53,7 @@ pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "m
|
||||
serde_json = "1.0.41"
|
||||
libsecp256k1 = "0.3.2"
|
||||
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master"}
|
||||
|
||||
|
||||
[features]
|
||||
@@ -67,6 +70,7 @@ std = [
|
||||
"inherents/std",
|
||||
"sp-core/std",
|
||||
"sp-api/std",
|
||||
"sp-keystore",
|
||||
"sp-std/std",
|
||||
"sp-io/std",
|
||||
"frame-support/std",
|
||||
|
||||
@@ -658,14 +658,18 @@ const fn availability_threshold(n_validators: usize) -> usize {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use std::sync::Arc;
|
||||
use futures::executor::block_on;
|
||||
use primitives::v0::PARACHAIN_KEY_TYPE_ID;
|
||||
use primitives::v1::{BlockNumber, Hash};
|
||||
use primitives::v1::{
|
||||
SignedAvailabilityBitfield, CompactStatement as Statement, ValidityAttestation, CollatorId,
|
||||
CandidateCommitments, SignedStatement, CandidateDescriptor, ValidationCode,
|
||||
};
|
||||
use sp_keystore::{SyncCryptoStorePtr, SyncCryptoStore};
|
||||
use frame_support::traits::{OnFinalize, OnInitialize};
|
||||
use keyring::Sr25519Keyring;
|
||||
|
||||
use sc_keystore::LocalKeystore;
|
||||
use crate::mock::{
|
||||
new_test_ext, Configuration, Paras, System, Inclusion,
|
||||
GenesisConfig as MockGenesisConfig, Test,
|
||||
@@ -724,10 +728,11 @@ mod tests {
|
||||
assert!(candidate.descriptor().check_collator_signature().is_ok());
|
||||
}
|
||||
|
||||
fn back_candidate(
|
||||
async fn back_candidate(
|
||||
candidate: CommittedCandidateReceipt,
|
||||
validators: &[Sr25519Keyring],
|
||||
group: &[ValidatorIndex],
|
||||
keystore: &SyncCryptoStorePtr,
|
||||
signing_context: &SigningContext,
|
||||
kind: BackingKind,
|
||||
) -> BackedCandidate {
|
||||
@@ -748,11 +753,12 @@ mod tests {
|
||||
*validator_indices.get_mut(idx_in_group).unwrap() = true;
|
||||
|
||||
let signature = SignedStatement::sign(
|
||||
&keystore,
|
||||
Statement::Valid(candidate_hash),
|
||||
signing_context,
|
||||
*val_idx,
|
||||
&key.pair().into(),
|
||||
).signature().clone();
|
||||
&key.public().into(),
|
||||
).await.unwrap().signature().clone();
|
||||
|
||||
validity_votes.push(ValidityAttestation::Explicit(signature).into());
|
||||
}
|
||||
@@ -823,7 +829,8 @@ mod tests {
|
||||
val_ids.iter().map(|v| v.public().into()).collect()
|
||||
}
|
||||
|
||||
fn sign_bitfield(
|
||||
async fn sign_bitfield(
|
||||
keystore: &SyncCryptoStorePtr,
|
||||
key: &Sr25519Keyring,
|
||||
validator_index: ValidatorIndex,
|
||||
bitfield: AvailabilityBitfield,
|
||||
@@ -832,11 +839,12 @@ mod tests {
|
||||
-> SignedAvailabilityBitfield
|
||||
{
|
||||
SignedAvailabilityBitfield::sign(
|
||||
&keystore,
|
||||
bitfield,
|
||||
&signing_context,
|
||||
validator_index,
|
||||
&key.pair().into(),
|
||||
)
|
||||
&key.public().into(),
|
||||
).await.unwrap()
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -931,6 +939,10 @@ mod tests {
|
||||
Sr25519Keyring::Dave,
|
||||
Sr25519Keyring::Ferdie,
|
||||
];
|
||||
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::in_memory());
|
||||
for validator in validators.iter() {
|
||||
SyncCryptoStore::sr25519_generate_new(&*keystore, PARACHAIN_KEY_TYPE_ID, Some(&validator.to_seed())).unwrap();
|
||||
}
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
@@ -953,12 +965,13 @@ mod tests {
|
||||
{
|
||||
let mut bare_bitfield = default_bitfield();
|
||||
bare_bitfield.0.push(false);
|
||||
let signed = sign_bitfield(
|
||||
let signed = block_on(sign_bitfield(
|
||||
&keystore,
|
||||
&validators[0],
|
||||
0,
|
||||
bare_bitfield,
|
||||
&signing_context,
|
||||
);
|
||||
));
|
||||
|
||||
assert!(Inclusion::process_bitfields(
|
||||
vec![signed],
|
||||
@@ -969,12 +982,13 @@ mod tests {
|
||||
// duplicate.
|
||||
{
|
||||
let bare_bitfield = default_bitfield();
|
||||
let signed = sign_bitfield(
|
||||
let signed = block_on(sign_bitfield(
|
||||
&keystore,
|
||||
&validators[0],
|
||||
0,
|
||||
bare_bitfield,
|
||||
&signing_context,
|
||||
);
|
||||
));
|
||||
|
||||
assert!(Inclusion::process_bitfields(
|
||||
vec![signed.clone(), signed],
|
||||
@@ -985,19 +999,21 @@ mod tests {
|
||||
// out of order.
|
||||
{
|
||||
let bare_bitfield = default_bitfield();
|
||||
let signed_0 = sign_bitfield(
|
||||
let signed_0 = block_on(sign_bitfield(
|
||||
&keystore,
|
||||
&validators[0],
|
||||
0,
|
||||
bare_bitfield.clone(),
|
||||
&signing_context,
|
||||
);
|
||||
));
|
||||
|
||||
let signed_1 = sign_bitfield(
|
||||
let signed_1 = block_on(sign_bitfield(
|
||||
&keystore,
|
||||
&validators[1],
|
||||
1,
|
||||
bare_bitfield,
|
||||
&signing_context,
|
||||
);
|
||||
));
|
||||
|
||||
assert!(Inclusion::process_bitfields(
|
||||
vec![signed_1, signed_0],
|
||||
@@ -1009,12 +1025,13 @@ mod tests {
|
||||
{
|
||||
let mut bare_bitfield = default_bitfield();
|
||||
*bare_bitfield.0.get_mut(0).unwrap() = true;
|
||||
let signed = sign_bitfield(
|
||||
let signed = block_on(sign_bitfield(
|
||||
&keystore,
|
||||
&validators[0],
|
||||
0,
|
||||
bare_bitfield,
|
||||
&signing_context,
|
||||
);
|
||||
));
|
||||
|
||||
assert!(Inclusion::process_bitfields(
|
||||
vec![signed],
|
||||
@@ -1025,12 +1042,13 @@ mod tests {
|
||||
// empty bitfield signed: always OK, but kind of useless.
|
||||
{
|
||||
let bare_bitfield = default_bitfield();
|
||||
let signed = sign_bitfield(
|
||||
let signed = block_on(sign_bitfield(
|
||||
&keystore,
|
||||
&validators[0],
|
||||
0,
|
||||
bare_bitfield,
|
||||
&signing_context,
|
||||
);
|
||||
));
|
||||
|
||||
assert!(Inclusion::process_bitfields(
|
||||
vec![signed],
|
||||
@@ -1055,12 +1073,13 @@ mod tests {
|
||||
PendingAvailabilityCommitments::insert(chain_a, default_candidate.commitments);
|
||||
|
||||
*bare_bitfield.0.get_mut(0).unwrap() = true;
|
||||
let signed = sign_bitfield(
|
||||
let signed = block_on(sign_bitfield(
|
||||
&keystore,
|
||||
&validators[0],
|
||||
0,
|
||||
bare_bitfield,
|
||||
&signing_context,
|
||||
);
|
||||
));
|
||||
|
||||
assert!(Inclusion::process_bitfields(
|
||||
vec![signed],
|
||||
@@ -1087,12 +1106,13 @@ mod tests {
|
||||
});
|
||||
|
||||
*bare_bitfield.0.get_mut(0).unwrap() = true;
|
||||
let signed = sign_bitfield(
|
||||
let signed = block_on(sign_bitfield(
|
||||
&keystore,
|
||||
&validators[0],
|
||||
0,
|
||||
bare_bitfield,
|
||||
&signing_context,
|
||||
);
|
||||
));
|
||||
|
||||
// no core is freed
|
||||
assert_eq!(
|
||||
@@ -1120,6 +1140,10 @@ mod tests {
|
||||
Sr25519Keyring::Dave,
|
||||
Sr25519Keyring::Ferdie,
|
||||
];
|
||||
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::in_memory());
|
||||
for validator in validators.iter() {
|
||||
SyncCryptoStore::sr25519_generate_new(&*keystore, PARACHAIN_KEY_TYPE_ID, Some(&validator.to_seed())).unwrap();
|
||||
}
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
@@ -1200,12 +1224,13 @@ mod tests {
|
||||
return None
|
||||
};
|
||||
|
||||
Some(sign_bitfield(
|
||||
Some(block_on(sign_bitfield(
|
||||
&keystore,
|
||||
key,
|
||||
i as ValidatorIndex,
|
||||
to_sign,
|
||||
&signing_context,
|
||||
))
|
||||
)))
|
||||
}).collect();
|
||||
|
||||
assert!(Inclusion::process_bitfields(
|
||||
@@ -1251,6 +1276,10 @@ mod tests {
|
||||
Sr25519Keyring::Dave,
|
||||
Sr25519Keyring::Ferdie,
|
||||
];
|
||||
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::in_memory());
|
||||
for validator in validators.iter() {
|
||||
SyncCryptoStore::sr25519_generate_new(&*keystore, PARACHAIN_KEY_TYPE_ID, Some(&validator.to_seed())).unwrap();
|
||||
}
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
@@ -1308,13 +1337,14 @@ mod tests {
|
||||
&mut candidate,
|
||||
);
|
||||
|
||||
let backed = back_candidate(
|
||||
let backed = block_on(back_candidate(
|
||||
candidate,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Inclusion::process_candidates(
|
||||
@@ -1353,21 +1383,23 @@ mod tests {
|
||||
&mut candidate_b,
|
||||
);
|
||||
|
||||
let backed_a = back_candidate(
|
||||
let backed_a = block_on(back_candidate(
|
||||
candidate_a,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
let backed_b = back_candidate(
|
||||
let backed_b = block_on(back_candidate(
|
||||
candidate_b,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(1)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
// out-of-order manifests as unscheduled.
|
||||
assert_eq!(
|
||||
@@ -1394,13 +1426,14 @@ mod tests {
|
||||
&mut candidate,
|
||||
);
|
||||
|
||||
let backed = back_candidate(
|
||||
let backed = block_on(back_candidate(
|
||||
candidate,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Lacking,
|
||||
);
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Inclusion::process_candidates(
|
||||
@@ -1429,13 +1462,14 @@ mod tests {
|
||||
&mut candidate,
|
||||
);
|
||||
|
||||
let backed = back_candidate(
|
||||
let backed = block_on(back_candidate(
|
||||
candidate,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Inclusion::process_candidates(
|
||||
@@ -1463,13 +1497,14 @@ mod tests {
|
||||
&mut candidate,
|
||||
);
|
||||
|
||||
let backed = back_candidate(
|
||||
let backed = block_on(back_candidate(
|
||||
candidate,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(2)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Inclusion::process_candidates(
|
||||
@@ -1504,13 +1539,14 @@ mod tests {
|
||||
// change the candidate after signing.
|
||||
candidate.descriptor.pov_hash = Hash::from([2; 32]);
|
||||
|
||||
let backed = back_candidate(
|
||||
let backed = block_on(back_candidate(
|
||||
candidate,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(2)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Inclusion::process_candidates(
|
||||
@@ -1537,13 +1573,14 @@ mod tests {
|
||||
&mut candidate,
|
||||
);
|
||||
|
||||
let backed = back_candidate(
|
||||
let backed = block_on(back_candidate(
|
||||
candidate,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
let candidate = TestCandidateBuilder::default().build();
|
||||
<PendingAvailability<Test>>::insert(&chain_a, CandidatePendingAvailability {
|
||||
@@ -1586,13 +1623,14 @@ mod tests {
|
||||
// this is not supposed to happen
|
||||
<PendingAvailabilityCommitments>::insert(&chain_a, candidate.commitments.clone());
|
||||
|
||||
let backed = back_candidate(
|
||||
let backed = block_on(back_candidate(
|
||||
candidate,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Inclusion::process_candidates(
|
||||
@@ -1622,13 +1660,14 @@ mod tests {
|
||||
&mut candidate,
|
||||
);
|
||||
|
||||
let backed = back_candidate(
|
||||
let backed = block_on(back_candidate(
|
||||
candidate,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
Paras::schedule_code_upgrade(
|
||||
chain_a,
|
||||
@@ -1663,13 +1702,14 @@ mod tests {
|
||||
&mut candidate,
|
||||
);
|
||||
|
||||
let backed = back_candidate(
|
||||
let backed = block_on(back_candidate(
|
||||
candidate,
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Inclusion::process_candidates(
|
||||
@@ -1697,6 +1737,10 @@ mod tests {
|
||||
Sr25519Keyring::Dave,
|
||||
Sr25519Keyring::Ferdie,
|
||||
];
|
||||
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::in_memory());
|
||||
for validator in validators.iter() {
|
||||
SyncCryptoStore::sr25519_generate_new(&*keystore, PARACHAIN_KEY_TYPE_ID, Some(&validator.to_seed())).unwrap();
|
||||
}
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
@@ -1776,29 +1820,32 @@ mod tests {
|
||||
&mut candidate_c,
|
||||
);
|
||||
|
||||
let backed_a = back_candidate(
|
||||
let backed_a = block_on(back_candidate(
|
||||
candidate_a.clone(),
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
let backed_b = back_candidate(
|
||||
let backed_b = block_on(back_candidate(
|
||||
candidate_b.clone(),
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(1)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
let backed_c = back_candidate(
|
||||
let backed_c = block_on(back_candidate(
|
||||
candidate_c.clone(),
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(2)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
let occupied_cores = Inclusion::process_candidates(
|
||||
vec![backed_a, backed_b, backed_c],
|
||||
@@ -1871,6 +1918,10 @@ mod tests {
|
||||
Sr25519Keyring::Dave,
|
||||
Sr25519Keyring::Ferdie,
|
||||
];
|
||||
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::in_memory());
|
||||
for validator in validators.iter() {
|
||||
SyncCryptoStore::sr25519_generate_new(&*keystore, PARACHAIN_KEY_TYPE_ID, Some(&validator.to_seed())).unwrap();
|
||||
}
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
@@ -1909,13 +1960,14 @@ mod tests {
|
||||
&mut candidate_a,
|
||||
);
|
||||
|
||||
let backed_a = back_candidate(
|
||||
let backed_a = block_on(back_candidate(
|
||||
candidate_a.clone(),
|
||||
&validators,
|
||||
group_validators(GroupIndex::from(0)).unwrap().as_ref(),
|
||||
&keystore,
|
||||
&signing_context,
|
||||
BackingKind::Threshold,
|
||||
);
|
||||
));
|
||||
|
||||
let occupied_cores = Inclusion::process_candidates(
|
||||
vec![backed_a],
|
||||
@@ -1958,6 +2010,10 @@ mod tests {
|
||||
Sr25519Keyring::Dave,
|
||||
Sr25519Keyring::Ferdie,
|
||||
];
|
||||
let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::in_memory());
|
||||
for validator in validators.iter() {
|
||||
SyncCryptoStore::sr25519_generate_new(&*keystore, PARACHAIN_KEY_TYPE_ID, Some(&validator.to_seed())).unwrap();
|
||||
}
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
|
||||
Reference in New Issue
Block a user