diff --git a/lite/commit.go b/lite/commit.go index a03651b5..7c0fc750 100644 --- a/lite/commit.go +++ b/lite/commit.go @@ -10,9 +10,10 @@ import ( // 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 -// set. The next validator set (which is proven from the block header) allows -// us to revert to block-by-block updating of lite Verifier's latest validator -// set, even in the face of arbitrarily large power changes. +// set. +// The next validator set (which is proven from the block header) allows us to +// 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 { SignedHeader types.SignedHeader `json:"signed_header"` Validators *types.ValidatorSet `json:"validator_set"` @@ -34,22 +35,22 @@ func NewFullCommit(signedHeader types.SignedHeader, valset, nextValset *types.Va // commit! func (fc FullCommit) ValidateFull(chainID string) error { 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()) { - 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.Validators.Hash(), ) } 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()) { - 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.NextValidators.Hash(), ) diff --git a/lite/doc.go b/lite/doc.go index c02b5021..8023a5d0 100644 --- a/lite/doc.go +++ b/lite/doc.go @@ -42,13 +42,13 @@ ValidatorSets. Verifier -A Verifier validates a new SignedHeader given the currently known state. There -are two different types of Verifiers provided. + Verifier validates a new SignedHeader given the currently known state. There +re two different types of Verifiers provided. -BaseVerifier - 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 -SignedHeader, 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 +erifier - given a validator set and a height, this Verifier verifies +hat > 2/3 of the voting power of the given validator set had signed the +ignedHeader, and that the SignedHeader was to be signed by the exact given +alidator set, and that the height of the commit is at least height (or greater). DynamicVerifier - this Verifier implements an auto-update and persistence diff --git a/lite/proxy/query_test.go b/lite/proxy/query_test.go index d92a486e..28c4063f 100644 --- a/lite/proxy/query_test.go +++ b/lite/proxy/query_test.go @@ -54,7 +54,7 @@ func _TestAppProofs(t *testing.T) { source := certclient.NewProvider(chainID, cl) seed, err := source.LatestFullCommit(chainID, 1, 1) 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. done := make(chan int64) @@ -139,7 +139,7 @@ func TestTxProofs(t *testing.T) { source := certclient.NewProvider(chainID, cl) seed, err := source.LatestFullCommit(chainID, brh-2, brh-2) 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. key := types.Tx([]byte("bogus")).Hash() diff --git a/lite/types.go b/lite/types.go deleted file mode 100644 index 0e269e50..00000000 --- a/lite/types.go +++ /dev/null @@ -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 -} diff --git a/lite/base_verifier.go b/lite/verifier.go similarity index 52% rename from lite/base_verifier.go rename to lite/verifier.go index 96dc4d25..7680da0e 100644 --- a/lite/base_verifier.go +++ b/lite/verifier.go @@ -10,53 +10,43 @@ import ( "github.com/tendermint/tendermint/types" ) -var _ Verifier = (*BaseVerifier)(nil) - -// BaseVerifier lets us check the validity of SignedHeaders at height or -// later, requiring sufficient votes (> 2/3) from the given valset. -// To verify blocks produced by a blockchain with mutable validator sets, -// 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 { +// verifier lets us check the validity of SignedHeaders at height or later, +// requiring sufficient votes (> 2/3) from the given valset. To verify blocks +// produced by a blockchain with mutable validator sets, use the +// DynamicVerifier. +type verifier struct { chainID string height int64 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. -func NewBaseVerifier(chainID string, height int64, valset *types.ValidatorSet) *BaseVerifier { +func NewVerifier(chainID string, height int64, valset *types.ValidatorSet) *verifier { if valset.IsNilOrEmpty() { - panic("NewBaseVerifier requires a valid valset") + panic("NewVerifier requires a valid valset") } - return &BaseVerifier{ + return &verifier{ chainID: chainID, height: height, valset: valset, } } -// Implements Verifier. -func (bv *BaseVerifier) ChainID() string { +func (bv *verifier) ChainID() string { return bv.chainID } -// Implements Verifier. -func (bv *BaseVerifier) Verify(signedHeader types.SignedHeader) error { - +func (bv *verifier) Verify(signedHeader types.SignedHeader) error { // We can't verify commits for a different chain. 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) } // We can't verify commits older than 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) } diff --git a/lite/base_verifier_test.go b/lite/verifier_test.go similarity index 95% rename from lite/base_verifier_test.go rename to lite/verifier_test.go index 714219bb..0474af4d 100644 --- a/lite/base_verifier_test.go +++ b/lite/verifier_test.go @@ -10,7 +10,7 @@ import ( "github.com/tendermint/tendermint/types" ) -func TestBaseVerifier(t *testing.T) { +func TestVerifier(t *testing.T) { assert := assert.New(t) keys := pks.GenPrivKeys(4) @@ -18,7 +18,7 @@ func TestBaseVerifier(t *testing.T) { vals := keys.ToValidators(20, 10) // and a Verifier based on our known set chainID := "test-static" - cert := NewBaseVerifier(chainID, 2, vals) + cert := NewVerifier(chainID, 2, vals) cases := []struct { keys pks.PrivKeys