From 7527c2b455423ae59248133738b179fe08922a62 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Tue, 4 Oct 2022 14:57:29 -0400 Subject: [PATCH] fix RPC limit add blob signing domain --- .../beacon_chain/src/block_verification.rs | 33 ++++--------------- .../lighthouse_network/src/rpc/protocol.rs | 12 ++++++- .../network/src/beacon_processor/mod.rs | 2 -- consensus/types/src/blobs_sidecar.rs | 4 +-- consensus/types/src/chain_spec.rs | 7 +++- consensus/types/src/config_and_preset.rs | 1 + consensus/types/src/lib.rs | 4 ++- 7 files changed, 30 insertions(+), 33 deletions(-) diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index 3a578b63a..f83bc535d 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -134,10 +134,7 @@ pub enum BlockError { /// its parent. ParentUnknown(Arc>), /// 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 @@ -152,10 +149,7 @@ pub enum BlockError { /// ## 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. @@ -174,9 +168,7 @@ pub enum BlockError { /// /// 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 @@ -189,10 +181,7 @@ pub enum BlockError { /// /// 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 @@ -207,10 +196,7 @@ pub enum BlockError { /// ## 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 @@ -234,10 +220,7 @@ pub enum BlockError { /// ## 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. /// @@ -293,9 +276,7 @@ pub enum BlockError { /// /// The peer sent us an invalid block, but I'm not really sure how to score this in an /// "optimistic" sync world. - ParentExecutionPayloadInvalid { - parent_root: Hash256, - }, + ParentExecutionPayloadInvalid { parent_root: Hash256 }, } /// Returned when block validation failed due to some issue verifying diff --git a/beacon_node/lighthouse_network/src/rpc/protocol.rs b/beacon_node/lighthouse_network/src/rpc/protocol.rs index c0c8e83ea..3840aa3ba 100644 --- a/beacon_node/lighthouse_network/src/rpc/protocol.rs +++ b/beacon_node/lighthouse_network/src/rpc/protocol.rs @@ -20,8 +20,10 @@ use tokio_util::{ codec::Framed, compat::{Compat, FuturesAsyncReadCompatExt}, }; +use types::BlobsSidecar; +use types::SignedBlobsSidecar; use types::{ - BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockMerge, EthSpec, ForkContext, + BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockMerge, Blob, EthSpec, ForkContext, ForkName, Hash256, MainnetEthSpec, Signature, SignedBeaconBlock, }; @@ -98,6 +100,14 @@ lazy_static! { .as_ssz_bytes() .len(); + pub static ref SIGNED_BLOBS_SIDECAR_MIN: usize = SignedBlobsSidecar { + message: BlobsSidecar::::empty(), + signature: Signature::empty(), + }.as_ssz_bytes() + .len(); + + pub static ref SIGNED_BLOBS_SIDECAR_MAX: usize = *SIGNED_BLOBS_SIDECAR_MIN // Max size of variable length `blobs` field + + (MainnetEthSpec::max_blobs_per_block() * as Encode>::ssz_fixed_len()); } /// The maximum bytes that can be sent across the RPC pre-merge. diff --git a/beacon_node/network/src/beacon_processor/mod.rs b/beacon_node/network/src/beacon_processor/mod.rs index 9d42db449..7d7f6602e 100644 --- a/beacon_node/network/src/beacon_processor/mod.rs +++ b/beacon_node/network/src/beacon_processor/mod.rs @@ -1182,8 +1182,6 @@ impl BeaconProcessor { self.spawn_worker(item, toolbox); } else if let Some(item) = bbrange_queue.pop() { self.spawn_worker(item, toolbox); - } else if let Some(item) = txbbrange_queue.pop() { - self.spawn_worker(item, toolbox); } else if let Some(item) = bbroots_queue.pop() { self.spawn_worker(item, toolbox); // Check slashings after all other consensus messages so we prioritize diff --git a/consensus/types/src/blobs_sidecar.rs b/consensus/types/src/blobs_sidecar.rs index f00d457af..75100a041 100644 --- a/consensus/types/src/blobs_sidecar.rs +++ b/consensus/types/src/blobs_sidecar.rs @@ -12,7 +12,7 @@ use tree_hash_derive::TreeHash; pub struct BlobsSidecar { pub beacon_block_root: Hash256, pub beacon_block_slot: Slot, - pub blobs: VariableList, E::MaxBlobsPerBlock>, + pub blobs: VariableList, E::MaxBlobsPerBlock>, pub kzg_aggregate_proof: KzgProof, } @@ -24,6 +24,6 @@ impl BlobsSidecar { // Fixed part Self::empty().as_ssz_bytes().len() // Max size of variable length `blobs` field - + (E::max_blobs_per_block() * as Encode>::ssz_fixed_len()) + + (E::max_blobs_per_block() * as Encode>::ssz_fixed_len()) } } diff --git a/consensus/types/src/chain_spec.rs b/consensus/types/src/chain_spec.rs index 279a449e5..aa477b22e 100644 --- a/consensus/types/src/chain_spec.rs +++ b/consensus/types/src/chain_spec.rs @@ -13,6 +13,7 @@ use tree_hash::TreeHash; pub enum Domain { BeaconProposer, BeaconAttester, + BlobsSideCar, Randao, Deposit, VoluntaryExit, @@ -22,7 +23,6 @@ pub enum Domain { ContributionAndProof, SyncCommitteeSelectionProof, ApplicationMask(ApplicationDomain), - BlobsSideCar, } /// Lighthouse's internal configuration struct. @@ -99,6 +99,7 @@ pub struct ChainSpec { */ pub(crate) domain_beacon_proposer: u32, pub(crate) domain_beacon_attester: u32, + pub(crate) domain_blobs_sidecar: u32, pub(crate) domain_randao: u32, pub(crate) domain_deposit: u32, pub(crate) domain_voluntary_exit: u32, @@ -340,6 +341,7 @@ impl ChainSpec { match domain { Domain::BeaconProposer => self.domain_beacon_proposer, Domain::BeaconAttester => self.domain_beacon_attester, + Domain::BlobsSideCar => self.domain_blobs_sidecar, Domain::Randao => self.domain_randao, Domain::Deposit => self.domain_deposit, Domain::VoluntaryExit => self.domain_voluntary_exit, @@ -529,6 +531,7 @@ impl ChainSpec { domain_voluntary_exit: 4, domain_selection_proof: 5, domain_aggregate_and_proof: 6, + domain_blobs_sidecar: 10, // 0x0a000000 /* * Fork choice @@ -743,6 +746,7 @@ impl ChainSpec { domain_voluntary_exit: 4, domain_selection_proof: 5, domain_aggregate_and_proof: 6, + domain_blobs_sidecar: 10, /* * Fork choice @@ -1181,6 +1185,7 @@ mod tests { test_domain(Domain::BeaconProposer, spec.domain_beacon_proposer, &spec); test_domain(Domain::BeaconAttester, spec.domain_beacon_attester, &spec); + test_domain(Domain::BlobsSideCar, spec.domain_blobs_sidecar, &spec); test_domain(Domain::Randao, spec.domain_randao, &spec); test_domain(Domain::Deposit, spec.domain_deposit, &spec); test_domain(Domain::VoluntaryExit, spec.domain_voluntary_exit, &spec); diff --git a/consensus/types/src/config_and_preset.rs b/consensus/types/src/config_and_preset.rs index e624afe2d..74b07717a 100644 --- a/consensus/types/src/config_and_preset.rs +++ b/consensus/types/src/config_and_preset.rs @@ -72,6 +72,7 @@ pub fn get_extra_fields(spec: &ChainSpec) -> HashMap { "bls_withdrawal_prefix".to_uppercase() => u8_hex(spec.bls_withdrawal_prefix_byte), "domain_beacon_proposer".to_uppercase() => u32_hex(spec.domain_beacon_proposer), "domain_beacon_attester".to_uppercase() => u32_hex(spec.domain_beacon_attester), + "domain_blobs_sidecar".to_uppercase() => u32_hex(spec.domain_blobs_sidecar), "domain_randao".to_uppercase()=> u32_hex(spec.domain_randao), "domain_deposit".to_uppercase()=> u32_hex(spec.domain_deposit), "domain_voluntary_exit".to_uppercase() => u32_hex(spec.domain_voluntary_exit), diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index be63c43c5..4bb383dfb 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -157,6 +157,7 @@ pub use crate::signed_beacon_block::{ SignedBeaconBlockHash, SignedBeaconBlockMerge, SignedBlindedBeaconBlock, }; pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader; +pub use crate::signed_blobs_sidecar::SignedBlobsSidecar; pub use crate::signed_contribution_and_proof::SignedContributionAndProof; pub use crate::signed_voluntary_exit::SignedVoluntaryExit; pub use crate::signing_data::{SignedRoot, SigningData}; @@ -183,7 +184,8 @@ pub type Uint256 = ethereum_types::U256; pub type Address = H160; pub type ForkVersion = [u8; 4]; pub type BLSFieldElement = Uint256; -pub type Blob = FixedVector; +pub type Blob = FixedVector::FieldElementsPerBlob>; +pub type Polynomial = VariableList::FieldElementsPerBlob>; pub use bls::{ AggregatePublicKey, AggregateSignature, Keypair, PublicKey, PublicKeyBytes, SecretKey,