Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
df828ac
Indentation fix.
eskimor Mar 18, 2021
06d4d90
Prepare request-response for PoV fetching.
eskimor Mar 18, 2021
6a940eb
Drop old PoV distribution.
eskimor Mar 18, 2021
a7fc368
WIP: Fetch PoV directly from backing.
eskimor Mar 18, 2021
9847b81
Merge branch 'master' into rk-pov-distribution-2590
eskimor Mar 19, 2021
e03ff75
Backing compiles.
eskimor Mar 19, 2021
a49b4d4
Runtime access and connection management for PoV distribution.
eskimor Mar 23, 2021
545e950
Get rid of seemingly dead code.
eskimor Mar 23, 2021
47d9f5f
Implement PoV fetching.
eskimor Mar 23, 2021
0a283ab
Don't send `ConnectToValidators` for empty list.
eskimor Mar 24, 2021
afd795f
Even better - no need to check over and over again.
eskimor Mar 24, 2021
1c3eec8
PoV fetching implemented.
eskimor Mar 24, 2021
fb24855
Merge branch 'master' into rk-pov-distribution-2590
eskimor Mar 24, 2021
cceddce
Check PoV hash upon reception.
eskimor Mar 24, 2021
89f0bf9
Implement retry of PoV fetching in backing.
eskimor Mar 25, 2021
ab75fea
Avoid pointless validation spawning.
eskimor Mar 25, 2021
10da891
Merge branch 'master' into rk-pov-distribution-2590
eskimor Mar 25, 2021
3915a57
Add jaeger span to pov requesting.
eskimor Mar 25, 2021
fa6409e
Add back tracing.
eskimor Mar 25, 2021
8b9c2d4
Review remarks.
eskimor Mar 25, 2021
2d27be5
Merge branch 'master' into rk-pov-distribution-2590
eskimor Mar 25, 2021
4af7d2e
Whitespace.
eskimor Mar 25, 2021
5c09829
Whitespace again.
eskimor Mar 26, 2021
ea9bde4
Cleanup + fix tests.
eskimor Mar 27, 2021
4207eaf
Log to log target in overseer.
eskimor Mar 27, 2021
3691061
Fix more tests.
eskimor Mar 27, 2021
b1a201a
Don't fail if group cannot be found.
eskimor Mar 27, 2021
298fe9d
Simple test for PoV fetcher.
eskimor Mar 27, 2021
af9f12c
Handle missing group membership better.
eskimor Mar 27, 2021
0c30792
Add test for retry functionality.
eskimor Mar 27, 2021
eb47465
Fix flaky test.
eskimor Mar 27, 2021
071bcca
Merge branch 'master' into rk-pov-distribution-2590
eskimor Mar 27, 2021
3fa5791
Spaces again.
eskimor Mar 28, 2021
82d4a11
Guide updates.
eskimor Mar 28, 2021
b58a2ab
Merge branch 'master' into rk-pov-distribution-2590
eskimor Mar 28, 2021
a0609e7
Spaces.
eskimor Mar 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP: Fetch PoV directly from backing.
  • Loading branch information
eskimor committed Mar 18, 2021
commit a7fc368d288cd060d6d4ef9a84db7afb306c552b
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node/core/backing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2018"
futures = "0.3.12"
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
polkadot-primitives = { path = "../../../primitives" }
polkadot-node-network-protocol = { path = "../../network/protocol" }
polkadot-node-primitives = { path = "../../primitives" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
Expand Down
107 changes: 73 additions & 34 deletions node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@ use polkadot_primitives::v1::{
use polkadot_node_primitives::{
Statement, SignedFullStatement, ValidationResult,
};
use polkadot_subsystem::{
PerLeafSpan, Stage,
jaeger,
messages::{
AllMessages, AvailabilityStoreMessage, CandidateBackingMessage, CandidateSelectionMessage,
CandidateValidationMessage, PoVDistributionMessage, ProvisionableData,
ProvisionerMessage, StatementDistributionMessage, ValidationFailed, RuntimeApiRequest,
},
};
use polkadot_subsystem::{PerLeafSpan, Stage, errors::RuntimeApiError, jaeger, messages::{AllMessages, AvailabilityStoreMessage, CandidateBackingMessage, CandidateSelectionMessage, CandidateValidationMessage, IfDisconnected, NetworkBridgeMessage, PoVDistributionMessage, ProvisionableData, ProvisionerMessage, RuntimeApiRequest, StatementDistributionMessage, ValidationFailed}};
use polkadot_node_subsystem_util::{
self as util,
request_session_index_for_child,
Expand All @@ -54,6 +46,10 @@ use polkadot_node_subsystem_util::{
FromJobCommand,
metrics::{self, prometheus},
};
use polkadot_node_subsystem_util::Error as UtilError;
use polkadot_node_network_protocol::request_response::{Recipient, Requests, request::{OutgoingRequest, RequestError}, v1::{
PoVFetchingRequest, PoVFetchingResponse
}};
use statement_table::{
generic::AttestedCandidate as TableAttestedCandidate,
Context as TableContextTrait,
Expand All @@ -65,6 +61,7 @@ use statement_table::{
},
};
use thiserror::Error;
use util::request_session_info;

const LOG_TARGET: &str = "parachain::candidate-backing";

Expand All @@ -76,8 +73,18 @@ enum Error {
InvalidSignature,
#[error("Failed to send candidates {0:?}")]
Send(Vec<BackedCandidate>),
#[error("FetchPoV request error")]
FetchPoV(#[source] RequestError),
#[error("FetchPoV channel closed before receipt")]
FetchPoV(#[source] oneshot::Canceled),
FetchPoVCanceled(#[source] oneshot::Canceled),
#[error("FetchPoV runtime request failed in utilities")]
FetchPoVUtil(#[source] UtilError),
#[error("FetchPoV runtime request failed")]
FetchPoVRuntime(#[source] RuntimeApiError),
#[error("FetchPoV could not find session")]
FetchPoVNoSuchSession,
#[error("FetchPoV could not find index of signing validator")]
FetchPoVInvalidValidatorIndex,
#[error("ValidateFromChainState channel closed before receipt")]
ValidateFromChainState(#[source] oneshot::Canceled),
#[error("StoreAvailableData channel closed before receipt")]
Expand All @@ -94,6 +101,14 @@ enum Error {
UtilError(#[from] util::Error),
}

/// PoV data to validate.
enum PoVData {
/// Allready available (from candidate selection).
Ready(Arc<PoV>),
/// Needs to be fetched from validator (we are checking a signed statement).
FetchFromValidator(ValidatorIndex),
}

enum ValidatedCandidateCommand {
// We were instructed to second the candidate.
Second(BackgroundValidationResult),
Expand Down Expand Up @@ -336,18 +351,46 @@ async fn make_pov_available(
Ok(Ok(()))
}

async fn request_pov_from_distribution(
async fn request_pov(
tx_from: &mut mpsc::Sender<FromJobCommand>,
parent: Hash,
descriptor: CandidateDescriptor,
from_validator: ValidatorIndex,
) -> Result<Arc<PoV>, Error> {
let (tx, rx) = oneshot::channel();

tx_from.send(AllMessages::PoVDistribution(
PoVDistributionMessage::FetchPoV(parent, descriptor, tx)
).into()).await?;

rx.await.map_err(Error::FetchPoV)
let session_index = request_session_index_for_child(parent, &mut tx_from)
.await.map_err(Error::FetchPoVUtil)?
.await.map_err(Error::FetchPoVCanceled)?
.map_err(Error::FetchPoVRuntime)?;
let session_info = request_session_info(parent, session_index, &mut tx_from)
.await.map_err(Error::FetchPoVUtil)?
.await.map_err(Error::FetchPoVCanceled)?
.map_err(Error::FetchPoVRuntime)?
.ok_or(Error::FetchPoVNoSuchSession)?;
let authority_id = session_info.discovery_keys.get(from_validator.0 as _)
.ok_or(Error::FetchPoVInvalidValidatorIndex);

let (req, pending_response) = OutgoingRequest::new(
Recipient::Authority(authority_id),
PoVFetchingRequest {
relay_parent: parent,
descriptor,
},
);
let full_req = Requests::PoVFetching(req);

tx_from.send(FromJobCommand::SendMessage(AllMessages::NetworkBridge(
NetworkBridgeMessage::SendRequests(
vec![full_req],
IfDisconnected::ImmediateError
)
))).await?;

let response = pending_response.await.map_err(Error::FetchPoV)?;
match response {
PoVFetchingResponse::PoV(compressed) => {
}
PoVFetchingResponse::NoSuchPoV => {
}
}

async fn request_candidate_validation(
Expand Down Expand Up @@ -380,7 +423,7 @@ struct BackgroundValidationParams<F> {
tx_command: mpsc::Sender<ValidatedCandidateCommand>,
candidate: CandidateReceipt,
relay_parent: Hash,
pov: Option<Arc<PoV>>,
pov: PoVData,
validator_index: Option<ValidatorIndex>,
n_validators: usize,
span: Option<jaeger::Span>,
Expand All @@ -403,13 +446,14 @@ async fn validate_and_make_available(
} = params;

let pov = match pov {
Some(pov) => pov,
None => {
PoVData::Ready(pov) => pov,
PoVData::FetchFromValidator(validator_index) => {
let _span = span.as_ref().map(|s| s.child("request-pov"));
request_pov_from_distribution(
request_pov(
&mut tx_from,
relay_parent,
candidate.descriptor.clone(),
validator_index,
).await?
}
};
Expand Down Expand Up @@ -822,6 +866,7 @@ impl CandidateBackingJob {
async fn kick_off_validation_work(
&mut self,
summary: TableSummary,
statement: SignedFullStatement,
span: Option<jaeger::Span>,
) -> Result<(), Error> {
let candidate_hash = summary.candidate;
Expand Down Expand Up @@ -860,7 +905,7 @@ impl CandidateBackingJob {
tx_command: self.background_validation_tx.clone(),
candidate,
relay_parent: self.parent,
pov: None,
pov: PoVData::FetchFromValidator(statement.validator_index()),
validator_index: self.table_context.validator.as_ref().map(|v| v.index()),
n_validators: self.table_context.validators.len(),
span,
Expand All @@ -885,7 +930,11 @@ impl CandidateBackingJob {
summary.group_id,
);

self.kick_off_validation_work(summary, span).await?;
self.kick_off_validation_work(
summary,
statement,
span,
).await?;
}
}
}
Expand Down Expand Up @@ -986,16 +1035,6 @@ impl CandidateBackingJob {
Ok(())
}

async fn distribute_pov(
&mut self,
descriptor: CandidateDescriptor,
pov: Arc<PoV>,
) -> Result<(), Error> {
self.tx_from.send(AllMessages::from(
PoVDistributionMessage::DistributePoV(self.parent, descriptor, pov),
).into()).await.map_err(Into::into)
}

async fn distribute_signed_statement(&mut self, s: SignedFullStatement) -> Result<(), Error> {
let smsg = StatementDistributionMessage::Share(self.parent, s);

Expand Down