Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add current relay block to ValidationParams #879

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Get current relay block head without messing with signatures
Turns out we already had a client object available which implemented
the necessary trait; the difficulty was just that I didn't know that
a. the trait existed, or that
b. the client in our possession implemented that trait.

This does make things much neater; it just means propagating the
trait bound backwards as implemented here.
  • Loading branch information
coriolinus committed Mar 5, 2020
commit f81b1f6aeaa1bd9fdf0287fe2c73371fa885ebc3
2 changes: 2 additions & 0 deletions network/src/legacy/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use polkadot_primitives::parachain::{
CandidateReceipt, ParachainHost, ValidatorIndex, Collation, PoVBlock, ErasureChunk,
};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;

use futures::prelude::*;
use futures::{task::SpawnExt, future::ready};
Expand Down Expand Up @@ -133,6 +134,7 @@ impl<P, T: Clone> Clone for Router<P, T> {
}

impl<P: ProvideRuntimeApi<Block> + Send + Sync + 'static, T> Router<P, T> where
P: HeaderBackend<Block>,
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
T: Clone + Executor + Send + 'static,
{
Expand Down
3 changes: 2 additions & 1 deletion network/src/legacy/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use polkadot_primitives::parachain::{
ValidatorId, PoVBlock,
};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;

use futures::prelude::*;
use futures::task::SpawnExt;
Expand Down Expand Up @@ -167,7 +168,7 @@ impl<P, T> ValidationNetwork<P, T> {

/// A long-lived network which can create parachain statement routing processes on demand.
impl<P, T> ParachainNetwork for ValidationNetwork<P, T> where
P: ProvideRuntimeApi<Block> + Send + Sync + 'static,
P: ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static,
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
T: Clone + Executor + Send + Sync + 'static,
{
Expand Down
7 changes: 4 additions & 3 deletions network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use polkadot_validation::{
};
use sc_network::{config::Roles, Event, PeerId};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;

use std::collections::HashMap;
use std::pin::Pin;
Expand Down Expand Up @@ -110,7 +111,7 @@ pub fn start<C, Api, SP>(
executor: SP,
) -> Result<Service, futures::task::SpawnError> where
C: ChainContext + 'static,
Api: ProvideRuntimeApi<Block> + Send + Sync + 'static,
Api: ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static,
Api::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
SP: Spawn + Clone + Send + 'static,
{
Expand Down Expand Up @@ -566,7 +567,7 @@ async fn worker_loop<Api, Sp>(
mut receiver: mpsc::Receiver<ServiceToWorkerMsg>,
executor: Sp,
) where
Api: ProvideRuntimeApi<Block> + Send + Sync + 'static,
Api: ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static,
Api::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
Sp: Spawn + Clone + Send + 'static,
{
Expand Down Expand Up @@ -690,7 +691,7 @@ async fn statement_import_loop<Api>(
mut exit: exit_future::Exit,
executor: impl Spawn,
) where
Api: ProvideRuntimeApi<Block> + Send + Sync + 'static,
Api: ProvideRuntimeApi<Block> + HeaderBackend<Block> + Send + Sync + 'static,
Api::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
{
let topic = crate::legacy::router::attestation_topic(relay_parent);
Expand Down
21 changes: 8 additions & 13 deletions validation/src/collation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use std::sync::Arc;

use polkadot_primitives::{
BlakeTwo256, Block, Hash, HashT, BlockId, Balance, BlockNumber,
BlakeTwo256, Block, Hash, HashT, BlockId, Balance,
parachain::{
CollatorId, CandidateReceipt, CollationInfo,
ParachainHost, Id as ParaId, Collation, FeeSchedule, ErasureChunk,
Expand All @@ -31,6 +31,7 @@ use polkadot_primitives::{
};
use polkadot_erasure_coding as erasure;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use parachain::{
wasm_executor::{self, ExecutionMode}, UpwardMessage,
};
Expand Down Expand Up @@ -65,20 +66,18 @@ pub trait Collators: Clone {
}

/// A future which resolves when a collation is available.
pub async fn collation_fetch<C: Collators, P, GCRB>(
pub async fn collation_fetch<C: Collators, P>(
parachain: ParaId,
relay_parent_hash: Hash,
get_current_relay_block: GCRB,
collators: C,
client: Arc<P>,
max_block_data_size: Option<u64>,
) -> Result<(Collation, HeadData, Balance),C::Error>
where
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
C: Collators + Unpin,
P: ProvideRuntimeApi<Block>,
P: ProvideRuntimeApi<Block> + HeaderBackend<Block>,
<C as Collators>::Collation: Unpin,
GCRB: Fn() -> BlockNumber,
{
let relay_parent = BlockId::hash(relay_parent_hash);

Expand All @@ -89,7 +88,6 @@ pub async fn collation_fetch<C: Collators, P, GCRB>(
let res = validate_collation(
&*client,
&relay_parent,
get_current_relay_block(),
&collation,
max_block_data_size,
);
Expand Down Expand Up @@ -284,15 +282,14 @@ pub fn validate_chunk(
fn do_validation<P>(
client: &P,
relay_parent: &BlockId,
current_relay_block: BlockNumber,
pov_block: &PoVBlock,
para_id: ParaId,
max_block_data_size: Option<u64>,
fees_charged: Option<Balance>,
head_data: &HeadData,
upward_messages: &Vec<UpwardMessage>,
) -> Result<(HeadData, Balance), Error> where
P: ProvideRuntimeApi<Block>,
P: ProvideRuntimeApi<Block> + HeaderBackend<Block>,
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
{
use parachain::ValidationParams;
Expand All @@ -315,7 +312,7 @@ fn do_validation<P>(
let params = ValidationParams {
parent_head: chain_status.head_data.0.clone(),
block_data: pov_block.block_data.0.clone(),
current_relay_block,
current_relay_block: client.info().best_number,
};

let ext = Externalities::new(chain_status.balance, chain_status.fee_schedule);
Expand Down Expand Up @@ -405,13 +402,12 @@ pub fn validate_receipt<P>(
receipt: &CandidateReceipt,
max_block_data_size: Option<u64>,
) -> Result<Vec<ErasureChunk>, Error> where
P: ProvideRuntimeApi<Block>,
P: ProvideRuntimeApi<Block> + HeaderBackend<Block>,
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
{
let (parent_head, _fees) = do_validation(
client,
relay_parent,
receipt.current_relay_block,
pov_block,
receipt.parachain_index,
max_block_data_size,
Expand Down Expand Up @@ -457,11 +453,10 @@ pub fn validate_receipt<P>(
pub fn validate_collation<P>(
client: &P,
relay_parent: &BlockId,
current_relay_block: BlockNumber,
collation: &Collation,
max_block_data_size: Option<u64>,
) -> Result<(HeadData, Balance), Error> where
P: ProvideRuntimeApi<Block>,
P: ProvideRuntimeApi<Block> + HeaderBackend<Block>,
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
{
let para_id = collation.info.parachain_index;
Expand Down
3 changes: 2 additions & 1 deletion validation/src/shared_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use super::{GroupInfo, TableRouter};
use self::includable::IncludabilitySender;
use primitives::Pair;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;

mod includable;

Expand Down Expand Up @@ -267,7 +268,7 @@ impl<Fetch: Future + Unpin> ParachainWork<Fetch> {
impl Send + FnMut(&BlockId, &PoVBlock, &CandidateReceipt) -> Result<ErasureChunk, ()> + Unpin,
>
where
P: Send + Sync + 'static,
P: HeaderBackend<Block> + Send + Sync + 'static,
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
{
let max_block_data_size = self.max_block_data_size;
Expand Down
10 changes: 3 additions & 7 deletions validation/src/validation_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use sp_blockchain::HeaderBackend;
use block_builder::BlockBuilderApi;
use consensus::SelectChain;
use futures::{future::ready, prelude::*, task::{Spawn, SpawnExt}};
use polkadot_primitives::{Block, Hash, BlockId, BlockNumber};
use polkadot_primitives::{Block, Hash, BlockId};
use polkadot_primitives::parachain::{
Chain, ParachainHost, Id as ParaId, ValidatorIndex, ValidatorId, ValidatorPair,
};
Expand Down Expand Up @@ -368,19 +368,16 @@ impl<C, N, P, SP> ParachainValidationInstances<C, N, P, SP> where
}

// launch parachain work asynchronously.
fn launch_work<GCRB>(
fn launch_work(
&self,
relay_parent: Hash,
validation_para: ParaId,
build_router: N::BuildTableRouter,
max_block_data_size: Option<u64>,
authorities_num: usize,
local_id: ValidatorIndex,
get_current_relay_block: GCRB,
)
where
GCRB: Fn() -> BlockNumber + Send,
{
where {
let (collators, client) = (self.collators.clone(), self.client.clone());
let availability_store = self.availability_store.clone();

Expand All @@ -389,7 +386,6 @@ impl<C, N, P, SP> ParachainValidationInstances<C, N, P, SP> where
let collation_work = crate::collation::collation_fetch(
validation_para,
relay_parent,
get_current_relay_block,
collators,
client.clone(),
max_block_data_size,
Expand Down