frame/authority-discovery: Have authorities() return both current and next (#6788)

* frame/authority-discovery: Have authorities() return both current and next

Authority address lookups on the DHT happen periodically (every 10
mintues) and are rather slow (~10 seconds).

In order to smooth the transition period between two sessions, have the
runtime module return both the current as well as the next authority
set. Thereby the client authority module will:

1. Publish its addresses one session in advance.

2. Prefetch the addresses of authorities of the next session in advance.

* frame/authority-discovery: Deduplicate authority ids

* frame/authority-discovery: Don't dedup on_genesis authorities

* frame/authority-discovery: Remove mut and sort on comparison in tests

* frame/authority-discovery: Use BTreeSet for deduplication
This commit is contained in:
Max Inden
2020-09-02 17:20:51 +02:00
committed by GitHub
parent 2f9e2577c1
commit 1d10db3184
3 changed files with 71 additions and 29 deletions
@@ -99,7 +99,7 @@ pub enum Role {
///
/// 2. **Discovers other authorities**
///
/// 1. Retrieves the current set of authorities.
/// 1. Retrieves the current and next set of authorities.
///
/// 2. Starts DHT queries for the ids of the authorities.
///
@@ -447,7 +447,7 @@ where
.collect::<HashMap<_, _>>()
};
// Check if the event origins from an authority in the current authority set.
// Check if the event origins from an authority in the current or next authority set.
let authority_id: &AuthorityId = authorities
.get(&remote_key)
.ok_or(Error::MatchingHashedAuthorityIdWithAuthorityId)?;
@@ -514,12 +514,12 @@ where
Ok(())
}
/// Retrieve our public keys within the current authority set.
/// Retrieve our public keys within the current and next authority set.
//
// A node might have multiple authority discovery keys within its keystore, e.g. an old one and
// one for the upcoming session. In addition it could be participating in the current authority
// set with two keys. The function does not return all of the local authority discovery public
// keys, but only the ones intersecting with the current authority set.
// one for the upcoming session. In addition it could be participating in the current and (/ or)
// next authority set with two keys. The function does not return all of the local authority
// discovery public keys, but only the ones intersecting with the current or next authority set.
fn get_own_public_keys_within_authority_set(
key_store: &BareCryptoStorePtr,
client: &Client,
@@ -530,14 +530,14 @@ where
.collect::<HashSet<_>>();
let id = BlockId::hash(client.info().best_hash);
let current_authorities = client.runtime_api()
let authorities = client.runtime_api()
.authorities(&id)
.map_err(Error::CallingRuntime)?
.into_iter()
.map(std::convert::Into::into)
.collect::<HashSet<_>>();
let intersection = local_pub_keys.intersection(&current_authorities)
let intersection = local_pub_keys.intersection(&authorities)
.cloned()
.map(std::convert::Into::into)
.collect();