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
This commit is contained in:
parent
4eba26572b
commit
ed9643b846
@ -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<T: BeaconChainTypes> BeaconChain<T> {
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user