Support sending and receiving multiple Justifications (#8266)

* client/network: support sending multiple justifications

* network: flag support for multiple justifications in protobuf request

* Update client/network/src/protocol.rs

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>

* network: update comment on protobuf field

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
Jon Häggblad
2021-04-28 12:59:50 +02:00
committed by GitHub
parent 1f02ec8ce4
commit d3d02d8851
7 changed files with 69 additions and 22 deletions
@@ -168,7 +168,7 @@ impl<H: HeaderT> generic::BlockAnnounce<H> {
pub mod generic {
use bitflags::bitflags;
use codec::{Encode, Decode, Input, Output};
use sp_runtime::EncodedJustification;
use sp_runtime::{EncodedJustification, Justifications};
use super::{
RemoteReadResponse, Transactions, Direction,
RequestId, BlockAttributes, RemoteCallResponse, ConsensusEngineId,
@@ -254,6 +254,8 @@ pub mod generic {
pub message_queue: Option<Vec<u8>>,
/// Justification if requested.
pub justification: Option<EncodedJustification>,
/// Justifications if requested.
pub justifications: Option<Justifications>,
}
/// Identifies starting point of a block sequence.
+15 -7
View File
@@ -833,8 +833,9 @@ impl<B: BlockT> ChainSync<B> {
.drain(self.best_queued_number + One::one())
.into_iter()
.map(|block_data| {
let justifications =
legacy_justification_mapping(block_data.block.justification);
let justifications = block_data.block.justifications.or(
legacy_justification_mapping(block_data.block.justification)
);
IncomingBlock {
hash: block_data.block.hash,
header: block_data.block.header,
@@ -854,11 +855,14 @@ impl<B: BlockT> ChainSync<B> {
}
validate_blocks::<B>(&blocks, who, Some(request))?;
blocks.into_iter().map(|b| {
let justifications = b.justifications.or(
legacy_justification_mapping(b.justification)
);
IncomingBlock {
hash: b.hash,
header: b.header,
body: b.body,
justifications: legacy_justification_mapping(b.justification),
justifications,
origin: Some(who.clone()),
allow_missing_state: true,
import_existing: false,
@@ -963,11 +967,14 @@ impl<B: BlockT> ChainSync<B> {
// When request.is_none() this is a block announcement. Just accept blocks.
validate_blocks::<B>(&blocks, who, None)?;
blocks.into_iter().map(|b| {
let justifications = b.justifications.or(
legacy_justification_mapping(b.justification)
);
IncomingBlock {
hash: b.hash,
header: b.header,
body: b.body,
justifications: legacy_justification_mapping(b.justification),
justifications,
origin: Some(who.clone()),
allow_missing_state: true,
import_existing: false,
@@ -1043,7 +1050,7 @@ impl<B: BlockT> ChainSync<B> {
return Err(BadPeer(who, rep::BAD_JUSTIFICATION));
}
block.justification
block.justifications.or(legacy_justification_mapping(block.justification))
} else {
// we might have asked the peer for a justification on a block that we assumed it
// had but didn't (regardless of whether it had a justification for it or not).
@@ -1058,7 +1065,7 @@ impl<B: BlockT> ChainSync<B> {
if let Some((peer, hash, number, j)) = self
.extra_justifications
.on_response(who, legacy_justification_mapping(justification))
.on_response(who, justification)
{
return Ok(OnBlockJustification::Import { peer, hash, number, justifications: j })
}
@@ -1655,7 +1662,7 @@ impl<B: BlockT> ChainSync<B> {
// This is purely during a backwards compatible transitionary period and should be removed
// once we can assume all nodes can send and receive multiple Justifications
// The ID tag is hardcoded here to avoid depending on the GRANDPA crate.
// TODO: https://github.com/paritytech/substrate/issues/8172
// See: https://github.com/paritytech/substrate/issues/8172
fn legacy_justification_mapping(justification: Option<EncodedJustification>) -> Option<Justifications> {
justification.map(|just| (*b"FRNK", just).into())
}
@@ -2163,6 +2170,7 @@ mod test {
receipt: None,
message_queue: None,
justification: None,
justifications: None,
}
).collect(),
}
@@ -228,6 +228,7 @@ mod test {
message_queue: None,
receipt: None,
justification: None,
justifications: None,
}).collect()
}