From ed9643b8462e985422e78aeb8095f1b375eebbe5 Mon Sep 17 00:00:00 2001 From: pscott <30843220+pscott@users.noreply.github.com> Date: Thu, 12 Dec 2019 07:05:07 +0100 Subject: [PATCH] Add maximum slot limit when processing blocks (#668) * Add maximum slot limit when processing blocks * Fix clippy warning * Update comments * Change MAXIMUM_BLOCK_SLOT_NUMBER to 2^32 * Update graffiti versioning --- beacon_node/beacon_chain/src/beacon_chain.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index b5ed74e19..8b0e879aa 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -39,7 +39,7 @@ use types::*; // Must be 32-bytes or panic. // // |-------must be this long------| -pub const GRAFFITI: &str = "sigp/lighthouse-0.0.0-prerelease"; +pub const GRAFFITI: &str = "sigp/lighthouse-0.1.0-prerelease"; /// If true, everytime a block is processed the pre-state, post-state and block are written to SSZ /// files in the temp directory. @@ -47,6 +47,9 @@ pub const GRAFFITI: &str = "sigp/lighthouse-0.0.0-prerelease"; /// Only useful for testing. const WRITE_BLOCK_PROCESSING_SSZ: bool = cfg!(feature = "write_ssz_files"); +/// Maximum block slot number. Block with slots bigger than this constant will NOT be processed. +const MAXIMUM_BLOCK_SLOT_NUMBER: u64 = 4_294_967_296; // 2^32 + #[derive(Debug, PartialEq)] pub enum BlockProcessingOutcome { /// Block was valid and imported into the block graph. @@ -69,6 +72,8 @@ pub enum BlockProcessingOutcome { }, /// Block is already known, no need to re-import. BlockIsAlreadyKnown, + /// The block slot exceeds the MAXIMUM_BLOCK_SLOT_NUMBER. + BlockSlotLimitReached, /// The block could not be applied to the state, it is invalid. PerBlockProcessingError(BlockProcessingError), } @@ -1174,6 +1179,10 @@ impl BeaconChain { return Ok(BlockProcessingOutcome::GenesisBlock); } + if block.slot >= MAXIMUM_BLOCK_SLOT_NUMBER { + return Ok(BlockProcessingOutcome::BlockSlotLimitReached); + } + if block.slot <= finalized_slot { return Ok(BlockProcessingOutcome::WouldRevertFinalizedSlot { block_slot: block.slot,