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: observer rewards #855

Merged
merged 57 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
27f981b
add proto file for crosschain events
kingpinXD Jul 13, 2023
6a18920
add proto file for observer and emission events
kingpinXD Jul 13, 2023
6aa735f
remove unnecessary print lines
kingpinXD Jul 13, 2023
21c97ed
Merge branch 'develop' into refactor/typed-events
kingpinXD Jul 13, 2023
ea1123f
move node account from x/crosschain to x/observer
kingpinXD Jul 13, 2023
afd5d69
cli tests for observer module
kingpinXD Jul 14, 2023
945b468
resolve conflicts for status.go
kingpinXD Jul 17, 2023
7437fbe
add ignore annotations for gosec
kingpinXD Jul 18, 2023
4560925
add ignore annotations for gosec
kingpinXD Jul 18, 2023
6939020
move permission flags to observer module
kingpinXD Jul 18, 2023
4b631c5
add cli tests for permission_flags
kingpinXD Jul 19, 2023
2cd7092
add last block count
kingpinXD Jul 19, 2023
469bae5
move keygen to observer module
kingpinXD Jul 19, 2023
b29814e
remove extra proto files
kingpinXD Jul 19, 2023
09ee703
modify makefile to remove old types
kingpinXD Jul 19, 2023
054cc1b
fix unit tests for keygen
kingpinXD Jul 19, 2023
253175b
add modifying keygen to Begin Block
kingpinXD Jul 20, 2023
262f65e
add modifying keygen to Begin Block
kingpinXD Jul 20, 2023
b1d03f1
add migrator for node accounts in v6.0.0
kingpinXD Jul 20, 2023
a9f7641
add migrator for keygen and permission flags in v6.0.0
kingpinXD Jul 20, 2023
2a69338
modify consensus version in version map to trigger migration function
kingpinXD Jul 20, 2023
e5b3ce9
add log lines to explain migration
kingpinXD Jul 20, 2023
9782bf1
Set value for last block height count
kingpinXD Jul 20, 2023
c0d104d
add early return if LastBlockHeight count is not found
kingpinXD Jul 20, 2023
1cf887d
reset lasBlock observer count on on change in value
kingpinXD Jul 21, 2023
967e8dd
reset lasBlock observer count on on change in value
kingpinXD Jul 21, 2023
a04ae76
Add grpc query for last observer count
kingpinXD Jul 21, 2023
6e2c6df
rebase develop to merge changes for typed events
kingpinXD Jul 21, 2023
452206c
fix errors due to types in inbound voter
kingpinXD Jul 21, 2023
5c4637e
increment to version 7
kingpinXD Jul 21, 2023
7eadeaf
rebase develop to add blame logic to observer module
kingpinXD Jul 24, 2023
c2c4dab
add emissions test structure
kingpinXD Jul 25, 2023
0eda7fa
add new query for emissions
kingpinXD Jul 25, 2023
db38fc5
add new query for emissions
kingpinXD Jul 25, 2023
70ab971
add withdrawble_emisions.proto
kingpinXD Jul 25, 2023
67b0abe
observer emissions cli test
kingpinXD Jul 26, 2023
9d4de8e
remove test table
kingpinXD Jul 26, 2023
9841742
reduce test to use 20 randomized ballots
kingpinXD Jul 26, 2023
8499d8c
rebased develop
kingpinXD Jul 26, 2023
a136a0e
enable slashing even if all finalized ballots were fake
kingpinXD Jul 31, 2023
425418f
Add comments to explain logic
kingpinXD Jul 31, 2023
13813f0
Merge branch 'develop' into feature/observer-rewards
kingpinXD Jul 31, 2023
e476632
Merge branch 'develop' into feature/observer-rewards
kingpinXD Aug 1, 2023
9dae8c6
generate specs
kingpinXD Aug 1, 2023
8c4fc8a
rebase develop
kingpinXD Aug 1, 2023
ad32324
add creation height to ballot
kingpinXD Aug 1, 2023
6f7159e
modify identifiers to more meaningful names
kingpinXD Aug 8, 2023
3a1a4c3
include code suggestions
kingpinXD Aug 9, 2023
637584c
rebase develop
kingpinXD Aug 9, 2023
aef6b96
Merge branch 'develop' into feature/observer-rewards
lumtis Aug 10, 2023
d0015e4
modify protobuf styles
kingpinXD Aug 10, 2023
0d2dce7
add proto format
kingpinXD Aug 10, 2023
55c3930
update specs to match changes in proto files
kingpinXD Aug 10, 2023
8d11f40
Add proto-format back to the the makefile
kingpinXD Aug 11, 2023
90d9450
rebase develop
kingpinXD Aug 11, 2023
371a017
generate api specs
kingpinXD Aug 11, 2023
6d1dbcb
Merge branch 'develop' into feature/observer-rewards
kingpinXD Aug 14, 2023
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
5 changes: 4 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ func New(
keys[emissionsModuleTypes.MemStoreKey],
app.GetSubspace(emissionsModuleTypes.ModuleName),
authtypes.FeeCollectorName,
app.BankKeeper,
app.StakingKeeper,
app.ZetaObserverKeeper,
)
// Create Ethermint keepers
tracer := cast.ToString(appOpts.Get(srvflags.EVMTracer))
Expand Down Expand Up @@ -461,7 +464,7 @@ func New(
zetaCoreModule.NewAppModule(appCodec, app.ZetaCoreKeeper, app.StakingKeeper),
zetaObserverModule.NewAppModule(appCodec, *app.ZetaObserverKeeper, app.AccountKeeper, app.BankKeeper),
fungibleModule.NewAppModule(appCodec, app.FungibleKeeper, app.AccountKeeper, app.BankKeeper),
emissionsModule.NewAppModule(appCodec, app.EmissionsKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.ZetaObserverKeeper),
emissionsModule.NewAppModule(appCodec, app.EmissionsKeeper, app.AccountKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
)

Expand Down
54 changes: 54 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27442,6 +27442,21 @@ paths:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/zetacore/emissions/get_emmisons_factors:
get:
summary: Queries a list of GetEmmisonsFactors items.
operationId: Query_GetEmmisonsFactors
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/emissionsQueryGetEmmisonsFactorsResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/zetacore/emissions/list_addresses:
get:
summary: Queries a list of ListBalances items.
Expand Down Expand Up @@ -27472,6 +27487,26 @@ paths:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/zetacore/emissions/show_available_emissions/{address}:
get:
summary: Queries a list of ShowAvailableEmissions items.
operationId: Query_ShowAvailableEmissions
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/emissionsQueryShowAvailableEmissionsResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: address
in: path
required: true
type: string
tags:
- Query
/zeta-chain/zetacore/fungible/foreign_coins:
get:
summary: Queries a list of ForeignCoins items.
Expand Down Expand Up @@ -50370,6 +50405,15 @@ definitions:
type: string
tx_signer:
type: string
emissionsQueryGetEmmisonsFactorsResponse:
type: object
properties:
reservesFactor:
type: string
bondFactor:
type: string
durationFactor:
type: string
emissionsQueryListPoolAddressesResponse:
type: object
properties:
Expand All @@ -50379,6 +50423,11 @@ definitions:
type: string
emission_module_address:
type: string
emissionsQueryShowAvailableEmissionsResponse:
type: object
properties:
amount:
type: string
fungibleForeignCoins:
type: object
properties:
Expand Down Expand Up @@ -50855,6 +50904,8 @@ definitions:
type: string
duration_factor_constant:
type: string
observer_slash_amount:
type: string
description: Params defines the parameters for the module.
zetacoreemissionsQueryParamsResponse:
type: object
Expand Down Expand Up @@ -50886,6 +50937,9 @@ definitions:
items:
type: object
$ref: '#/definitions/observerAdmin_Policy'
ballot_maturity_blocks:
type: string
format: int64
description: Params defines the parameters for the module.
zetacoreobserverQueryParamsResponse:
type: object
Expand Down
33 changes: 25 additions & 8 deletions proto/emissions/events.proto
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
syntax = "proto3";
package zetachain.zetacore.emissions;

import "gogoproto/gogo.proto";

option go_package = "github.com/zeta-chain/zetacore/x/emissions/types";

message EventBlockEmissions {
string msg_type_url = 1;
string bond_factor = 2;
string reserves_factor = 3;
string duration_factor = 4;
string validator_rewards_for_block = 5;
string observer_rewards_for_block = 6;
string tss_rewards_for_block = 7;
enum EmissionType {
option (gogoproto.goproto_enum_stringer) = true;
Slash = 0;
Rewards = 1;
}
message ObserverEmission {
EmissionType emission_type = 1;
string observer_address = 2;
string amount = 3;
lumtis marked this conversation as resolved.
Show resolved Hide resolved
}

message EventObserverEmissions {
string msg_type_url = 1;
repeated ObserverEmission emissions = 2;
}
message EventBlockEmissions {
string msg_type_url = 1;
string bond_factor = 2 ;
string reserves_factor = 3 ;
string duration_factor = 4 ;
string validator_rewards_for_block = 5 ;
string observer_rewards_for_block = 6 ;
string tss_rewards_for_block = 7 ;
}
17 changes: 9 additions & 8 deletions proto/emissions/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ option go_package = "github.com/zeta-chain/zetacore/x/emissions/types";
// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;
string max_bond_factor = 1;
string min_bond_factor = 2;
string avg_block_time = 3;
string target_bond_ratio = 4;
string validator_emission_percentage = 5;
string observer_emission_percentage = 6;
string tss_signer_emission_percentage = 7;
string duration_factor_constant = 8;
string max_bond_factor =1 ;
string min_bond_factor =2;
string avg_block_time =3 ;
string target_bond_ratio =4;
string validator_emission_percentage=5;
string observer_emission_percentage=6;
string tss_signer_emission_percentage=7;
string duration_factor_constant=8;
string observer_slash_amount=9;
lumtis marked this conversation as resolved.
Show resolved Hide resolved
}
37 changes: 34 additions & 3 deletions proto/emissions/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ service Query {
option (google.api.http).get = "/zeta-chain/zetacore/emissions/params";
}
// Queries a list of ListBalances items.
rpc ListPoolAddresses(QueryListPoolAddressesRequest) returns (QueryListPoolAddressesResponse) {
option (google.api.http).get = "/zeta-chain/zetacore/emissions/list_addresses";
}
rpc ListPoolAddresses(QueryListPoolAddressesRequest) returns (QueryListPoolAddressesResponse) {
option (google.api.http).get = "/zeta-chain/zetacore/emissions/list_addresses";
}

// Queries a list of GetEmmisonsFactors items.
rpc GetEmmisonsFactors(QueryGetEmmisonsFactorsRequest) returns (QueryGetEmmisonsFactorsResponse) {
option (google.api.http).get = "/zeta-chain/zetacore/emissions/get_emmisons_factors";
}

// Queries a list of ShowAvailableEmissions items.
rpc ShowAvailableEmissions(QueryShowAvailableEmissionsRequest) returns (QueryShowAvailableEmissionsResponse) {
option (google.api.http).get = "/zeta-chain/zetacore/emissions/show_available_emissions/{address}";
}
lumtis marked this conversation as resolved.
Show resolved Hide resolved

// this line is used by starport scaffolding # 2
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand All @@ -36,3 +48,22 @@ message QueryListPoolAddressesResponse {
string undistributed_tss_balances_address = 2;
string emission_module_address = 3;
}

message QueryGetEmmisonsFactorsRequest {
}

message QueryGetEmmisonsFactorsResponse {
string reservesFactor = 1;
string bondFactor = 2;
string durationFactor = 3;
}

message QueryShowAvailableEmissionsRequest {
string address = 1;
}

message QueryShowAvailableEmissionsResponse {
string amount = 1;
}

// this line is used by starport scaffolding # 3
14 changes: 14 additions & 0 deletions proto/emissions/withdrawable_emisions.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package zetachain.zetacore.emissions;

import "gogoproto/gogo.proto";

option go_package = "github.com/zeta-chain/zetacore/x/emissions/types";

message WithdrawableEmissions {
string address = 1;
string amount = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
8 changes: 7 additions & 1 deletion proto/observer/ballot.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ message Ballot {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
BallotStatus ballot_status = 7;
BallotStatus ballot_status =7;
int64 Ballot_creation_height=8;
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}

message BallotListForHeight {
int64 height = 1;
repeated string ballots_index_list = 2;
}
1 change: 1 addition & 0 deletions proto/observer/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ message GenesisState {
PermissionFlags permissionFlags = 4;
Params params = 5;
Keygen keygen = 6;
LastObserverCount lastObserverCount = 7;
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 4 additions & 2 deletions proto/observer/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ enum Policy_Type {

message Admin_Policy {
Policy_Type policy_type = 1;
string address = 2;
string address =2 ;
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}


// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;
repeated ObserverParams observer_params = 1;
repeated Admin_Policy admin_policy = 2;
}
int64 ballot_maturity_blocks = 3;
kevinssgh marked this conversation as resolved.
Show resolved Hide resolved
}
97 changes: 83 additions & 14 deletions testutil/network/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,23 @@ package network

import (
"encoding/json"
"fmt"
"strconv"
"testing"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ethcfg "github.com/evmos/ethermint/cmd/config"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/stretchr/testify/assert"
"github.com/zeta-chain/zetacore/app"
cmdcfg "github.com/zeta-chain/zetacore/cmd/zetacored/config"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/testutil/nullify"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observerTypes "github.com/zeta-chain/zetacore/x/observer/types"
)

func Setconfig() {
config := sdk.GetConfig()
cmdcfg.SetBech32Prefixes(config)
ethcfg.SetBip44CoinType(config)
// Make sure address is compatible with ethereum
config.SetAddressVerifier(app.VerifyAddressFormat)
//config.Seal()
}

func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage, codec codec.Codec, observerList []string) map[string]json.RawMessage {
func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage, codec codec.Codec, observerList []string) {

// Cross-chain genesis state
var crossChainGenesis types.GenesisState
Expand Down Expand Up @@ -82,5 +74,82 @@ func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage
genesisState[stakingtypes.ModuleName] = stakingGenesisStateBz
genesisState[observerTypes.ModuleName] = observerGenesisBz
genesisState[evmtypes.ModuleName] = evmGenesisBz
return genesisState
}

func AddObserverData(t *testing.T, genesisState map[string]json.RawMessage, codec codec.Codec, ballots []*observerTypes.Ballot) *observerTypes.GenesisState {
state := observerTypes.GenesisState{}
assert.NoError(t, codec.UnmarshalJSON(genesisState[observerTypes.ModuleName], &state))
if len(ballots) > 0 {
state.Ballots = ballots
}
//params := observerTypes.DefaultParams()
//params.BallotMaturityBlocks = 3
state.Params.BallotMaturityBlocks = 3
state.Keygen = &observerTypes.Keygen{BlockNumber: 10, GranteePubkeys: []string{}}
permissionFlags := &observerTypes.PermissionFlags{}
nullify.Fill(&permissionFlags)
state.PermissionFlags = permissionFlags

buf, err := codec.MarshalJSON(&state)
assert.NoError(t, err)
genesisState[observerTypes.ModuleName] = buf
return &state
}
func AddCrosschainData(t *testing.T, n int, genesisState map[string]json.RawMessage, codec codec.Codec) *types.GenesisState {
state := types.GenesisState{}
assert.NoError(t, codec.UnmarshalJSON(genesisState[types.ModuleName], &state))
// TODO : Fix add EVM balance to deploy contracts
for i := 0; i < n; i++ {
state.CrossChainTxs = append(state.CrossChainTxs, &types.CrossChainTx{
Creator: "ANY",
Index: strconv.Itoa(i),
CctxStatus: &types.Status{
Status: types.CctxStatus_PendingInbound,
StatusMessage: "",
LastUpdateTimestamp: 0,
},
InboundTxParams: &types.InboundTxParams{InboundTxObservedHash: fmt.Sprintf("Hash-%d", i), Amount: math.OneUint()},
OutboundTxParams: []*types.OutboundTxParams{},
ZetaFees: math.OneUint()},
)
}
for i := 0; i < n; i++ {
state.ChainNoncesList = append(state.ChainNoncesList, &types.ChainNonces{Creator: "ANY", Index: strconv.Itoa(i), Signers: []string{}})
}
for i := 0; i < n; i++ {
state.GasPriceList = append(state.GasPriceList, &types.GasPrice{Creator: "ANY", ChainId: int64(i), Index: strconv.Itoa(i), Prices: []uint64{}, BlockNums: []uint64{}, Signers: []string{}})
}
for i := 0; i < n; i++ {
state.LastBlockHeightList = append(state.LastBlockHeightList, &types.LastBlockHeight{Creator: "ANY", Index: strconv.Itoa(i)})
}

state.Tss = &types.TSS{
TssPubkey: "tssPubkey",
TssParticipantList: []string{"tssParticipantList"},
OperatorAddressList: []string{"operatorAddressList"},
FinalizedZetaHeight: 1,
KeyGenZetaHeight: 1,
}
for i := 0; i < n; i++ {
outTxTracker := types.OutTxTracker{
Index: fmt.Sprintf("%d-%d", i, i),
ChainId: int64(i),
Nonce: uint64(i),
}
nullify.Fill(&outTxTracker)
state.OutTxTrackerList = append(state.OutTxTrackerList, outTxTracker)
}

for i := 0; i < n; i++ {
inTxHashToCctx := types.InTxHashToCctx{
InTxHash: strconv.Itoa(i),
}
nullify.Fill(&inTxHashToCctx)
state.InTxHashToCctxList = append(state.InTxHashToCctxList, inTxHashToCctx)
}

buf, err := codec.MarshalJSON(&state)
assert.NoError(t, err)
genesisState[types.ModuleName] = buf
return &state
}
Loading