Rename light to lite

This commit is contained in:
Adrian Brink
2017-11-09 17:37:18 -05:00
parent 1871a7c3d0
commit 248f176c1f
22 changed files with 153 additions and 153 deletions

View File

@ -12,8 +12,8 @@ import (
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
// SignStatusClient combines a SignClient and StatusClient. // SignStatusClient combines a SignClient and StatusClient.
@ -29,13 +29,13 @@ type provider struct {
// NewProvider can wrap any rpcclient to expose it as // NewProvider can wrap any rpcclient to expose it as
// a read-only provider. // a read-only provider.
func NewProvider(node SignStatusClient) light.Provider { func NewProvider(node SignStatusClient) lite.Provider {
return &provider{node: node} return &provider{node: node}
} }
// NewHTTPProvider can connects to a tendermint json-rpc endpoint // NewHTTPProvider can connect to a tendermint json-rpc endpoint
// at the given url, and uses that as a read-only provider. // at the given url, and uses that as a read-only provider.
func NewHTTPProvider(remote string) light.Provider { func NewHTTPProvider(remote string) lite.Provider {
return &provider{ return &provider{
node: rpcclient.NewHTTP(remote, "/websocket"), node: rpcclient.NewHTTP(remote, "/websocket"),
} }
@ -47,13 +47,13 @@ func (p *provider) StatusClient() rpcclient.StatusClient {
} }
// StoreCommit is a noop, as clients can only read from the chain... // StoreCommit is a noop, as clients can only read from the chain...
func (p *provider) StoreCommit(_ light.FullCommit) error { return nil } func (p *provider) StoreCommit(_ lite.FullCommit) error { return nil }
// GetHash gets the most recent validator and sees if it matches // GetHash gets the most recent validator and sees if it matches
// //
// TODO: improve when the rpc interface supports more functionality // TODO: improve when the rpc interface supports more functionality
func (p *provider) GetByHash(hash []byte) (light.FullCommit, error) { func (p *provider) GetByHash(hash []byte) (lite.FullCommit, error) {
var fc light.FullCommit var fc lite.FullCommit
vals, err := p.node.Validators(nil) vals, err := p.node.Validators(nil)
// if we get no validators, or a different height, return an error // if we get no validators, or a different height, return an error
if err != nil { if err != nil {
@ -62,13 +62,13 @@ func (p *provider) GetByHash(hash []byte) (light.FullCommit, error) {
p.updateHeight(vals.BlockHeight) p.updateHeight(vals.BlockHeight)
vhash := types.NewValidatorSet(vals.Validators).Hash() vhash := types.NewValidatorSet(vals.Validators).Hash()
if !bytes.Equal(hash, vhash) { if !bytes.Equal(hash, vhash) {
return fc, lightErr.ErrCommitNotFound() return fc, liteErr.ErrCommitNotFound()
} }
return p.seedFromVals(vals) return p.seedFromVals(vals)
} }
// GetByHeight gets the validator set by height // GetByHeight gets the validator set by height
func (p *provider) GetByHeight(h int) (fc light.FullCommit, err error) { func (p *provider) GetByHeight(h int) (fc lite.FullCommit, err error) {
commit, err := p.node.Commit(&h) commit, err := p.node.Commit(&h)
if err != nil { if err != nil {
return fc, err return fc, err
@ -77,7 +77,7 @@ func (p *provider) GetByHeight(h int) (fc light.FullCommit, err error) {
} }
// LatestCommit returns the newest commit stored. // LatestCommit returns the newest commit stored.
func (p *provider) LatestCommit() (fc light.FullCommit, err error) { func (p *provider) LatestCommit() (fc lite.FullCommit, err error) {
commit, err := p.GetLatestCommit() commit, err := p.GetLatestCommit()
if err != nil { if err != nil {
return fc, err return fc, err
@ -97,24 +97,24 @@ func (p *provider) GetLatestCommit() (*ctypes.ResultCommit, error) {
} }
// CommitFromResult ... // CommitFromResult ...
func CommitFromResult(result *ctypes.ResultCommit) light.Commit { func CommitFromResult(result *ctypes.ResultCommit) lite.Commit {
return (light.Commit)(result.SignedHeader) return (lite.Commit)(result.SignedHeader)
} }
func (p *provider) seedFromVals(vals *ctypes.ResultValidators) (light.FullCommit, error) { func (p *provider) seedFromVals(vals *ctypes.ResultValidators) (lite.FullCommit, error) {
// now get the commits and build a full commit // now get the commits and build a full commit
commit, err := p.node.Commit(&vals.BlockHeight) commit, err := p.node.Commit(&vals.BlockHeight)
if err != nil { if err != nil {
return light.FullCommit{}, err return lite.FullCommit{}, err
} }
fc := light.NewFullCommit( fc := lite.NewFullCommit(
CommitFromResult(commit), CommitFromResult(commit),
types.NewValidatorSet(vals.Validators), types.NewValidatorSet(vals.Validators),
) )
return fc, nil return fc, nil
} }
func (p *provider) seedFromCommit(commit *ctypes.ResultCommit) (fc light.FullCommit, err error) { func (p *provider) seedFromCommit(commit *ctypes.ResultCommit) (fc lite.FullCommit, err error) {
fc.Commit = CommitFromResult(commit) fc.Commit = CommitFromResult(commit)
// now get the proper validators // now get the proper validators
@ -126,7 +126,7 @@ func (p *provider) seedFromCommit(commit *ctypes.ResultCommit) (fc light.FullCom
// make sure they match the commit (as we cannot enforce height) // make sure they match the commit (as we cannot enforce height)
vset := types.NewValidatorSet(vals.Validators) vset := types.NewValidatorSet(vals.Validators)
if !bytes.Equal(vset.Hash(), commit.Header.ValidatorsHash) { if !bytes.Equal(vset.Hash(), commit.Header.ValidatorsHash) {
return fc, lightErr.ErrValidatorsChanged() return fc, liteErr.ErrValidatorsChanged()
} }
p.updateHeight(commit.Header.Height) p.updateHeight(commit.Header.Height)

View File

@ -6,8 +6,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclient "github.com/tendermint/tendermint/rpc/client"
rpctest "github.com/tendermint/tendermint/rpc/test" rpctest "github.com/tendermint/tendermint/rpc/test"
) )
@ -35,7 +35,7 @@ func TestProvider(t *testing.T) {
// let's check this is valid somehow // let's check this is valid somehow
assert.Nil(seed.ValidateBasic(chainID)) assert.Nil(seed.ValidateBasic(chainID))
cert := light.NewStatic(chainID, seed.Validators) cert := lite.NewStatic(chainID, seed.Validators)
// historical queries now work :) // historical queries now work :)
lower := sh - 5 lower := sh - 5
@ -53,7 +53,7 @@ func TestProvider(t *testing.T) {
// get by hash fails without match // get by hash fails without match
seed, err = p.GetByHash([]byte("foobar")) seed, err = p.GetByHash([]byte("foobar"))
assert.NotNil(err) assert.NotNil(err)
assert.True(lightErr.IsCommitNotFoundErr(err)) assert.True(liteErr.IsCommitNotFoundErr(err))
// storing the seed silently ignored // storing the seed silently ignored
err = p.StoreCommit(seed) err = p.StoreCommit(seed)

View File

@ -1,4 +1,4 @@
package light package lite
import ( import (
"bytes" "bytes"
@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
// Certifier checks the votes to make sure the block really is signed properly. // Certifier checks the votes to make sure the block really is signed properly.
@ -41,7 +41,7 @@ func NewFullCommit(commit Commit, vals *types.ValidatorSet) FullCommit {
} }
} }
// Height returns the of the header. // Height returns the height of the header.
func (c Commit) Height() int { func (c Commit) Height() int {
if c.Header == nil { if c.Header == nil {
return 0 return 0
@ -78,7 +78,7 @@ func (c Commit) ValidateBasic(chainID string) error {
// make sure the header and commit match (height and hash) // make sure the header and commit match (height and hash)
if c.Commit.Height() != c.Header.Height { if c.Commit.Height() != c.Header.Height {
return lightErr.ErrHeightMismatch(c.Commit.Height(), c.Header.Height) return liteErr.ErrHeightMismatch(c.Commit.Height(), c.Header.Height)
} }
hhash := c.Header.Hash() hhash := c.Header.Hash()
chash := c.Commit.BlockID.Hash chash := c.Commit.BlockID.Hash

View File

@ -1,5 +1,5 @@
/* /*
Package light allows you to securely validate headers Package lite allows you to securely validate headers
without a full node. without a full node.
This library pulls together all the crypto and algorithms, This library pulls together all the crypto and algorithms,
@ -130,4 +130,4 @@ to manually verify the new validator set hash using off-chain
means (the same as getting the initial hash). means (the same as getting the initial hash).
*/ */
package light package lite

View File

@ -1,9 +1,9 @@
package light package lite
import ( import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
var _ Certifier = &Dynamic{} var _ Certifier = &Dynamic{}
@ -69,7 +69,7 @@ func (c *Dynamic) Update(fc FullCommit) error {
// ignore all checkpoints in the past -> only to the future // ignore all checkpoints in the past -> only to the future
h := fc.Height() h := fc.Height()
if h <= c.lastHeight { if h <= c.lastHeight {
return lightErr.ErrPastTime() return liteErr.ErrPastTime()
} }
// first, verify if the input is self-consistent.... // first, verify if the input is self-consistent....
@ -85,7 +85,7 @@ func (c *Dynamic) Update(fc FullCommit) error {
err = c.Validators().VerifyCommitAny(fc.Validators, c.ChainID(), err = c.Validators().VerifyCommitAny(fc.Validators, c.ChainID(),
commit.BlockID, h, commit) commit.BlockID, h, commit)
if err != nil { if err != nil {
return lightErr.ErrTooMuchChange() return liteErr.ErrTooMuchChange()
} }
// looks good, we can update // looks good, we can update

View File

@ -1,4 +1,4 @@
package light_test package lite_test
import ( import (
"testing" "testing"
@ -8,8 +8,8 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
"github.com/tendermint/tendermint/light/errors" "github.com/tendermint/tendermint/lite/errors"
) )
// TestDynamicCert just makes sure it still works like StaticCert // TestDynamicCert just makes sure it still works like StaticCert
@ -18,15 +18,15 @@ func TestDynamicCert(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
// require := require.New(t) // require := require.New(t)
keys := light.GenValKeys(4) keys := lite.GenValKeys(4)
// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do! // 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
vals := keys.ToValidators(20, 10) vals := keys.ToValidators(20, 10)
// and a certifier based on our known set // and a certifier based on our known set
chainID := "test-dyno" chainID := "test-dyno"
cert := light.NewDynamic(chainID, vals, 0) cert := lite.NewDynamic(chainID, vals, 0)
cases := []struct { cases := []struct {
keys light.ValKeys keys lite.ValKeys
vals *types.ValidatorSet vals *types.ValidatorSet
height int height int
first, last int // who actually signs first, last int // who actually signs
@ -65,9 +65,9 @@ func TestDynamicUpdate(t *testing.T) {
assert, require := assert.New(t), require.New(t) assert, require := assert.New(t), require.New(t)
chainID := "test-dyno-up" chainID := "test-dyno-up"
keys := light.GenValKeys(5) keys := lite.GenValKeys(5)
vals := keys.ToValidators(20, 0) vals := keys.ToValidators(20, 0)
cert := light.NewDynamic(chainID, vals, 40) cert := lite.NewDynamic(chainID, vals, 40)
// one valid block to give us a sense of time // one valid block to give us a sense of time
h := 100 h := 100
@ -81,7 +81,7 @@ func TestDynamicUpdate(t *testing.T) {
// we try to update with some blocks // we try to update with some blocks
cases := []struct { cases := []struct {
keys light.ValKeys keys lite.ValKeys
vals *types.ValidatorSet vals *types.ValidatorSet
height int height int
first, last int // who actually signs first, last int // who actually signs

View File

@ -8,8 +8,8 @@ import (
wire "github.com/tendermint/go-wire" wire "github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
const ( const (
@ -20,7 +20,7 @@ const (
) )
// SaveFullCommit exports the seed in binary / go-wire style // SaveFullCommit exports the seed in binary / go-wire style
func SaveFullCommit(fc light.FullCommit, path string) error { func SaveFullCommit(fc lite.FullCommit, path string) error {
f, err := os.Create(path) f, err := os.Create(path)
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
@ -33,7 +33,7 @@ func SaveFullCommit(fc light.FullCommit, path string) error {
} }
// SaveFullCommitJSON exports the seed in a json format // SaveFullCommitJSON exports the seed in a json format
func SaveFullCommitJSON(fc light.FullCommit, path string) error { func SaveFullCommitJSON(fc lite.FullCommit, path string) error {
f, err := os.Create(path) f, err := os.Create(path)
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
@ -45,12 +45,12 @@ func SaveFullCommitJSON(fc light.FullCommit, path string) error {
} }
// LoadFullCommit loads the full commit from the file system. // LoadFullCommit loads the full commit from the file system.
func LoadFullCommit(path string) (light.FullCommit, error) { func LoadFullCommit(path string) (lite.FullCommit, error) {
var fc light.FullCommit var fc lite.FullCommit
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return fc, lightErr.ErrCommitNotFound() return fc, liteErr.ErrCommitNotFound()
} }
return fc, errors.WithStack(err) return fc, errors.WithStack(err)
} }
@ -62,12 +62,12 @@ func LoadFullCommit(path string) (light.FullCommit, error) {
} }
// LoadFullCommitJSON loads the commit from the file system in JSON format. // LoadFullCommitJSON loads the commit from the file system in JSON format.
func LoadFullCommitJSON(path string) (light.FullCommit, error) { func LoadFullCommitJSON(path string) (lite.FullCommit, error) {
var fc light.FullCommit var fc lite.FullCommit
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return fc, lightErr.ErrCommitNotFound() return fc, liteErr.ErrCommitNotFound()
} }
return fc, errors.WithStack(err) return fc, errors.WithStack(err)
} }

View File

@ -10,7 +10,7 @@ import (
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
) )
func tmpFile() string { func tmpFile() string {
@ -27,7 +27,7 @@ func TestSerializeFullCommits(t *testing.T) {
h := 25 h := 25
// build a fc // build a fc
keys := light.GenValKeys(5) keys := lite.GenValKeys(5)
vals := keys.ToValidators(10, 0) vals := keys.ToValidators(10, 0)
fc := keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, 5) fc := keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, 5)

View File

@ -24,8 +24,8 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
// nolint // nolint
@ -44,7 +44,7 @@ type provider struct {
// NewProvider creates the parent dir and subdirs // NewProvider creates the parent dir and subdirs
// for validators and checkpoints as needed // for validators and checkpoints as needed
func NewProvider(dir string) light.Provider { func NewProvider(dir string) lite.Provider {
valDir := filepath.Join(dir, ValDir) valDir := filepath.Join(dir, ValDir)
checkDir := filepath.Join(dir, CheckDir) checkDir := filepath.Join(dir, CheckDir)
for _, d := range []string{valDir, checkDir} { for _, d := range []string{valDir, checkDir} {
@ -66,7 +66,7 @@ func (p *provider) encodeHeight(h int) string {
} }
// StoreCommit saves a full commit after it has been verified. // StoreCommit saves a full commit after it has been verified.
func (p *provider) StoreCommit(fc light.FullCommit) error { func (p *provider) StoreCommit(fc lite.FullCommit) error {
// make sure the fc is self-consistent before saving // make sure the fc is self-consistent before saving
err := fc.ValidateBasic(fc.Commit.Header.ChainID) err := fc.ValidateBasic(fc.Commit.Header.ChainID)
if err != nil { if err != nil {
@ -88,11 +88,11 @@ func (p *provider) StoreCommit(fc light.FullCommit) error {
} }
// GetByHeight returns the closest commit with height <= h. // GetByHeight returns the closest commit with height <= h.
func (p *provider) GetByHeight(h int) (light.FullCommit, error) { func (p *provider) GetByHeight(h int) (lite.FullCommit, error) {
// first we look for exact match, then search... // first we look for exact match, then search...
path := filepath.Join(p.checkDir, p.encodeHeight(h)) path := filepath.Join(p.checkDir, p.encodeHeight(h))
fc, err := LoadFullCommit(path) fc, err := LoadFullCommit(path)
if lightErr.IsCommitNotFoundErr(err) { if liteErr.IsCommitNotFoundErr(err) {
path, err = p.searchForHeight(h) path, err = p.searchForHeight(h)
if err == nil { if err == nil {
fc, err = LoadFullCommit(path) fc, err = LoadFullCommit(path)
@ -102,7 +102,7 @@ func (p *provider) GetByHeight(h int) (light.FullCommit, error) {
} }
// LatestCommit returns the newest commit stored. // LatestCommit returns the newest commit stored.
func (p *provider) LatestCommit() (fc light.FullCommit, err error) { func (p *provider) LatestCommit() (fc lite.FullCommit, err error) {
// Note to future: please update by 2077 to avoid rollover // Note to future: please update by 2077 to avoid rollover
return p.GetByHeight(math.MaxInt32 - 1) return p.GetByHeight(math.MaxInt32 - 1)
} }
@ -125,7 +125,7 @@ func (p *provider) searchForHeight(h int) (string, error) {
sort.Strings(files) sort.Strings(files)
i := sort.SearchStrings(files, desired) i := sort.SearchStrings(files, desired)
if i == 0 { if i == 0 {
return "", lightErr.ErrCommitNotFound() return "", liteErr.ErrCommitNotFound()
} }
found := files[i-1] found := files[i-1]
path := filepath.Join(p.checkDir, found) path := filepath.Join(p.checkDir, found)
@ -133,7 +133,7 @@ func (p *provider) searchForHeight(h int) (string, error) {
} }
// GetByHash returns a commit exactly matching this validator hash. // GetByHash returns a commit exactly matching this validator hash.
func (p *provider) GetByHash(hash []byte) (light.FullCommit, error) { func (p *provider) GetByHash(hash []byte) (lite.FullCommit, error) {
path := filepath.Join(p.valDir, p.encodeHash(hash)) path := filepath.Join(p.valDir, p.encodeHash(hash))
return LoadFullCommit(path) return LoadFullCommit(path)
} }

View File

@ -10,12 +10,12 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
"github.com/tendermint/tendermint/light/files" "github.com/tendermint/tendermint/lite/files"
) )
func checkEqual(stored, loaded light.FullCommit, chainID string) error { func checkEqual(stored, loaded lite.FullCommit, chainID string) error {
err := loaded.ValidateBasic(chainID) err := loaded.ValidateBasic(chainID)
if err != nil { if err != nil {
return err return err
@ -36,28 +36,28 @@ func TestFileProvider(t *testing.T) {
chainID := "test-files" chainID := "test-files"
appHash := []byte("some-data") appHash := []byte("some-data")
keys := light.GenValKeys(5) keys := lite.GenValKeys(5)
count := 10 count := 10
// make a bunch of seeds... // make a bunch of seeds...
seeds := make([]light.FullCommit, count) seeds := make([]lite.FullCommit, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
// two seeds for each validator, to check how we handle dups // two seeds for each validator, to check how we handle dups
// (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ... // (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ...
vals := keys.ToValidators(10, int64(count/2)) vals := keys.ToValidators(10, int64(count/2))
h := 20 + 10*i h := 20 + 10*i
check := keys.GenCommit(chainID, h, nil, vals, appHash, 0, 5) check := keys.GenCommit(chainID, h, nil, vals, appHash, 0, 5)
seeds[i] = light.NewFullCommit(check, vals) seeds[i] = lite.NewFullCommit(check, vals)
} }
// check provider is empty // check provider is empty
seed, err := p.GetByHeight(20) seed, err := p.GetByHeight(20)
require.NotNil(err) require.NotNil(err)
assert.True(lightErr.IsCommitNotFoundErr(err)) assert.True(liteErr.IsCommitNotFoundErr(err))
seed, err = p.GetByHash(seeds[3].ValidatorsHash()) seed, err = p.GetByHash(seeds[3].ValidatorsHash())
require.NotNil(err) require.NotNil(err)
assert.True(lightErr.IsCommitNotFoundErr(err)) assert.True(liteErr.IsCommitNotFoundErr(err))
// now add them all to the provider // now add them all to the provider
for _, s := range seeds { for _, s := range seeds {
@ -92,5 +92,5 @@ func TestFileProvider(t *testing.T) {
// and proper error for too low // and proper error for too low
_, err = p.GetByHeight(5) _, err = p.GetByHeight(5)
assert.NotNil(err) assert.NotNil(err)
assert.True(lightErr.IsCommitNotFoundErr(err)) assert.True(liteErr.IsCommitNotFoundErr(err))
} }

View File

@ -1,4 +1,4 @@
package light package lite
import ( import (
"time" "time"

View File

@ -1,9 +1,9 @@
package light package lite
import ( import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
// Inquiring wraps a dynamic certifier and implements an auto-update strategy. If a call to Certify // Inquiring wraps a dynamic certifier and implements an auto-update strategy. If a call to Certify
@ -63,7 +63,7 @@ func (c *Inquiring) Certify(commit Commit) error {
} }
err = c.cert.Certify(commit) err = c.cert.Certify(commit)
if !lightErr.IsValidatorsChangedErr(err) { if !liteErr.IsValidatorsChangedErr(err) {
return err return err
} }
err = c.updateToHash(commit.Header.ValidatorsHash) err = c.updateToHash(commit.Header.ValidatorsHash)
@ -119,7 +119,7 @@ func (c *Inquiring) updateToHash(vhash []byte) error {
} }
err = c.cert.Update(fc) err = c.cert.Update(fc)
// handle IsTooMuchChangeErr by using divide and conquer // handle IsTooMuchChangeErr by using divide and conquer
if lightErr.IsTooMuchChangeErr(err) { if liteErr.IsTooMuchChangeErr(err) {
err = c.updateToHeight(fc.Height()) err = c.updateToHeight(fc.Height())
} }
return err return err
@ -134,12 +134,12 @@ func (c *Inquiring) updateToHeight(h int) error {
} }
start, end := c.LastHeight(), fc.Height() start, end := c.LastHeight(), fc.Height()
if end <= start { if end <= start {
return lightErr.ErrNoPathFound() return liteErr.ErrNoPathFound()
} }
err = c.Update(fc) err = c.Update(fc)
// we can handle IsTooMuchChangeErr specially // we can handle IsTooMuchChangeErr specially
if !lightErr.IsTooMuchChangeErr(err) { if !liteErr.IsTooMuchChangeErr(err) {
return err return err
} }

View File

@ -1,5 +1,5 @@
// nolint: vetshadow // nolint: vetshadow
package light_test package lite_test
import ( import (
"fmt" "fmt"
@ -8,22 +8,22 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
) )
func TestInquirerValidPath(t *testing.T) { func TestInquirerValidPath(t *testing.T) {
assert, require := assert.New(t), require.New(t) assert, require := assert.New(t), require.New(t)
trust := light.NewMemStoreProvider() trust := lite.NewMemStoreProvider()
source := light.NewMemStoreProvider() source := lite.NewMemStoreProvider()
// set up the validators to generate test blocks // set up the validators to generate test blocks
var vote int64 = 10 var vote int64 = 10
keys := light.GenValKeys(5) keys := lite.GenValKeys(5)
// construct a bunch of commits, each with one more height than the last // construct a bunch of commits, each with one more height than the last
chainID := "inquiry-test" chainID := "inquiry-test"
count := 50 count := 50
commits := make([]light.FullCommit, count) commits := make([]lite.FullCommit, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
// extend the keys by 1 each time // extend the keys by 1 each time
keys = keys.Extend(1) keys = keys.Extend(1)
@ -34,7 +34,7 @@ func TestInquirerValidPath(t *testing.T) {
} }
// initialize a certifier with the initial state // initialize a certifier with the initial state
cert := light.NewInquiring(chainID, commits[0], trust, source) cert := lite.NewInquiring(chainID, commits[0], trust, source)
// this should fail validation.... // this should fail validation....
commit := commits[count-1].Commit commit := commits[count-1].Commit
@ -60,17 +60,17 @@ func TestInquirerValidPath(t *testing.T) {
func TestInquirerMinimalPath(t *testing.T) { func TestInquirerMinimalPath(t *testing.T) {
assert, require := assert.New(t), require.New(t) assert, require := assert.New(t), require.New(t)
trust := light.NewMemStoreProvider() trust := lite.NewMemStoreProvider()
source := light.NewMemStoreProvider() source := lite.NewMemStoreProvider()
// set up the validators to generate test blocks // set up the validators to generate test blocks
var vote int64 = 10 var vote int64 = 10
keys := light.GenValKeys(5) keys := lite.GenValKeys(5)
// construct a bunch of commits, each with one more height than the last // construct a bunch of commits, each with one more height than the last
chainID := "minimal-path" chainID := "minimal-path"
count := 12 count := 12
commits := make([]light.FullCommit, count) commits := make([]lite.FullCommit, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
// extend the validators, so we are just below 2/3 // extend the validators, so we are just below 2/3
keys = keys.Extend(len(keys)/2 - 1) keys = keys.Extend(len(keys)/2 - 1)
@ -81,7 +81,7 @@ func TestInquirerMinimalPath(t *testing.T) {
} }
// initialize a certifier with the initial state // initialize a certifier with the initial state
cert := light.NewInquiring(chainID, commits[0], trust, source) cert := lite.NewInquiring(chainID, commits[0], trust, source)
// this should fail validation.... // this should fail validation....
commit := commits[count-1].Commit commit := commits[count-1].Commit
@ -107,17 +107,17 @@ func TestInquirerMinimalPath(t *testing.T) {
func TestInquirerVerifyHistorical(t *testing.T) { func TestInquirerVerifyHistorical(t *testing.T) {
assert, require := assert.New(t), require.New(t) assert, require := assert.New(t), require.New(t)
trust := light.NewMemStoreProvider() trust := lite.NewMemStoreProvider()
source := light.NewMemStoreProvider() source := lite.NewMemStoreProvider()
// set up the validators to generate test blocks // set up the validators to generate test blocks
var vote int64 = 10 var vote int64 = 10
keys := light.GenValKeys(5) keys := lite.GenValKeys(5)
// construct a bunch of commits, each with one more height than the last // construct a bunch of commits, each with one more height than the last
chainID := "inquiry-test" chainID := "inquiry-test"
count := 10 count := 10
commits := make([]light.FullCommit, count) commits := make([]lite.FullCommit, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
// extend the keys by 1 each time // extend the keys by 1 each time
keys = keys.Extend(1) keys = keys.Extend(1)
@ -128,7 +128,7 @@ func TestInquirerVerifyHistorical(t *testing.T) {
} }
// initialize a certifier with the initial state // initialize a certifier with the initial state
cert := light.NewInquiring(chainID, commits[0], trust, source) cert := lite.NewInquiring(chainID, commits[0], trust, source)
// store a few commits as trust // store a few commits as trust
for _, i := range []int{2, 5} { for _, i := range []int{2, 5} {

View File

@ -1,10 +1,10 @@
package light package lite
import ( import (
"encoding/hex" "encoding/hex"
"sort" "sort"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
type memStoreProvider struct { type memStoreProvider struct {
@ -60,7 +60,7 @@ func (m *memStoreProvider) GetByHeight(h int) (FullCommit, error) {
return fc, nil return fc, nil
} }
} }
return FullCommit{}, lightErr.ErrCommitNotFound() return FullCommit{}, liteErr.ErrCommitNotFound()
} }
// GetByHash returns the FullCommit for the hash or an error if the commit is not found. // GetByHash returns the FullCommit for the hash or an error if the commit is not found.
@ -68,7 +68,7 @@ func (m *memStoreProvider) GetByHash(hash []byte) (FullCommit, error) {
var err error var err error
fc, ok := m.byHash[m.encodeHash(hash)] fc, ok := m.byHash[m.encodeHash(hash)]
if !ok { if !ok {
err = lightErr.ErrCommitNotFound() err = liteErr.ErrCommitNotFound()
} }
return fc, err return fc, err
} }
@ -77,7 +77,7 @@ func (m *memStoreProvider) GetByHash(hash []byte) (FullCommit, error) {
func (m *memStoreProvider) LatestCommit() (FullCommit, error) { func (m *memStoreProvider) LatestCommit() (FullCommit, error) {
l := len(m.byHeight) l := len(m.byHeight)
if l == 0 { if l == 0 {
return FullCommit{}, lightErr.ErrCommitNotFound() return FullCommit{}, liteErr.ErrCommitNotFound()
} }
return m.byHeight[l-1], nil return m.byHeight[l-1], nil
} }

View File

@ -1,33 +1,33 @@
package light_test package lite_test
import ( import (
"fmt" "fmt"
"testing" "testing"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
) )
func BenchmarkGenCommit20(b *testing.B) { func BenchmarkGenCommit20(b *testing.B) {
keys := light.GenValKeys(20) keys := lite.GenValKeys(20)
benchmarkGenCommit(b, keys) benchmarkGenCommit(b, keys)
} }
func BenchmarkGenCommit100(b *testing.B) { func BenchmarkGenCommit100(b *testing.B) {
keys := light.GenValKeys(100) keys := lite.GenValKeys(100)
benchmarkGenCommit(b, keys) benchmarkGenCommit(b, keys)
} }
func BenchmarkGenCommitSec20(b *testing.B) { func BenchmarkGenCommitSec20(b *testing.B) {
keys := light.GenSecpValKeys(20) keys := lite.GenSecpValKeys(20)
benchmarkGenCommit(b, keys) benchmarkGenCommit(b, keys)
} }
func BenchmarkGenCommitSec100(b *testing.B) { func BenchmarkGenCommitSec100(b *testing.B) {
keys := light.GenSecpValKeys(100) keys := lite.GenSecpValKeys(100)
benchmarkGenCommit(b, keys) benchmarkGenCommit(b, keys)
} }
func benchmarkGenCommit(b *testing.B, keys light.ValKeys) { func benchmarkGenCommit(b *testing.B, keys lite.ValKeys) {
chainID := fmt.Sprintf("bench-%d", len(keys)) chainID := fmt.Sprintf("bench-%d", len(keys))
vals := keys.ToValidators(20, 10) vals := keys.ToValidators(20, 10)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
@ -39,7 +39,7 @@ func benchmarkGenCommit(b *testing.B, keys light.ValKeys) {
// this benchmarks generating one key // this benchmarks generating one key
func BenchmarkGenValKeys(b *testing.B) { func BenchmarkGenValKeys(b *testing.B) {
keys := light.GenValKeys(20) keys := lite.GenValKeys(20)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
keys = keys.Extend(1) keys = keys.Extend(1)
} }
@ -47,7 +47,7 @@ func BenchmarkGenValKeys(b *testing.B) {
// this benchmarks generating one key // this benchmarks generating one key
func BenchmarkGenSecpValKeys(b *testing.B) { func BenchmarkGenSecpValKeys(b *testing.B) {
keys := light.GenSecpValKeys(20) keys := lite.GenSecpValKeys(20)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
keys = keys.Extend(1) keys = keys.Extend(1)
} }
@ -63,7 +63,7 @@ func BenchmarkToValidators100(b *testing.B) {
// this benchmarks constructing the validator set (.PubKey() * nodes) // this benchmarks constructing the validator set (.PubKey() * nodes)
func benchmarkToValidators(b *testing.B, nodes int) { func benchmarkToValidators(b *testing.B, nodes int) {
keys := light.GenValKeys(nodes) keys := lite.GenValKeys(nodes)
for i := 1; i <= b.N; i++ { for i := 1; i <= b.N; i++ {
keys.ToValidators(int64(2*i), int64(i)) keys.ToValidators(int64(2*i), int64(i))
} }
@ -75,36 +75,36 @@ func BenchmarkToValidatorsSec100(b *testing.B) {
// this benchmarks constructing the validator set (.PubKey() * nodes) // this benchmarks constructing the validator set (.PubKey() * nodes)
func benchmarkToValidatorsSec(b *testing.B, nodes int) { func benchmarkToValidatorsSec(b *testing.B, nodes int) {
keys := light.GenSecpValKeys(nodes) keys := lite.GenSecpValKeys(nodes)
for i := 1; i <= b.N; i++ { for i := 1; i <= b.N; i++ {
keys.ToValidators(int64(2*i), int64(i)) keys.ToValidators(int64(2*i), int64(i))
} }
} }
func BenchmarkCertifyCommit20(b *testing.B) { func BenchmarkCertifyCommit20(b *testing.B) {
keys := light.GenValKeys(20) keys := lite.GenValKeys(20)
benchmarkCertifyCommit(b, keys) benchmarkCertifyCommit(b, keys)
} }
func BenchmarkCertifyCommit100(b *testing.B) { func BenchmarkCertifyCommit100(b *testing.B) {
keys := light.GenValKeys(100) keys := lite.GenValKeys(100)
benchmarkCertifyCommit(b, keys) benchmarkCertifyCommit(b, keys)
} }
func BenchmarkCertifyCommitSec20(b *testing.B) { func BenchmarkCertifyCommitSec20(b *testing.B) {
keys := light.GenSecpValKeys(20) keys := lite.GenSecpValKeys(20)
benchmarkCertifyCommit(b, keys) benchmarkCertifyCommit(b, keys)
} }
func BenchmarkCertifyCommitSec100(b *testing.B) { func BenchmarkCertifyCommitSec100(b *testing.B) {
keys := light.GenSecpValKeys(100) keys := lite.GenSecpValKeys(100)
benchmarkCertifyCommit(b, keys) benchmarkCertifyCommit(b, keys)
} }
func benchmarkCertifyCommit(b *testing.B, keys light.ValKeys) { func benchmarkCertifyCommit(b *testing.B, keys lite.ValKeys) {
chainID := "bench-certify" chainID := "bench-certify"
vals := keys.ToValidators(20, 10) vals := keys.ToValidators(20, 10)
cert := light.NewStatic(chainID, vals) cert := lite.NewStatic(chainID, vals)
check := keys.GenCommit(chainID, 123, nil, vals, []byte("foo"), 0, len(keys)) check := keys.GenCommit(chainID, 123, nil, vals, []byte("foo"), 0, len(keys))
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
err := cert.Certify(check) err := cert.Certify(check)

View File

@ -1,4 +1,4 @@
package light package lite
// Provider is used to get more validators by other means. // Provider is used to get more validators by other means.
// //

View File

@ -1,5 +1,5 @@
// nolint: vetshadow // nolint: vetshadow
package light_test package lite_test
import ( import (
"testing" "testing"
@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
light "github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
// missingProvider doens't store anything, always a miss // missingProvider doens't store anything, always a miss
@ -16,43 +16,43 @@ import (
type missingProvider struct{} type missingProvider struct{}
// NewMissingProvider returns a provider which does not store anything and always misses. // NewMissingProvider returns a provider which does not store anything and always misses.
func NewMissingProvider() light.Provider { func NewMissingProvider() lite.Provider {
return missingProvider{} return missingProvider{}
} }
func (missingProvider) StoreCommit(_ light.FullCommit) error { return nil } func (missingProvider) StoreCommit(_ lite.FullCommit) error { return nil }
func (missingProvider) GetByHeight(_ int) (light.FullCommit, error) { func (missingProvider) GetByHeight(_ int) (lite.FullCommit, error) {
return light.FullCommit{}, lightErr.ErrCommitNotFound() return lite.FullCommit{}, liteErr.ErrCommitNotFound()
} }
func (missingProvider) GetByHash(_ []byte) (light.FullCommit, error) { func (missingProvider) GetByHash(_ []byte) (lite.FullCommit, error) {
return light.FullCommit{}, lightErr.ErrCommitNotFound() return lite.FullCommit{}, liteErr.ErrCommitNotFound()
} }
func (missingProvider) LatestCommit() (light.FullCommit, error) { func (missingProvider) LatestCommit() (lite.FullCommit, error) {
return light.FullCommit{}, lightErr.ErrCommitNotFound() return lite.FullCommit{}, liteErr.ErrCommitNotFound()
} }
func TestMemProvider(t *testing.T) { func TestMemProvider(t *testing.T) {
p := light.NewMemStoreProvider() p := lite.NewMemStoreProvider()
checkProvider(t, p, "test-mem", "empty") checkProvider(t, p, "test-mem", "empty")
} }
func TestCacheProvider(t *testing.T) { func TestCacheProvider(t *testing.T) {
p := light.NewCacheProvider( p := lite.NewCacheProvider(
NewMissingProvider(), NewMissingProvider(),
light.NewMemStoreProvider(), lite.NewMemStoreProvider(),
NewMissingProvider(), NewMissingProvider(),
) )
checkProvider(t, p, "test-cache", "kjfhekfhkewhgit") checkProvider(t, p, "test-cache", "kjfhekfhkewhgit")
} }
func checkProvider(t *testing.T, p light.Provider, chainID, app string) { func checkProvider(t *testing.T, p lite.Provider, chainID, app string) {
assert, require := assert.New(t), require.New(t) assert, require := assert.New(t), require.New(t)
appHash := []byte(app) appHash := []byte(app)
keys := light.GenValKeys(5) keys := lite.GenValKeys(5)
count := 10 count := 10
// make a bunch of commits... // make a bunch of commits...
commits := make([]light.FullCommit, count) commits := make([]lite.FullCommit, count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
// two commits for each validator, to check how we handle dups // two commits for each validator, to check how we handle dups
// (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ... // (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ...
@ -64,11 +64,11 @@ func checkProvider(t *testing.T, p light.Provider, chainID, app string) {
// check provider is empty // check provider is empty
fc, err := p.GetByHeight(20) fc, err := p.GetByHeight(20)
require.NotNil(err) require.NotNil(err)
assert.True(lightErr.IsCommitNotFoundErr(err)) assert.True(liteErr.IsCommitNotFoundErr(err))
fc, err = p.GetByHash(commits[3].ValidatorsHash()) fc, err = p.GetByHash(commits[3].ValidatorsHash())
require.NotNil(err) require.NotNil(err)
assert.True(lightErr.IsCommitNotFoundErr(err)) assert.True(liteErr.IsCommitNotFoundErr(err))
// now add them all to the provider // now add them all to the provider
for _, s := range commits { for _, s := range commits {
@ -101,7 +101,7 @@ func checkProvider(t *testing.T, p light.Provider, chainID, app string) {
} }
// this will make a get height, and if it is good, set the data as well // this will make a get height, and if it is good, set the data as well
func checkGetHeight(t *testing.T, p light.Provider, ask, expect int) { func checkGetHeight(t *testing.T, p lite.Provider, ask, expect int) {
fc, err := p.GetByHeight(ask) fc, err := p.GetByHeight(ask)
require.Nil(t, err, "%+v", err) require.Nil(t, err, "%+v", err)
if assert.Equal(t, expect, fc.Height()) { if assert.Equal(t, expect, fc.Height()) {
@ -116,13 +116,13 @@ func TestCacheGetsBestHeight(t *testing.T) {
// we will write data to the second level of the cache (p2), // we will write data to the second level of the cache (p2),
// and see what gets cached, stored in // and see what gets cached, stored in
p := light.NewMemStoreProvider() p := lite.NewMemStoreProvider()
p2 := light.NewMemStoreProvider() p2 := lite.NewMemStoreProvider()
cp := light.NewCacheProvider(p, p2) cp := lite.NewCacheProvider(p, p2)
chainID := "cache-best-height" chainID := "cache-best-height"
appHash := []byte("01234567") appHash := []byte("01234567")
keys := light.GenValKeys(5) keys := lite.GenValKeys(5)
count := 10 count := 10
// set a bunch of commits // set a bunch of commits

View File

@ -1,4 +1,4 @@
package light package lite
import ( import (
"bytes" "bytes"
@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
var _ Certifier = &Static{} var _ Certifier = &Static{}
@ -61,7 +61,7 @@ func (c *Static) Certify(commit Commit) error {
// make sure it has the same validator set we have (static means static) // make sure it has the same validator set we have (static means static)
if !bytes.Equal(c.Hash(), commit.Header.ValidatorsHash) { if !bytes.Equal(c.Hash(), commit.Header.ValidatorsHash) {
return lightErr.ErrValidatorsChanged() return liteErr.ErrValidatorsChanged()
} }
// then make sure we have the proper signatures for this // then make sure we have the proper signatures for this

View File

@ -1,4 +1,4 @@
package light_test package lite_test
import ( import (
"testing" "testing"
@ -7,8 +7,8 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/lite"
lightErr "github.com/tendermint/tendermint/light/errors" liteErr "github.com/tendermint/tendermint/lite/errors"
) )
func TestStaticCert(t *testing.T) { func TestStaticCert(t *testing.T) {
@ -16,15 +16,15 @@ func TestStaticCert(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
// require := require.New(t) // require := require.New(t)
keys := light.GenValKeys(4) keys := lite.GenValKeys(4)
// 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do! // 20, 30, 40, 50 - the first 3 don't have 2/3, the last 3 do!
vals := keys.ToValidators(20, 10) vals := keys.ToValidators(20, 10)
// and a certifier based on our known set // and a certifier based on our known set
chainID := "test-static" chainID := "test-static"
cert := light.NewStatic(chainID, vals) cert := lite.NewStatic(chainID, vals)
cases := []struct { cases := []struct {
keys light.ValKeys keys lite.ValKeys
vals *types.ValidatorSet vals *types.ValidatorSet
height int height int
first, last int // who actually signs first, last int // who actually signs
@ -51,7 +51,7 @@ func TestStaticCert(t *testing.T) {
} else { } else {
assert.NotNil(err) assert.NotNil(err)
if tc.changed { if tc.changed {
assert.True(lightErr.IsValidatorsChangedErr(err), "%+v", err) assert.True(liteErr.IsValidatorsChangedErr(err), "%+v", err)
} }
} }
} }