Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix balance spec tests #6777

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export function processEffectiveBalanceUpdates(

// epochTransitionCache.balances is set in processRewardsAndPenalties(), so it's recycled here for performance.
// It defaults to `state.balances.getAll()` to make Typescript happy and for spec tests
const balances = cache.balances ?? state.balances.getAll();
const balances = state.balances.getAll();

// TODO: (@matthewkeil) This was causing additional failures but should not. Check the EpochTransitionCache for why
// const balances = cache.balances ?? state.balances.getAll();

for (let i = 0, len = balances.length; i < len; i++) {
const balance = balances[i];
Expand All @@ -55,7 +58,7 @@ export function processEffectiveBalanceUpdates(
// Too big
effectiveBalance > balance + DOWNWARD_THRESHOLD ||
// Too small. Check effectiveBalance < MAX_EFFECTIVE_BALANCE to prevent unnecessary updates
(effectiveBalance < MAX_EFFECTIVE_BALANCE && effectiveBalance < balance - UPWARD_THRESHOLD)
effectiveBalance + UPWARD_THRESHOLD < balance
) {
// Update the state tree
// Should happen rarely, so it's fine to update the tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export function processRewardsAndPenalties(
const balances = state.balances.getAll();

for (let i = 0, len = rewards.length; i < len; i++) {
balances[i] += rewards[i] - penalties[i] - (slashingPenalties[i] ?? 0);
const result = balances[i] + rewards[i] - penalties[i] - (slashingPenalties[i] ?? 0)
balances[i] = Math.max(result, 0);
}

// important: do not change state one balance at a time. Set them all at once, constructing the tree in one go
Expand Down
Loading