mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-07 15:27:21 +00:00
Add block data size check (#230)
* Add block data size check * Pass max_block_data_size everywhere * Fix build after merge * Fix ParachainWork initialization * Fix tests compilation
This commit is contained in:
committed by
Gavin Wood
parent
7a123fe8e9
commit
10ae8d48f5
@@ -136,6 +136,7 @@ impl SharedTableInner {
|
||||
context: &TableContext,
|
||||
router: &R,
|
||||
statement: table::SignedStatement,
|
||||
max_block_data_size: Option<u64>,
|
||||
) -> Option<ParachainWork<
|
||||
<R::FetchValidationProof as IntoFuture>::Future,
|
||||
>> {
|
||||
@@ -191,7 +192,8 @@ impl SharedTableInner {
|
||||
work.map(|work| ParachainWork {
|
||||
extrinsic_store: self.extrinsic_store.clone(),
|
||||
relay_parent: context.parent_hash.clone(),
|
||||
work
|
||||
work,
|
||||
max_block_data_size,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -265,6 +267,7 @@ pub struct ParachainWork<Fetch> {
|
||||
work: Work<Fetch>,
|
||||
relay_parent: Hash,
|
||||
extrinsic_store: ExtrinsicStore,
|
||||
max_block_data_size: Option<u64>,
|
||||
}
|
||||
|
||||
impl<Fetch: Future> ParachainWork<Fetch> {
|
||||
@@ -279,11 +282,13 @@ impl<Fetch: Future> ParachainWork<Fetch> {
|
||||
P: Send + Sync + 'static,
|
||||
P::Api: ParachainHost<Block>,
|
||||
{
|
||||
let max_block_data_size = self.max_block_data_size;
|
||||
let validate = move |id: &_, collation: &_| {
|
||||
let res = ::collation::validate_collation(
|
||||
&*api,
|
||||
id,
|
||||
collation,
|
||||
max_block_data_size,
|
||||
);
|
||||
|
||||
match res {
|
||||
@@ -373,13 +378,15 @@ impl<Fetch, F, Err> Future for PrimedParachainWork<Fetch, F>
|
||||
pub struct SharedTable {
|
||||
context: Arc<TableContext>,
|
||||
inner: Arc<Mutex<SharedTableInner>>,
|
||||
max_block_data_size: Option<u64>,
|
||||
}
|
||||
|
||||
impl Clone for SharedTable {
|
||||
fn clone(&self) -> Self {
|
||||
SharedTable {
|
||||
Self {
|
||||
context: self.context.clone(),
|
||||
inner: self.inner.clone(),
|
||||
max_block_data_size: self.max_block_data_size,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -395,10 +402,12 @@ impl SharedTable {
|
||||
key: Arc<ed25519::Pair>,
|
||||
parent_hash: Hash,
|
||||
extrinsic_store: ExtrinsicStore,
|
||||
max_block_data_size: Option<u64>,
|
||||
) -> Self {
|
||||
let index_mapping = authorities.iter().enumerate().map(|(i, k)| (i as ValidatorIndex, k.clone())).collect();
|
||||
Self {
|
||||
context: Arc::new(TableContext { groups, key, parent_hash, index_mapping, }),
|
||||
max_block_data_size,
|
||||
inner: Arc::new(Mutex::new(SharedTableInner {
|
||||
table: Table::default(),
|
||||
validated: HashMap::new(),
|
||||
@@ -447,7 +456,7 @@ impl SharedTable {
|
||||
) -> Option<ParachainWork<
|
||||
<R::FetchValidationProof as IntoFuture>::Future,
|
||||
>> {
|
||||
self.inner.lock().import_remote_statement(&*self.context, router, statement)
|
||||
self.inner.lock().import_remote_statement(&*self.context, router, statement, self.max_block_data_size)
|
||||
}
|
||||
|
||||
/// Import many statements at once.
|
||||
@@ -467,7 +476,7 @@ impl SharedTable {
|
||||
let mut inner = self.inner.lock();
|
||||
|
||||
iterable.into_iter().map(move |statement| {
|
||||
inner.import_remote_statement(&*self.context, router, statement)
|
||||
inner.import_remote_statement(&*self.context, router, statement, self.max_block_data_size)
|
||||
}).collect()
|
||||
}
|
||||
|
||||
@@ -612,6 +621,7 @@ mod tests {
|
||||
local_key.clone(),
|
||||
parent_hash,
|
||||
ExtrinsicStore::new_in_memory(),
|
||||
None,
|
||||
);
|
||||
|
||||
let candidate = CandidateReceipt {
|
||||
@@ -665,6 +675,7 @@ mod tests {
|
||||
local_key.clone(),
|
||||
parent_hash,
|
||||
ExtrinsicStore::new_in_memory(),
|
||||
None,
|
||||
);
|
||||
|
||||
let candidate = CandidateReceipt {
|
||||
@@ -720,6 +731,7 @@ mod tests {
|
||||
},
|
||||
relay_parent,
|
||||
extrinsic_store: store.clone(),
|
||||
max_block_data_size: None,
|
||||
};
|
||||
|
||||
let validated = producer.prime_with(|_, _| Ok(Extrinsic { outgoing_messages: Vec::new() }))
|
||||
@@ -760,6 +772,7 @@ mod tests {
|
||||
},
|
||||
relay_parent,
|
||||
extrinsic_store: store.clone(),
|
||||
max_block_data_size: None,
|
||||
};
|
||||
|
||||
let validated = producer.prime_with(|_, _| Ok(Extrinsic { outgoing_messages: Vec::new() }))
|
||||
@@ -797,6 +810,7 @@ mod tests {
|
||||
local_key.clone(),
|
||||
parent_hash,
|
||||
ExtrinsicStore::new_in_memory(),
|
||||
None,
|
||||
);
|
||||
|
||||
let candidate = CandidateReceipt {
|
||||
@@ -861,6 +875,7 @@ mod tests {
|
||||
local_key.clone(),
|
||||
parent_hash,
|
||||
ExtrinsicStore::new_in_memory(),
|
||||
None,
|
||||
);
|
||||
|
||||
let candidate = CandidateReceipt {
|
||||
@@ -909,6 +924,7 @@ mod tests {
|
||||
Arc::new(AuthorityKeyring::Alice.pair()),
|
||||
Default::default(),
|
||||
ExtrinsicStore::new_in_memory(),
|
||||
None,
|
||||
);
|
||||
let expected_mapping = authorities.iter().enumerate().map(|(i, k)| (i as ValidatorIndex, k.clone())).collect();
|
||||
assert_eq!(shared_table.context.index_mapping, expected_mapping);
|
||||
|
||||
Reference in New Issue
Block a user