abci: VoteInfo, ValidatorUpdate. See ADR-018

This commit is contained in:
Ethan Buchman
2018-08-06 00:18:24 -04:00
parent f26b83f15f
commit e3f54ece2f
18 changed files with 706 additions and 452 deletions

View File

@@ -1,7 +1,6 @@
package types
import (
"bytes"
"fmt"
"reflect"
"time"
@@ -56,7 +55,7 @@ func (tm2pb) Header(header *Header) abci.Header {
}
}
func (tm2pb) ValidatorWithoutPubKey(val *Validator) abci.Validator {
func (tm2pb) Validator(val *Validator) abci.Validator {
return abci.Validator{
Address: val.PubKey.Address(),
Power: val.VotingPower,
@@ -78,11 +77,10 @@ func (tm2pb) PartSetHeader(header PartSetHeader) abci.PartSetHeader {
}
// XXX: panics on unknown pubkey type
func (tm2pb) Validator(val *Validator) abci.Validator {
return abci.Validator{
Address: val.PubKey.Address(),
PubKey: TM2PB.PubKey(val.PubKey),
Power: val.VotingPower,
func (tm2pb) ValidatorUpdate(val *Validator) abci.ValidatorUpdate {
return abci.ValidatorUpdate{
PubKey: TM2PB.PubKey(val.PubKey),
Power: val.VotingPower,
}
}
@@ -106,10 +104,10 @@ func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey {
}
// XXX: panics on nil or unknown pubkey type
func (tm2pb) Validators(vals *ValidatorSet) []abci.Validator {
validators := make([]abci.Validator, vals.Size())
func (tm2pb) ValidatorUpdates(vals *ValidatorSet) []abci.ValidatorUpdate {
validators := make([]abci.ValidatorUpdate, vals.Size())
for i, val := range vals.Validators {
validators[i] = TM2PB.Validator(val)
validators[i] = TM2PB.ValidatorUpdate(val)
}
return validators
}
@@ -156,7 +154,7 @@ func (tm2pb) Evidence(ev Evidence, valSet *ValidatorSet, evTime time.Time) abci.
return abci.Evidence{
Type: evType,
Validator: TM2PB.ValidatorWithoutPubKey(val),
Validator: TM2PB.Validator(val),
Height: ev.Height(),
Time: evTime,
TotalVotingPower: valSet.TotalVotingPower(),
@@ -164,12 +162,11 @@ func (tm2pb) Evidence(ev Evidence, valSet *ValidatorSet, evTime time.Time) abci.
}
// XXX: panics on nil or unknown pubkey type
func (tm2pb) ValidatorFromPubKeyAndPower(pubkey crypto.PubKey, power int64) abci.Validator {
func (tm2pb) NewValidatorUpdate(pubkey crypto.PubKey, power int64) abci.ValidatorUpdate {
pubkeyABCI := TM2PB.PubKey(pubkey)
return abci.Validator{
Address: pubkey.Address(),
PubKey: pubkeyABCI,
Power: power,
return abci.ValidatorUpdate{
PubKey: pubkeyABCI,
Power: power,
}
}
@@ -205,7 +202,7 @@ func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
}
}
func (pb2tm) Validators(vals []abci.Validator) ([]*Validator, error) {
func (pb2tm) ValidatorUpdates(vals []abci.ValidatorUpdate) ([]*Validator, error) {
tmVals := make([]*Validator, len(vals))
for i, v := range vals {
pub, err := PB2TM.PubKey(v.PubKey)
@@ -214,17 +211,13 @@ func (pb2tm) Validators(vals []abci.Validator) ([]*Validator, error) {
}
// If the app provided an address too, it must match.
// This is just a sanity check.
if len(v.Address) > 0 {
/*if len(v.Address) > 0 {
if !bytes.Equal(pub.Address(), v.Address) {
return nil, fmt.Errorf("Validator.Address (%X) does not match PubKey.Address (%X)",
v.Address, pub.Address())
}
}
tmVals[i] = &Validator{
Address: pub.Address(),
PubKey: pub,
VotingPower: v.Power,
}
}*/
tmVals[i] = NewValidator(pub, v.Power)
}
return tmVals, nil
}