mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 22:47:56 +00:00
Req/res optimization for statement distribution (#2803)
* Wip * Increase proposer timeout. * WIP. * Better timeout values now that we are going to be connected to all nodes. (#2778) * Better timeout values. * Fix typo. * Fix validator bandwidth. * Fix compilation. * Better and more consistent sizes. Most importantly code size is now 5 Meg, which is the limit we currently want to support in statement distribution. * Introduce statement fetching request. * WIP * Statement cache retrieval logic. * Review remarks by @rphmeier * Fixes. * Better requester logic. * WIP: Handle requester messages. * Missing dep. * Fix request launching logic. * Finish fetching logic. * Sending logic. * Redo code size calculations. Now that max code size is compressed size. * Update Cargo.lock (new dep) * Get request receiver to statement distribution. * Expose new functionality for responding to requests. * Cleanup. * Responder logic. * Fixes + Cleanup. * Cargo.lock * Whitespace. * Add lost copyright. * Launch responder task. * Typo. * info -> warn * Typo. * Fix. * Fix. * Update comment. * Doc fix. * Better large statement heuristics. * Fix tests. * Fix network bridge tests. * Add test for size estimate. * Very simple tests that checks we get LargeStatement. * Basic check, that fetching of large candidates is performed. * More tests. * Basic metrics for responder. * More metrics. * Use Encode::encoded_size(). * Some useful spans. * Get rid of redundant metrics. * Don't add peer on duplicate. * Properly check hash instead of relying on signatures alone. * Preserve ordering + better flood protection. * Get rid of redundant clone. * Don't shutdown responder on failed query. And add test for this. * Smaller fixes. * Quotes. * Better queue size calculation. * A bit saner response sizes. * Fixes.
This commit is contained in:
@@ -291,10 +291,7 @@ pub mod v1 {
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use polkadot_primitives::v1::{
|
||||
CandidateIndex, CollatorId, Hash, Id as ParaId, SignedAvailabilityBitfield,
|
||||
CollatorSignature,
|
||||
};
|
||||
use polkadot_primitives::v1::{CandidateHash, CandidateIndex, CollatorId, CollatorSignature, CompactStatement, Hash, Id as ParaId, SignedAvailabilityBitfield, ValidatorIndex, ValidatorSignature};
|
||||
use polkadot_node_primitives::{
|
||||
approval::{IndirectAssignmentCert, IndirectSignedApprovalVote},
|
||||
SignedFullStatement,
|
||||
@@ -313,7 +310,68 @@ pub mod v1 {
|
||||
pub enum StatementDistributionMessage {
|
||||
/// A signed full statement under a given relay-parent.
|
||||
#[codec(index = 0)]
|
||||
Statement(Hash, SignedFullStatement)
|
||||
Statement(Hash, SignedFullStatement),
|
||||
/// Seconded statement with large payload (e.g. containing a runtime upgrade).
|
||||
///
|
||||
/// We only gossip the hash in that case, actual payloads can be fetched from sending node
|
||||
/// via req/response.
|
||||
#[codec(index = 1)]
|
||||
LargeStatement(StatementMetadata),
|
||||
}
|
||||
|
||||
/// Data that maes a statement unique.
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq, Hash)]
|
||||
pub struct StatementMetadata {
|
||||
/// Relayt parent this statement is relevant under.
|
||||
pub relay_parent: Hash,
|
||||
/// Hash of the candidate that got validated.
|
||||
pub candidate_hash: CandidateHash,
|
||||
/// Validator that attested the valididty.
|
||||
pub signed_by: ValidatorIndex,
|
||||
/// Signature of seconding validator.
|
||||
pub signature: ValidatorSignature,
|
||||
}
|
||||
|
||||
impl StatementDistributionMessage {
|
||||
/// Get meta data of the given `StatementDistributionMessage`.
|
||||
pub fn get_metadata(&self) -> StatementMetadata {
|
||||
match self {
|
||||
Self::Statement(relay_parent, statement) => StatementMetadata {
|
||||
relay_parent: *relay_parent,
|
||||
candidate_hash: statement.payload().candidate_hash(),
|
||||
signed_by: statement.validator_index(),
|
||||
signature: statement.signature().clone(),
|
||||
},
|
||||
Self::LargeStatement(metadata) => metadata.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get fingerprint describing the contained statement uniquely.
|
||||
pub fn get_fingerprint(&self) -> (CompactStatement, ValidatorIndex) {
|
||||
match self {
|
||||
Self::Statement(_, statement) =>
|
||||
(statement.payload().to_compact(), statement.validator_index()),
|
||||
Self::LargeStatement(meta) =>
|
||||
(CompactStatement::Seconded(meta.candidate_hash), meta.signed_by),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get contained relay parent.
|
||||
pub fn get_relay_parent(&self) -> Hash {
|
||||
match self {
|
||||
Self::Statement(r, _) => *r,
|
||||
Self::LargeStatement(meta) => meta.relay_parent,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether or not this message contains a large statement.
|
||||
pub fn is_large_statement(&self) -> bool {
|
||||
if let Self::LargeStatement(_) = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Network messages used by the approval distribution subsystem.
|
||||
|
||||
Reference in New Issue
Block a user