Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fully validate a block before publishing #4168

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
09ba87c
fully validate a block before publishing
realbigsean Apr 5, 2023
23c804e
remove error on publish
realbigsean Apr 5, 2023
7ce5ad5
Revert "remove error on publish"
realbigsean Apr 5, 2023
2625007
publish block prior to payload verification and fork choice
realbigsean Apr 5, 2023
5cbdd5f
don't publish blocks that are slashable
realbigsean Apr 5, 2023
771abe7
get beacon chain tests compiling
realbigsean Apr 5, 2023
2394c97
use observed proposals cache
realbigsean Apr 5, 2023
0531088
update observed proposals cache to report slashability correctly
realbigsean Apr 5, 2023
8f38805
improve logging
realbigsean Apr 6, 2023
451288e
fix compile
realbigsean Apr 6, 2023
1a3afdb
consolidate block proposal caches
realbigsean Apr 7, 2023
1da556e
Use head state for exit verification
paulhauner Apr 12, 2023
db6ace5
Empty commit
paulhauner Apr 12, 2023
35d8c98
Bump versions
paulhauner Apr 12, 2023
12c1b46
Merge branch 'hotfix-exit-verification' of https://github.com/sigp/li…
realbigsean Apr 13, 2023
01431d4
Merge branch 'stable' of https://github.com/sigp/lighthouse into ligh…
realbigsean Apr 24, 2023
93837e3
Merge branch 'unstable' of https://github.com/sigp/lighthouse into li…
realbigsean Apr 24, 2023
746b4ef
add publish delay to logs for lighthouse relay
realbigsean Apr 24, 2023
5ae9ec9
remove 202 errors
realbigsean Apr 28, 2023
00cd8da
return 200 on non-slashable duplicates
realbigsean Apr 28, 2023
3cb19e8
Merge branch 'stable' of https://github.com/sigp/lighthouse into ligh…
realbigsean May 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
signature_verified_block,
count_unrealized,
notify_execution_layer,
|| Ok(()),
)
.await
{
Expand Down Expand Up @@ -2670,6 +2671,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
unverified_block: B,
count_unrealized: CountUnrealized,
notify_execution_layer: NotifyExecutionLayer,
publish_fn: impl FnOnce() -> Result<(), BlockError<T::EthSpec>> + Send + 'static,
) -> Result<Hash256, BlockError<T::EthSpec>> {
// Start the Prometheus timer.
let _full_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_TIMES);
Expand All @@ -2688,6 +2690,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&chain,
notify_execution_layer,
)?;
publish_fn()?;
chain
.import_execution_pending_block(execution_pending, count_unrealized)
.await
Expand Down
44 changes: 36 additions & 8 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ pub enum BlockError<T: EthSpec> {
/// its parent.
ParentUnknown(Arc<SignedBeaconBlock<T>>),
/// The block skips too many slots and is a DoS risk.
TooManySkippedSlots { parent_slot: Slot, block_slot: Slot },
TooManySkippedSlots {
parent_slot: Slot,
block_slot: Slot,
},
/// The block slot is greater than the present slot.
///
/// ## Peer scoring
Expand All @@ -157,7 +160,10 @@ pub enum BlockError<T: EthSpec> {
/// ## Peer scoring
///
/// The peer has incompatible state transition logic and is faulty.
StateRootMismatch { block: Hash256, local: Hash256 },
StateRootMismatch {
block: Hash256,
local: Hash256,
},
/// The block was a genesis block, these blocks cannot be re-imported.
GenesisBlock,
/// The slot is finalized, no need to import.
Expand All @@ -176,7 +182,9 @@ pub enum BlockError<T: EthSpec> {
///
/// It's unclear if this block is valid, but it conflicts with finality and shouldn't be
/// imported.
NotFinalizedDescendant { block_parent_root: Hash256 },
NotFinalizedDescendant {
block_parent_root: Hash256,
},
/// Block is already known, no need to re-import.
///
/// ## Peer scoring
Expand All @@ -189,7 +197,10 @@ pub enum BlockError<T: EthSpec> {
///
/// The `proposer` has already proposed a block at this slot. The existing block may or may not
/// be equal to the given block.
RepeatProposal { proposer: u64, slot: Slot },
RepeatProposal {
proposer: u64,
slot: Slot,
},
/// The block slot exceeds the MAXIMUM_BLOCK_SLOT_NUMBER.
///
/// ## Peer scoring
Expand All @@ -204,7 +215,10 @@ pub enum BlockError<T: EthSpec> {
/// ## Peer scoring
///
/// The block is invalid and the peer is faulty.
IncorrectBlockProposer { block: u64, local_shuffling: u64 },
IncorrectBlockProposer {
block: u64,
local_shuffling: u64,
},
/// The proposal signature in invalid.
///
/// ## Peer scoring
Expand All @@ -228,7 +242,10 @@ pub enum BlockError<T: EthSpec> {
/// ## Peer scoring
///
/// The block is invalid and the peer is faulty.
BlockIsNotLaterThanParent { block_slot: Slot, parent_slot: Slot },
BlockIsNotLaterThanParent {
block_slot: Slot,
parent_slot: Slot,
},
/// At least one block in the chain segment did not have it's parent root set to the root of
/// the prior block.
///
Expand Down Expand Up @@ -284,7 +301,11 @@ pub enum BlockError<T: EthSpec> {
/// If it's actually our fault (e.g. our execution node database is corrupt) we have bigger
/// problems to worry about than losing peers, and we're doing the network a favour by
/// disconnecting.
ParentExecutionPayloadInvalid { parent_root: Hash256 },
ParentExecutionPayloadInvalid {
parent_root: Hash256,
},
PublishError,
SlashablePublish,
}

/// Returned when block validation failed due to some issue verifying
Expand Down Expand Up @@ -863,8 +884,9 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
if chain
.observed_block_producers
.write()
.observe_proposer(block.message())
.observe_proposal(block_root, block.message())
.map_err(|e| BlockError::BeaconChainError(e.into()))?
.proposer_previously_observed()
{
return Err(BlockError::RepeatProposal {
proposer: block.message().proposer_index(),
Expand Down Expand Up @@ -1109,6 +1131,12 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
chain: &Arc<BeaconChain<T>>,
notify_execution_layer: NotifyExecutionLayer,
) -> Result<Self, BlockError<T::EthSpec>> {
chain
.observed_block_producers
.write()
.observe_proposal(block_root, block.message())
.map_err(|e| BlockError::BeaconChainError(e.into()))?;

if let Some(parent) = chain
.canonical_head
.fork_choice_read_lock()
Expand Down
1 change: 0 additions & 1 deletion beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ where
observed_sync_aggregators: <_>::default(),
// TODO: allow for persisting and loading the pool from disk.
observed_block_producers: <_>::default(),
// TODO: allow for persisting and loading the pool from disk.
observed_voluntary_exits: <_>::default(),
observed_proposer_slashings: <_>::default(),
observed_attester_slashings: <_>::default(),
Expand Down
Loading