mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 23:41:02 +00:00
Refactor and fix usage of get_session_index() and get_session_info_by_index() (#4735)
* Rename/refactor around get_session_index Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * choose proper head for fetching session Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * revert rename Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix comments Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * renaming and more comments Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * review feedback Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Run Fetch task in correct session Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Log warning when ancestors unavailable Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fixes Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
This commit is contained in:
@@ -190,8 +190,26 @@ impl DisputeSender {
|
||||
dispute: (SessionIndex, CandidateHash),
|
||||
) -> Result<()> {
|
||||
let (session_index, candidate_hash) = dispute;
|
||||
// We need some relay chain head for context for receiving session info information:
|
||||
let ref_head = self.active_sessions.values().next().ok_or(NonFatal::NoActiveHeads)?;
|
||||
// A relay chain head is required as context for receiving session info information from runtime and
|
||||
// storage. We will iterate `active_sessions` to find a suitable head. We assume that there is at
|
||||
// least one active head which, by `session_index`, is at least as recent as the `dispute` passed in.
|
||||
// We need to avoid picking an older one from a session that might not yet exist in storage.
|
||||
// Related to <https://github.com/paritytech/polkadot/issues/4730> .
|
||||
let ref_head = self
|
||||
.active_sessions
|
||||
.iter()
|
||||
.find_map(|(active_session_index, head_hash)| {
|
||||
// There might be more than one session index that is at least as recent as the dispute
|
||||
// so we just pick the first one. Keep in mind we are talking about the session index for the
|
||||
// child of block identified by `head_hash` and not the session index for the block.
|
||||
if active_session_index >= &session_index {
|
||||
Some(head_hash)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.ok_or(NonFatal::NoActiveHeads)?;
|
||||
|
||||
let info = runtime
|
||||
.get_session_info_by_index(ctx.sender(), *ref_head, session_index)
|
||||
.await?;
|
||||
@@ -293,7 +311,7 @@ impl DisputeSender {
|
||||
ctx: &mut Context,
|
||||
runtime: &mut RuntimeInfo,
|
||||
) -> Result<bool> {
|
||||
let new_sessions = get_active_session_indeces(ctx, runtime, &self.active_heads).await?;
|
||||
let new_sessions = get_active_session_indices(ctx, runtime, &self.active_heads).await?;
|
||||
let new_sessions_raw: HashSet<_> = new_sessions.keys().collect();
|
||||
let old_sessions_raw: HashSet<_> = self.active_sessions.keys().collect();
|
||||
let updated = new_sessions_raw != old_sessions_raw;
|
||||
@@ -306,14 +324,15 @@ impl DisputeSender {
|
||||
/// Retrieve the currently active sessions.
|
||||
///
|
||||
/// List is all indices of all active sessions together with the head that was used for the query.
|
||||
async fn get_active_session_indeces<Context: SubsystemContext>(
|
||||
async fn get_active_session_indices<Context: SubsystemContext>(
|
||||
ctx: &mut Context,
|
||||
runtime: &mut RuntimeInfo,
|
||||
active_heads: &Vec<Hash>,
|
||||
) -> Result<HashMap<SessionIndex, Hash>> {
|
||||
let mut indeces = HashMap::new();
|
||||
// Iterate all heads we track as active and fetch the child' session indices.
|
||||
for head in active_heads {
|
||||
let session_index = runtime.get_session_index(ctx.sender(), *head).await?;
|
||||
let session_index = runtime.get_session_index_for_child(ctx.sender(), *head).await?;
|
||||
indeces.insert(session_index, *head);
|
||||
}
|
||||
Ok(indeces)
|
||||
|
||||
@@ -204,7 +204,8 @@ impl SendTask {
|
||||
active_sessions: &HashMap<SessionIndex, Hash>,
|
||||
) -> Result<HashSet<AuthorityDiscoveryId>> {
|
||||
let ref_head = self.request.0.candidate_receipt.descriptor.relay_parent;
|
||||
// Parachain validators:
|
||||
// Retrieve all authorities which participated in the parachain consensus of the session
|
||||
// in which the candidate was backed.
|
||||
let info = runtime
|
||||
.get_session_info_by_index(ctx.sender(), ref_head, self.request.0.session_index)
|
||||
.await?;
|
||||
@@ -219,7 +220,8 @@ impl SendTask {
|
||||
.map(|(_, v)| v.clone())
|
||||
.collect();
|
||||
|
||||
// Current authorities:
|
||||
// Retrieve all authorities for the current session as indicated by the active
|
||||
// heads we are tracking.
|
||||
for (session_index, head) in active_sessions.iter() {
|
||||
let info =
|
||||
runtime.get_session_info_by_index(ctx.sender(), *head, *session_index).await?;
|
||||
|
||||
Reference in New Issue
Block a user