Skip to content

Commit

Permalink
feat: apply the ostracon's change that replace StakingPower with `V…
Browse files Browse the repository at this point in the history
…otingPower` and `StakingPower` with `VotingWeight`.

Finschia/ostracon#449

Signed-off-by: zemyblue <zemyblue@gmail.com>
  • Loading branch information
zemyblue committed Jul 28, 2022
1 parent ea98f03 commit 9b22188
Show file tree
Hide file tree
Showing 14 changed files with 672 additions and 661 deletions.
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ require (
replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/line/ostracon => github.com/tnasu/ostracon v1.0.3-0.20220728111707-feba108bf018

google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ 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/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 +1106,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.20220728111707-feba108bf018 h1:vOPqNcM9tNntroYNS9AnCKSGsbQsnygqGcLN3WzD2UU=
github.com/tnasu/ostracon v1.0.3-0.20220728111707-feba108bf018/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

0 comments on commit 9b22188

Please sign in to comment.