mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 22:01:20 +00:00
Rename light to lite
This commit is contained in:
@ -12,8 +12,8 @@ import (
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
)
|
||||
|
||||
// SignStatusClient combines a SignClient and StatusClient.
|
||||
@ -29,13 +29,13 @@ type provider struct {
|
||||
|
||||
// NewProvider can wrap any rpcclient to expose it as
|
||||
// a read-only provider.
|
||||
func NewProvider(node SignStatusClient) light.Provider {
|
||||
func NewProvider(node SignStatusClient) lite.Provider {
|
||||
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.
|
||||
func NewHTTPProvider(remote string) light.Provider {
|
||||
func NewHTTPProvider(remote string) lite.Provider {
|
||||
return &provider{
|
||||
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...
|
||||
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
|
||||
//
|
||||
// TODO: improve when the rpc interface supports more functionality
|
||||
func (p *provider) GetByHash(hash []byte) (light.FullCommit, error) {
|
||||
var fc light.FullCommit
|
||||
func (p *provider) GetByHash(hash []byte) (lite.FullCommit, error) {
|
||||
var fc lite.FullCommit
|
||||
vals, err := p.node.Validators(nil)
|
||||
// if we get no validators, or a different height, return an error
|
||||
if err != nil {
|
||||
@ -62,13 +62,13 @@ func (p *provider) GetByHash(hash []byte) (light.FullCommit, error) {
|
||||
p.updateHeight(vals.BlockHeight)
|
||||
vhash := types.NewValidatorSet(vals.Validators).Hash()
|
||||
if !bytes.Equal(hash, vhash) {
|
||||
return fc, lightErr.ErrCommitNotFound()
|
||||
return fc, liteErr.ErrCommitNotFound()
|
||||
}
|
||||
return p.seedFromVals(vals)
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return fc, err
|
||||
@ -77,7 +77,7 @@ func (p *provider) GetByHeight(h int) (fc light.FullCommit, err error) {
|
||||
}
|
||||
|
||||
// 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()
|
||||
if err != nil {
|
||||
return fc, err
|
||||
@ -97,24 +97,24 @@ func (p *provider) GetLatestCommit() (*ctypes.ResultCommit, error) {
|
||||
}
|
||||
|
||||
// CommitFromResult ...
|
||||
func CommitFromResult(result *ctypes.ResultCommit) light.Commit {
|
||||
return (light.Commit)(result.SignedHeader)
|
||||
func CommitFromResult(result *ctypes.ResultCommit) lite.Commit {
|
||||
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
|
||||
commit, err := p.node.Commit(&vals.BlockHeight)
|
||||
if err != nil {
|
||||
return light.FullCommit{}, err
|
||||
return lite.FullCommit{}, err
|
||||
}
|
||||
fc := light.NewFullCommit(
|
||||
fc := lite.NewFullCommit(
|
||||
CommitFromResult(commit),
|
||||
types.NewValidatorSet(vals.Validators),
|
||||
)
|
||||
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)
|
||||
|
||||
// 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)
|
||||
vset := types.NewValidatorSet(vals.Validators)
|
||||
if !bytes.Equal(vset.Hash(), commit.Header.ValidatorsHash) {
|
||||
return fc, lightErr.ErrValidatorsChanged()
|
||||
return fc, liteErr.ErrValidatorsChanged()
|
||||
}
|
||||
|
||||
p.updateHeight(commit.Header.Height)
|
@ -6,8 +6,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
rpctest "github.com/tendermint/tendermint/rpc/test"
|
||||
)
|
||||
@ -35,7 +35,7 @@ func TestProvider(t *testing.T) {
|
||||
|
||||
// let's check this is valid somehow
|
||||
assert.Nil(seed.ValidateBasic(chainID))
|
||||
cert := light.NewStatic(chainID, seed.Validators)
|
||||
cert := lite.NewStatic(chainID, seed.Validators)
|
||||
|
||||
// historical queries now work :)
|
||||
lower := sh - 5
|
||||
@ -53,7 +53,7 @@ func TestProvider(t *testing.T) {
|
||||
// get by hash fails without match
|
||||
seed, err = p.GetByHash([]byte("foobar"))
|
||||
assert.NotNil(err)
|
||||
assert.True(lightErr.IsCommitNotFoundErr(err))
|
||||
assert.True(liteErr.IsCommitNotFoundErr(err))
|
||||
|
||||
// storing the seed silently ignored
|
||||
err = p.StoreCommit(seed)
|
@ -1,4 +1,4 @@
|
||||
package light
|
||||
package lite
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"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.
|
||||
@ -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 {
|
||||
if c.Header == nil {
|
||||
return 0
|
||||
@ -78,7 +78,7 @@ func (c Commit) ValidateBasic(chainID string) error {
|
||||
|
||||
// make sure the header and commit match (height and hash)
|
||||
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()
|
||||
chash := c.Commit.BlockID.Hash
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Package light allows you to securely validate headers
|
||||
Package lite allows you to securely validate headers
|
||||
without a full node.
|
||||
|
||||
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).
|
||||
|
||||
*/
|
||||
package light
|
||||
package lite
|
@ -1,9 +1,9 @@
|
||||
package light
|
||||
package lite
|
||||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
)
|
||||
|
||||
var _ Certifier = &Dynamic{}
|
||||
@ -69,7 +69,7 @@ func (c *Dynamic) Update(fc FullCommit) error {
|
||||
// ignore all checkpoints in the past -> only to the future
|
||||
h := fc.Height()
|
||||
if h <= c.lastHeight {
|
||||
return lightErr.ErrPastTime()
|
||||
return liteErr.ErrPastTime()
|
||||
}
|
||||
|
||||
// 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(),
|
||||
commit.BlockID, h, commit)
|
||||
if err != nil {
|
||||
return lightErr.ErrTooMuchChange()
|
||||
return liteErr.ErrTooMuchChange()
|
||||
}
|
||||
|
||||
// looks good, we can update
|
@ -1,4 +1,4 @@
|
||||
package light_test
|
||||
package lite_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -8,8 +8,8 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
"github.com/tendermint/tendermint/light/errors"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
"github.com/tendermint/tendermint/lite/errors"
|
||||
)
|
||||
|
||||
// TestDynamicCert just makes sure it still works like StaticCert
|
||||
@ -18,15 +18,15 @@ func TestDynamicCert(t *testing.T) {
|
||||
assert := assert.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!
|
||||
vals := keys.ToValidators(20, 10)
|
||||
// and a certifier based on our known set
|
||||
chainID := "test-dyno"
|
||||
cert := light.NewDynamic(chainID, vals, 0)
|
||||
cert := lite.NewDynamic(chainID, vals, 0)
|
||||
|
||||
cases := []struct {
|
||||
keys light.ValKeys
|
||||
keys lite.ValKeys
|
||||
vals *types.ValidatorSet
|
||||
height int
|
||||
first, last int // who actually signs
|
||||
@ -65,9 +65,9 @@ func TestDynamicUpdate(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
|
||||
chainID := "test-dyno-up"
|
||||
keys := light.GenValKeys(5)
|
||||
keys := lite.GenValKeys(5)
|
||||
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
|
||||
h := 100
|
||||
@ -81,7 +81,7 @@ func TestDynamicUpdate(t *testing.T) {
|
||||
|
||||
// we try to update with some blocks
|
||||
cases := []struct {
|
||||
keys light.ValKeys
|
||||
keys lite.ValKeys
|
||||
vals *types.ValidatorSet
|
||||
height int
|
||||
first, last int // who actually signs
|
@ -8,8 +8,8 @@ import (
|
||||
|
||||
wire "github.com/tendermint/go-wire"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -20,7 +20,7 @@ const (
|
||||
)
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
@ -33,7 +33,7 @@ func SaveFullCommit(fc light.FullCommit, path string) error {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
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.
|
||||
func LoadFullCommit(path string) (light.FullCommit, error) {
|
||||
var fc light.FullCommit
|
||||
func LoadFullCommit(path string) (lite.FullCommit, error) {
|
||||
var fc lite.FullCommit
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return fc, lightErr.ErrCommitNotFound()
|
||||
return fc, liteErr.ErrCommitNotFound()
|
||||
}
|
||||
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.
|
||||
func LoadFullCommitJSON(path string) (light.FullCommit, error) {
|
||||
var fc light.FullCommit
|
||||
func LoadFullCommitJSON(path string) (lite.FullCommit, error) {
|
||||
var fc lite.FullCommit
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return fc, lightErr.ErrCommitNotFound()
|
||||
return fc, liteErr.ErrCommitNotFound()
|
||||
}
|
||||
return fc, errors.WithStack(err)
|
||||
}
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
)
|
||||
|
||||
func tmpFile() string {
|
||||
@ -27,7 +27,7 @@ func TestSerializeFullCommits(t *testing.T) {
|
||||
h := 25
|
||||
|
||||
// build a fc
|
||||
keys := light.GenValKeys(5)
|
||||
keys := lite.GenValKeys(5)
|
||||
vals := keys.ToValidators(10, 0)
|
||||
fc := keys.GenFullCommit(chainID, h, nil, vals, appHash, 0, 5)
|
||||
|
@ -24,8 +24,8 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
)
|
||||
|
||||
// nolint
|
||||
@ -44,7 +44,7 @@ type provider struct {
|
||||
|
||||
// NewProvider creates the parent dir and subdirs
|
||||
// for validators and checkpoints as needed
|
||||
func NewProvider(dir string) light.Provider {
|
||||
func NewProvider(dir string) lite.Provider {
|
||||
valDir := filepath.Join(dir, ValDir)
|
||||
checkDir := filepath.Join(dir, 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.
|
||||
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
|
||||
err := fc.ValidateBasic(fc.Commit.Header.ChainID)
|
||||
if err != nil {
|
||||
@ -88,11 +88,11 @@ func (p *provider) StoreCommit(fc light.FullCommit) error {
|
||||
}
|
||||
|
||||
// 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...
|
||||
path := filepath.Join(p.checkDir, p.encodeHeight(h))
|
||||
fc, err := LoadFullCommit(path)
|
||||
if lightErr.IsCommitNotFoundErr(err) {
|
||||
if liteErr.IsCommitNotFoundErr(err) {
|
||||
path, err = p.searchForHeight(h)
|
||||
if err == nil {
|
||||
fc, err = LoadFullCommit(path)
|
||||
@ -102,7 +102,7 @@ func (p *provider) GetByHeight(h int) (light.FullCommit, error) {
|
||||
}
|
||||
|
||||
// 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
|
||||
return p.GetByHeight(math.MaxInt32 - 1)
|
||||
}
|
||||
@ -125,7 +125,7 @@ func (p *provider) searchForHeight(h int) (string, error) {
|
||||
sort.Strings(files)
|
||||
i := sort.SearchStrings(files, desired)
|
||||
if i == 0 {
|
||||
return "", lightErr.ErrCommitNotFound()
|
||||
return "", liteErr.ErrCommitNotFound()
|
||||
}
|
||||
found := files[i-1]
|
||||
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.
|
||||
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))
|
||||
return LoadFullCommit(path)
|
||||
}
|
@ -10,12 +10,12 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
"github.com/tendermint/tendermint/light/files"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
"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)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -36,28 +36,28 @@ func TestFileProvider(t *testing.T) {
|
||||
|
||||
chainID := "test-files"
|
||||
appHash := []byte("some-data")
|
||||
keys := light.GenValKeys(5)
|
||||
keys := lite.GenValKeys(5)
|
||||
count := 10
|
||||
|
||||
// make a bunch of seeds...
|
||||
seeds := make([]light.FullCommit, count)
|
||||
seeds := make([]lite.FullCommit, count)
|
||||
for i := 0; i < count; i++ {
|
||||
// two seeds for each validator, to check how we handle dups
|
||||
// (10, 0), (10, 1), (10, 1), (10, 2), (10, 2), ...
|
||||
vals := keys.ToValidators(10, int64(count/2))
|
||||
h := 20 + 10*i
|
||||
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
|
||||
seed, err := p.GetByHeight(20)
|
||||
require.NotNil(err)
|
||||
assert.True(lightErr.IsCommitNotFoundErr(err))
|
||||
assert.True(liteErr.IsCommitNotFoundErr(err))
|
||||
|
||||
seed, err = p.GetByHash(seeds[3].ValidatorsHash())
|
||||
require.NotNil(err)
|
||||
assert.True(lightErr.IsCommitNotFoundErr(err))
|
||||
assert.True(liteErr.IsCommitNotFoundErr(err))
|
||||
|
||||
// now add them all to the provider
|
||||
for _, s := range seeds {
|
||||
@ -92,5 +92,5 @@ func TestFileProvider(t *testing.T) {
|
||||
// and proper error for too low
|
||||
_, err = p.GetByHeight(5)
|
||||
assert.NotNil(err)
|
||||
assert.True(lightErr.IsCommitNotFoundErr(err))
|
||||
assert.True(liteErr.IsCommitNotFoundErr(err))
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package light
|
||||
package lite
|
||||
|
||||
import (
|
||||
"time"
|
@ -1,9 +1,9 @@
|
||||
package light
|
||||
package lite
|
||||
|
||||
import (
|
||||
"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
|
||||
@ -63,7 +63,7 @@ func (c *Inquiring) Certify(commit Commit) error {
|
||||
}
|
||||
|
||||
err = c.cert.Certify(commit)
|
||||
if !lightErr.IsValidatorsChangedErr(err) {
|
||||
if !liteErr.IsValidatorsChangedErr(err) {
|
||||
return err
|
||||
}
|
||||
err = c.updateToHash(commit.Header.ValidatorsHash)
|
||||
@ -119,7 +119,7 @@ func (c *Inquiring) updateToHash(vhash []byte) error {
|
||||
}
|
||||
err = c.cert.Update(fc)
|
||||
// handle IsTooMuchChangeErr by using divide and conquer
|
||||
if lightErr.IsTooMuchChangeErr(err) {
|
||||
if liteErr.IsTooMuchChangeErr(err) {
|
||||
err = c.updateToHeight(fc.Height())
|
||||
}
|
||||
return err
|
||||
@ -134,12 +134,12 @@ func (c *Inquiring) updateToHeight(h int) error {
|
||||
}
|
||||
start, end := c.LastHeight(), fc.Height()
|
||||
if end <= start {
|
||||
return lightErr.ErrNoPathFound()
|
||||
return liteErr.ErrNoPathFound()
|
||||
}
|
||||
err = c.Update(fc)
|
||||
|
||||
// we can handle IsTooMuchChangeErr specially
|
||||
if !lightErr.IsTooMuchChangeErr(err) {
|
||||
if !liteErr.IsTooMuchChangeErr(err) {
|
||||
return err
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// nolint: vetshadow
|
||||
package light_test
|
||||
package lite_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -8,22 +8,22 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
)
|
||||
|
||||
func TestInquirerValidPath(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
trust := light.NewMemStoreProvider()
|
||||
source := light.NewMemStoreProvider()
|
||||
trust := lite.NewMemStoreProvider()
|
||||
source := lite.NewMemStoreProvider()
|
||||
|
||||
// set up the validators to generate test blocks
|
||||
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
|
||||
chainID := "inquiry-test"
|
||||
count := 50
|
||||
commits := make([]light.FullCommit, count)
|
||||
commits := make([]lite.FullCommit, count)
|
||||
for i := 0; i < count; i++ {
|
||||
// extend the keys by 1 each time
|
||||
keys = keys.Extend(1)
|
||||
@ -34,7 +34,7 @@ func TestInquirerValidPath(t *testing.T) {
|
||||
}
|
||||
|
||||
// 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....
|
||||
commit := commits[count-1].Commit
|
||||
@ -60,17 +60,17 @@ func TestInquirerValidPath(t *testing.T) {
|
||||
|
||||
func TestInquirerMinimalPath(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
trust := light.NewMemStoreProvider()
|
||||
source := light.NewMemStoreProvider()
|
||||
trust := lite.NewMemStoreProvider()
|
||||
source := lite.NewMemStoreProvider()
|
||||
|
||||
// set up the validators to generate test blocks
|
||||
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
|
||||
chainID := "minimal-path"
|
||||
count := 12
|
||||
commits := make([]light.FullCommit, count)
|
||||
commits := make([]lite.FullCommit, count)
|
||||
for i := 0; i < count; i++ {
|
||||
// extend the validators, so we are just below 2/3
|
||||
keys = keys.Extend(len(keys)/2 - 1)
|
||||
@ -81,7 +81,7 @@ func TestInquirerMinimalPath(t *testing.T) {
|
||||
}
|
||||
|
||||
// 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....
|
||||
commit := commits[count-1].Commit
|
||||
@ -107,17 +107,17 @@ func TestInquirerMinimalPath(t *testing.T) {
|
||||
|
||||
func TestInquirerVerifyHistorical(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
trust := light.NewMemStoreProvider()
|
||||
source := light.NewMemStoreProvider()
|
||||
trust := lite.NewMemStoreProvider()
|
||||
source := lite.NewMemStoreProvider()
|
||||
|
||||
// set up the validators to generate test blocks
|
||||
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
|
||||
chainID := "inquiry-test"
|
||||
count := 10
|
||||
commits := make([]light.FullCommit, count)
|
||||
commits := make([]lite.FullCommit, count)
|
||||
for i := 0; i < count; i++ {
|
||||
// extend the keys by 1 each time
|
||||
keys = keys.Extend(1)
|
||||
@ -128,7 +128,7 @@ func TestInquirerVerifyHistorical(t *testing.T) {
|
||||
}
|
||||
|
||||
// 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
|
||||
for _, i := range []int{2, 5} {
|
@ -1,10 +1,10 @@
|
||||
package light
|
||||
package lite
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"sort"
|
||||
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
)
|
||||
|
||||
type memStoreProvider struct {
|
||||
@ -60,7 +60,7 @@ func (m *memStoreProvider) GetByHeight(h int) (FullCommit, error) {
|
||||
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.
|
||||
@ -68,7 +68,7 @@ func (m *memStoreProvider) GetByHash(hash []byte) (FullCommit, error) {
|
||||
var err error
|
||||
fc, ok := m.byHash[m.encodeHash(hash)]
|
||||
if !ok {
|
||||
err = lightErr.ErrCommitNotFound()
|
||||
err = liteErr.ErrCommitNotFound()
|
||||
}
|
||||
return fc, err
|
||||
}
|
||||
@ -77,7 +77,7 @@ func (m *memStoreProvider) GetByHash(hash []byte) (FullCommit, error) {
|
||||
func (m *memStoreProvider) LatestCommit() (FullCommit, error) {
|
||||
l := len(m.byHeight)
|
||||
if l == 0 {
|
||||
return FullCommit{}, lightErr.ErrCommitNotFound()
|
||||
return FullCommit{}, liteErr.ErrCommitNotFound()
|
||||
}
|
||||
return m.byHeight[l-1], nil
|
||||
}
|
@ -1,33 +1,33 @@
|
||||
package light_test
|
||||
package lite_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
)
|
||||
|
||||
func BenchmarkGenCommit20(b *testing.B) {
|
||||
keys := light.GenValKeys(20)
|
||||
keys := lite.GenValKeys(20)
|
||||
benchmarkGenCommit(b, keys)
|
||||
}
|
||||
|
||||
func BenchmarkGenCommit100(b *testing.B) {
|
||||
keys := light.GenValKeys(100)
|
||||
keys := lite.GenValKeys(100)
|
||||
benchmarkGenCommit(b, keys)
|
||||
}
|
||||
|
||||
func BenchmarkGenCommitSec20(b *testing.B) {
|
||||
keys := light.GenSecpValKeys(20)
|
||||
keys := lite.GenSecpValKeys(20)
|
||||
benchmarkGenCommit(b, keys)
|
||||
}
|
||||
|
||||
func BenchmarkGenCommitSec100(b *testing.B) {
|
||||
keys := light.GenSecpValKeys(100)
|
||||
keys := lite.GenSecpValKeys(100)
|
||||
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))
|
||||
vals := keys.ToValidators(20, 10)
|
||||
for i := 0; i < b.N; i++ {
|
||||
@ -39,7 +39,7 @@ func benchmarkGenCommit(b *testing.B, keys light.ValKeys) {
|
||||
|
||||
// this benchmarks generating one key
|
||||
func BenchmarkGenValKeys(b *testing.B) {
|
||||
keys := light.GenValKeys(20)
|
||||
keys := lite.GenValKeys(20)
|
||||
for i := 0; i < b.N; i++ {
|
||||
keys = keys.Extend(1)
|
||||
}
|
||||
@ -47,7 +47,7 @@ func BenchmarkGenValKeys(b *testing.B) {
|
||||
|
||||
// this benchmarks generating one key
|
||||
func BenchmarkGenSecpValKeys(b *testing.B) {
|
||||
keys := light.GenSecpValKeys(20)
|
||||
keys := lite.GenSecpValKeys(20)
|
||||
for i := 0; i < b.N; i++ {
|
||||
keys = keys.Extend(1)
|
||||
}
|
||||
@ -63,7 +63,7 @@ func BenchmarkToValidators100(b *testing.B) {
|
||||
|
||||
// this benchmarks constructing the validator set (.PubKey() * nodes)
|
||||
func benchmarkToValidators(b *testing.B, nodes int) {
|
||||
keys := light.GenValKeys(nodes)
|
||||
keys := lite.GenValKeys(nodes)
|
||||
for i := 1; i <= b.N; 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)
|
||||
func benchmarkToValidatorsSec(b *testing.B, nodes int) {
|
||||
keys := light.GenSecpValKeys(nodes)
|
||||
keys := lite.GenSecpValKeys(nodes)
|
||||
for i := 1; i <= b.N; i++ {
|
||||
keys.ToValidators(int64(2*i), int64(i))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCertifyCommit20(b *testing.B) {
|
||||
keys := light.GenValKeys(20)
|
||||
keys := lite.GenValKeys(20)
|
||||
benchmarkCertifyCommit(b, keys)
|
||||
}
|
||||
|
||||
func BenchmarkCertifyCommit100(b *testing.B) {
|
||||
keys := light.GenValKeys(100)
|
||||
keys := lite.GenValKeys(100)
|
||||
benchmarkCertifyCommit(b, keys)
|
||||
}
|
||||
|
||||
func BenchmarkCertifyCommitSec20(b *testing.B) {
|
||||
keys := light.GenSecpValKeys(20)
|
||||
keys := lite.GenSecpValKeys(20)
|
||||
benchmarkCertifyCommit(b, keys)
|
||||
}
|
||||
|
||||
func BenchmarkCertifyCommitSec100(b *testing.B) {
|
||||
keys := light.GenSecpValKeys(100)
|
||||
keys := lite.GenSecpValKeys(100)
|
||||
benchmarkCertifyCommit(b, keys)
|
||||
}
|
||||
|
||||
func benchmarkCertifyCommit(b *testing.B, keys light.ValKeys) {
|
||||
func benchmarkCertifyCommit(b *testing.B, keys lite.ValKeys) {
|
||||
chainID := "bench-certify"
|
||||
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))
|
||||
for i := 0; i < b.N; i++ {
|
||||
err := cert.Certify(check)
|
@ -1,4 +1,4 @@
|
||||
package light
|
||||
package lite
|
||||
|
||||
// Provider is used to get more validators by other means.
|
||||
//
|
@ -1,5 +1,5 @@
|
||||
// nolint: vetshadow
|
||||
package light_test
|
||||
package lite_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -7,8 +7,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
light "github.com/tendermint/tendermint/light"
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
)
|
||||
|
||||
// missingProvider doens't store anything, always a miss
|
||||
@ -16,43 +16,43 @@ import (
|
||||
type missingProvider struct{}
|
||||
|
||||
// NewMissingProvider returns a provider which does not store anything and always misses.
|
||||
func NewMissingProvider() light.Provider {
|
||||
func NewMissingProvider() lite.Provider {
|
||||
return missingProvider{}
|
||||
}
|
||||
|
||||
func (missingProvider) StoreCommit(_ light.FullCommit) error { return nil }
|
||||
func (missingProvider) GetByHeight(_ int) (light.FullCommit, error) {
|
||||
return light.FullCommit{}, lightErr.ErrCommitNotFound()
|
||||
func (missingProvider) StoreCommit(_ lite.FullCommit) error { return nil }
|
||||
func (missingProvider) GetByHeight(_ int) (lite.FullCommit, error) {
|
||||
return lite.FullCommit{}, liteErr.ErrCommitNotFound()
|
||||
}
|
||||
func (missingProvider) GetByHash(_ []byte) (light.FullCommit, error) {
|
||||
return light.FullCommit{}, lightErr.ErrCommitNotFound()
|
||||
func (missingProvider) GetByHash(_ []byte) (lite.FullCommit, error) {
|
||||
return lite.FullCommit{}, liteErr.ErrCommitNotFound()
|
||||
}
|
||||
func (missingProvider) LatestCommit() (light.FullCommit, error) {
|
||||
return light.FullCommit{}, lightErr.ErrCommitNotFound()
|
||||
func (missingProvider) LatestCommit() (lite.FullCommit, error) {
|
||||
return lite.FullCommit{}, liteErr.ErrCommitNotFound()
|
||||
}
|
||||
|
||||
func TestMemProvider(t *testing.T) {
|
||||
p := light.NewMemStoreProvider()
|
||||
p := lite.NewMemStoreProvider()
|
||||
checkProvider(t, p, "test-mem", "empty")
|
||||
}
|
||||
|
||||
func TestCacheProvider(t *testing.T) {
|
||||
p := light.NewCacheProvider(
|
||||
p := lite.NewCacheProvider(
|
||||
NewMissingProvider(),
|
||||
light.NewMemStoreProvider(),
|
||||
lite.NewMemStoreProvider(),
|
||||
NewMissingProvider(),
|
||||
)
|
||||
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)
|
||||
appHash := []byte(app)
|
||||
keys := light.GenValKeys(5)
|
||||
keys := lite.GenValKeys(5)
|
||||
count := 10
|
||||
|
||||
// make a bunch of commits...
|
||||
commits := make([]light.FullCommit, count)
|
||||
commits := make([]lite.FullCommit, count)
|
||||
for i := 0; i < count; i++ {
|
||||
// two commits for each validator, to check how we handle dups
|
||||
// (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
|
||||
fc, err := p.GetByHeight(20)
|
||||
require.NotNil(err)
|
||||
assert.True(lightErr.IsCommitNotFoundErr(err))
|
||||
assert.True(liteErr.IsCommitNotFoundErr(err))
|
||||
|
||||
fc, err = p.GetByHash(commits[3].ValidatorsHash())
|
||||
require.NotNil(err)
|
||||
assert.True(lightErr.IsCommitNotFoundErr(err))
|
||||
assert.True(liteErr.IsCommitNotFoundErr(err))
|
||||
|
||||
// now add them all to the provider
|
||||
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
|
||||
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)
|
||||
require.Nil(t, err, "%+v", err)
|
||||
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),
|
||||
// and see what gets cached, stored in
|
||||
p := light.NewMemStoreProvider()
|
||||
p2 := light.NewMemStoreProvider()
|
||||
cp := light.NewCacheProvider(p, p2)
|
||||
p := lite.NewMemStoreProvider()
|
||||
p2 := lite.NewMemStoreProvider()
|
||||
cp := lite.NewCacheProvider(p, p2)
|
||||
|
||||
chainID := "cache-best-height"
|
||||
appHash := []byte("01234567")
|
||||
keys := light.GenValKeys(5)
|
||||
keys := lite.GenValKeys(5)
|
||||
count := 10
|
||||
|
||||
// set a bunch of commits
|
@ -1,4 +1,4 @@
|
||||
package light
|
||||
package lite
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
)
|
||||
|
||||
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)
|
||||
if !bytes.Equal(c.Hash(), commit.Header.ValidatorsHash) {
|
||||
return lightErr.ErrValidatorsChanged()
|
||||
return liteErr.ErrValidatorsChanged()
|
||||
}
|
||||
|
||||
// then make sure we have the proper signatures for this
|
@ -1,4 +1,4 @@
|
||||
package light_test
|
||||
package lite_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -7,8 +7,8 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/tendermint/tendermint/light"
|
||||
lightErr "github.com/tendermint/tendermint/light/errors"
|
||||
"github.com/tendermint/tendermint/lite"
|
||||
liteErr "github.com/tendermint/tendermint/lite/errors"
|
||||
)
|
||||
|
||||
func TestStaticCert(t *testing.T) {
|
||||
@ -16,15 +16,15 @@ func TestStaticCert(t *testing.T) {
|
||||
assert := assert.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!
|
||||
vals := keys.ToValidators(20, 10)
|
||||
// and a certifier based on our known set
|
||||
chainID := "test-static"
|
||||
cert := light.NewStatic(chainID, vals)
|
||||
cert := lite.NewStatic(chainID, vals)
|
||||
|
||||
cases := []struct {
|
||||
keys light.ValKeys
|
||||
keys lite.ValKeys
|
||||
vals *types.ValidatorSet
|
||||
height int
|
||||
first, last int // who actually signs
|
||||
@ -51,7 +51,7 @@ func TestStaticCert(t *testing.T) {
|
||||
} else {
|
||||
assert.NotNil(err)
|
||||
if tc.changed {
|
||||
assert.True(lightErr.IsValidatorsChangedErr(err), "%+v", err)
|
||||
assert.True(liteErr.IsValidatorsChangedErr(err), "%+v", err)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user