diff --git a/substrate/executor/src/native_executor.rs b/substrate/executor/src/native_executor.rs index 72ba2d33a727d..724c44299f940 100644 --- a/substrate/executor/src/native_executor.rs +++ b/substrate/executor/src/native_executor.rs @@ -124,6 +124,8 @@ impl CodeExecutor for NativeExecutor { + /// The round consensus was reached in. + pub round_number: u32, + /// The hash of the header justified. + pub hash: H, + /// The signatures and signers of the hash. + pub signatures: Vec<([u8; 32], Signature)> + } + + // TODO: remove this after poc-2 + /// Justification back compat + #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] + #[serde(untagged)] + pub enum BlockJustification { + /// Poc-1 format. + V1(V1Justification), + /// Poc-2 format. + V2(Justification), + } + + impl BlockJustification { + /// Convert to PoC-2 justification format. + pub fn to_justification(self) -> Justification { + match self { + BlockJustification::V2(j) => j, + BlockJustification::V1(j) => { + Justification { + round_number: j.round_number, + hash: j.hash, + signatures: j.signatures.into_iter().map(|(a, s)| (a.into(), s)).collect(), + } + } + } + } + } + /// Block data sent in the response. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] pub struct BlockData { @@ -221,7 +260,7 @@ pub mod generic { /// Block message queue if requested. pub message_queue: Option>, /// Justification if requested. - pub justification: Option>, + pub justification: Option>, } /// Identifies starting point of a block sequence. diff --git a/substrate/network/src/protocol.rs b/substrate/network/src/protocol.rs index 6d23f1c7bd864..d46ff839c3f85 100644 --- a/substrate/network/src/protocol.rs +++ b/substrate/network/src/protocol.rs @@ -142,7 +142,8 @@ impl Protocol where let message: Message = match serde_json::from_slice(data) { Ok(m) => m, Err(e) => { - debug!("Invalid packet from {}: {}", peer_id, e); + debug!(target: "sync", "Invalid packet from {}: {}", peer_id, e); + trace!(target: "sync", "Invalid packet: {}", String::from_utf8_lossy(data)); io.disable_peer(peer_id); return; } @@ -159,13 +160,13 @@ impl Protocol where match mem::replace(&mut peer.block_request, None) { Some(r) => r, None => { - debug!("Unexpected response packet from {}", peer_id); + debug!(target: "sync", "Unexpected response packet from {}", peer_id); io.disable_peer(peer_id); return; } } } else { - debug!("Unexpected packet from {}", peer_id); + debug!(target: "sync", "Unexpected packet from {}", peer_id); io.disable_peer(peer_id); return; } @@ -259,13 +260,14 @@ impl Protocol where } let number = header.number().clone(); let hash = header.hash(); + let justification = if get_justification { self.chain.justification(&BlockId::Hash(hash)).unwrap_or(None) } else { None }; let block_data = message::generic::BlockData { hash: hash, header: if get_header { Some(header) } else { None }, body: (if get_body { self.chain.body(&BlockId::Hash(hash)).unwrap_or(None) } else { None }).map(|body| message::Body::Extrinsics(body)), receipt: None, message_queue: None, - justification: if get_justification { self.chain.justification(&BlockId::Hash(hash)).unwrap_or(None) } else { None }, + justification: justification.map(|j| message::generic::BlockJustification::V2(j)), }; blocks.push(block_data); match request.direction { diff --git a/substrate/network/src/sync.rs b/substrate/network/src/sync.rs index 8a296d4534f4f..e75fcd16f9d57 100644 --- a/substrate/network/src/sync.rs +++ b/substrate/network/src/sync.rs @@ -258,7 +258,7 @@ impl ChainSync where let result = protocol.chain().import( is_best, header, - justification, + justification.to_justification(), block.body.map(|b| b.to_extrinsics()), ); match result {