mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
Code, PoV compression and remove CompressedPoV struct (#2852)
* use compressed blob in candidate-validation * add some tests for compressed code blobs * remove CompressedPoV and apply compression in collation-generation * decompress BlockData before executing * don't produce oversized collations * add test for PoV decompression failure * fix tests and clean up * fix test * address review and fix CI * take this )
This commit is contained in:
committed by
GitHub
parent
bb48c47fbf
commit
896ec8dbc3
@@ -42,7 +42,7 @@ use polkadot_node_subsystem_util::{
|
||||
request_availability_cores,
|
||||
metrics::{self, prometheus},
|
||||
};
|
||||
use polkadot_node_primitives::{SignedFullStatement, Statement, PoV, CompressedPoV};
|
||||
use polkadot_node_primitives::{SignedFullStatement, Statement, PoV};
|
||||
|
||||
const COST_UNEXPECTED_MESSAGE: Rep = Rep::CostMinor("An unexpected message");
|
||||
|
||||
@@ -660,27 +660,6 @@ async fn send_collation(
|
||||
receipt: CandidateReceipt,
|
||||
pov: PoV,
|
||||
) {
|
||||
let pov = match CompressedPoV::compress(&pov) {
|
||||
Ok(compressed) => {
|
||||
tracing::trace!(
|
||||
target: LOG_TARGET,
|
||||
size = %pov.block_data.0.len(),
|
||||
compressed = %compressed.len(),
|
||||
peer_id = ?request.peer,
|
||||
"Sending collation."
|
||||
);
|
||||
compressed
|
||||
},
|
||||
Err(error) => {
|
||||
tracing::error!(
|
||||
target: LOG_TARGET,
|
||||
?error,
|
||||
"Failed to create `CompressedPov`",
|
||||
);
|
||||
return
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(_) = request.send_response(CollationFetchingResponse::Collation(receipt, pov)) {
|
||||
tracing::warn!(
|
||||
target: LOG_TARGET,
|
||||
@@ -1519,7 +1498,7 @@ mod tests {
|
||||
)
|
||||
.expect("Decoding should work");
|
||||
assert_eq!(receipt, candidate);
|
||||
assert_eq!(pov.decompress().unwrap(), pov_block);
|
||||
assert_eq!(pov, pov_block);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -1158,49 +1158,33 @@ where
|
||||
|
||||
modify_reputation(ctx, *peer_id, COST_WRONG_PARA).await;
|
||||
}
|
||||
Ok(CollationFetchingResponse::Collation(receipt, compressed_pov)) => {
|
||||
match compressed_pov.decompress() {
|
||||
Ok(pov) => {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
para_id = %para_id,
|
||||
hash = ?hash,
|
||||
candidate_hash = ?receipt.hash(),
|
||||
"Received collation",
|
||||
);
|
||||
Ok(CollationFetchingResponse::Collation(receipt, pov)) => {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
para_id = %para_id,
|
||||
hash = ?hash,
|
||||
candidate_hash = ?receipt.hash(),
|
||||
"Received collation",
|
||||
);
|
||||
|
||||
// Actual sending:
|
||||
let _span = jaeger::Span::new(&pov, "received-collation");
|
||||
let (mut tx, _) = oneshot::channel();
|
||||
std::mem::swap(&mut tx, &mut (per_req.to_requester));
|
||||
let result = tx.send((receipt, pov));
|
||||
// Actual sending:
|
||||
let _span = jaeger::Span::new(&pov, "received-collation");
|
||||
let (mut tx, _) = oneshot::channel();
|
||||
std::mem::swap(&mut tx, &mut (per_req.to_requester));
|
||||
let result = tx.send((receipt, pov));
|
||||
|
||||
if let Err(_) = result {
|
||||
tracing::warn!(
|
||||
target: LOG_TARGET,
|
||||
hash = ?hash,
|
||||
para_id = ?para_id,
|
||||
peer_id = ?peer_id,
|
||||
"Sending response back to requester failed (receiving side closed)"
|
||||
);
|
||||
} else {
|
||||
metrics_result = Ok(());
|
||||
success = "true";
|
||||
}
|
||||
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::warn!(
|
||||
target: LOG_TARGET,
|
||||
hash = ?hash,
|
||||
para_id = ?para_id,
|
||||
peer_id = ?peer_id,
|
||||
?error,
|
||||
"Failed to extract PoV",
|
||||
);
|
||||
modify_reputation(ctx, *peer_id, COST_CORRUPTED_MESSAGE).await;
|
||||
}
|
||||
};
|
||||
if let Err(_) = result {
|
||||
tracing::warn!(
|
||||
target: LOG_TARGET,
|
||||
hash = ?hash,
|
||||
para_id = ?para_id,
|
||||
peer_id = ?peer_id,
|
||||
"Sending response back to requester failed (receiving side closed)"
|
||||
);
|
||||
} else {
|
||||
metrics_result = Ok(());
|
||||
success = "true";
|
||||
}
|
||||
}
|
||||
};
|
||||
metrics.on_request(metrics_result);
|
||||
@@ -1227,7 +1211,7 @@ mod tests {
|
||||
CollatorPair, ValidatorId, ValidatorIndex, CoreState, CandidateDescriptor,
|
||||
GroupRotationInfo, ScheduledCore, OccupiedCore, GroupIndex,
|
||||
};
|
||||
use polkadot_node_primitives::{BlockData, CompressedPoV};
|
||||
use polkadot_node_primitives::BlockData;
|
||||
use polkadot_node_subsystem_util::TimeoutExt;
|
||||
use polkadot_subsystem_testhelpers as test_helpers;
|
||||
use polkadot_subsystem::messages::{RuntimeApiMessage, RuntimeApiRequest};
|
||||
@@ -1859,9 +1843,9 @@ mod tests {
|
||||
response_channel.send(Ok(
|
||||
CollationFetchingResponse::Collation(
|
||||
candidate_a.clone(),
|
||||
CompressedPoV::compress(&PoV {
|
||||
PoV {
|
||||
block_data: BlockData(vec![]),
|
||||
}).unwrap(),
|
||||
},
|
||||
).encode()
|
||||
)).expect("Sending response should succeed");
|
||||
|
||||
@@ -1889,9 +1873,9 @@ mod tests {
|
||||
response_channel.send(Ok(
|
||||
CollationFetchingResponse::Collation(
|
||||
candidate_b.clone(),
|
||||
CompressedPoV::compress(&PoV {
|
||||
PoV {
|
||||
block_data: BlockData(vec![1, 2, 3]),
|
||||
}).unwrap(),
|
||||
},
|
||||
).encode()
|
||||
)).expect("Sending response should succeed");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user