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

Add VotingPower to abci.Evidence #312

Merged
merged 5 commits into from
Sep 6, 2021
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
472 changes: 236 additions & 236 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions evidence/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ func TestEvidencePoolBasic(t *testing.T) {
var evidenceBytes int64
switch keyType := voterSet.Voters[0].PubKey.(type) {
case ed25519.PubKey:
evidenceBytes = 372
evidenceBytes = 375
case bls.PubKey:
evidenceBytes = 436
evidenceBytes = 439
case composite.PubKey:
evidenceBytes = 436
evidenceBytes = 439
default:
assert.Fail(t, fmt.Sprintf("unknown public key: %s", keyType))
}
Expand Down
10 changes: 5 additions & 5 deletions proto/ostracon/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -356,22 +356,22 @@ message TxResult {
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
int64 power = 3; // The staking power

// *** Ostracon Extended Fields ***
int64 voting_power = 1000; // The voting power
}

// ValidatorUpdate
message ValidatorUpdate {
ostracon.crypto.PublicKey pub_key = 1 [(gogoproto.nullable) = false];
int64 power = 2;
int64 power = 2; // The staking power
}

// VoteInfo
message VoteInfo {
Validator validator = 1 [(gogoproto.nullable) = false];
bool signed_last_block = 2;

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

enum EvidenceType {
Expand Down
109 changes: 74 additions & 35 deletions proto/ostracon/types/evidence.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions proto/ostracon/types/evidence.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ message DuplicateVoteEvidence {
int64 total_voting_power = 3;
int64 validator_power = 4;
google.protobuf.Timestamp timestamp = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];

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

// LightClientAttackEvidence contains evidence of a set of validators attempting to mislead a light client.
Expand Down
4 changes: 1 addition & 3 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,7 @@ func getBeginBlockValidatorInfo(block *types.Block, store Store,
for i, voter := range lastVoterSet.Voters {
commitSig := block.LastCommit.Signatures[i]
voteInfos[i] = abci.VoteInfo{
Validator: types.OC2PB.Validator(voter),
// TODO We need to change distribution of cosmos-sdk in order to reference this power for reward later
VotingPower: voter.VotingPower,
Validator: types.OC2PB.Validator(voter),
SignedLastBlock: !commitSig.Absent(),
}
}
Expand Down
2 changes: 2 additions & 0 deletions state/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func TestBeginBlockByzantineValidators(t *testing.T) {
defer proxyApp.Stop() //nolint:errcheck // ignore for tests

state, stateDB, privVals := makeState(2, 12)
state.Validators.Validators[0].VotingPower = 10
stateStore := sm.NewStore(stateDB)

defaultEvidenceTime := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
Expand All @@ -161,6 +162,7 @@ func TestBeginBlockByzantineValidators(t *testing.T) {
// we don't need to worry about validating the evidence as long as they pass validate basic
dve := types.NewMockDuplicateVoteEvidenceWithValidator(3, defaultEvidenceTime, privVal, state.ChainID)
dve.ValidatorPower = 1000
dve.VotingPower = state.Validators.Validators[0].VotingPower
lcae := &types.LightClientAttackEvidence{
ConflictingBlock: &types.LightBlock{
SignedHeader: &types.SignedHeader{
Expand Down
15 changes: 8 additions & 7 deletions types/evidence.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type DuplicateVoteEvidence struct {

// abci specific information
TotalVotingPower int64
VotingPower int64
ValidatorPower int64
Timestamp time.Time
}
Expand Down Expand Up @@ -83,6 +84,7 @@ func NewDuplicateVoteEvidence(vote1, vote2 *Vote, blockTime time.Time, voterSet
VoteA: voteA,
VoteB: voteB,
TotalVotingPower: voterSet.TotalVotingPower(),
VotingPower: val.VotingPower,
ValidatorPower: val.StakingPower,
Timestamp: blockTime,
}
Expand All @@ -93,8 +95,9 @@ func (dve *DuplicateVoteEvidence) ABCI() []abci.Evidence {
return []abci.Evidence{{
Type: abci.EvidenceType_DUPLICATE_VOTE,
Validator: abci.Validator{
Address: dve.VoteA.ValidatorAddress,
Power: dve.ValidatorPower,
Address: dve.VoteA.ValidatorAddress,
Power: dve.ValidatorPower,
VotingPower: dve.VotingPower,
},
Height: dve.VoteA.Height,
Time: dve.Timestamp,
Expand Down Expand Up @@ -163,6 +166,7 @@ func (dve *DuplicateVoteEvidence) ToProto() *tmproto.DuplicateVoteEvidence {
VoteA: voteA,
VoteB: voteB,
TotalVotingPower: dve.TotalVotingPower,
VotingPower: dve.VotingPower,
ValidatorPower: dve.ValidatorPower,
Timestamp: dve.Timestamp,
}
Expand All @@ -189,6 +193,7 @@ func DuplicateVoteEvidenceFromProto(pb *tmproto.DuplicateVoteEvidence) (*Duplica
VoteA: vA,
VoteB: vB,
TotalVotingPower: pb.TotalVotingPower,
VotingPower: pb.VotingPower,
ValidatorPower: pb.ValidatorPower,
Timestamp: pb.Timestamp,
}
Expand Down Expand Up @@ -219,13 +224,9 @@ var _ Evidence = &LightClientAttackEvidence{}
func (l *LightClientAttackEvidence) ABCI() []abci.Evidence {
abciEv := make([]abci.Evidence, len(l.ByzantineValidators))
for idx, val := range l.ByzantineValidators {
pb := abci.Validator{
Address: val.Address,
Power: val.StakingPower,
}
abciEv[idx] = abci.Evidence{
Type: abci.EvidenceType_LIGHT_CLIENT_ATTACK,
Validator: pb,
Validator: OC2PB.Validator(val),
Height: l.Height(),
Time: l.Timestamp,
TotalVotingPower: l.TotalVotingPower,
Expand Down
5 changes: 3 additions & 2 deletions types/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ func (oc2pb) Header(header *Header) tmproto.Header {

func (oc2pb) Validator(val *Validator) abci.Validator {
return abci.Validator{
Address: val.PubKey.Address(),
Power: val.StakingPower,
Address: val.PubKey.Address(),
Power: val.StakingPower,
VotingPower: val.VotingPower,
}
}

Expand Down