Validator DHT (#494)

* Route validators for any active set through sc-authority-discovery

Additionally adds an RPC route to retrieve their P2P addresses.

* Have the coordinator get peers from substrate

* Have the RPC return one address, not up to 3

Prevents the coordinator from believing it has 3 peers when it has one.

* Add missing feature to serai-client

* Correct network argument in serai-client for p2p_validators call

* Add a test in serai-client to check DHT population with a much quicker failure than the coordinator tests

* Update to latest Substrate

Removes distinguishing BABE/AuthorityDiscovery keys which causes
sc_authority_discovery to populate as desired.

* Update to a properly tagged substrate commit

* Add all dialed to peers to GossipSub

* cargo fmt

* Reduce common code in serai-coordinator-tests with amore involved new_test

* Use a recursive async function to spawn `n` DockerTests with the necessary networking configuration

* Merge UNIQUE_ID and ONE_AT_A_TIME

* Tidy up the new recursive code in tests/coordinator

* Use a Mutex in CONTEXT to let it be set multiple times

* Make complimentary edits to full-stack tests

* Augment coordinator P2p connection logs

* Drop lock acquisitions before recursing

* Better scope lock acquisitions in full-stack, preventing a deadlock

* Ensure OUTER_OPS is reset across the test boundary

* Add cargo deny allowance for dockertest fork
This commit is contained in:
Luke Parker
2023-12-22 21:09:18 -05:00
committed by GitHub
parent 00774c29d7
commit b493e3e31f
28 changed files with 1551 additions and 1225 deletions

View File

@@ -11,6 +11,7 @@ use core::marker::PhantomData;
// Re-export all components
pub use serai_primitives as primitives;
pub use primitives::{BlockNumber, Header};
use primitives::{NetworkId, NETWORKS};
pub use frame_system as system;
pub use frame_support as support;
@@ -43,7 +44,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, KeyTypeId,
traits::{Convert, BlakeTwo256, Block as BlockT},
transaction_validity::{TransactionSource, TransactionValidity},
Perbill, ApplyExtrinsicResult,
BoundedVec, Perbill, ApplyExtrinsicResult,
};
use primitives::{PublicKey, AccountLookup, SubstrateAmount};
@@ -377,6 +378,13 @@ mod benches {
);
}
sp_api::decl_runtime_apis! {
#[api_version(1)]
pub trait SeraiRuntimeApi {
fn validators(network_id: NetworkId) -> Vec<PublicKey>;
}
}
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
@@ -561,10 +569,41 @@ sp_api::impl_runtime_apis! {
impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime {
fn authorities() -> Vec<AuthorityDiscoveryId> {
Babe::authorities()
// Converts to `[u8; 32]` so it can be hashed
let serai_validators = Babe::authorities()
.into_iter()
.map(|(id, _)| AuthorityDiscoveryId::from(id.into_inner()))
.collect()
.map(|(id, _)| id.into_inner().0)
.collect::<hashbrown::HashSet<_>>();
let mut all = serai_validators;
for network in NETWORKS {
if network == NetworkId::Serai {
continue;
}
let participants =
ValidatorSets::participants_for_latest_decided_set(network)
.map_or(vec![], BoundedVec::into_inner);
for (participant, _) in participants {
all.insert(participant.0);
}
}
all.into_iter().map(|id| AuthorityDiscoveryId::from(PublicKey::from_raw(id))).collect()
}
}
impl crate::SeraiRuntimeApi<Block> for Runtime {
fn validators(network_id: NetworkId) -> Vec<PublicKey> {
if network_id == NetworkId::Serai {
Babe::authorities()
.into_iter()
.map(|(id, _)| id.into_inner())
.collect()
} else {
ValidatorSets::participants_for_latest_decided_set(network_id)
.map_or(
vec![],
|vec| vec.into_inner().into_iter().map(|(validator, _)| validator).collect()
)
}
}
}
}