Skip to content

Commit c9a10c8

Browse files
committed
per_slot_processing modified
1 parent 7a87982 commit c9a10c8

File tree

5 files changed

+33
-11
lines changed

5 files changed

+33
-11
lines changed

consensus/state_processing/src/per_epoch_processing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod capella;
1818
pub mod effective_balance_updates;
1919
pub mod epoch_processing_summary;
2020
pub mod errors;
21+
pub mod gloas;
2122
pub mod historical_roots_update;
2223
pub mod justification_and_finalization_state;
2324
pub mod registry_updates;

consensus/state_processing/src/per_epoch_processing/altair.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ use crate::epoch_cache::initialize_epoch_cache;
66
use crate::per_epoch_processing::single_pass::{SinglePassConfig, process_epoch_single_pass};
77
use crate::per_epoch_processing::{
88
capella::process_historical_summaries_update,
9+
gloas::process_builder_pending_payments,
910
historical_roots_update::process_historical_roots_update,
1011
resets::{process_eth1_data_reset, process_randao_mixes_reset, process_slashings_reset},
1112
};
1213
pub use inactivity_updates::process_inactivity_updates_slow;
1314
pub use justification_and_finalization::process_justification_and_finalization;
1415
pub use participation_flag_updates::process_participation_flag_updates;
15-
pub use process_builder_pending_payments::process_builder_pending_payments;
1616
pub use rewards_and_penalties::process_rewards_and_penalties_slow;
1717
pub use sync_committee_updates::process_sync_committee_updates;
1818
use types::{BeaconState, ChainSpec, EthSpec, RelativeEpoch};
1919

2020
pub mod inactivity_updates;
2121
pub mod justification_and_finalization;
2222
pub mod participation_flag_updates;
23-
pub mod process_builder_pending_payments;
2423
pub mod rewards_and_penalties;
2524
pub mod sync_committee_updates;
2625

@@ -79,7 +78,7 @@ pub fn process_epoch<E: EthSpec>(
7978

8079
process_sync_committee_updates(state, spec)?;
8180

82-
if state.fork_name_unchecked().gloas_enabled() {
81+
if state.builder_pending_payments().is_ok() {
8382
process_builder_pending_payments(state, spec)?;
8483
}
8584

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub use process_builder_pending_payments::process_builder_pending_payments;
2+
3+
mod process_builder_pending_payments;
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use super::Error;
1+
use crate::EpochProcessingError;
22
use safe_arith::SafeArith;
33
use types::{BeaconState, BuilderPendingPayment, ChainSpec, EthSpec, Vector};
44

55
pub fn process_builder_pending_payments<E: EthSpec>(
66
state: &mut BeaconState<E>,
77
spec: &ChainSpec,
8-
) -> Result<(), Error> {
8+
) -> Result<(), EpochProcessingError> {
99
let quorum = get_builder_payment_quorum_threshold(state, spec)?;
1010

1111
// Collect qualifying payments
@@ -18,9 +18,8 @@ pub fn process_builder_pending_payments<E: EthSpec>(
1818
.collect::<Vec<_>>();
1919

2020
// Update `builder_pending_withdrawals` with qualifying `builder_pending_payments`
21-
qualifying_payments
22-
.into_iter()
23-
.try_for_each(|payment| -> Result<(), Error> {
21+
qualifying_payments.into_iter().try_for_each(
22+
|payment| -> Result<(), EpochProcessingError> {
2423
let exit_queue_epoch =
2524
state.compute_exit_epoch_and_update_churn(payment.withdrawal.amount, spec)?;
2625
let withdrawable_epoch =
@@ -30,7 +29,8 @@ pub fn process_builder_pending_payments<E: EthSpec>(
3029
withdrawal.withdrawable_epoch = withdrawable_epoch;
3130
state.builder_pending_withdrawals_mut()?.push(withdrawal)?;
3231
Ok(())
33-
})?;
32+
},
33+
)?;
3434

3535
// Move remaining `builder_pending_payments` to start of list and set the rest to default
3636
let new_payments = state
@@ -49,7 +49,7 @@ pub fn process_builder_pending_payments<E: EthSpec>(
4949
pub fn get_builder_payment_quorum_threshold<E: EthSpec>(
5050
state: &BeaconState<E>,
5151
spec: &ChainSpec,
52-
) -> Result<u64, Error> {
52+
) -> Result<u64, EpochProcessingError> {
5353
let total_active_balance = state.get_total_active_balance()?;
5454

5555
let quorum = total_active_balance
@@ -58,5 +58,5 @@ pub fn get_builder_payment_quorum_threshold<E: EthSpec>(
5858

5959
quorum
6060
.safe_div(spec.builder_payment_threshold_denominator)
61-
.map_err(Error::from)
61+
.map_err(EpochProcessingError::from)
6262
}

consensus/state_processing/src/per_slot_processing.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub enum Error {
1313
EpochProcessingError(EpochProcessingError),
1414
ArithError(ArithError),
1515
InconsistentStateFork(InconsistentFork),
16+
BitfieldError(ssz::BitfieldError),
1617
}
1718

1819
impl From<ArithError> for Error {
@@ -21,6 +22,12 @@ impl From<ArithError> for Error {
2122
}
2223
}
2324

25+
impl From<ssz::BitfieldError> for Error {
26+
fn from(e: ssz::BitfieldError) -> Self {
27+
Self::BitfieldError(e)
28+
}
29+
}
30+
2431
/// Advances a state forward by one slot, performing per-epoch processing if required.
2532
///
2633
/// If the root of the supplied `state` is known, then it can be passed as `state_root`. If
@@ -49,6 +56,18 @@ pub fn per_slot_processing<E: EthSpec>(
4956

5057
state.slot_mut().safe_add_assign(1)?;
5158

59+
// Unset the next payload availability
60+
if state.fork_name_unchecked().gloas_enabled() {
61+
let next_slot_index = state
62+
.slot()
63+
.as_usize()
64+
.safe_add(1)?
65+
.safe_rem(E::slots_per_historical_root())?;
66+
state
67+
.execution_payload_availability_mut()?
68+
.set(next_slot_index, false)?;
69+
}
70+
5271
// Process fork upgrades here. Note that multiple upgrades can potentially run
5372
// in sequence if they are scheduled in the same Epoch (common in testnets)
5473
if state.slot().safe_rem(E::slots_per_epoch())? == 0 {

0 commit comments

Comments
 (0)