Port availability recovery to use req/res (#2694)

* add AvailableDataFetchingRequest

* rename AvailabilityFetchingRequest to ChunkFetchingRequest

* rename AvailabilityFetchingResponse to Chunk_

* add AvailableDataFetching request

* add available data fetching request to availability recovery message

* remove availability recovery message

* fix

* update network bridge

* port availability recovery to request/response

* use validators.len(), not shuffling

* fix availability recovery tests

* update guide

* Update node/network/availability-recovery/src/lib.rs

Co-authored-by: Bernhard Schuster <bernhard@ahoi.io>

* Update node/network/availability-recovery/src/lib.rs

Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>

* remove println

Co-authored-by: Bernhard Schuster <bernhard@ahoi.io>
Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
This commit is contained in:
Robert Habermeier
2021-03-25 15:34:24 +01:00
committed by GitHub
parent 349879df6b
commit 8a396c678f
19 changed files with 379 additions and 1067 deletions
@@ -18,7 +18,10 @@
use parity_scale_codec::{Decode, Encode};
use polkadot_primitives::v1::{CandidateHash, CandidateReceipt, ErasureChunk, ValidatorIndex, CompressedPoV, Hash};
use polkadot_primitives::v1::{
AvailableData, CandidateHash, CandidateReceipt, ErasureChunk, ValidatorIndex,
CompressedPoV, Hash,
};
use polkadot_primitives::v1::Id as ParaId;
use super::request::IsRequest;
@@ -26,16 +29,16 @@ use super::Protocol;
/// Request an availability chunk.
#[derive(Debug, Copy, Clone, Encode, Decode)]
pub struct AvailabilityFetchingRequest {
pub struct ChunkFetchingRequest {
/// Hash of candidate we want a chunk for.
pub candidate_hash: CandidateHash,
/// The index of the chunk to fetch.
pub index: ValidatorIndex,
}
/// Receive a rqeuested erasure chunk.
/// Receive a requested erasure chunk.
#[derive(Debug, Clone, Encode, Decode)]
pub enum AvailabilityFetchingResponse {
pub enum ChunkFetchingResponse {
/// The requested chunk data.
#[codec(index = 0)]
Chunk(ChunkResponse),
@@ -44,10 +47,19 @@ pub enum AvailabilityFetchingResponse {
NoSuchChunk,
}
impl From<Option<ChunkResponse>> for ChunkFetchingResponse {
fn from(x: Option<ChunkResponse>) -> Self {
match x {
Some(c) => ChunkFetchingResponse::Chunk(c),
None => ChunkFetchingResponse::NoSuchChunk,
}
}
}
/// Skimmed down variant of `ErasureChunk`.
///
/// Instead of transmitting a full `ErasureChunk` we transmit `ChunkResponse` in
/// `AvailabilityFetchingResponse`, which omits the chunk's index. The index is already known by
/// `ChunkFetchingResponse`, which omits the chunk's index. The index is already known by
/// the requester and by not transmitting it, we ensure the requester is going to use his index
/// value for validating the response, thus making sure he got what he requested.
#[derive(Debug, Clone, Encode, Decode)]
@@ -66,7 +78,7 @@ impl From<ErasureChunk> for ChunkResponse {
impl ChunkResponse {
/// Re-build an `ErasureChunk` from response and request.
pub fn recombine_into_chunk(self, req: &AvailabilityFetchingRequest) -> ErasureChunk {
pub fn recombine_into_chunk(self, req: &ChunkFetchingRequest) -> ErasureChunk {
ErasureChunk {
chunk: self.chunk,
proof: self.proof,
@@ -75,9 +87,9 @@ impl ChunkResponse {
}
}
impl IsRequest for AvailabilityFetchingRequest {
type Response = AvailabilityFetchingResponse;
const PROTOCOL: Protocol = Protocol::AvailabilityFetching;
impl IsRequest for ChunkFetchingRequest {
type Response = ChunkFetchingResponse;
const PROTOCOL: Protocol = Protocol::ChunkFetching;
}
/// Request the advertised collation at that relay-parent.
@@ -101,3 +113,35 @@ impl IsRequest for CollationFetchingRequest {
type Response = CollationFetchingResponse;
const PROTOCOL: Protocol = Protocol::CollationFetching;
}
/// Request the entire available data for a candidate.
#[derive(Debug, Clone, Encode, Decode)]
pub struct AvailableDataFetchingRequest {
/// The candidate hash to get the available data for.
pub candidate_hash: CandidateHash,
}
/// Receive a requested available data.
#[derive(Debug, Clone, Encode, Decode)]
pub enum AvailableDataFetchingResponse {
/// The requested data.
#[codec(index = 0)]
AvailableData(AvailableData),
/// Node was not in possession of the requested data.
#[codec(index = 1)]
NoSuchData,
}
impl From<Option<AvailableData>> for AvailableDataFetchingResponse {
fn from(x: Option<AvailableData>) -> Self {
match x {
Some(data) => AvailableDataFetchingResponse::AvailableData(data),
None => AvailableDataFetchingResponse::NoSuchData,
}
}
}
impl IsRequest for AvailableDataFetchingRequest {
type Response = AvailableDataFetchingResponse;
const PROTOCOL: Protocol = Protocol::AvailableDataFetching;
}