Fix session index lookup for activated leaf (#4850)

This commit is contained in:
Chris Sosnin
2022-03-11 14:14:48 +03:00
committed by GitHub
parent 6fc2da146f
commit 681f3f4ed9
3 changed files with 21 additions and 19 deletions
@@ -45,7 +45,7 @@ use polkadot_primitives::v2::{
};
use polkadot_subsystem::{
messages::{
AllMessages, AvailabilityDistributionMessage, AvailabilityStoreMessage,
AllMessages, AvailabilityDistributionMessage, AvailabilityStoreMessage, ChainApiMessage,
NetworkBridgeMessage, RuntimeApiMessage, RuntimeApiRequest,
},
ActivatedLeaf, ActiveLeavesUpdate, FromOverseer, LeafStatus, OverseerSignal,
@@ -278,6 +278,14 @@ impl TestState {
},
}
},
AllMessages::ChainApi(ChainApiMessage::Ancestors { hash, k, response_channel }) => {
let chain = &self.relay_chain;
let maybe_block_position = chain.iter().position(|h| *h == hash);
let ancestors = maybe_block_position
.map(|idx| chain[..idx].iter().rev().take(k).copied().collect())
.unwrap_or_default();
response_channel.send(Ok(ancestors)).expect("Receiver is expected to be alive");
},
_ => {},
}
}