Skip to content

Commit

Permalink
Fix process_deposits bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Nov 8, 2024
1 parent 27ce1a0 commit da953b8
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ pub fn process_deposits<E: EthSpec>(
if state.eth1_deposit_index() < eth1_deposit_index_limit {
let expected_deposit_len = std::cmp::min(
E::MaxDeposits::to_u64(),
state.get_outstanding_deposit_len()?,
eth1_deposit_index_limit.safe_sub(state.eth1_deposit_index())?,
);
block_verify!(
deposits.len() as u64 == expected_deposit_len,
Expand Down
13 changes: 0 additions & 13 deletions consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1783,19 +1783,6 @@ impl<E: EthSpec> BeaconState<E> {
}
}

/// Get the number of outstanding deposits.
///
/// Returns `Err` if the state is invalid.
pub fn get_outstanding_deposit_len(&self) -> Result<u64, Error> {
self.eth1_data()
.deposit_count
.checked_sub(self.eth1_deposit_index())
.ok_or(Error::InvalidDepositState {
deposit_count: self.eth1_data().deposit_count,
deposit_index: self.eth1_deposit_index(),
})
}

/// Build all caches (except the tree hash cache), if they need to be built.
pub fn build_caches(&mut self, spec: &ChainSpec) -> Result<(), Error> {
self.build_all_committee_caches(spec)?;
Expand Down
37 changes: 0 additions & 37 deletions consensus/types/src/beacon_state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,43 +307,6 @@ mod committees {
}
}

mod get_outstanding_deposit_len {
use super::*;

async fn state() -> BeaconState<MinimalEthSpec> {
get_harness(16, Slot::new(0))
.await
.chain
.head_beacon_state_cloned()
}

#[tokio::test]
async fn returns_ok() {
let mut state = state().await;
assert_eq!(state.get_outstanding_deposit_len(), Ok(0));

state.eth1_data_mut().deposit_count = 17;
*state.eth1_deposit_index_mut() = 16;
assert_eq!(state.get_outstanding_deposit_len(), Ok(1));
}

#[tokio::test]
async fn returns_err_if_the_state_is_invalid() {
let mut state = state().await;
// The state is invalid, deposit count is lower than deposit index.
state.eth1_data_mut().deposit_count = 16;
*state.eth1_deposit_index_mut() = 17;

assert_eq!(
state.get_outstanding_deposit_len(),
Err(BeaconStateError::InvalidDepositState {
deposit_count: 16,
deposit_index: 17,
})
);
}
}

#[test]
fn decode_base_and_altair() {
type E = MainnetEthSpec;
Expand Down

0 comments on commit da953b8

Please sign in to comment.