-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
} | ||
for i, withdrawal := range withdrawals { | ||
if withdrawal.WithdrawalIndex != expected[i].WithdrawalIndex { | ||
return nil, errors.New("invalid withdrawal index") |
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.
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) { |
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.
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
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 "failure invalid withdrawal amount"
scenario is a duplicate of another test. We also need a "failure wrong number of full withdrawals"
scenario.
beacon-chain/state/interfaces.go
Outdated
@@ -65,6 +65,7 @@ type ReadOnlyBeaconState interface { | |||
LatestExecutionPayloadHeader() (interfaces.ExecutionData, error) | |||
LastWithdrawalValidatorIndex() (types.ValidatorIndex, error) | |||
ExpectedWithdrawals() ([]*enginev1.Withdrawal, error) | |||
NextWithdrawalIndex() (uint64, error) |
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.
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") |
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.
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", |
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.
We don't have more than max withdrawals here
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.
we do, the fully withdrawable indices are more than 16
}, | ||
{ | ||
Args: args{ | ||
Name: "success more than max partially withdrawals", |
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.
We don't have more than max withdrawals here
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.
same as above
}, | ||
{ | ||
Args: args{ | ||
Name: "failure invalid withdrawal amount", |
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.
This test is the same as "failure invalid validator index"
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.
no it's not, the third withdrawal is a partial one
}, | ||
{ | ||
Args: args{ | ||
Name: "failure validator not withdrawable", |
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.
Name: "failure validator not withdrawable", | |
Name: "failure validator not partially withdrawable", |
Implement process withdrawal logic, as part of block operations.