mirror of
https://github.com/ChainSafe/lodestar.git
synced 2026-01-09 15:48:08 -05:00
Fix test
This commit is contained in:
@@ -122,8 +122,8 @@ function getBuilderWithdrawals(
|
||||
? state.builderPendingWithdrawals.getAllReadonly()
|
||||
: null;
|
||||
|
||||
let i = 0;
|
||||
for (i = 0; i < state.builderPendingWithdrawals.length; i++) {
|
||||
let processedCount = 0;
|
||||
for (let i = 0; i < state.builderPendingWithdrawals.length; i++) {
|
||||
const withdrawal = allBuilderPendingWithdrawals
|
||||
? allBuilderPendingWithdrawals[i]
|
||||
: state.builderPendingWithdrawals.getReadonly(i);
|
||||
@@ -162,9 +162,10 @@ function getBuilderWithdrawals(
|
||||
balanceAfterWithdrawals.set(builderIndex, balance - withdrawableBalance);
|
||||
}
|
||||
}
|
||||
processedCount++;
|
||||
}
|
||||
|
||||
return {builderWithdrawals, withdrawalIndex, processedCount: i};
|
||||
return {builderWithdrawals, withdrawalIndex, processedCount};
|
||||
}
|
||||
|
||||
function getPendingPartialWithdrawals(
|
||||
@@ -192,8 +193,8 @@ function getPendingPartialWithdrawals(
|
||||
: null;
|
||||
|
||||
// EIP-7002: Execution layer triggerable withdrawals
|
||||
let i = 0;
|
||||
for (i = 0; i < state.pendingPartialWithdrawals.length; i++) {
|
||||
let processedCount = 0;
|
||||
for (let i = 0; i < state.pendingPartialWithdrawals.length; i++) {
|
||||
const withdrawal = allPendingPartialWithdrawals
|
||||
? allPendingPartialWithdrawals[i]
|
||||
: state.pendingPartialWithdrawals.getReadonly(i);
|
||||
@@ -229,9 +230,10 @@ function getPendingPartialWithdrawals(
|
||||
withdrawalIndex++;
|
||||
balanceAfterWithdrawals.set(withdrawal.validatorIndex, balance - Number(withdrawableBalance));
|
||||
}
|
||||
processedCount++;
|
||||
}
|
||||
|
||||
return {pendingPartialWithdrawals, withdrawalIndex, processedCount: i};
|
||||
return {pendingPartialWithdrawals, withdrawalIndex, processedCount};
|
||||
}
|
||||
|
||||
function getValidatorsSweepWithdrawals(
|
||||
@@ -247,10 +249,10 @@ function getValidatorsSweepWithdrawals(
|
||||
const isPostElectra = fork >= ForkSeq.electra;
|
||||
|
||||
const validatorsLimit = Math.min(state.validators.length, MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP);
|
||||
let n = 0;
|
||||
let processedCount = 0;
|
||||
// Just run a bounded loop max iterating over all withdrawals
|
||||
// however breaks out once we have MAX_WITHDRAWALS_PER_PAYLOAD
|
||||
for (n = 0; n < validatorsLimit; n++) {
|
||||
for (let n = 0; n < validatorsLimit; n++) {
|
||||
if (sweepWithdrawals.length + numPriorWithdrawal === MAX_WITHDRAWALS_PER_PAYLOAD) {
|
||||
break;
|
||||
}
|
||||
@@ -272,6 +274,7 @@ function getValidatorsSweepWithdrawals(
|
||||
// early skip for balance = 0 as its now more likely that validator has exited/slashed with
|
||||
// balance zero than not have withdrawal credentials set
|
||||
if (balance === 0 || !hasWithdrawableCredentials) {
|
||||
processedCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -300,9 +303,10 @@ function getValidatorsSweepWithdrawals(
|
||||
withdrawalIndex++;
|
||||
balanceAfterWithdrawals.set(validatorIndex, balance - partialAmount);
|
||||
}
|
||||
processedCount++;
|
||||
}
|
||||
|
||||
return {sweepWithdrawals: sweepWithdrawals, processedCount: n};
|
||||
return {sweepWithdrawals: sweepWithdrawals, processedCount};
|
||||
}
|
||||
|
||||
function applyWithdrawals(
|
||||
|
||||
@@ -10,14 +10,14 @@ describe("getExpectedWithdrawals", () => {
|
||||
|
||||
const testCases: (WithdrawalOpts & {withdrawals: number; sampled: number})[] = [
|
||||
// Best case when every probe results into a withdrawal candidate
|
||||
{excessBalance: 1, eth1Credentials: 1, withdrawable: 0, withdrawn: 0, withdrawals: 16, sampled: 15},
|
||||
{excessBalance: 1, eth1Credentials: 1, withdrawable: 0, withdrawn: 0, withdrawals: 16, sampled: 16},
|
||||
// Normal case based on mainnet conditions: mainnet network conditions: 95% reward rate
|
||||
{excessBalance: 0.95, eth1Credentials: 0.1, withdrawable: 0.05, withdrawn: 0, withdrawals: 16, sampled: 219},
|
||||
{excessBalance: 0.95, eth1Credentials: 0.1, withdrawable: 0.05, withdrawn: 0, withdrawals: 16, sampled: 220},
|
||||
// Intermediate good case
|
||||
{excessBalance: 0.95, eth1Credentials: 0.3, withdrawable: 0.05, withdrawn: 0, withdrawals: 16, sampled: 42},
|
||||
{excessBalance: 0.95, eth1Credentials: 0.7, withdrawable: 0.05, withdrawn: 0, withdrawals: 16, sampled: 18},
|
||||
{excessBalance: 0.95, eth1Credentials: 0.3, withdrawable: 0.05, withdrawn: 0, withdrawals: 16, sampled: 43},
|
||||
{excessBalance: 0.95, eth1Credentials: 0.7, withdrawable: 0.05, withdrawn: 0, withdrawals: 16, sampled: 19},
|
||||
// Intermediate bad case
|
||||
{excessBalance: 0.1, eth1Credentials: 0.1, withdrawable: 0, withdrawn: 0, withdrawals: 16, sampled: 1020},
|
||||
{excessBalance: 0.1, eth1Credentials: 0.1, withdrawable: 0, withdrawn: 0, withdrawals: 16, sampled: 1021},
|
||||
// Expected 141069 but gets bounded by 16384
|
||||
{excessBalance: 0.01, eth1Credentials: 0.01, withdrawable: 0, withdrawn: 0, withdrawals: 2, sampled: 16384},
|
||||
// Expected 250000 but gets bounded by 16384
|
||||
|
||||
Reference in New Issue
Block a user