Skip to content

Commit 2357bf1

Browse files
authored
Merge pull request #326 from KiraCore/v0.1.25-rc.10
v0.1.25-rc.10 -> master
2 parents dc77c1f + 311ffdd commit 2357bf1

33 files changed

+3857
-89
lines changed

RELEASE.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
**Features:**
44

5-
- Removed setup step from main workflow
6-
- Added new transfer test to local tests
7-
- Fixed utils script missing home flags for some of the transaction queries
8-
- Added faucet account to local network setup
5+
- Snapshot period to 1000
6+
- Add example scripts
7+
- Add query for validator performance during snapshot period

app/app.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88

99
customante "github.com/KiraCore/sekai/app/ante"
1010
"github.com/KiraCore/sekai/middleware"
11+
"github.com/KiraCore/sekai/x/distributor"
12+
distributorkeeper "github.com/KiraCore/sekai/x/distributor/keeper"
13+
distributortypes "github.com/KiraCore/sekai/x/distributor/types"
1114
"github.com/KiraCore/sekai/x/evidence"
1215
evidencekeeper "github.com/KiraCore/sekai/x/evidence/keeper"
1316
evidencetypes "github.com/KiraCore/sekai/x/evidence/types"
@@ -92,6 +95,7 @@ var (
9295
customstaking.AppModuleBasic{},
9396
customgov.AppModuleBasic{},
9497
spending.AppModuleBasic{},
98+
distributor.AppModuleBasic{},
9599
ubi.AppModuleBasic{},
96100
evidence.AppModuleBasic{},
97101
tokens.AppModuleBasic{},
@@ -100,10 +104,11 @@ var (
100104

101105
// module account permissions
102106
maccPerms = map[string][]string{
103-
authtypes.FeeCollectorName: nil,
104-
govtypes.ModuleName: nil,
105-
minttypes.ModuleName: {authtypes.Minter},
106-
spendingtypes.ModuleName: nil,
107+
authtypes.FeeCollectorName: nil,
108+
govtypes.ModuleName: nil,
109+
minttypes.ModuleName: {authtypes.Minter},
110+
spendingtypes.ModuleName: nil,
111+
distributortypes.ModuleName: nil,
107112
}
108113

109114
// module accounts that are allowed to receive tokens
@@ -138,6 +143,7 @@ type SekaiApp struct {
138143
EvidenceKeeper evidencekeeper.Keeper
139144
SpendingKeeper spendingkeeper.Keeper
140145
UbiKeeper ubikeeper.Keeper
146+
DistrKeeper distributorkeeper.Keeper
141147

142148
// Module Manager
143149
mm *module.Manager
@@ -180,6 +186,7 @@ func NewInitApp(
180186
stakingtypes.ModuleName,
181187
govtypes.ModuleName,
182188
spendingtypes.ModuleName,
189+
distributortypes.ModuleName,
183190
ubitypes.ModuleName,
184191
tokenstypes.ModuleName,
185192
feeprocessingtypes.ModuleName,
@@ -223,6 +230,7 @@ func NewInitApp(
223230
app.CustomStakingKeeper = *customStakingKeeper.SetHooks(
224231
stakingtypes.NewMultiStakingHooks(app.CustomSlashingKeeper.Hooks()),
225232
)
233+
app.DistrKeeper = distributorkeeper.NewKeeper(keys[distributortypes.ModuleName], appCodec, app.AccountKeeper, app.BankKeeper, app.CustomStakingKeeper, app.CustomGovKeeper)
226234

227235
app.UpgradeKeeper = upgradekeeper.NewKeeper(keys[upgradetypes.StoreKey], appCodec, app.CustomStakingKeeper)
228236

@@ -291,6 +299,7 @@ func NewInitApp(
291299
customgov.NewAppModule(app.CustomGovKeeper),
292300
tokens.NewAppModule(app.TokensKeeper, app.CustomGovKeeper),
293301
spending.NewAppModule(app.SpendingKeeper, app.CustomGovKeeper, app.BankKeeper),
302+
distributor.NewAppModule(app.DistrKeeper, app.CustomGovKeeper),
294303
ubi.NewAppModule(app.UbiKeeper, app.CustomGovKeeper),
295304
feeprocessing.NewAppModule(app.FeeProcessingKeeper),
296305
evidence.NewAppModule(app.EvidenceKeeper),
@@ -305,6 +314,7 @@ func NewInitApp(
305314
upgradetypes.ModuleName, slashingtypes.ModuleName,
306315
evidencetypes.ModuleName, stakingtypes.ModuleName,
307316
spendingtypes.ModuleName, ubitypes.ModuleName,
317+
distributortypes.ModuleName,
308318
)
309319
app.mm.SetOrderEndBlockers(
310320
banktypes.ModuleName, upgradetypes.ModuleName, tokenstypes.ModuleName,
@@ -314,6 +324,7 @@ func NewInitApp(
314324
stakingtypes.ModuleName,
315325
feeprocessingtypes.ModuleName,
316326
spendingtypes.ModuleName, ubitypes.ModuleName,
327+
distributortypes.ModuleName,
317328
)
318329

319330
// NOTE: The genutils moodule must occur after staking so that pools are
@@ -335,6 +346,7 @@ func NewInitApp(
335346
spendingtypes.ModuleName,
336347
ubitypes.ModuleName,
337348
paramstypes.ModuleName,
349+
distributortypes.ModuleName,
338350
)
339351

340352
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)

proto/kira/distributor/genesis.proto

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
syntax = "proto3";
2+
package kira.distributor;
3+
4+
option go_package = "github.com/KiraCore/sekai/x/distributor/types";
5+
6+
import "gogoproto/gogo.proto";
7+
8+
message ValidatorVote {
9+
string cons_addr = 1;
10+
int64 height = 2;
11+
}
12+
13+
// GenesisState defines the distributor module's genesis state.
14+
message GenesisState {
15+
// fees that are kept in treasury that is not distributed yet - community pool
16+
repeated string fees_treasury = 1 [
17+
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
18+
(gogoproto.nullable) = false
19+
];
20+
// fees collected from genesis
21+
repeated string fees_collected = 2 [
22+
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
23+
(gogoproto.nullable) = false
24+
];
25+
// number of blocks considered for reward calculation
26+
int64 snap_period = 3;
27+
// validator historical votes
28+
repeated ValidatorVote validator_votes = 4 [(gogoproto.nullable) = false];
29+
}
30+
31+
// https://www.notion.so/kira-network/KIP-73-Fee-Reward-Distributor-v1-32b3d1dc90024befa7bb9680c6a425cd
32+
33+
// {
34+
// snap_period: <integer>,
35+
// snap_block: <integer>,
36+
// snap_balances: [ {
37+
// denom: <string>,
38+
// amount: <integer> },
39+
// { ... }, ... ]
40+
// }
41+
42+
// How to distribute multiple currency fees?
43+
// How to manage distributed and not distributed rewards, current fee balance?
44+
// Distribute the rewards every block - keep remainings
45+
// Check how SDK distribution module detect who produce the block
46+
// How to get accumulated history of participation of previous blocks? (Slashing module still keeps the history or it should be added again?)

proto/kira/distributor/query.proto

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
syntax = "proto3";
2+
package kira.distributor;
3+
4+
import "cosmos/base/query/v1beta1/pagination.proto";
5+
import "gogoproto/gogo.proto";
6+
import "google/protobuf/any.proto";
7+
import "google/api/annotations.proto";
8+
9+
option go_package = "github.com/KiraCore/sekai/x/distributor/types";
10+
11+
// Query defines the gRPC querier service.
12+
service Query {
13+
// FeesTreasury queries fee treasury
14+
rpc FeesTreasury(QueryFeesTreasuryRequest) returns (QueryFeesTreasuryResponse) {
15+
option (google.api.http).get =
16+
"/kira/distributor/v1beta1/fees_treasury";
17+
}
18+
// FeesCollected queries fees collected from genesis
19+
rpc FeesCollected(QueryFeesCollectedRequest) returns (QueryFeesCollectedResponse) {
20+
option (google.api.http).get = "/kira/distributor/v1beta1/fees_collected";
21+
}
22+
// SnapshotPeriod queries number of blocks considered for reward calculation
23+
rpc SnapshotPeriod(QuerySnapshotPeriodRequest) returns (QuerySnapshotPeriodResponse) {
24+
option (google.api.http).get = "/kira/distributor/v1beta1/snapshot_period";
25+
}
26+
// SnapPeriodPerformance queries number of blocks signed during the snap period
27+
rpc SnapshotPeriodPerformance(QuerySnapshotPeriodPerformanceRequest) returns (QuerySnapshotPeriodPerformanceResponse) {
28+
option (google.api.http).get = "/kira/distributor/v1beta1/snapshot_period_performance/{validator_address}";
29+
}
30+
}
31+
32+
message QueryFeesTreasuryRequest {
33+
}
34+
35+
message QueryFeesTreasuryResponse {
36+
repeated string coins = 1 [
37+
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
38+
(gogoproto.nullable) = false
39+
];
40+
}
41+
42+
message QueryFeesCollectedRequest {}
43+
44+
message QueryFeesCollectedResponse {
45+
repeated string coins = 1 [
46+
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
47+
(gogoproto.nullable) = false
48+
];
49+
}
50+
51+
message QuerySnapshotPeriodRequest {}
52+
53+
message QuerySnapshotPeriodResponse {
54+
int64 snapshot_period = 1;
55+
}
56+
57+
message QuerySnapshotPeriodPerformanceRequest {
58+
string validator_address = 1;
59+
}
60+
61+
message QuerySnapshotPeriodPerformanceResponse {
62+
int64 performance = 1;
63+
int64 snapshot_period = 2;
64+
}

proto/kira/distributor/tx.proto

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
syntax = "proto3";
2+
package kira.distributor;
3+
4+
option go_package = "github.com/KiraCore/sekai/x/distributor/types";
5+
option (gogoproto.equal_all) = true;
6+
7+
import "gogoproto/gogo.proto";
8+
import "google/protobuf/any.proto";
9+
import "cosmos_proto/cosmos.proto";
10+
11+
// Msg defines the distributor Msg service.
12+
service Msg {
13+
}

proto/kira/gov/network_properties.proto

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum NetworkProperty {
3535
MIN_IDENTITY_APPROVAL_TIP = 17 [(gogoproto.enumvalue_customname) = "MinIdentityApprovalTip"]; // minimum amount of tip to be paid to the approver per request
3636
UNIQUE_IDENTITY_KEYS = 18 [(gogoproto.enumvalue_customname) = "UniqueIdentityKeys"]; // manages unique identity keys to be used as an address identifier
3737
UBI_HARDCAP = 19 [(gogoproto.enumvalue_customname) = "UbiHardcap"]; // a maximum amount of additional KEX that can be created per year
38+
VALIDATORS_FEE_SHARE = 20 [(gogoproto.enumvalue_customname) = "ValidatorsFeeShare"]; // the percentage that validators get from collected fees
3839
}
3940

4041
message NetworkPropertyValue {
@@ -65,4 +66,5 @@ message NetworkProperties {
6566
uint64 min_identity_approval_tip = 18; // minimum amount of tip to be paid to the approver per request
6667
string unique_identity_keys = 19; // manages unique identity keys to be used as an address identifier
6768
uint64 ubi_hardcap = 20; // a maximum amount of additional KEX that can be created per year
69+
uint64 validators_fee_share = 21; // the percentage that validators get from collected fees
6870
}

scripts/commands/query-distributor.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
# query collected fees so far
4+
sekaid query distributor fees-collected
5+
6+
# query fees treasury
7+
sekaid query distributor fees-treasury
8+
9+
# query snapshot period
10+
sekaid query distributor snapshot-period
11+
12+
# query validator performance
13+
sekaid query distributor snapshot-period-performance kiravaloper177endc8f4tnl44q0x2qct6g9l5af6nm2vlzxd6

types/constants.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package types
33
const (
44
// we set page iteration limit for safety
55
PageIterationLimit = 512
6-
SekaiVersion = "v0.1.24-rc.8"
6+
SekaiVersion = "v0.1.25-rc.10"
77
CosmosVersion = "v0.45.1"
88
)

x/distributor/abci.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package distributor
2+
3+
import (
4+
"time"
5+
6+
abci "github.com/tendermint/tendermint/abci/types"
7+
8+
"github.com/KiraCore/sekai/x/distributor/keeper"
9+
"github.com/KiraCore/sekai/x/distributor/types"
10+
"github.com/cosmos/cosmos-sdk/telemetry"
11+
sdk "github.com/cosmos/cosmos-sdk/types"
12+
)
13+
14+
// BeginBlocker sets the proposer for determining distributor during endblock
15+
// and distribute rewards for the previous block
16+
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
17+
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
18+
19+
// determine the total power signing the block
20+
var previousTotalPower, sumPreviousPrecommitPower int64
21+
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
22+
previousTotalPower += voteInfo.Validator.Power
23+
if voteInfo.SignedLastBlock {
24+
sumPreviousPrecommitPower += voteInfo.Validator.Power
25+
}
26+
}
27+
28+
// TODO this is Tendermint-dependent
29+
// ref https://github.com/cosmos/cosmos-sdk/issues/3095
30+
if ctx.BlockHeight() > 1 {
31+
previousProposer := k.GetPreviousProposerConsAddr(ctx)
32+
k.AllocateTokens(ctx, sumPreviousPrecommitPower, previousTotalPower, previousProposer, req.LastCommitInfo.GetVotes())
33+
}
34+
35+
for _, bondedVote := range req.LastCommitInfo.GetVotes() {
36+
k.SetValidatorVote(ctx, bondedVote.Validator.Address, ctx.BlockHeight())
37+
}
38+
39+
// remove votes older than snap period
40+
snapPeriod := k.GetSnapPeriod(ctx)
41+
allVotes := k.GetAllValidatorVotes(ctx)
42+
for _, vote := range allVotes {
43+
if vote.Height+snapPeriod <= ctx.BlockHeight() {
44+
consAddr, err := sdk.ConsAddressFromBech32(vote.ConsAddr)
45+
if err != nil {
46+
panic(err)
47+
}
48+
k.DeleteValidatorVote(ctx, consAddr, vote.Height)
49+
}
50+
}
51+
52+
// record the proposer for when we payout on the next block
53+
consAddr := sdk.ConsAddress(req.Header.ProposerAddress)
54+
k.SetPreviousProposerConsAddr(ctx, consAddr)
55+
}

0 commit comments

Comments
 (0)