-
-
Notifications
You must be signed in to change notification settings - Fork 479
feat: add EL triggered consolidation and remove ExecutionLayer prefix
#6865
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1ffc97e
init commit
ensi321 a433a7e
Add consolidation request
ensi321 460bcde
fix lint
ensi321 19bf82f
Remove ExecutionLayer prefix
ensi321 8f2be82
Address comment
ensi321 a46f0a6
Fix verification logic
ensi321 c3e6d2d
lint
ensi321 ca89533
Add todo
ensi321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 0 additions & 111 deletions
111
packages/state-transition/src/block/processConsolidation.ts
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
packages/state-transition/src/block/processConsolidationRequest.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import {electra, ssz} from "@lodestar/types"; | ||
| import {FAR_FUTURE_EPOCH, MIN_ACTIVATION_BALANCE, PENDING_CONSOLIDATIONS_LIMIT} from "@lodestar/params"; | ||
|
|
||
| import {CachedBeaconStateElectra} from "../types.js"; | ||
| import {getConsolidationChurnLimit, isActiveValidator} from "../util/validator.js"; | ||
| import {hasExecutionWithdrawalCredential} from "../util/electra.js"; | ||
| import {computeConsolidationEpochAndUpdateChurn} from "../util/epoch.js"; | ||
|
|
||
| export function processConsolidationRequest( | ||
| state: CachedBeaconStateElectra, | ||
| consolidationRequest: electra.ConsolidationRequest | ||
| ): void { | ||
|
|
||
| // If the pending consolidations queue is full, consolidation requests are ignored | ||
| if (state.pendingConsolidations.length >= PENDING_CONSOLIDATIONS_LIMIT) { | ||
| return; | ||
| } | ||
|
|
||
| // If there is too little available consolidation churn limit, consolidation requests are ignored | ||
| if (getConsolidationChurnLimit(state) <= MIN_ACTIVATION_BALANCE) { | ||
| return; | ||
| } | ||
|
|
||
| const {sourcePubkey, targetPubkey} = consolidationRequest; | ||
| const sourceIndex = state.epochCtx.getValidatorIndex(sourcePubkey); | ||
| const targetIndex = state.epochCtx.getValidatorIndex(targetPubkey); | ||
|
|
||
| if (sourceIndex === undefined || targetIndex === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| // Verify that source != target, so a consolidation cannot be used as an exit. | ||
| if (sourceIndex === targetIndex){ | ||
| return; | ||
| } | ||
|
|
||
| const sourceValidator = state.validators.getReadonly(sourceIndex); | ||
| const targetValidator = state.validators.getReadonly(targetIndex); | ||
| const sourceWithdrawalAddress = sourceValidator.withdrawalCredentials.subarray(12); | ||
| const currentEpoch = state.epochCtx.epoch; | ||
|
|
||
| // Verify withdrawal credentials | ||
| if ( | ||
| !hasExecutionWithdrawalCredential(sourceValidator.withdrawalCredentials) || | ||
| !hasExecutionWithdrawalCredential(targetValidator.withdrawalCredentials) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| if (Buffer.compare(sourceWithdrawalAddress, consolidationRequest.sourceAddress) !== 0) { | ||
| return; | ||
| } | ||
|
|
||
| // Verify the source and the target are active | ||
| if (!isActiveValidator(sourceValidator, currentEpoch) || !isActiveValidator(targetValidator, currentEpoch)) { | ||
| return; | ||
| } | ||
|
|
||
| // Verify exits for source and target have not been initiated | ||
| if (sourceValidator.exitEpoch !== FAR_FUTURE_EPOCH || targetValidator.exitEpoch !== FAR_FUTURE_EPOCH) { | ||
| return; | ||
| } | ||
|
|
||
| // TODO Electra: See if we can get rid of big int | ||
| const exitEpoch = computeConsolidationEpochAndUpdateChurn(state, BigInt(sourceValidator.effectiveBalance)); | ||
| sourceValidator.exitEpoch = exitEpoch; | ||
| sourceValidator.withdrawableEpoch = exitEpoch + state.config.MIN_VALIDATOR_WITHDRAWABILITY_DELAY; | ||
|
|
||
| const pendingConsolidation = ssz.electra.PendingConsolidation.toViewDU({ | ||
| sourceIndex, | ||
| targetIndex, | ||
| }); | ||
| state.pendingConsolidations.push(pendingConsolidation); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.