mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-12 14:57:12 +00:00
rename BaseVerifier to verifier, remove Verifier interface
This commit is contained in:
parent
6b38564409
commit
2f96903494
@ -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(),
|
||||
)
|
||||
|
12
lite/doc.go
12
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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user