Skip to content

Commit

Permalink
Return an error if block too big in block production
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Nov 15, 2021
1 parent 47ac20f commit 2a1e383
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use safe_arith::SafeArith;
use slasher::Slasher;
use slog::{crit, debug, error, info, trace, warn, Logger};
use slot_clock::SlotClock;
use ssz::Encode;
use state_processing::{
common::get_indexed_attestation,
per_block_processing,
Expand Down Expand Up @@ -3004,6 +3005,19 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Signature::empty(),
);

let block_size = block.ssz_bytes_len();
debug!(
self.log,
"Produced block on state";
"block_size" => block_size,
);

metrics::observe(&metrics::BLOCK_SIZE, block_size as f64);

if block_size > self.config.max_network_size {
return Err(BlockProductionError::BlockTooLarge(block_size));
}

let process_timer = metrics::start_timer(&metrics::BLOCK_PRODUCTION_PROCESS_TIMES);
per_block_processing(
&mut state,
Expand Down
3 changes: 3 additions & 0 deletions beacon_node/beacon_chain/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct ChainConfig {
pub reconstruct_historic_states: bool,
/// Whether timeouts on `TimeoutRwLock`s are enabled or not.
pub enable_lock_timeouts: bool,
/// The max size of a message that can be sent over the network.
pub max_network_size: usize,
}

impl Default for ChainConfig {
Expand All @@ -25,6 +27,7 @@ impl Default for ChainConfig {
weak_subjectivity_checkpoint: None,
reconstruct_historic_states: false,
enable_lock_timeouts: true,
max_network_size: 10 * 1_048_576, // 10M
}
}
}
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ pub enum BlockProductionError {
GetPayloadFailed(execution_layer::Error),
FailedToReadFinalizedBlock(store::Error),
MissingFinalizedBlock(Hash256),
BlockTooLarge(usize),
}

easy_from_to!(BlockProcessingError, BlockProductionError);
Expand Down
5 changes: 5 additions & 0 deletions beacon_node/beacon_chain/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ lazy_static! {
"Number of attestations in a block"
);

pub static ref BLOCK_SIZE: Result<Histogram> = try_create_histogram(
"beacon_block_total_size",
"Size of a signed beacon block"
);

/*
* Unaggregated Attestation Verification
*/
Expand Down
2 changes: 2 additions & 0 deletions beacon_node/lighthouse_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub mod rpc;
mod service;
pub mod types;

pub use config::GOSSIP_MAX_SIZE;

use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use std::str::FromStr;

Expand Down
2 changes: 2 additions & 0 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ pub fn get_config<E: EthSpec>(
};
}

client_config.chain.max_network_size = lighthouse_network::GOSSIP_MAX_SIZE;

if cli_args.is_present("slasher") {
let slasher_dir = if let Some(slasher_dir) = cli_args.value_of("slasher-dir") {
PathBuf::from(slasher_dir)
Expand Down

0 comments on commit 2a1e383

Please sign in to comment.