mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 04:07:57 +00:00
Make the maximum block size configurable (#7499)
* Make the maximum block size configurable This pr makes the maximum block size configurable. The maximum block size is used after proposing a new block to check if the new block is not exceeding the maximum. * Update primitives/consensus/common/src/evaluation.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Added comment Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
@@ -42,6 +42,15 @@ use std::marker::PhantomData;
|
||||
use prometheus_endpoint::Registry as PrometheusRegistry;
|
||||
use sc_proposer_metrics::MetricsLink as PrometheusMetrics;
|
||||
|
||||
/// Default maximum block size in bytes used by [`Proposer`].
|
||||
///
|
||||
/// Can be overwritten by [`ProposerFactory::set_maxium_block_size`].
|
||||
///
|
||||
/// Be aware that there is also an upper packet size on what the networking code
|
||||
/// will accept. If the block doesn't fit in such a package, it can not be
|
||||
/// transferred to other nodes.
|
||||
pub const DEFAULT_MAX_BLOCK_SIZE: usize = 4 * 1024 * 1024 + 512;
|
||||
|
||||
/// Proposer factory.
|
||||
pub struct ProposerFactory<A, B, C> {
|
||||
spawn_handle: Box<dyn SpawnNamed>,
|
||||
@@ -53,6 +62,7 @@ pub struct ProposerFactory<A, B, C> {
|
||||
metrics: PrometheusMetrics,
|
||||
/// phantom member to pin the `Backend` type.
|
||||
_phantom: PhantomData<B>,
|
||||
max_block_size: usize,
|
||||
}
|
||||
|
||||
impl<A, B, C> ProposerFactory<A, B, C> {
|
||||
@@ -68,8 +78,17 @@ impl<A, B, C> ProposerFactory<A, B, C> {
|
||||
transaction_pool,
|
||||
metrics: PrometheusMetrics::new(prometheus),
|
||||
_phantom: PhantomData,
|
||||
max_block_size: DEFAULT_MAX_BLOCK_SIZE,
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the maximum block size in bytes.
|
||||
///
|
||||
/// The default value for the maximum block size is:
|
||||
/// [`DEFAULT_MAX_BLOCK_SIZE`].
|
||||
pub fn set_maximum_block_size(&mut self, size: usize) {
|
||||
self.max_block_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, Block, C, A> ProposerFactory<A, B, C>
|
||||
@@ -103,6 +122,7 @@ impl<B, Block, C, A> ProposerFactory<A, B, C>
|
||||
now,
|
||||
metrics: self.metrics.clone(),
|
||||
_phantom: PhantomData,
|
||||
max_block_size: self.max_block_size,
|
||||
};
|
||||
|
||||
proposer
|
||||
@@ -143,6 +163,7 @@ pub struct Proposer<B, Block: BlockT, C, A: TransactionPool> {
|
||||
now: Box<dyn Fn() -> time::Instant + Send + Sync>,
|
||||
metrics: PrometheusMetrics,
|
||||
_phantom: PhantomData<B>,
|
||||
max_block_size: usize,
|
||||
}
|
||||
|
||||
impl<A, B, Block, C> sp_consensus::Proposer<Block> for
|
||||
@@ -334,7 +355,12 @@ impl<A, B, Block, C> Proposer<B, Block, C, A>
|
||||
error!("Failed to verify block encoding/decoding");
|
||||
}
|
||||
|
||||
if let Err(err) = evaluation::evaluate_initial(&block, &self.parent_hash, self.parent_number) {
|
||||
if let Err(err) = evaluation::evaluate_initial(
|
||||
&block,
|
||||
&self.parent_hash,
|
||||
self.parent_number,
|
||||
self.max_block_size,
|
||||
) {
|
||||
error!("Failed to evaluate authored block: {:?}", err);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user