mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 15:11:03 +00:00
Introduce a "dynamic" block size limit for proposing (#8588)
* Introduce a "dynamic" block size limit for proposing This adds support for using a dynamic block size limit per call to `propose`. This is required for Cumulus/Parachains to always use stay in the limits of the maximum allowed PoV size. As described in the docs, the block limit is only checked in the process of pushing transactions. As we normally do some other operations in `on_finalize`, it can happen that the block size still grows when there is some proof being collected (as we do for parachains). This means, that the given block limit needs to be rather conservative on the actual value and should not be the upper limit. * Update client/basic-authorship/src/basic_authorship.rs Co-authored-by: Andronik Ordian <write@reusable.software> * More future proof encoded size updating * Use `ProofRecorderInner` * Update client/basic-authorship/src/basic_authorship.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/basic-authorship/src/basic_authorship.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/basic-authorship/src/basic_authorship.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/consensus/slots/src/lib.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/consensus/slots/src/slots.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/basic-authorship/src/basic_authorship.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/basic-authorship/src/basic_authorship.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Update client/basic-authorship/src/basic_authorship.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
@@ -39,9 +39,6 @@ pub enum Error {
|
||||
/// Proposal had wrong number.
|
||||
#[error("Proposal had wrong number. Expected {expected:?}, got {got:?}")]
|
||||
WrongNumber { expected: BlockNumber, got: BlockNumber },
|
||||
/// Proposal exceeded the maximum size.
|
||||
#[error("Proposal size {block_size} exceeds maximum allowed size of {max_block_size}.")]
|
||||
ProposalTooLarge { block_size: usize, max_block_size: usize },
|
||||
}
|
||||
|
||||
/// Attempt to evaluate a substrate block as a node block, returning error
|
||||
@@ -50,17 +47,12 @@ pub fn evaluate_initial<Block: BlockT>(
|
||||
proposal: &Block,
|
||||
parent_hash: &<Block as BlockT>::Hash,
|
||||
parent_number: <<Block as BlockT>::Header as HeaderT>::Number,
|
||||
max_block_size: usize,
|
||||
) -> Result<()> {
|
||||
|
||||
let encoded = Encode::encode(proposal);
|
||||
let proposal = Block::decode(&mut &encoded[..])
|
||||
.map_err(|e| Error::BadProposalFormat(e))?;
|
||||
|
||||
if encoded.len() > max_block_size {
|
||||
return Err(Error::ProposalTooLarge { max_block_size, block_size: encoded.len() })
|
||||
}
|
||||
|
||||
if *parent_hash != *proposal.header().parent_hash() {
|
||||
return Err(Error::WrongParentHash {
|
||||
expected: format!("{:?}", *parent_hash),
|
||||
|
||||
@@ -196,6 +196,13 @@ pub trait Proposer<B: BlockT> {
|
||||
/// a maximum duration for building this proposal is given. If building the proposal takes
|
||||
/// longer than this maximum, the proposal will be very likely discarded.
|
||||
///
|
||||
/// If `block_size_limit` is given, the proposer should push transactions until the block size
|
||||
/// limit is hit. Depending on the `finalize_block` implementation of the runtime, it probably
|
||||
/// incorporates other operations (that are happening after the block limit is hit). So,
|
||||
/// when the block size estimation also includes a proof that is recorded alongside the block
|
||||
/// production, the proof can still grow. This means that the `block_size_limit` should not be
|
||||
/// the hard limit of what is actually allowed.
|
||||
///
|
||||
/// # Return
|
||||
///
|
||||
/// Returns a future that resolves to a [`Proposal`] or to [`Error`].
|
||||
@@ -204,6 +211,7 @@ pub trait Proposer<B: BlockT> {
|
||||
inherent_data: InherentData,
|
||||
inherent_digests: DigestFor<B>,
|
||||
max_duration: Duration,
|
||||
block_size_limit: Option<usize>,
|
||||
) -> Self::Proposal;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user