rename BaseVerifier to verifier, remove Verifier interface

This commit is contained in:
Anton Kaliaev 2019-08-15 16:01:06 +04:00
parent 6b38564409
commit 2f96903494
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
6 changed files with 31 additions and 56 deletions

View File

@ -10,9 +10,10 @@ import (
// FullCommit contains a SignedHeader (the block's header and a commit that // FullCommit contains a SignedHeader (the block's header and a commit that
// signs it), the validator set which signed the commit, and the next validator // signs it), the validator set which signed the commit, and the next validator
// set. The next validator set (which is proven from the block header) allows // set.
// us to revert to block-by-block updating of lite Verifier's latest validator // The next validator set (which is proven from the block header) allows us to
// set, even in the face of arbitrarily large power changes. // revert to block-by-block updating of lite Verifier's latest validator set,
// even in the face of arbitrarily large power changes.
type FullCommit struct { type FullCommit struct {
SignedHeader types.SignedHeader `json:"signed_header"` SignedHeader types.SignedHeader `json:"signed_header"`
Validators *types.ValidatorSet `json:"validator_set"` Validators *types.ValidatorSet `json:"validator_set"`
@ -34,22 +35,22 @@ func NewFullCommit(signedHeader types.SignedHeader, valset, nextValset *types.Va
// commit! // commit!
func (fc FullCommit) ValidateFull(chainID string) error { func (fc FullCommit) ValidateFull(chainID string) error {
if fc.Validators.Size() == 0 { if fc.Validators.Size() == 0 {
return errors.New("empty FullCommit.Validators") return errors.New("empty Validators")
} }
if !bytes.Equal(fc.SignedHeader.ValidatorsHash, fc.Validators.Hash()) { if !bytes.Equal(fc.SignedHeader.ValidatorsHash, fc.Validators.Hash()) {
return fmt.Errorf("header has ValidatorsHash %X but valset hash is %X", return fmt.Errorf("header has ValidatorsHash %X, but valset hash is %X",
fc.SignedHeader.ValidatorsHash, fc.SignedHeader.ValidatorsHash,
fc.Validators.Hash(), fc.Validators.Hash(),
) )
} }
if fc.NextValidators.Size() == 0 { if fc.NextValidators.Size() == 0 {
return errors.New("empty FullCommit.NextValidators") return errors.New("empty NextValidators")
} }
if !bytes.Equal(fc.SignedHeader.NextValidatorsHash, fc.NextValidators.Hash()) { if !bytes.Equal(fc.SignedHeader.NextValidatorsHash, fc.NextValidators.Hash()) {
return fmt.Errorf("header has next ValidatorsHash %X but next valset hash is %X", return fmt.Errorf("header has next ValidatorsHash %X, but next valset hash is %X",
fc.SignedHeader.NextValidatorsHash, fc.SignedHeader.NextValidatorsHash,
fc.NextValidators.Hash(), fc.NextValidators.Hash(),
) )

View File

@ -42,13 +42,13 @@ ValidatorSets.
Verifier Verifier
A Verifier validates a new SignedHeader given the currently known state. There Verifier validates a new SignedHeader given the currently known state. There
are two different types of Verifiers provided. re two different types of Verifiers provided.
BaseVerifier - given a validator set and a height, this Verifier verifies erifier - given a validator set and a height, this Verifier verifies
that > 2/3 of the voting power of the given validator set had signed the hat > 2/3 of the voting power of the given validator set had signed the
SignedHeader, and that the SignedHeader was to be signed by the exact given ignedHeader, and that the SignedHeader was to be signed by the exact given
validator set, and that the height of the commit is at least height (or alidator set, and that the height of the commit is at least height (or
greater). greater).
DynamicVerifier - this Verifier implements an auto-update and persistence DynamicVerifier - this Verifier implements an auto-update and persistence

View File

@ -54,7 +54,7 @@ func _TestAppProofs(t *testing.T) {
source := certclient.NewProvider(chainID, cl) source := certclient.NewProvider(chainID, cl)
seed, err := source.LatestFullCommit(chainID, 1, 1) seed, err := source.LatestFullCommit(chainID, 1, 1)
require.NoError(err, "%#v", err) require.NoError(err, "%#v", err)
cert := lite.NewBaseVerifier(chainID, seed.Height(), seed.Validators) cert := lite.NewVerifier(chainID, seed.Height(), seed.Validators)
// Wait for tx confirmation. // Wait for tx confirmation.
done := make(chan int64) done := make(chan int64)
@ -139,7 +139,7 @@ func TestTxProofs(t *testing.T) {
source := certclient.NewProvider(chainID, cl) source := certclient.NewProvider(chainID, cl)
seed, err := source.LatestFullCommit(chainID, brh-2, brh-2) seed, err := source.LatestFullCommit(chainID, brh-2, brh-2)
require.NoError(err, "%#v", err) require.NoError(err, "%#v", err)
cert := lite.NewBaseVerifier(chainID, seed.Height(), seed.Validators) cert := lite.NewVerifier(chainID, seed.Height(), seed.Validators)
// First let's make sure a bogus transaction hash returns a valid non-existence proof. // First let's make sure a bogus transaction hash returns a valid non-existence proof.
key := types.Tx([]byte("bogus")).Hash() key := types.Tx([]byte("bogus")).Hash()

View File

@ -1,16 +0,0 @@
package lite
import (
"github.com/tendermint/tendermint/types"
)
// NOTE: The Verifier interface is deprecated. BaseVerifier can continue to
// exist, but this interface isn't very useful on its own to declare here.
//
// Verifier checks the votes to make sure the block really is signed properly.
// Verifier must know the current or recent set of validitors by some other
// means.
type Verifier interface {
Verify(sheader types.SignedHeader) error
ChainID() string
}

View File

@ -10,53 +10,43 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
var _ Verifier = (*BaseVerifier)(nil) // verifier lets us check the validity of SignedHeaders at height or later,
// requiring sufficient votes (> 2/3) from the given valset. To verify blocks
// BaseVerifier lets us check the validity of SignedHeaders at height or // produced by a blockchain with mutable validator sets, use the
// later, requiring sufficient votes (> 2/3) from the given valset. // DynamicVerifier.
// To verify blocks produced by a blockchain with mutable validator sets, type verifier struct {
// use the DynamicVerifier.
//
// NOTE: Verifier as a supported interface is deprecated, it may be reasonable
// to rename this to simply "verifier" and to remove that interface
// declaration. See also Provider, which is not a Verifier, but is a
// Provider.
type BaseVerifier struct {
chainID string chainID string
height int64 height int64
valset *types.ValidatorSet valset *types.ValidatorSet
} }
// NewBaseVerifier returns a new Verifier initialized with a validator set at // NewVerifier returns a new Verifier initialized with a validator set at
// some height. // some height.
func NewBaseVerifier(chainID string, height int64, valset *types.ValidatorSet) *BaseVerifier { func NewVerifier(chainID string, height int64, valset *types.ValidatorSet) *verifier {
if valset.IsNilOrEmpty() { if valset.IsNilOrEmpty() {
panic("NewBaseVerifier requires a valid valset") panic("NewVerifier requires a valid valset")
} }
return &BaseVerifier{ return &verifier{
chainID: chainID, chainID: chainID,
height: height, height: height,
valset: valset, valset: valset,
} }
} }
// Implements Verifier. func (bv *verifier) ChainID() string {
func (bv *BaseVerifier) ChainID() string {
return bv.chainID return bv.chainID
} }
// Implements Verifier. func (bv *verifier) Verify(signedHeader types.SignedHeader) error {
func (bv *BaseVerifier) Verify(signedHeader types.SignedHeader) error {
// We can't verify commits for a different chain. // We can't verify commits for a different chain.
if signedHeader.ChainID != bv.chainID { if signedHeader.ChainID != bv.chainID {
return cmn.NewError("BaseVerifier chainID is %v, cannot verify chainID %v", return cmn.NewError("verifier chainID is %v, cannot verify chainID %v",
bv.chainID, signedHeader.ChainID) bv.chainID, signedHeader.ChainID)
} }
// We can't verify commits older than bv.height. // We can't verify commits older than bv.height.
if signedHeader.Height < bv.height { if signedHeader.Height < bv.height {
return cmn.NewError("BaseVerifier height is %v, cannot verify height %v", return cmn.NewError("verifier height is %v, cannot verify height %v",
bv.height, signedHeader.Height) bv.height, signedHeader.Height)
} }

View File

@ -10,7 +10,7 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
func TestBaseVerifier(t *testing.T) { func TestVerifier(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
keys := pks.GenPrivKeys(4) keys := pks.GenPrivKeys(4)
@ -18,7 +18,7 @@ func TestBaseVerifier(t *testing.T) {
vals := keys.ToValidators(20, 10) vals := keys.ToValidators(20, 10)
// and a Verifier based on our known set // and a Verifier based on our known set
chainID := "test-static" chainID := "test-static"
cert := NewBaseVerifier(chainID, 2, vals) cert := NewVerifier(chainID, 2, vals)
cases := []struct { cases := []struct {
keys pks.PrivKeys keys pks.PrivKeys