-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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
42 changes: 38 additions & 4 deletions
42
cl/transition/impl/eth2/statechange/process_pending_consolidations.go
This file contains 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 |
---|---|---|
@@ -1,11 +1,45 @@ | ||
package statechange | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/erigontech/erigon-lib/log/v3" | ||
"github.com/erigontech/erigon/cl/abstract" | ||
"github.com/erigontech/erigon/cl/cltypes/solid" | ||
"github.com/erigontech/erigon/cl/phase1/core/state" | ||
) | ||
|
||
func ProcessPendingConsolidations(s abstract.BeaconState) error { | ||
return errors.New("not implemented") | ||
func ProcessPendingConsolidations(s abstract.BeaconState) { | ||
nextEpoch := s.Slot()/s.BeaconConfig().SlotsPerEpoch + 1 | ||
nextConsolidationIndex := 0 | ||
s.GetPendingConsolidations().Range(func(i int, c *solid.PendingConsolidation, length int) bool { | ||
sourceValidator, err := s.ValidatorForValidatorIndex(int(c.SourceIndex)) | ||
if err != nil { | ||
log.Warn("Failed to get source validator for consolidation", "index", c.SourceIndex) | ||
nextConsolidationIndex++ | ||
return true | ||
} | ||
if sourceValidator.Slashed() { | ||
nextConsolidationIndex++ | ||
return true | ||
} | ||
if sourceValidator.WithdrawableEpoch() > nextEpoch { | ||
return false // stop processing | ||
} | ||
// Calculate the consolidated balance | ||
maxEffectiveBalance := state.GetMaxEffectiveBalanceByVersion(sourceValidator, s.BeaconConfig(), s.Version()) | ||
vBalance, err := s.ValidatorBalance(int(c.SourceIndex)) | ||
if err != nil { | ||
log.Warn("Failed to get validator balance for consolidation", "index", c.SourceIndex) | ||
nextConsolidationIndex++ | ||
return true | ||
} | ||
sourceEffectiveBalance := min(vBalance, maxEffectiveBalance) | ||
// Move active balance to target. Excess balance is withdrawable. | ||
state.DecreaseBalance(s, c.SourceIndex, sourceEffectiveBalance) | ||
state.IncreaseBalance(s, c.TargetIndex, sourceEffectiveBalance) | ||
nextConsolidationIndex++ | ||
return true | ||
}) | ||
pendingConsolidations := s.GetPendingConsolidations().ShallowCopy() | ||
pendingConsolidations.Cut(nextConsolidationIndex) | ||
s.SetPendingConsolidations(pendingConsolidations) | ||
} |