Skip to content

Commit

Permalink
Merge pull request #146 from Layr-Labs/alex/fix-inprogress-checkpoint…
Browse files Browse the repository at this point in the history
…-status

fix: correctly calculate share diff for a partially-complete checkpoint
  • Loading branch information
wadealexc authored Aug 30, 2024
2 parents 568591c + 71db834 commit cf63185
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cli/core/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ func GetStatus(ctx context.Context, eigenpodAddress string, eth *ethclient.Clien
checkpointableValidators, err := SelectCheckpointableValidators(eth, eigenpodAddress, allValidators, checkpointTimestamp)
PanicOnError("failed to find checkpointable validators", err)

sumBeaconBalancesGwei := sumActiveValidatorBeaconBalancesGwei(activeValidators, allBeaconBalances, state)
sumBeaconBalancesGwei := new(big.Float).SetUint64(uint64(sumActiveValidatorBeaconBalancesGwei(activeValidators, allBeaconBalances, state)))

sumRestakedBalancesGwei, err := sumRestakedBalancesGwei(eth, eigenpodAddress, activeValidators)
sumRestakedBalancesU64, err := sumRestakedBalancesGwei(eth, eigenpodAddress, activeValidators)
PanicOnError("failed to calculate sum of onchain validator balances", err)
sumRestakedBalancesGwei := new(big.Float).SetUint64(uint64(sumRestakedBalancesU64))

for i := 0; i < len(allValidators); i++ {
validator := allValidators[i].Validator
Expand Down Expand Up @@ -173,6 +174,12 @@ func GetStatus(ctx context.Context, eigenpodAddress string, eth *ethclient.Clien
// Change in the pod's native ETH balance (already calculated for us when the checkpoint was started)
nativeETHDeltaGwei = new(big.Float).SetUint64(checkpoint.PodBalanceGwei)

// Remove already-computed delta from an in-progress checkpoint
sumRestakedBalancesGwei = new(big.Float).Sub(
sumRestakedBalancesGwei,
new(big.Float).SetInt(checkpoint.BalanceDeltasGwei),
)

activeCheckpoint = &Checkpoint{
ProofsRemaining: checkpoint.ProofsRemaining.Uint64(),
StartedAt: checkpointTimestamp,
Expand Down Expand Up @@ -200,8 +207,8 @@ func GetStatus(ctx context.Context, eigenpodAddress string, eth *ethclient.Clien
//
// beaconETHDeltaGwei = sumBeaconBalancesGwei - sumRestakedBalancesGwei
beaconETHDeltaGwei := new(big.Float).Sub(
new(big.Float).SetUint64(uint64(sumBeaconBalancesGwei)),
new(big.Float).SetUint64(uint64(sumRestakedBalancesGwei)),
sumBeaconBalancesGwei,
sumRestakedBalancesGwei,
)

// Sum of these two deltas represents the change in shares after this checkpoint
Expand Down
4 changes: 4 additions & 0 deletions cli/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func GweiToEther(val *big.Float) *big.Float {
return new(big.Float).Quo(val, big.NewFloat(params.GWei))
}

func GweiToWei(val *big.Float) *big.Float {
return new(big.Float).Mul(val, big.NewFloat(params.GWei))
}

func IweiToEther(val *big.Int) *big.Float {
return new(big.Float).Quo(new(big.Float).SetInt(val), big.NewFloat(params.Ether))
}
Expand Down

0 comments on commit cf63185

Please sign in to comment.