Skip to content
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

feat(slash): Add the historical voting power to the slashing record #271

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
643a0ea
detail the return error for operator info
TimmyExogenous Sep 5, 2024
50ed377
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 6, 2024
eb69bbd
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 10, 2024
b75ee4d
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 10, 2024
ae24f6b
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 11, 2024
ff65b01
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 17, 2024
d5660be
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 19, 2024
063417a
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 20, 2024
7009f0c
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 20, 2024
dac10ab
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 23, 2024
3b58f4e
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 24, 2024
686a808
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 24, 2024
27fac4f
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 24, 2024
66bbf7e
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 25, 2024
7174462
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 26, 2024
02d2eb2
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 29, 2024
b129fff
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 8, 2024
bdef6f0
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 10, 2024
34299cd
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 12, 2024
e7c1d3f
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 14, 2024
39902dd
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 15, 2024
dd4904d
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 18, 2024
59d1089
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 20, 2024
59a06bd
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Nov 4, 2024
6f27a39
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Nov 6, 2024
dc4bf40
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Nov 7, 2024
71f6b78
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Nov 11, 2024
13f1f52
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Dec 3, 2024
1847fb5
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Dec 5, 2024
1540196
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Dec 9, 2024
7296ec1
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Dec 11, 2024
7f02f95
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Dec 19, 2024
f5934f0
add historical votin power to the slashing execution record and add s…
TimmyExogenous Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions proto/exocore/operator/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ message SlashExecutionInfo {
repeated SlashFromAssetsPool slash_assets_pool = 4 [(gogoproto.nullable) = false];
// undelegation_filter_height records the height before which undelegations are not slashed
int64 undelegation_filter_height = 5;
// the historical voting power at the time of the slash event.
int64 historical_voting_power = 6;
}

// OperatorSlashInfo is the slash info of operator
Expand Down
11 changes: 9 additions & 2 deletions x/operator/keeper/slash.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"encoding/json"
"strings"

"github.com/ExocoreNetwork/exocore/utils"
Expand Down Expand Up @@ -87,6 +88,7 @@ func (k *Keeper) SlashAssets(ctx sdk.Context, snapshotHeight int64, parameter *t
SlashUndelegations: make([]types.SlashFromUndelegation, 0),
SlashAssetsPool: make([]types.SlashFromAssetsPool, 0),
UndelegationFilterHeight: snapshotHeight,
HistoricalVotingPower: parameter.Power,
}
// slash from the unbonding stakers
if parameter.SlashEventHeight < ctx.BlockHeight() {
Expand Down Expand Up @@ -155,10 +157,15 @@ func (k *Keeper) Slash(ctx sdk.Context, parameter *types.SlashInputInfo) error {
if err != nil {
return err
}
snapshotKeyLastHeight, snapshot, err := k.LoadVotingPowerSnapshot(ctx, parameter.AVSAddr, parameter.SlashEventHeight)
slashEventEpochStartHeight, snapshot, err := k.LoadVotingPowerSnapshot(ctx, parameter.AVSAddr, parameter.SlashEventHeight)
if err != nil {
return err
}
k.Logger(ctx).Info("execute slashing", "eventHeight", parameter.SlashEventHeight, "avsAddr", parameter.AVSAddr, "operator", parameter.Operator, "slashID", parameter.SlashID, "slashType", parameter.SlashType)
// Marshal the snapshot to improve the user experience when printing the voting power decimal through the logger
// so we don't have to address the error here.
snapshotJSON, _ := json.Marshal(snapshot)
k.Logger(ctx).Info("the voting power snapshot info is:", "filter_height", slashEventEpochStartHeight, "snapshot", string(snapshotJSON))
// get the historical voting power from the snapshot for the other AVSs
if !parameter.IsDogFood {
votingPower := types.GetSpecifiedVotingPower(parameter.Operator.String(), snapshot.OperatorVotingPowers)
Expand All @@ -178,7 +185,7 @@ func (k *Keeper) Slash(ctx sdk.Context, parameter *types.SlashInputInfo) error {
// slash assets according to the input information
// using cache context to ensure the atomicity of slash execution.
cc, writeFunc := ctx.CacheContext()
executionInfo, err := k.SlashAssets(cc, snapshotKeyLastHeight, parameter)
executionInfo, err := k.SlashAssets(cc, slashEventEpochStartHeight, parameter)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion x/operator/keeper/usd_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ func (k *Keeper) CalculateUSDValueForOperator(
return err
}
decimal = assetInfo.AssetBasicInfo.Decimals
ret.StakingAndWaitUnbonding = ret.StakingAndWaitUnbonding.Add(CalculateUSDValue(state.TotalAmount.Add(state.PendingUndelegationAmount), price.Value, decimal, price.Decimal))
usdValue := CalculateUSDValue(state.TotalAmount.Add(state.PendingUndelegationAmount), price.Value, decimal, price.Decimal)
ctx.Logger().Info("CalculateUSDValueForOperator: get price for slash", "assetID", assetID, "assetDecimal", decimal, "price", price, "totalAmount", state.TotalAmount, "pendingUndelegationAmount", state.PendingUndelegationAmount, "StakingAndWaitUnbonding", ret.StakingAndWaitUnbonding, "addUSDValue", usdValue)
ret.StakingAndWaitUnbonding = ret.StakingAndWaitUnbonding.Add(usdValue)
} else {
if prices == nil {
return errorsmod.Wrap(operatortypes.ErrValueIsNilOrZero, "CalculateUSDValueForOperator prices map is nil")
Expand Down
94 changes: 47 additions & 47 deletions x/operator/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading