Fix process_deposits bug

This commit is contained in:
Pawan Dhananjay
2024-11-07 21:11:18 -08:00
parent 27ce1a08d9
commit da953b8155
3 changed files with 1 additions and 51 deletions

View File

@@ -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,

View File

@@ -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)?;

View File

@@ -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;