types: comments; compiles; evidence test

This commit is contained in:
Ethan Buchman
2017-08-28 19:46:38 -04:00
parent 50850cf8a2
commit 9cdcffbe4b
4 changed files with 103 additions and 15 deletions

View File

@ -7,36 +7,44 @@ import (
"github.com/tendermint/go-crypto"
)
// ErrEvidenceInvalid wraps a piece of evidence and the error denoting how or why it is invalid.
type ErrEvidenceInvalid struct {
Evidence Evidence
Error error
Evidence Evidence
ErrorValue error
}
func NewEvidenceInvalidErr(ev Evidence, err error) *ErrEvidenceInvalid {
return &ErrEvidenceInvalid{ev, err}
}
// Error returns a string representation of the error.
func (err *ErrEvidenceInvalid) Error() string {
return fmt.Sprintf("Invalid evidence: %v. Evidence: %v", err.Error, err.Evidence)
return fmt.Sprintf("Invalid evidence: %v. Evidence: %v", err.ErrorValue, err.Evidence)
}
// Evidence represents any provable malicious activity by a validator
type Evidence interface {
Verify() error
Verify(chainID string) error
Address() []byte
}
//-------------------------------------------
// DuplicateVoteEvidence contains evidence a validator signed two conflicting votes.
type DuplicateVoteEvidence struct {
PubKey crypto.PubKey
VoteA *Vote
VoteB *Vote
}
// Address returns the address of the validator
// Address returns the address of the validator.
func (dve *DuplicateVoteEvidence) Address() []byte {
return dve.PubKey.Address()
}
// Verify returns an error if the two votes aren't from the same validator, for the same H/R/S, but for different blocks
func (dve *DuplicateVoteEvidence) Verify() error {
// Verify returns an error if the two votes aren't conflicting.
// To be conflicting, they must be from the same validator, for the same H/R/S, but for different blocks.
func (dve *DuplicateVoteEvidence) Verify(chainID string) error {
// H/R/S must be the same
if dve.VoteA.Height != dve.VoteB.Height ||
dve.VoteA.Round != dve.VoteB.Round ||
@ -59,10 +67,10 @@ func (dve *DuplicateVoteEvidence) Verify() error {
}
// Signatures must be valid
if !dve.PubKey.Verify(SignBytes(chainID, dve.VoteA), dve.VoteA.Signature) {
if !dve.PubKey.VerifyBytes(SignBytes(chainID, dve.VoteA), dve.VoteA.Signature) {
return ErrVoteInvalidSignature
}
if !dve.PubKey.Verify(SignBytes(chainID, dve.VoteB), dve.VoteB.Signature) {
if !dve.PubKey.VerifyBytes(SignBytes(chainID, dve.VoteB), dve.VoteB.Signature) {
return ErrVoteInvalidSignature
}