diff --git a/consensus/types/src/core/consts.rs b/consensus/types/src/core/consts.rs index 546875e054..2c67657ee6 100644 --- a/consensus/types/src/core/consts.rs +++ b/consensus/types/src/core/consts.rs @@ -28,4 +28,14 @@ pub mod deneb { pub mod gloas { pub const BUILDER_INDEX_SELF_BUILD: u64 = u64::MAX; pub const BUILDER_INDEX_FLAG: u64 = 1 << 40; + + // Fork choice constants + pub type PayloadStatus = u8; + pub const PAYLOAD_STATUS_PENDING: PayloadStatus = 0; + pub const PAYLOAD_STATUS_EMPTY: PayloadStatus = 1; + pub const PAYLOAD_STATUS_FULL: PayloadStatus = 2; + + pub const ATTESTATION_TIMELINESS_INDEX: usize = 0; + pub const PTC_TIMELINESS_INDEX: usize = 1; + pub const NUM_BLOCK_TIMELINESS_DEADLINES: usize = 2; } diff --git a/consensus/types/src/core/eth_spec.rs b/consensus/types/src/core/eth_spec.rs index 09ef9ce8da..a4b22da3f8 100644 --- a/consensus/types/src/core/eth_spec.rs +++ b/consensus/types/src/core/eth_spec.rs @@ -437,6 +437,11 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq + fn max_builders_per_withdrawals_sweep() -> usize { Self::MaxBuildersPerWithdrawalsSweep::to_usize() } + + /// Returns the `PAYLOAD_TIMELY_THRESHOLD` constant (PTC_SIZE / 2). + fn payload_timely_threshold() -> usize { + Self::PTCSize::to_usize() / 2 + } } /// Macro to inherit some type values from another EthSpec. diff --git a/testing/ef_tests/src/cases/fork_choice.rs b/testing/ef_tests/src/cases/fork_choice.rs index 8e9d438a24..6096b3ccc4 100644 --- a/testing/ef_tests/src/cases/fork_choice.rs +++ b/testing/ef_tests/src/cases/fork_choice.rs @@ -296,6 +296,11 @@ impl Case for ForkChoiceTest { self.description.clone() } + fn is_enabled_for_fork(fork_name: ForkName) -> bool { + // Gloas fork choice not yet implemented + fork_name != ForkName::Gloas + } + fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> { let tester = Tester::new(self, testing_spec::(fork_name))?; diff --git a/testing/ef_tests/src/cases/operations.rs b/testing/ef_tests/src/cases/operations.rs index 86e63ca363..0a01c1a115 100644 --- a/testing/ef_tests/src/cases/operations.rs +++ b/testing/ef_tests/src/cases/operations.rs @@ -8,7 +8,7 @@ use state_processing::common::update_progressive_balances_cache::initialize_prog use state_processing::epoch_cache::initialize_epoch_cache; use state_processing::per_block_processing::process_operations::{ altair_deneb, base, gloas, process_consolidation_requests, process_deposit_requests, - process_withdrawal_requests, + process_payload_attestation, process_withdrawal_requests, }; use state_processing::{ ConsensusContext, @@ -28,7 +28,7 @@ use types::{ Attestation, AttesterSlashing, BeaconBlock, BeaconBlockBody, BeaconBlockBodyBellatrix, BeaconBlockBodyCapella, BeaconBlockBodyDeneb, BeaconBlockBodyElectra, BeaconBlockBodyFulu, BeaconState, BlindedPayload, ConsolidationRequest, Deposit, DepositRequest, ExecutionPayload, - ForkVersionDecode, FullPayload, ProposerSlashing, SignedBlsToExecutionChange, + ForkVersionDecode, FullPayload, PayloadAttestation, ProposerSlashing, SignedBlsToExecutionChange, SignedVoluntaryExit, SyncAggregate, WithdrawalRequest, }; @@ -545,6 +545,32 @@ impl Operation for ConsolidationRequest { } } +impl Operation for PayloadAttestation { + fn handler_name() -> String { + "payload_attestation".into() + } + + fn is_enabled_for_fork(fork_name: ForkName) -> bool { + fork_name.gloas_enabled() + } + + fn decode(path: &Path, _fork_name: ForkName, _spec: &ChainSpec) -> Result { + ssz_decode_file(path) + } + + fn apply_to( + &self, + state: &mut BeaconState, + spec: &ChainSpec, + _extra: &Operations, + ) -> Result<(), BlockProcessingError> { + initialize_epoch_cache(state, spec)?; + initialize_progressive_balances_cache(state, spec)?; + let mut ctxt = ConsensusContext::new(state.slot()); + process_payload_attestation(state, self, 0, VerifySignatures::True, &mut ctxt, spec) + } +} + impl> LoadCase for Operations { fn load_from_dir(path: &Path, fork_name: ForkName) -> Result { let spec = &testing_spec::(fork_name); diff --git a/testing/ef_tests/tests/tests.rs b/testing/ef_tests/tests/tests.rs index 7d6c1b8c31..1d5de6981e 100644 --- a/testing/ef_tests/tests/tests.rs +++ b/testing/ef_tests/tests/tests.rs @@ -118,6 +118,12 @@ fn operations_bls_to_execution_change() { OperationsHandler::::default().run(); } +#[test] +fn operations_payload_attestation() { + OperationsHandler::>::default().run(); + OperationsHandler::>::default().run(); +} + #[test] fn sanity_blocks() { SanityBlocksHandler::::default().run();