Revert "only increment deposit index on state for old deposit flow"

This reverts commit 817d4235ae.
This commit is contained in:
realbigsean
2024-05-11 05:00:47 -04:00
parent 817d4235ae
commit 5f09453287
7 changed files with 13 additions and 43 deletions

View File

@@ -549,7 +549,6 @@ impl<E: EthSpec> Eth1ChainBackend<E> for CachingEth1Backend<E> {
// [New in Electra:EIP6110] // [New in Electra:EIP6110]
let deposit_index_limit = let deposit_index_limit =
if let Ok(deposit_receipts_start_index) = state.deposit_receipts_start_index() { if let Ok(deposit_receipts_start_index) = state.deposit_receipts_start_index() {
dbg!("deposit_receipts_start_index", deposit_receipts_start_index);
std::cmp::min(deposit_count, deposit_receipts_start_index) std::cmp::min(deposit_count, deposit_receipts_start_index)
} else { } else {
deposit_count deposit_count
@@ -562,14 +561,6 @@ impl<E: EthSpec> Eth1ChainBackend<E> for CachingEth1Backend<E> {
let next = deposit_index; let next = deposit_index;
let last = std::cmp::min(deposit_index_limit, next + E::MaxDeposits::to_u64()); let last = std::cmp::min(deposit_index_limit, next + E::MaxDeposits::to_u64());
dbg!(
next,
last,
deposit_count,
deposit_index_limit,
E::MaxDeposits::to_u64()
);
self.core self.core
.deposits() .deposits()
.read() .read()

View File

@@ -439,7 +439,7 @@ impl Eth1GenesisService {
None None
}; };
apply_deposit(&mut state, data, proof, true, spec) apply_deposit(&mut state, data, proof, spec)
.map_err(|e| format!("Error whilst processing deposit: {:?}", e)) .map_err(|e| format!("Error whilst processing deposit: {:?}", e))
})?; })?;

View File

@@ -38,7 +38,7 @@ pub fn initialize_beacon_state_from_eth1<E: EthSpec>(
.map_err(BlockProcessingError::MerkleTreeError)?; .map_err(BlockProcessingError::MerkleTreeError)?;
state.eth1_data_mut().deposit_root = deposit_tree.root(); state.eth1_data_mut().deposit_root = deposit_tree.root();
let Deposit { proof, data } = deposit; let Deposit { proof, data } = deposit;
apply_deposit(&mut state, data, Some(proof), true, spec)?; apply_deposit(&mut state, data, Some(proof), spec)?;
} }
process_activations(&mut state, spec)?; process_activations(&mut state, spec)?;

View File

@@ -417,7 +417,7 @@ pub fn process_deposits<E: EthSpec>(
// Update the state in series. // Update the state in series.
for deposit in deposits { for deposit in deposits {
apply_deposit(state, deposit.data.clone(), None, true, spec)?; apply_deposit(state, deposit.data.clone(), None, spec)?;
} }
Ok(()) Ok(())
@@ -428,7 +428,6 @@ pub fn apply_deposit<E: EthSpec>(
state: &mut BeaconState<E>, state: &mut BeaconState<E>,
deposit_data: DepositData, deposit_data: DepositData,
proof: Option<FixedVector<Hash256, U33>>, proof: Option<FixedVector<Hash256, U33>>,
increment_deposit_index: bool,
spec: &ChainSpec, spec: &ChainSpec,
) -> Result<(), BlockProcessingError> { ) -> Result<(), BlockProcessingError> {
let deposit_index = state.eth1_deposit_index() as usize; let deposit_index = state.eth1_deposit_index() as usize;
@@ -441,9 +440,7 @@ pub fn apply_deposit<E: EthSpec>(
.map_err(|e| e.into_with_index(deposit_index))?; .map_err(|e| e.into_with_index(deposit_index))?;
} }
if increment_deposit_index {
state.eth1_deposit_index_mut().safe_add_assign(1)?; state.eth1_deposit_index_mut().safe_add_assign(1)?;
}
// Get an `Option<u64>` where `u64` is the validator index if this deposit public key // Get an `Option<u64>` where `u64` is the validator index if this deposit public key
// already exists in the beacon_state. // already exists in the beacon_state.
@@ -462,12 +459,6 @@ pub fn apply_deposit<E: EthSpec>(
.get(index as usize) .get(index as usize)
.ok_or(BeaconStateError::UnknownValidator(index as usize))?; .ok_or(BeaconStateError::UnknownValidator(index as usize))?;
dbg!(is_compounding_withdrawal_credential(
deposit_data.withdrawal_credentials,
spec
));
dbg!(validator.has_eth1_withdrawal_credential(spec));
dbg!(is_valid_deposit_signature(&deposit_data, spec).is_ok());
if is_compounding_withdrawal_credential(deposit_data.withdrawal_credentials, spec) if is_compounding_withdrawal_credential(deposit_data.withdrawal_credentials, spec)
&& validator.has_eth1_withdrawal_credential(spec) && validator.has_eth1_withdrawal_credential(spec)
&& is_valid_deposit_signature(&deposit_data, spec).is_ok() && is_valid_deposit_signature(&deposit_data, spec).is_ok()
@@ -500,8 +491,6 @@ pub fn apply_deposit<E: EthSpec>(
amount, amount,
) )
}; };
dbg!(effective_balance, state_balance);
dbg!(&deposit_data.pubkey, &deposit_data.withdrawal_credentials);
// Create a new validator. // Create a new validator.
let validator = Validator { let validator = Validator {
pubkey: deposit_data.pubkey, pubkey: deposit_data.pubkey,
@@ -529,7 +518,6 @@ pub fn apply_deposit<E: EthSpec>(
// [New in Electra:EIP7251] // [New in Electra:EIP7251]
if let Ok(pending_balance_deposits) = state.pending_balance_deposits_mut() { if let Ok(pending_balance_deposits) = state.pending_balance_deposits_mut() {
dbg!(new_validator_index, amount);
pending_balance_deposits.push(PendingBalanceDeposit { pending_balance_deposits.push(PendingBalanceDeposit {
index: new_validator_index as u64, index: new_validator_index as u64,
amount, amount,
@@ -653,7 +641,7 @@ pub fn process_deposit_receipts<E: EthSpec>(
amount: receipt.amount, amount: receipt.amount,
signature: receipt.signature.clone().into(), signature: receipt.signature.clone().into(),
}; };
apply_deposit(state, deposit_data, None, false, spec)? apply_deposit(state, deposit_data, None, spec)?
} }
Ok(()) Ok(())

View File

@@ -2151,7 +2151,6 @@ impl<E: EthSpec> BeaconState<E> {
if *balance > spec.min_activation_balance { if *balance > spec.min_activation_balance {
let excess_balance = balance.safe_sub(spec.min_activation_balance)?; let excess_balance = balance.safe_sub(spec.min_activation_balance)?;
*balance = spec.min_activation_balance; *balance = spec.min_activation_balance;
dbg!(validator_index, excess_balance);
self.pending_balance_deposits_mut()? self.pending_balance_deposits_mut()?
.push(PendingBalanceDeposit { .push(PendingBalanceDeposit {
index: validator_index as u64, index: validator_index as u64,
@@ -2201,7 +2200,6 @@ impl<E: EthSpec> BeaconState<E> {
if validator.has_eth1_withdrawal_credential(spec) { if validator.has_eth1_withdrawal_credential(spec) {
validator.withdrawal_credentials.as_fixed_bytes_mut()[0] = validator.withdrawal_credentials.as_fixed_bytes_mut()[0] =
spec.compounding_withdrawal_prefix_byte; spec.compounding_withdrawal_prefix_byte;
dbg!(validator.withdrawal_credentials);
self.queue_excess_active_balance(validator_index, spec)?; self.queue_excess_active_balance(validator_index, spec)?;
} }
Ok(()) Ok(())

View File

@@ -171,9 +171,7 @@ impl<E: EthSpec> Operation<E> for Deposit {
spec: &ChainSpec, spec: &ChainSpec,
_: &Operations<E, Self>, _: &Operations<E, Self>,
) -> Result<(), BlockProcessingError> { ) -> Result<(), BlockProcessingError> {
let res = process_deposits(state, &[self.clone()], spec); process_deposits(state, &[self.clone()], spec)
dbg!(serde_json::to_string(state).unwrap());
res
} }
} }

View File

@@ -60,9 +60,6 @@ impl<E: EthSpec> Case for SanityBlocks<E> {
} }
fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> { fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> {
if _case_index != 74 || fork_name != ForkName::Electra {
return Ok(());
}
self.metadata.bls_setting.unwrap_or_default().check()?; self.metadata.bls_setting.unwrap_or_default().check()?;
let mut bulk_state = self.pre.clone(); let mut bulk_state = self.pre.clone();
@@ -114,15 +111,13 @@ impl<E: EthSpec> Case for SanityBlocks<E> {
spec, spec,
)?; )?;
// if block.state_root() == bulk_state.update_tree_hash_cache().unwrap() if block.state_root() == bulk_state.update_tree_hash_cache().unwrap()
// && block.state_root() == indiv_state.update_tree_hash_cache().unwrap() && block.state_root() == indiv_state.update_tree_hash_cache().unwrap()
// { {
// Ok(()) Ok(())
// } else { } else {
// Err(BlockProcessingError::StateRootMismatch) Err(BlockProcessingError::StateRootMismatch)
// } }
Ok::<_, BlockProcessingError>(())
}) })
.map(|_| (bulk_state, indiv_state)); .map(|_| (bulk_state, indiv_state));