mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-09 03:17:55 +00:00
Merge branch 'gloas-serve-envelope-rpc' into epbs-devnet-0
This commit is contained in:
@@ -15,8 +15,11 @@ use tree_hash_derive::TreeHash;
|
||||
use typenum::Unsigned;
|
||||
|
||||
use crate::{
|
||||
SignedExecutionPayloadBid,
|
||||
attestation::{AttestationBase, AttestationData, IndexedAttestationBase},
|
||||
Address, SignedBlsToExecutionChange, SignedExecutionPayloadBid,
|
||||
attestation::{
|
||||
AttestationBase, AttestationData, AttestationElectra, IndexedAttestationBase,
|
||||
IndexedAttestationElectra, PayloadAttestation, PayloadAttestationData,
|
||||
},
|
||||
block::{
|
||||
BeaconBlockBodyAltair, BeaconBlockBodyBase, BeaconBlockBodyBellatrix,
|
||||
BeaconBlockBodyCapella, BeaconBlockBodyDeneb, BeaconBlockBodyElectra, BeaconBlockBodyFulu,
|
||||
@@ -26,12 +29,12 @@ use crate::{
|
||||
core::{ChainSpec, Domain, Epoch, EthSpec, Graffiti, Hash256, SignedRoot, Slot},
|
||||
deposit::{Deposit, DepositData},
|
||||
execution::{
|
||||
AbstractExecPayload, BlindedPayload, Eth1Data, ExecutionPayload, ExecutionRequests,
|
||||
FullPayload,
|
||||
AbstractExecPayload, BlindedPayload, BlsToExecutionChange, Eth1Data, ExecutionPayload,
|
||||
ExecutionRequests, FullPayload,
|
||||
},
|
||||
exit::{SignedVoluntaryExit, VoluntaryExit},
|
||||
fork::{Fork, ForkName, InconsistentFork, map_fork_name},
|
||||
slashing::{AttesterSlashingBase, ProposerSlashing},
|
||||
slashing::{AttesterSlashingBase, AttesterSlashingElectra, ProposerSlashing},
|
||||
state::BeaconStateError,
|
||||
sync_committee::SyncAggregate,
|
||||
test_utils::TestRandom,
|
||||
@@ -724,6 +727,135 @@ impl<E: EthSpec, Payload: AbstractExecPayload<E>> EmptyBlock for BeaconBlockGloa
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockGloas<E, Payload> {
|
||||
/// Returns a full Gloas block with all variable-length fields at max capacity.
|
||||
/// Used for computing the maximum SSZ-encoded size.
|
||||
pub fn full(spec: &ChainSpec) -> Self {
|
||||
let header = BeaconBlockHeader {
|
||||
slot: Slot::new(1),
|
||||
proposer_index: 0,
|
||||
parent_root: Hash256::zero(),
|
||||
state_root: Hash256::zero(),
|
||||
body_root: Hash256::zero(),
|
||||
};
|
||||
|
||||
let signed_header = SignedBeaconBlockHeader {
|
||||
message: header,
|
||||
signature: Signature::empty(),
|
||||
};
|
||||
|
||||
let indexed_attestation = IndexedAttestationElectra {
|
||||
attesting_indices: VariableList::new(vec![0_u64; E::MaxValidatorsPerSlot::to_usize()])
|
||||
.unwrap(),
|
||||
data: AttestationData::default(),
|
||||
signature: AggregateSignature::empty(),
|
||||
};
|
||||
|
||||
let proposer_slashing = ProposerSlashing {
|
||||
signed_header_1: signed_header.clone(),
|
||||
signed_header_2: signed_header,
|
||||
};
|
||||
|
||||
let attester_slashing = AttesterSlashingElectra {
|
||||
attestation_1: indexed_attestation.clone(),
|
||||
attestation_2: indexed_attestation,
|
||||
};
|
||||
|
||||
let attestation = AttestationElectra {
|
||||
aggregation_bits: BitList::with_capacity(E::MaxValidatorsPerSlot::to_usize()).unwrap(),
|
||||
data: AttestationData::default(),
|
||||
signature: AggregateSignature::empty(),
|
||||
committee_bits: BitVector::default(),
|
||||
};
|
||||
|
||||
let deposit_data = DepositData {
|
||||
pubkey: PublicKeyBytes::empty(),
|
||||
withdrawal_credentials: Hash256::zero(),
|
||||
amount: 0,
|
||||
signature: SignatureBytes::empty(),
|
||||
};
|
||||
|
||||
let deposit = Deposit {
|
||||
proof: FixedVector::from_elem(Hash256::zero()),
|
||||
data: deposit_data,
|
||||
};
|
||||
|
||||
let signed_voluntary_exit = SignedVoluntaryExit {
|
||||
message: VoluntaryExit {
|
||||
epoch: Epoch::new(1),
|
||||
validator_index: 1,
|
||||
},
|
||||
signature: Signature::empty(),
|
||||
};
|
||||
|
||||
let signed_bls_to_execution_change = SignedBlsToExecutionChange {
|
||||
message: BlsToExecutionChange {
|
||||
validator_index: 0,
|
||||
from_bls_pubkey: PublicKeyBytes::empty(),
|
||||
to_execution_address: Address::zero(),
|
||||
},
|
||||
signature: Signature::empty(),
|
||||
};
|
||||
|
||||
let payload_attestation = PayloadAttestation {
|
||||
aggregation_bits: BitVector::default(),
|
||||
data: PayloadAttestationData {
|
||||
beacon_block_root: Hash256::zero(),
|
||||
slot: Slot::new(0),
|
||||
payload_present: false,
|
||||
blob_data_available: false,
|
||||
},
|
||||
signature: AggregateSignature::empty(),
|
||||
};
|
||||
|
||||
let mut block = BeaconBlockGloas::<E, Payload>::empty(spec);
|
||||
|
||||
for _ in 0..E::MaxProposerSlashings::to_usize() {
|
||||
block
|
||||
.body
|
||||
.proposer_slashings
|
||||
.push(proposer_slashing.clone())
|
||||
.unwrap();
|
||||
}
|
||||
for _ in 0..E::max_attester_slashings_electra() {
|
||||
block
|
||||
.body
|
||||
.attester_slashings
|
||||
.push(attester_slashing.clone())
|
||||
.unwrap();
|
||||
}
|
||||
for _ in 0..E::max_attestations_electra() {
|
||||
block.body.attestations.push(attestation.clone()).unwrap();
|
||||
}
|
||||
for _ in 0..E::MaxDeposits::to_usize() {
|
||||
block.body.deposits.push(deposit.clone()).unwrap();
|
||||
}
|
||||
for _ in 0..E::MaxVoluntaryExits::to_usize() {
|
||||
block
|
||||
.body
|
||||
.voluntary_exits
|
||||
.push(signed_voluntary_exit.clone())
|
||||
.unwrap();
|
||||
}
|
||||
for _ in 0..E::MaxBlsToExecutionChanges::to_usize() {
|
||||
block
|
||||
.body
|
||||
.bls_to_execution_changes
|
||||
.push(signed_bls_to_execution_change.clone())
|
||||
.unwrap();
|
||||
}
|
||||
for _ in 0..E::MaxPayloadAttestations::to_usize() {
|
||||
block
|
||||
.body
|
||||
.payload_attestations
|
||||
.push(payload_attestation.clone())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
block
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(EIP-7732) Mark's branch had the following implementation but not sure if it's needed so will just add header below for reference
|
||||
// impl<E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockEIP7732<E, Payload> {
|
||||
|
||||
|
||||
@@ -295,6 +295,7 @@ pub struct ChainSpec {
|
||||
/*
|
||||
* Networking Gloas
|
||||
*/
|
||||
pub max_request_payloads: u64,
|
||||
|
||||
/*
|
||||
* Networking Derived
|
||||
@@ -305,6 +306,7 @@ pub struct ChainSpec {
|
||||
pub max_blocks_by_root_request_deneb: usize,
|
||||
pub max_blobs_by_root_request: usize,
|
||||
pub max_data_columns_by_root_request: usize,
|
||||
pub max_payload_envelopes_by_root_request: usize,
|
||||
|
||||
/*
|
||||
* Application params
|
||||
@@ -700,6 +702,10 @@ impl ChainSpec {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max_request_payloads(&self) -> usize {
|
||||
self.max_request_payloads as usize
|
||||
}
|
||||
|
||||
pub fn max_request_blob_sidecars(&self, fork_name: ForkName) -> usize {
|
||||
if fork_name.electra_enabled() {
|
||||
self.max_request_blob_sidecars_electra as usize
|
||||
@@ -964,6 +970,8 @@ impl ChainSpec {
|
||||
max_blobs_by_root_request_common(self.max_request_blob_sidecars);
|
||||
self.max_data_columns_by_root_request =
|
||||
max_data_columns_by_root_request_common::<E>(self.max_request_blocks_deneb);
|
||||
self.max_payload_envelopes_by_root_request =
|
||||
max_blocks_by_root_request_common(self.max_request_payloads);
|
||||
|
||||
self
|
||||
}
|
||||
@@ -1228,6 +1236,7 @@ impl ChainSpec {
|
||||
builder_payment_threshold_numerator: 6,
|
||||
builder_payment_threshold_denominator: 10,
|
||||
min_builder_withdrawability_delay: Epoch::new(4096),
|
||||
max_request_payloads: 128,
|
||||
|
||||
/*
|
||||
* Network specific
|
||||
@@ -1293,6 +1302,7 @@ impl ChainSpec {
|
||||
min_epochs_for_data_column_sidecars_requests:
|
||||
default_min_epochs_for_data_column_sidecars_requests(),
|
||||
max_data_columns_by_root_request: default_data_columns_by_root_request(),
|
||||
max_payload_envelopes_by_root_request: default_max_payload_envelopes_by_root_request(),
|
||||
|
||||
/*
|
||||
* Application specific
|
||||
@@ -1622,6 +1632,7 @@ impl ChainSpec {
|
||||
builder_payment_threshold_numerator: 6,
|
||||
builder_payment_threshold_denominator: 10,
|
||||
min_builder_withdrawability_delay: Epoch::new(4096),
|
||||
max_request_payloads: 128,
|
||||
|
||||
/*
|
||||
* Network specific
|
||||
@@ -1678,6 +1689,7 @@ impl ChainSpec {
|
||||
min_epochs_for_data_column_sidecars_requests:
|
||||
default_min_epochs_for_data_column_sidecars_requests(),
|
||||
max_data_columns_by_root_request: default_data_columns_by_root_request(),
|
||||
max_payload_envelopes_by_root_request: default_max_payload_envelopes_by_root_request(),
|
||||
|
||||
/*
|
||||
* Application specific
|
||||
@@ -2342,6 +2354,14 @@ fn default_data_columns_by_root_request() -> usize {
|
||||
max_data_columns_by_root_request_common::<MainnetEthSpec>(default_max_request_blocks_deneb())
|
||||
}
|
||||
|
||||
fn default_max_payload_envelopes_by_root_request() -> usize {
|
||||
max_blocks_by_root_request_common(default_max_request_payloads())
|
||||
}
|
||||
|
||||
fn default_max_request_payloads() -> u64 {
|
||||
128
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
let chain_spec = MainnetEthSpec::default_spec();
|
||||
|
||||
@@ -8,7 +8,9 @@ use ssz_derive::{Decode, Encode};
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Encode, Decode, Deserialize, TestRandom, TreeHash, Educe)]
|
||||
#[derive(
|
||||
Debug, Default, Clone, Serialize, Encode, Decode, Deserialize, TestRandom, TreeHash, Educe,
|
||||
)]
|
||||
#[educe(PartialEq, Hash(bound(E: EthSpec)))]
|
||||
#[context_deserialize(ForkName)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
|
||||
@@ -8,6 +8,7 @@ use bls::{PublicKey, Signature};
|
||||
use context_deserialize::context_deserialize;
|
||||
use educe::Educe;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::{BYTES_PER_LENGTH_OFFSET, Encode as SszEncode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash_derive::TreeHash;
|
||||
@@ -22,6 +23,36 @@ pub struct SignedExecutionPayloadEnvelope<E: EthSpec> {
|
||||
}
|
||||
|
||||
impl<E: EthSpec> SignedExecutionPayloadEnvelope<E> {
|
||||
/// Returns the minimum SSZ-encoded size (all variable-length fields empty).
|
||||
pub fn min_size() -> usize {
|
||||
Self {
|
||||
message: ExecutionPayloadEnvelope::default(),
|
||||
signature: Signature::empty(),
|
||||
}
|
||||
.as_ssz_bytes()
|
||||
.len()
|
||||
}
|
||||
|
||||
/// Returns the maximum SSZ-encoded size.
|
||||
#[allow(clippy::arithmetic_side_effects)]
|
||||
pub fn max_size() -> usize {
|
||||
// Start from the min size (all variable-length fields empty)
|
||||
Self::min_size()
|
||||
// ExecutionPayloadGloas variable-length fields:
|
||||
+ (E::max_extra_data_bytes() * <u8 as SszEncode>::ssz_fixed_len())
|
||||
+ (E::max_transactions_per_payload()
|
||||
* (BYTES_PER_LENGTH_OFFSET + E::max_bytes_per_transaction()))
|
||||
+ (E::max_withdrawals_per_payload()
|
||||
* <crate::Withdrawal as SszEncode>::ssz_fixed_len())
|
||||
// ExecutionRequests variable-length fields:
|
||||
+ (E::max_deposit_requests_per_payload()
|
||||
* <crate::DepositRequest as SszEncode>::ssz_fixed_len())
|
||||
+ (E::max_withdrawal_requests_per_payload()
|
||||
* <crate::WithdrawalRequest as SszEncode>::ssz_fixed_len())
|
||||
+ (E::max_consolidation_requests_per_payload()
|
||||
* <crate::ConsolidationRequest as SszEncode>::ssz_fixed_len())
|
||||
}
|
||||
|
||||
pub fn slot(&self) -> Slot {
|
||||
self.message.slot
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user