-
-
Notifications
You must be signed in to change notification settings - Fork 328
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
fix: update getPendingBalanceToWithdraw
to work with uncommitted changes
#7375
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #7375 +/- ##
============================================
- Coverage 48.62% 48.61% -0.01%
============================================
Files 603 603
Lines 40516 40520 +4
Branches 2071 2071
============================================
Hits 19700 19700
- Misses 20778 20782 +4
Partials 38 38 |
Performance Report✔️ no performance regression detected Full benchmark results
|
@@ -76,6 +76,7 @@ export function processWithdrawalRequest( | |||
withdrawableEpoch, | |||
}); | |||
state.pendingPartialWithdrawals.push(pendingPartialWithdrawal); | |||
state.pendingPartialWithdrawals.commit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we commit once across multiple withdrawal requests?
eg:
for (...) {
processWithdrawalRequest(...);
}
state.pendingPartialWithdrawals.commit();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem is that we need to commit before we call getPendingBalanceToWithdraw
const pendingBalanceToWithdraw = getPendingBalanceToWithdraw(state, validatorIndex); |
since this calls getAllReadonly
.getAllReadonly() |
I am sure there is a better solution for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if we don't commit after we push the first withdrawal request the issue happens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nflaig calling commit()
at the middle of state transition is not great but this is a limitation at ssz side, we should be able to get all items without calling commit()
call state.pendingPartialWithdrawals.getAllReadonly()
at the start of processWithdrawalRequest
then modify getPendingBalanceToWithdraw
let total = 0;
for (let i = 0; i < state.pendingPartialWithdrawals.length; i++) {
const item = state.pendingPartialWithdrawals.get(i);
if (item.validatorIndex === validatorIndex) {
total += Number(item.amount);
}
return total;
}
performance should be the same, a unit test should help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call state.pendingPartialWithdrawals.getAllReadonly() at the start of processWithdrawalRequest
I think this would result in the same error, we need to call it outside of this loop
lodestar/packages/state-transition/src/block/processOperations.ts
Lines 74 to 76 in 06831cf
for (const elWithdrawalRequest of bodyElectra.executionRequests.withdrawals) { | |
processWithdrawalRequest(fork, stateElectra, elWithdrawalRequest); | |
} |
or we add something like cachedPendingPartialWithdrawals
which is just a nomral array and we use that instead to check pending balance to withdraw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or we add something like cachedPendingPartialWithdrawals which is just a nomral array and we use that instead to check pending balance to withdraw
Yea I was thinking about something like this. And whenever state.pendingPartialWithdrawals
gets updated during state transition, the cache needs to be updated manually as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like 582ead5 or you had somehting else in mind?
putting as draft for now until more testing is done |
getPendingBalanceToWithdraw
to work with uncommitted pendingPartialWithdrawals
getPendingBalanceToWithdraw
to work with uncommitted pendingPartialWithdrawals
getPendingBalanceToWithdraw
to work with uncommitted changes
…tation (#7419) Since ChainSafe/ssz#456 it's possible to use `getAllReadonly()` with uncommited changes. This PR essential reverts changes done in #7375 as it causes more memory allocation which is not ideal.
🎉 This PR is included in v1.26.0 🎉 |
Fixes
devnet-5
issuewhich happened when processing block with two withdrawal requests.
See discord for more context.