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: apply Ostracon's changes that replace StakingPower with VotingPower and VotingPower with VotingWeight. #614

Merged
merged 6 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (proto) [\#584](https://github.com/line/lbm-sdk/pull/564) remove `prove` field in the `GetTxsEventRequest` of `tx` proto
* (x/collection) [\#571](https://github.com/line/lbm-sdk/pull/571) add x/collection proto
* (x/collection) [\#574](https://github.com/line/lbm-sdk/pull/574) implement x/collection
* (amino) [\#600](https://github.com/line/lbm-sdk/pull/600) change amino codec path from `lbm-sdk/` to `cosmos-sdk/`
* (store) [\#605](https://github.com/line/lbm-sdk/pull/605) replace line/iavl and line/tm-db with cosmos/iavl and tendermint/tm-db.
* (server/grpc) [\#607](https://github.com/line/lbm-sdk/pull/607) revert gRPC block height header.
* (ostracon) [\#610](https://github.com/line/lbm-sdk/pull/610) apply change of prefix of key name in ostracon

### Improvements

Expand All @@ -76,6 +74,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
* (global) [\#603](https://github.com/line/lbm-sdk/pull/603) apply types/address.go from [email protected]
* (amino) [\#600](https://github.com/line/lbm-sdk/pull/600) change amino codec path from `lbm-sdk/` to `cosmos-sdk/`
* (ostracon) [\#610](https://github.com/line/lbm-sdk/pull/610) apply change of prefix of key name in ostracon
* (ostracon) [\#614](https://github.com/line/lbm-sdk/pull/614) apply Ostracon's changes that replace `StakingPower` with `VotingPower` and `StakingPower` with `VotingPower`

### Build, CI

Expand Down
9 changes: 4 additions & 5 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

180 changes: 180 additions & 0 deletions client/docs/swagger-ui/swagger.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/rpc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func StatusCommand() *cobra.Command {
ValidatorInfo: validatorInfo{
Address: status.ValidatorInfo.Address,
PubKey: pk,
VotingPower: status.ValidatorInfo.StakingPower,
VotingPower: status.ValidatorInfo.VotingPower,
},
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3
github.com/improbable-eng/grpc-web v0.15.0
github.com/jhump/protoreflect v1.10.3
github.com/line/ostracon v1.0.7-0.20220727044439-81b4fb7095a8
github.com/line/ostracon v1.0.7-0.20220729051742-2231684789c6
github.com/line/wasmvm v1.0.0-0.10.0
github.com/magiconair/properties v1.8.6
github.com/mailru/easyjson v0.7.7
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QT
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
github.com/line/gorocksdb v0.0.0-20210406043732-d4bea34b6d55/go.mod h1:DHRJroSL7NaRkpvocRx3OtRsleXVsYSxBI9SfHFlTQ0=
github.com/line/ostracon v1.0.7-0.20220727044439-81b4fb7095a8 h1:dm25pZI2k7kM00jKHX17xYQuOuOlaiBVA55DrHjx5JQ=
github.com/line/ostracon v1.0.7-0.20220727044439-81b4fb7095a8/go.mod h1:8gnHCqwRjbJfhVtQkl7KIfcubtpsIEmiN0u91B4EYWY=
github.com/line/ostracon v1.0.7-0.20220729051742-2231684789c6 h1:WKz4yaIW+TJgJv5uhmrHYC3UnohDHlXDT6GccvgV0AA=
github.com/line/ostracon v1.0.7-0.20220729051742-2231684789c6/go.mod h1:8gnHCqwRjbJfhVtQkl7KIfcubtpsIEmiN0u91B4EYWY=
github.com/line/tm-db/v2 v2.0.0-init.1.0.20220121012851-61d2bc1d9486 h1:uvXQdcWaUyNsgkXBz375FpQ285WEJaLXhQ5HtoNK/GU=
github.com/line/tm-db/v2 v2.0.0-init.1.0.20220121012851-61d2bc1d9486/go.mod h1:wmkyPabXjtVZ1dvRofmurjaceghywtCSYGqFuFS+TbI=
github.com/line/wasmvm v1.0.0-0.10.0 h1:lxKdyNrRug/Sk7h2pb0aBsbTMNTesQU+TM/edSS9cg0=
Expand Down Expand Up @@ -1108,6 +1108,8 @@ github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITn
github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tnasu/ostracon v1.0.3-0.20220729034634-5673e418c251 h1:0MBnlFqUFejtabXDfPQg1XxE7Rv5f3up+qslFuct1SQ=
github.com/tnasu/ostracon v1.0.3-0.20220729034634-5673e418c251/go.mod h1:8gnHCqwRjbJfhVtQkl7KIfcubtpsIEmiN0u91B4EYWY=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
Expand Down
3 changes: 3 additions & 0 deletions third_party/proto/ostracon/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ message Validator {
bytes address = 1; // The first 20 bytes of SHA256(public key)
// PubKey pub_key = 2 [(gogoproto.nullable)=false];
int64 power = 3; // The voting power

// *** Ostracon Extended Fields ***
int64 voting_weight = 1000; // The voting weight
}

// ValidatorUpdate
Expand Down
25 changes: 14 additions & 11 deletions third_party/proto/ostracon/types/evidence.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ message Evidence {

// DuplicateVoteEvidence contains evidence of a validator signed two conflicting votes.
message DuplicateVoteEvidence {
ostracon.types.Vote vote_a = 1;
ostracon.types.Vote vote_b = 2;
int64 total_voting_power = 3;
int64 validator_power = 4;
google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
ostracon.types.Vote vote_a = 1;
ostracon.types.Vote vote_b = 2;
int64 total_voting_power = 3; // total voting weight
int64 validator_power = 4; // voting power
google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];

// *** Ostracon Extended Fields ***
int64 voting_weight = 1000;
}

// LightClientAttackEvidence contains evidence of a set of validators attempting to mislead a light client.
message LightClientAttackEvidence {
ostracon.types.LightBlock conflicting_block = 1;
int64 common_height = 2;
repeated ostracon.types.Validator byzantine_validators = 3;
int64 total_voting_power = 4;
google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
ostracon.types.LightBlock conflicting_block = 1;
int64 common_height = 2;
repeated ostracon.types.Validator byzantine_validators = 3;
int64 total_voting_power = 4; // total voting weight
google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}

message EvidenceList {
repeated Evidence evidence = 1 [(gogoproto.nullable) = false];
}
}
3 changes: 3 additions & 0 deletions third_party/proto/ostracon/types/validator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ message Validator {
ostracon.crypto.PublicKey pub_key = 2 [(gogoproto.nullable) = false];
int64 voting_power = 3;
int64 proposer_priority = 4;

// *** Ostracon Extended Fields ***
int64 voting_weight = 1000;
}

message SimpleValidator {
Expand Down
4 changes: 2 additions & 2 deletions third_party/proto/ostracon/types/voter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ option go_package = "github.com/line/ostracon/proto/ostracon/types";
import "ostracon/types/validator.proto";

message VoterSet {
repeated ostracon.types.Validator voters = 1;
int64 total_voting_power = 2;
repeated ostracon.types.Validator voters = 1;
int64 total_voting_weight = 2;
}
4 changes: 2 additions & 2 deletions x/distribution/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
// determine the total power signing the block
var previousTotalPower, sumPreviousPrecommitPower int64
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
previousTotalPower += voteInfo.Validator.VotingPower
previousTotalPower += voteInfo.Validator.VotingWeight
if voteInfo.SignedLastBlock {
sumPreviousPrecommitPower += voteInfo.Validator.VotingPower
sumPreviousPrecommitPower += voteInfo.Validator.VotingWeight
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (k Keeper) AllocateTokens(

// TODO consider microslashing for missing votes.
// ref https://github.com/cosmos/cosmos-sdk/issues/2525#issuecomment-430838701
powerFraction := sdk.NewDec(vote.Validator.VotingPower).QuoTruncate(sdk.NewDec(totalPreviousPower))
powerFraction := sdk.NewDec(vote.Validator.VotingWeight).QuoTruncate(sdk.NewDec(totalPreviousPower))
reward := feesCollected.MulDecTruncate(voteMultiplier).MulDecTruncate(powerFraction)
k.AllocateTokensToValidator(ctx, validator, reward)
remaining = remaining.Sub(reward)
Expand Down
30 changes: 15 additions & 15 deletions x/distribution/keeper/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func TestAllocateTokensToManyValidators(t *testing.T) {
tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), true)

abciValA := abci.Validator{
Address: valConsPk1.Address(),
Power: 100,
VotingPower: 100,
Address: valConsPk1.Address(),
Power: 100,
VotingWeight: 100,
}
abciValB := abci.Validator{
Address: valConsPk2.Address(),
Power: 100,
VotingPower: 100,
Address: valConsPk2.Address(),
Power: 100,
VotingWeight: 100,
}

// assert initial state: zero outstanding rewards, zero community pool, zero commission, zero current rewards
Expand Down Expand Up @@ -137,19 +137,19 @@ func TestAllocateTokensTruncation(t *testing.T) {
tstaking.CreateValidator(valAddrs[2], valConsPk3, sdk.NewInt(100), true)

abciValA := abci.Validator{
Address: valConsPk1.Address(),
Power: 11,
VotingPower: 11,
Address: valConsPk1.Address(),
Power: 11,
VotingWeight: 11,
}
abciValB := abci.Validator{
Address: valConsPk2.Address(),
Power: 10,
VotingPower: 10,
Address: valConsPk2.Address(),
Power: 10,
VotingWeight: 10,
}
abciValС := abci.Validator{
Address: valConsPk3.Address(),
Power: 10,
VotingPower: 10,
Address: valConsPk3.Address(),
Power: 10,
VotingWeight: 10,
}

// assert initial state: zero outstanding rewards, zero community pool, zero commission, zero current rewards
Expand Down
10 changes: 5 additions & 5 deletions x/ibc/testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ type TestChain struct {
Connections []*TestConnection // track connectionID's created for this chain
}

func NewTestValidator(pubkey crypto.PubKey, stakingPower int64) *octypes.Validator {
val := octypes.NewValidator(pubkey, stakingPower)
val.VotingPower = val.StakingPower
func NewTestValidator(pubkey crypto.PubKey, votingPower int64) *octypes.Validator {
val := octypes.NewValidator(pubkey, votingPower)
val.VotingWeight = val.VotingPower
return val
}

Expand Down Expand Up @@ -367,9 +367,9 @@ func (chain *TestChain) GetVotersAtHeight(height int64) (*octypes.VoterSet, bool
panic(err)
}
// Validators saved in HistoricalInfo store have no voting power.
// We set voting power same as staking power for test.
// We set voting weight same as voting power for test.
for i := 0; i < len(ocVoters); i++ {
ocVoters[i].VotingPower = ocVoters[i].StakingPower
ocVoters[i].VotingWeight = ocVoters[i].VotingPower
}
return octypes.WrapValidatorsToVoterSet(ocVoters), true
}
Expand Down
6 changes: 3 additions & 3 deletions x/simulation/mock_ostracon.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ func RandomRequestBeginBlock(r *rand.Rand, params Params,

voteInfos[i] = abci.VoteInfo{
Validator: abci.Validator{
Address: pubkey.Address(),
Power: mVal.val.Power,
VotingPower: mVal.val.Power,
Address: pubkey.Address(),
Power: mVal.val.Power,
VotingWeight: mVal.val.Power,
},
SignedLastBlock: signed,
}
Expand Down
6 changes: 3 additions & 3 deletions x/slashing/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func TestBeginBlocker(t *testing.T) {
require.Equal(t, amt, app.StakingKeeper.Validator(ctx, addr).GetBondedTokens())

val := abci.Validator{
Address: pk.Address(),
Power: power,
VotingPower: power,
Address: pk.Address(),
Power: power,
VotingWeight: power,
}

// mark the validator as having signed
Expand Down
Loading