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(operator): Voting power snapshot #222

Merged
merged 38 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 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
a7f2be1
add a file for validator snapshot
TimmyExogenous Oct 15, 2024
1dc08b5
add the voting power snapshot data structure
TimmyExogenous Oct 18, 2024
8f0a108
implement the voting power snapshot
TimmyExogenous Oct 20, 2024
9b2081c
1. fix the issue of using incorrect height when slashing pending unde…
TimmyExogenous Oct 24, 2024
4d5662d
fix the voting power snapshot issues identified by the unit test
TimmyExogenous Oct 27, 2024
15ab189
fix the issues identified by code comment
TimmyExogenous Oct 29, 2024
5854c52
1. add cli and rpc for voting power snapshot
TimmyExogenous Oct 31, 2024
9842790
fix the issues regarding code comments
TimmyExogenous Nov 1, 2024
0338fe6
rebase to develop and fix the conflict
TimmyExogenous Nov 6, 2024
35ad190
1. use `ZeroInt` and `LegacyZeroDec` to replace `NewInt(0)` and `Lega…
TimmyExogenous Nov 10, 2024
d25846c
fix the incorrect comparison in GetImpactfulAVSForOperator
TimmyExogenous Nov 11, 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
4 changes: 2 additions & 2 deletions app/ante/cosmos/min_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (suite *AnteTestSuite) TestMinGasPriceDecorator() {
err := suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
suite.Require().NoError(err)

txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(0), denom, &testMsg)
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.ZeroInt(), denom, &testMsg)
return txBuilder.GetTx()
},
true,
Expand Down Expand Up @@ -96,7 +96,7 @@ func (suite *AnteTestSuite) TestMinGasPriceDecorator() {
err := suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
suite.Require().NoError(err)

txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(0), denom, &testMsg)
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.ZeroInt(), denom, &testMsg)
return txBuilder.GetTx()
},
false,
Expand Down
2 changes: 1 addition & 1 deletion app/ante/evm/fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (suite *AnteTestSuite) TestEthMinGasPriceDecorator() {
ToAddress: "evmos1dx67l23hz9l0k9hcher8xz04uj7wf3yu26l2yn",
Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: denom}},
}
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(0), denom, &testMsg)
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.ZeroInt(), denom, &testMsg)
return txBuilder.GetTx()
},
false,
Expand Down
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,6 @@ func (app *ExocoreApp) InitChainer(
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}

app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())

return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
Expand Down
1 change: 0 additions & 1 deletion precompiles/assets/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ func (s *AssetsPrecompileSuite) TestRunWithdrawPrincipal() {
readOnly: false,
expPass: true,
extra: func() {

stakerID, assetID := assetstype.GetStakerIDAndAssetID(s.ClientChains[0].LayerZeroChainID, s.Address.Bytes(), NSTAddress)
// check depositNST successfully updated stakerAssetInfo in assets_module
stakerAssetInfo, _ := s.App.AssetsKeeper.GetStakerSpecifiedAssetInfo(s.Ctx, stakerID, assetID)
Expand Down
2 changes: 1 addition & 1 deletion precompiles/assets/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (p Precompile) RegisterToken(

stakingAsset := &assetstypes.StakingAssetInfo{
AssetBasicInfo: asset,
StakingTotalAmount: sdkmath.NewInt(0),
StakingTotalAmount: sdkmath.ZeroInt(),
}

if err := p.assetsKeeper.RegisterNewTokenAndSetTokenFeeder(ctx, &oInfo); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions precompiles/avs/avs_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package avs_test

import (
"cosmossdk.io/math"
assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types"
"github.com/ExocoreNetwork/exocore/x/avs/types"
"math/big"
"strconv"
"time"

"cosmossdk.io/math"
assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types"
"github.com/ExocoreNetwork/exocore/x/avs/types"

sdkmath "cosmossdk.io/math"
operatorKeeper "github.com/ExocoreNetwork/exocore/x/operator/keeper"

Expand Down Expand Up @@ -650,7 +651,6 @@ func (suite *AVSManagerPrecompileSuite) TestRegisterOperatorToAVS() {
}

func (suite *AVSManagerPrecompileSuite) TestDeregisterOperatorFromAVS() {

// from := s.Address
operatorAddress := sdk.AccAddress(suite.Address.Bytes())
assetID := suite.AssetIDs
Expand Down Expand Up @@ -835,7 +835,7 @@ func (suite *AVSManagerPrecompileSuite) TestRunRegTaskInfo() {
suite.Ctx,
&assetstypes.StakingAssetInfo{
AssetBasicInfo: usdcClientChainAsset,
StakingTotalAmount: sdkmath.NewInt(0),
StakingTotalAmount: sdkmath.ZeroInt(),
},
)
suite.NoError(err)
Expand Down
17 changes: 10 additions & 7 deletions precompiles/avs/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package avs_test

import (
"fmt"
"math/big"
"time"

epochstypes "github.com/ExocoreNetwork/exocore/x/epochs/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/prysmaticlabs/prysm/v4/crypto/bls/blst"
"math/big"
"time"

utiltx "github.com/ExocoreNetwork/exocore/testutil/tx"

Expand Down Expand Up @@ -144,7 +145,7 @@ func (suite *AVSManagerPrecompileSuite) TestGetOptedInOperatorAccAddrs() {

func (suite *AVSManagerPrecompileSuite) TestAVSUSDValue() {
method := s.precompile.Methods[avsManagerPrecompile.MethodGetAVSUSDValue]
expectedUSDvalue := sdkmath.LegacyNewDec(0)
expectedUSDvalue := sdkmath.LegacyZeroDec()

setUp := func() {
suite.prepare()
Expand All @@ -162,7 +163,7 @@ func (suite *AVSManagerPrecompileSuite) TestAVSUSDValue() {
suite.Ctx,
&assetstype.StakingAssetInfo{
AssetBasicInfo: usdcClientChainAsset,
StakingTotalAmount: sdkmath.NewInt(0),
StakingTotalAmount: sdkmath.ZeroInt(),
},
)
suite.NoError(err)
Expand Down Expand Up @@ -232,7 +233,7 @@ func (suite *AVSManagerPrecompileSuite) TestAVSUSDValue() {

func (suite *AVSManagerPrecompileSuite) TestGetOperatorOptedUSDValue() {
method := s.precompile.Methods[avsManagerPrecompile.MethodGetOperatorOptedUSDValue]
expectedUSDvalue := sdkmath.LegacyNewDec(0)
expectedUSDvalue := sdkmath.LegacyZeroDec()

setUp := func() {
suite.prepare()
Expand All @@ -250,7 +251,7 @@ func (suite *AVSManagerPrecompileSuite) TestGetOperatorOptedUSDValue() {
suite.Ctx,
&assetstype.StakingAssetInfo{
AssetBasicInfo: usdcClientChainAsset,
StakingTotalAmount: sdkmath.NewInt(0),
StakingTotalAmount: sdkmath.ZeroInt(),
},
)
suite.NoError(err)
Expand Down Expand Up @@ -494,6 +495,7 @@ func (suite *AVSManagerPrecompileSuite) TestIsoperator() {
})
}
}

func (suite *AVSManagerPrecompileSuite) TestGetTaskInfo() {
method := suite.precompile.Methods[avsManagerPrecompile.MethodGetTaskInfo]
taskAddress := "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
Expand All @@ -507,7 +509,7 @@ func (suite *AVSManagerPrecompileSuite) TestGetTaskInfo() {
TaskResponsePeriod: 10,
StartingEpoch: 5,
TaskStatisticalPeriod: 60,
TaskTotalPower: sdk.Dec(sdkmath.NewInt(0)),
TaskTotalPower: sdk.Dec(sdkmath.ZeroInt()),
}
err := suite.App.AVSManagerKeeper.SetTaskInfo(suite.Ctx, info)
suite.NoError(err)
Expand Down Expand Up @@ -553,6 +555,7 @@ func (suite *AVSManagerPrecompileSuite) TestGetTaskInfo() {
})
}
}

func (suite *AVSManagerPrecompileSuite) TestGetCurrentEpoch() {
method := suite.precompile.Methods[avsManagerPrecompile.MethodGetCurrentEpoch]
testCases := []avsTestCases{
Expand Down
4 changes: 2 additions & 2 deletions precompiles/avs/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ func (suite *AVSManagerPrecompileSuite) TestOptOut() {
OptedInHeight: uint64(optInHeight),
OptedOutHeight: uint64(suite.Ctx.BlockHeight()),
},
AVSTotalShare: sdkmath.LegacyNewDec(0),
AVSOperatorShare: sdkmath.LegacyNewDec(0),
AVSTotalShare: sdkmath.LegacyZeroDec(),
AVSOperatorShare: sdkmath.LegacyZeroDec(),
AssetState: nil,
OperatorShare: sdkmath.LegacyDec{},
StakerShare: sdkmath.LegacyDec{},
Expand Down
2 changes: 1 addition & 1 deletion proto/exocore/operator/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ message AVSUSDValue {
// it's corresponding to the kvStore `KeyPrefixUSDValueForOperator`
message OperatorUSDValue {
// key is used for storing the voting power of specified operator and AVS,
// which is the combination of operator and AVS address.
// which is the combination of AVS and operator address.
string key = 1;
// value is the USD value states for the AVS address
OperatorOptedUSDValue opted_usd_value = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "OptedUSDValue"];
Expand Down
94 changes: 82 additions & 12 deletions proto/exocore/operator/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ option go_package = "github.com/ExocoreNetwork/exocore/x/operator/types";
// QueryOperatorInfoReq is the request to obtain the operator information.
message GetOperatorInfoReq {
// operator_addr is the operator address,its type should be a sdk.AccAddress
string operator_addr = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string operator_addr = 1
[(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryAllOperatorsRequest is the request to obtain all operators.
Expand Down Expand Up @@ -53,13 +54,15 @@ message QueryOperatorUSDValueRequest {
// QueryOperatorUSDValueResponse is the response to obtain the USD value for operator.
message QueryOperatorUSDValueResponse {
// usd_info includes the self and total staking for the operator and AVS
OperatorOptedUSDValue usd_values = 1 [(gogoproto.customname) = "USDValues"];
OperatorOptedUSDValue usd_values = 1
[(gogoproto.customname) = "USDValues"];
}

// QueryAVSUSDValueRequest is the request to obtain the USD value for AVS.
message QueryAVSUSDValueRequest {
// avs_address is the AVS address opted-in by the operator
string avs_address = 1 [(gogoproto.customname) = "AVSAddress"];
string avs_address = 1
[(gogoproto.customname) = "AVSAddress"];
}

// QueryOperatorSlashInfoRequest is the request to obtain the slash information for the specified
Expand Down Expand Up @@ -223,6 +226,55 @@ message QueryOptInfoRequest {
OperatorAVSAddress operator_and_avs = 1 [(gogoproto.embed) = true];
}

// QuerySnapshotHelperRequest is the request to obtain the voting power snapshot
// helper information.
message QuerySnapshotHelperRequest {
// avs address
string avs = 1;
}

// QuerySpecifiedSnapshotRequest is the request to obtain the voting power snapshot
// at the specified height.
message QuerySpecifiedSnapshotRequest {
// avs address
string avs = 1;
// height is used to specify the snapshot height you want to query.
int64 height = 2;
}

// VotingPowerSnapshotKeyHeight is used in the response of QuerySpecifiedSnapshot
// and QueryAllSnapshot
message VotingPowerSnapshotKeyHeight {
// snapshot_key_height when it is used in QuerySpecifiedSnapshot, it's the latest
// height with a snapshot key found based on the input height; this height is typically
// the start height of the epoch in which the input height is located.
// when it is used in QueryAllSnapshot, it's the height in the current snapshot key.
int64 snapshot_key_height =1;
// snapshot when it is used in QuerySpecifiedSnapshot, it is the final retrieved information
// containing the voting power set.
// when it is used in QueryAllSnapshot, It is the snapshot stored under `snapshot_key_height`,
// and its voting power set may be nil.
VotingPowerSnapshot snapshot = 2;
}

// QueryAllSnapshotRequest is the request to obtain all voting power snapshot
// for the specified AVS
message QueryAllSnapshotRequest {
// avs address
string avs = 1;
// pagination related options.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryAllSnapshotResponse is the response to obtain all voting power snapshot
// for the specified AVS
message QueryAllSnapshotResponse {
// snapshots is a list of all snapshots for the specified AVS.
repeated VotingPowerSnapshotKeyHeight snapshots = 1;
// pagination related response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// Query defines the gRPC querier service.
service Query {
// QueryOperatorInfo queries the operator information.
Expand Down Expand Up @@ -261,20 +313,22 @@ service Query {
}

// QueryOperatorUSDValue queries the opted-in USD value for the operator
rpc QueryOperatorUSDValue(QueryOperatorUSDValueRequest) returns (QueryOperatorUSDValueResponse) {
option (google.api.http).get = "/exocore/operator/v1/query_operator_usd_value/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
rpc QueryOperatorUSDValue(QueryOperatorUSDValueRequest) returns(QueryOperatorUSDValueResponse){
option (google.api.http).get =
"/exocore/operator/v1/operator_usd_value/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
}

// QueryAVSUSDValue queries the USD value for the AVS
rpc QueryAVSUSDValue(QueryAVSUSDValueRequest) returns (DecValueField) {
option (google.api.http).get = "/exocore/operator/v1/QueryAVSUSDValue";
rpc QueryAVSUSDValue(QueryAVSUSDValueRequest) returns(DecValueField){
option (google.api.http).get = "/exocore/operator/v1/avs_usd_value";
}

// QueryOperatorSlashInfo queries the slash information for the specified operator and AVS
rpc QueryOperatorSlashInfo(QueryOperatorSlashInfoRequest) returns (QueryOperatorSlashInfoResponse) {
option (google.api.http).get = "/exocore/operator/v1/query_operator_slash_info/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
rpc QueryOperatorSlashInfo(QueryOperatorSlashInfoRequest) returns(QueryOperatorSlashInfoResponse){
option (google.api.http).get =
"/exocore/operator/v1/operator_slash_info/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
}

// QueryAllOperatorConsAddrsByChainID queries all operators and their consensus addresses
Expand All @@ -287,7 +341,8 @@ service Query {
}

// QueryAllOperatorsWithOptInAVS queries operator list by avs.
rpc QueryAllOperatorsWithOptInAVS(QueryAllOperatorsByOptInAVSRequest) returns (QueryAllOperatorsByOptInAVSResponse) {
rpc QueryAllOperatorsWithOptInAVS(QueryAllOperatorsByOptInAVSRequest) returns (
QueryAllOperatorsByOptInAVSResponse) {
option (google.api.http) = {
get: "/exocore/operator/v1/opt/operator_list/{avs}"
};
Expand All @@ -307,6 +362,21 @@ service Query {
};
}

// QuerySnapshotHelper queries the snapshot helper of the AVS
rpc QuerySnapshotHelper(QuerySnapshotHelperRequest) returns (SnapshotHelper) {
option (google.api.http).get = "/exocore/operator/v1/snapshot_helper/{avs}";
}

// QuerySpecifiedSnapshot queries the voting power snapshot of specified AVS and height
rpc QuerySpecifiedSnapshot(QuerySpecifiedSnapshotRequest) returns (VotingPowerSnapshotKeyHeight) {
option (google.api.http).get = "/exocore/operator/v1/snapshot/{avs}/{height}";
}

// QueryAllSnapshot queries all voting power snapshot for the specified AVS
rpc QueryAllSnapshot(QueryAllSnapshotRequest) returns (QueryAllSnapshotResponse) {
option (google.api.http).get = "/exocore/operator/v1/all_snapshot/{avs}";
}

// Validators queries all validators that match the given status.
// When called from another module, this query might consume a high amount of
// gas if the pagination field is incorrectly set.
Expand Down
Loading
Loading