Allow both consensus and runtime to limit block building (#1581)

* Limit block size in runtime,

* Add test for basic authorship.

* Store length of extrinsics instead of computing it.

* Don't rely on note_extrinsic

* Use hashed version of storage and write test.

* Recompile runtime.
This commit is contained in:
Tomasz Drwięga
2019-02-01 13:58:23 +01:00
committed by Gav Wood
parent 381cf26f55
commit ecdd33a367
16 changed files with 170 additions and 44 deletions
@@ -16,7 +16,7 @@
//! Block evaluation and evaluation errors.
use super::MAX_TRANSACTIONS_SIZE;
use super::MAX_BLOCK_SIZE;
use parity_codec::Encode;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As};
@@ -43,7 +43,7 @@ error_chain! {
description("Proposal exceeded the maximum size."),
display(
"Proposal exceeded the maximum size of {} by {} bytes.",
MAX_TRANSACTIONS_SIZE, size.saturating_sub(MAX_TRANSACTIONS_SIZE)
MAX_BLOCK_SIZE, size.saturating_sub(MAX_BLOCK_SIZE)
),
}
}
@@ -61,12 +61,8 @@ pub fn evaluate_initial<Block: BlockT>(
let proposal = Block::decode(&mut &encoded[..])
.ok_or_else(|| ErrorKind::BadProposalFormat)?;
let transactions_size = proposal.extrinsics().iter().fold(0, |a, tx| {
a + Encode::encode(tx).len()
});
if transactions_size > MAX_TRANSACTIONS_SIZE {
bail!(ErrorKind::ProposalTooLarge(transactions_size))
if encoded.len() > MAX_BLOCK_SIZE {
bail!(ErrorKind::ProposalTooLarge(encoded.len()))
}
if *parent_hash != *proposal.header().parent_hash() {