mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
Compress the PoV block before sending it over the network (#2288)
* Compress the PoV block before sending it over the network This pr changes the way we send PoV blocks over the network. We now compress the PoV block before it is send over the network. This should reduce the size significant for PoVs which contain the runtime WASM for example. * Preallocate 1KB * Try something.. * Switch to zstd and some renamings * Make compression/decompression fail in browsers * Use some sane maximum value * Update roadmap/implementers-guide/src/types/network.md Co-authored-by: Andronik Ordian <write@reusable.software> * Fix and add test * add Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: Robert Habermeier <rphmeier@gmail.com>
This commit is contained in:
@@ -501,11 +501,19 @@ async fn send_collation(
|
||||
receipt: CandidateReceipt,
|
||||
pov: PoV,
|
||||
) {
|
||||
let wire_message = protocol_v1::CollatorProtocolMessage::Collation(
|
||||
request_id,
|
||||
receipt,
|
||||
pov,
|
||||
);
|
||||
let pov = match protocol_v1::CompressedPoV::compress(&pov) {
|
||||
Ok(pov) => pov,
|
||||
Err(error) => {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
error = ?error,
|
||||
"Failed to create `CompressedPov`",
|
||||
);
|
||||
return
|
||||
}
|
||||
};
|
||||
|
||||
let wire_message = protocol_v1::CollatorProtocolMessage::Collation(request_id, receipt, pov);
|
||||
|
||||
ctx.send_message(AllMessages::NetworkBridge(
|
||||
NetworkBridgeMessage::SendCollationMessage(
|
||||
@@ -1280,7 +1288,7 @@ mod tests {
|
||||
protocol_v1::CollatorProtocolMessage::Collation(req_id, receipt, pov) => {
|
||||
assert_eq!(req_id, request_id);
|
||||
assert_eq!(receipt, candidate);
|
||||
assert_eq!(pov, pov_block);
|
||||
assert_eq!(pov.decompress().unwrap(), pov_block);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ async fn received_collation<Context>(
|
||||
origin: PeerId,
|
||||
request_id: RequestId,
|
||||
receipt: CandidateReceipt,
|
||||
pov: PoV,
|
||||
pov: protocol_v1::CompressedPoV,
|
||||
)
|
||||
where
|
||||
Context: SubsystemContext<Message = CollatorProtocolMessage>
|
||||
@@ -368,6 +368,21 @@ where
|
||||
if let Some(per_request) = state.requests_info.remove(&id) {
|
||||
let _ = per_request.received.send(());
|
||||
if let Some(collator_id) = state.known_collators.get(&origin) {
|
||||
let pov = match pov.decompress() {
|
||||
Ok(pov) => pov,
|
||||
Err(error) => {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
%request_id,
|
||||
?error,
|
||||
"Failed to extract PoV",
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let _span = jaeger::pov_span(&pov, "received-collation");
|
||||
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
%request_id,
|
||||
@@ -529,9 +544,8 @@ where
|
||||
modify_reputation(ctx, origin, COST_UNEXPECTED_MESSAGE).await;
|
||||
}
|
||||
Collation(request_id, receipt, pov) => {
|
||||
let _span1 = state.span_per_relay_parent.get(&receipt.descriptor.relay_parent)
|
||||
let _span = state.span_per_relay_parent.get(&receipt.descriptor.relay_parent)
|
||||
.map(|s| s.child("received-collation"));
|
||||
let _span2 = jaeger::pov_span(&pov, "received-collation");
|
||||
received_collation(ctx, state, origin, request_id, receipt, pov).await;
|
||||
}
|
||||
}
|
||||
@@ -1295,9 +1309,9 @@ mod tests {
|
||||
protocol_v1::CollatorProtocolMessage::Collation(
|
||||
request_id,
|
||||
candidate_a.clone(),
|
||||
PoV {
|
||||
protocol_v1::CompressedPoV::compress(&PoV {
|
||||
block_data: BlockData(vec![]),
|
||||
},
|
||||
}).unwrap(),
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -1333,9 +1347,9 @@ mod tests {
|
||||
protocol_v1::CollatorProtocolMessage::Collation(
|
||||
request_id,
|
||||
candidate_b.clone(),
|
||||
PoV {
|
||||
protocol_v1::CompressedPoV::compress(&PoV {
|
||||
block_data: BlockData(vec![1, 2, 3]),
|
||||
},
|
||||
}).unwrap(),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user