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

implement process_withdrawals #11634

Merged
merged 9 commits into from
Nov 8, 2022
Merged

implement process_withdrawals #11634

merged 9 commits into from
Nov 8, 2022

Conversation

potuz
Copy link
Contributor

@potuz potuz commented Nov 7, 2022

Implement process withdrawal logic, as part of block operations.

@potuz potuz added Ready For Review A pull request ready for code review Withdrawals labels Nov 7, 2022
@potuz potuz requested a review from a team as a code owner November 7, 2022 19:36
@potuz potuz requested review from kasey, rauljordan and saolyn November 7, 2022 19:36
}
for i, withdrawal := range withdrawals {
if withdrawal.WithdrawalIndex != expected[i].WithdrawalIndex {
return nil, errors.New("invalid withdrawal index")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont feel strongly about this, but perhaps we can turn these errors into variables. It might be useful later...
var ErrInvalidWithdrawalIndex = errors.New("invalid withdrawal index")

if withdrawal.ValidatorIndex != expected[i].ValidatorIndex {
return nil, errors.New("invalid validator index")
}
if bytesutil.ToBytes20(withdrawal.ExecutionAddress) != bytesutil.ToBytes20(expected[i].ExecutionAddress) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better to use the isHexAddress function or any of the common functions from geth for address / also wondering if there's any benefit to doing !bytes.compare instead

Copy link
Contributor

@rkapka rkapka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "failure invalid withdrawal amount" scenario is a duplicate of another test. We also need a "failure wrong number of full withdrawals" scenario.

@@ -65,6 +65,7 @@ type ReadOnlyBeaconState interface {
LatestExecutionPayloadHeader() (interfaces.ExecutionData, error)
LastWithdrawalValidatorIndex() (types.ValidatorIndex, error)
ExpectedWithdrawals() ([]*enginev1.Withdrawal, error)
NextWithdrawalIndex() (uint64, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the third getter related to withdrawals. How about we extract them to a type ReadOnlyWithdrawals interface?

}
if len(withdrawals) > 0 {
if err := st.SetNextWithdrawalIndex(withdrawals[len(withdrawals)-1].WithdrawalIndex + 1); err != nil {
return nil, errors.Wrap(err, "could not set withdrawal index")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, errors.Wrap(err, "could not set withdrawal index")
return nil, errors.Wrap(err, "could not set next withdrawal index")

},
{
Args: args{
Name: "success more than max fully withdrawals",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have more than max withdrawals here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do, the fully withdrawable indices are more than 16

},
{
Args: args{
Name: "success more than max partially withdrawals",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have more than max withdrawals here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

},
{
Args: args{
Name: "failure invalid withdrawal amount",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is the same as "failure invalid validator index"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it's not, the third withdrawal is a partial one

},
{
Args: args{
Name: "failure validator not withdrawable",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Name: "failure validator not withdrawable",
Name: "failure validator not partially withdrawable",

@potuz potuz merged commit 90ecd23 into develop Nov 8, 2022
@delete-merged-branch delete-merged-branch bot deleted the process_withdrawals branch November 8, 2022 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants