Skip to content

Commit

Permalink
Use sliceFrom()
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed May 7, 2024
1 parent 2f6df3d commit a5b5fe0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
7 changes: 3 additions & 4 deletions packages/state-transition/src/block/processWithdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export function processWithdrawals(
state: CachedBeaconStateCapella | CachedBeaconStateElectra,
payload: capella.FullOrBlindedExecutionPayload
): void {
// const {withdrawals: expectedWithdrawals, partialWithdrawalsCount} = getExpectedWithdrawals(fork, state);
const {withdrawals: expectedWithdrawals} = getExpectedWithdrawals(fork, state);
const {withdrawals: expectedWithdrawals, partialWithdrawalsCount} = getExpectedWithdrawals(fork, state);
const numWithdrawals = expectedWithdrawals.length;

if (isCapellaPayloadHeader(payload)) {
Expand Down Expand Up @@ -57,8 +56,8 @@ export function processWithdrawals(
}

if (fork >= ForkSeq.electra) {
const _stateElectra = state as CachedBeaconStateElectra;
// TODO Electra: stateElectra.pendingPartialWithdrawals need to implement slicing mechanism for ListCompositeTreeViewDU
const stateElectra = state as CachedBeaconStateElectra;
stateElectra.pendingPartialWithdrawals = stateElectra.pendingPartialWithdrawals.sliceFrom(partialWithdrawalsCount);
}

// Update the nextWithdrawalIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {getActivationExitChurnLimit} from "../util/validator.js";
export function processPendingBalanceDeposits(state: CachedBeaconStateElectra): void {
const availableForProcessing = state.depositBalanceToConsume + BigInt(getActivationExitChurnLimit(state));
let processedAmount = 0n;
let _nextDepositIndex = 0;
let nextDepositIndex = 0;

for (const deposit of state.pendingBalanceDeposits.getAllReadonly()) {
const {amount} = deposit;
Expand All @@ -21,13 +21,11 @@ export function processPendingBalanceDeposits(state: CachedBeaconStateElectra):
}
increaseBalance(state, deposit.index, Number(amount));
processedAmount = processedAmount + amount;
_nextDepositIndex++;
nextDepositIndex++;
}

// TODO Electra: Impl slicing for ssz
const remainingPendingBalanceDeposits = [];
// const remainingPendingBalanceDeposits = state.pendingBalanceDeposits.slice()
// state.pendingBalanceDeposits = remainingPendingBalanceDeposits
const remainingPendingBalanceDeposits = state.pendingBalanceDeposits.sliceFrom(nextDepositIndex);
state.pendingBalanceDeposits = remainingPendingBalanceDeposits;

if (remainingPendingBalanceDeposits.length === 0) {
state.depositBalanceToConsume = 0n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {switchToCompoundingValidator} from "../util/electra.js";
*
*/
export function processPendingConsolidations(state: CachedBeaconStateElectra): void {
let _nextPendingConsolidation = 0;
let nextPendingConsolidation = 0;

for (const pendingConsolidation of state.pendingConsolidations.getAllReadonly()) {
const {sourceIndex, targetIndex} = pendingConsolidation;
const sourceValidator = state.validators.getReadonly(sourceIndex);

if (sourceValidator.slashed) {
_nextPendingConsolidation++;
nextPendingConsolidation++;
continue;
}

Expand All @@ -38,10 +38,8 @@ export function processPendingConsolidations(state: CachedBeaconStateElectra): v
decreaseBalance(state, sourceIndex, activeBalance);
increaseBalance(state, targetIndex, activeBalance);

_nextPendingConsolidation++;
nextPendingConsolidation++;
}

// TODO Electra: impl slicing for ssz
// const remainingPendingConsolidations = [];
// state.pendingConsolidations =remainingPendingConsolidations
state.pendingConsolidations = state.pendingConsolidations.sliceFrom(nextPendingConsolidation);
}

0 comments on commit a5b5fe0

Please sign in to comment.