-
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
Switch to compounding when consolidating with source==target #14511
Conversation
a4b49a9
to
177febd
Compare
177febd
to
bf95096
Compare
if err != nil { | ||
return err | ||
} | ||
if err := helpers.DecreaseBalance(st, pc.SourceIndex, activeBalance); err != nil { | ||
if sourceEffectiveBalance > validatorBalance { |
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.
nit: instead of this if statement what about using the min function for 1 to 1 readability
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.
|
||
sourcePubKey := bytesutil.ToBytes48(req.SourcePubkey) | ||
targetPubKey := bytesutil.ToBytes48(req.TargetPubkey) | ||
if sourcePubKey != targetPubKey { |
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.
I think it's better to do !bytes.Equals check than doing !=
} | ||
sourcePubkey := bytesutil.ToBytes48(cr.SourcePubkey) | ||
targetPubkey := bytesutil.ToBytes48(cr.TargetPubkey) | ||
if sourcePubkey == targetPubkey { |
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.
another check for bytes.Equal over ==
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.
sourcePubkey := bytesutil.ToBytes48(cr.SourcePubkey) | ||
targetPubkey := bytesutil.ToBytes48(cr.TargetPubkey) | ||
if sourcePubkey == targetPubkey { |
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.
+1, bytes.Equal does not alloc, but converting to [48]byte is a 48 byte alloc
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 would still need [48]byte
when calling ValidatorIndexByPubkey
in L224
srcIdx, ok := st.ValidatorIndexByPubkey(sourcePubkey)
tgtIdx, ok := st.ValidatorIndexByPubkey(targetPubkey)
// active_balance = get_active_balance(state, pending_consolidation.source_index) | ||
// decrease_balance(state, pending_consolidation.source_index, active_balance) | ||
// increase_balance(state, pending_consolidation.target_index, active_balance) | ||
// continue |
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.
??
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.
// increase_balance(state, pending_consolidation.target_index, active_balance) | ||
// continue | ||
// | ||
// def process_pending_consolidations(state: BeaconState) -> None: |
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.
Double checked this against spec, looks good.
@@ -101,6 +107,16 @@ func ProcessPendingConsolidations(ctx context.Context, st state.BeaconState) err | |||
// state: BeaconState, | |||
// consolidation_request: ConsolidationRequest | |||
// ) -> None: | |||
// if is_valid_switch_to_compounding_request(state, consolidation_request): |
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.
Double checked this comment block against spec and LGTM.
// if not is_active_validator(source_validator, current_epoch): | ||
// return False | ||
// | ||
// # Verify exit for source have not been initiated |
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.
// # Verify exit for source have not been initiated | |
// # Verify exit for source has not been initiated |
The spec has this typo corrected
// if has_eth1_withdrawal_credential(validator): | ||
// validator.withdrawal_credentials = COMPOUNDING_WITHDRAWAL_PREFIX + validator.withdrawal_credentials[1:] | ||
// queue_excess_active_balance(state, index) | ||
// validator.withdrawal_credentials = COMPOUNDING_WITHDRAWAL_PREFIX + validator.withdrawal_credentials[1:] |
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.
Review this against spec and LGTM.
bf95096
to
68b6526
Compare
} | ||
// As per the consensus specification, this error is not considered an assertion. | ||
// Therefore, if the source_pubkey is not found in validator_pubkeys, we simply return false. | ||
srcV, err := st.ValidatorAtIndex(srcIdx) |
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 you use ValidatorAtIndexReadOnly?
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 PR modifies the handling of switching validators to compounding credentials by consolidating the logic into the
process_consolidation_request
flow. Key code changes include:switch_to_compounding_validator
fromprocess_pending_consolidations
.switch_to_compounding_validator
fromapply_deposit
.is_valid_switch_to_compounding_request
.process_consolidation_request
to checkis_valid_switch_to_compounding_request
, and if valid, switch the source index validator to compounding.process_consolidation_request
to automatically switch the target validator to compounding if it has an eth1 credential.Note to the reviewers: In
process_consolidation_request
, we used to return errors in many places, but in the spec, it's a clean return. Since we process requests in one function, whereas the spec processes individual requests, returning errors is dangerous and could lead to a consensus fault. I've adjusted some returns to log and continue. I didn't modify the ones where it says an error can't happen. Please review carefullyReference: ethereum/consensus-specs#3918