make install works

This commit is contained in:
Ethan Frey 2017-10-20 20:50:22 +02:00
parent 40bb1fdca5
commit 1b7bec230d
4 changed files with 44 additions and 35 deletions

View File

@ -12,7 +12,6 @@ import (
"github.com/tendermint/go-wire/data"
"github.com/tendermint/iavl"
"github.com/tendermint/light-client/proofs"
rpcclient "github.com/tendermint/tendermint/rpc/client"
rpcclient "github.com/tendermint/tendermint/rpc/client"

View File

@ -124,14 +124,14 @@ func (h Handler) initSeed(ctx sdk.Context, store state.SimpleDB,
// verify that the header looks reasonable
chainID := t.ChainID()
s := NewChainSet(store)
err = s.Register(chainID, ctx.BlockHeight(), t.Seed.Height())
err = s.Register(chainID, ctx.BlockHeight(), t.Commit.Height())
if err != nil {
return res, err
}
space := stack.PrefixedStore(chainID, store)
provider := newDBProvider(space)
err = provider.StoreSeed(t.Seed)
err = provider.StoreCommit(t.Commit)
return res, err
}
@ -147,21 +147,21 @@ func (h Handler) updateSeed(ctx sdk.Context, store state.SimpleDB,
}
// load the certifier for this chain
seed := t.Seed
fc := t.Commit
space := stack.PrefixedStore(chainID, store)
cert, err := newCertifier(space, chainID, seed.Height())
cert, err := newCertifier(space, chainID, fc.Height())
if err != nil {
return res, err
}
// this will import the seed if it is valid in the current context
err = cert.Update(seed.Checkpoint, seed.Validators)
// this will import the commit if it is valid in the current context
err = cert.Update(fc)
if err != nil {
return res, ErrInvalidCommit(err)
}
// update the tracked height in chain info
err = s.Update(chainID, t.Seed.Height())
err = s.Update(chainID, fc.Height())
return res, err
}

View File

@ -3,6 +3,7 @@ package ibc
import (
wire "github.com/tendermint/go-wire"
"github.com/tendermint/light-client/certifiers"
certerr "github.com/tendermint/light-client/certifiers/errors"
"github.com/cosmos/cosmos-sdk/stack"
"github.com/cosmos/cosmos-sdk/state"
@ -21,22 +22,22 @@ func newCertifier(store state.SimpleDB, chainID string, h int) (*certifiers.Inqu
// each chain has their own prefixed subspace
p := newDBProvider(store)
var seed certifiers.FullCommit
var fc certifiers.FullCommit
var err error
if h > 0 {
// this gets the most recent verified seed below the specified height
seed, err = p.GetByHeight(h)
// this gets the most recent verified commit below the specified height
fc, err = p.GetByHeight(h)
} else {
// 0 or negative means start at latest seed
seed, err = certifiers.LatestSeed(p)
// 0 or negative means start at latest commit
fc, err = p.LatestCommit()
}
if err != nil {
return nil, ErrHeaderNotFound(h)
}
// we have no source for untrusted keys, but use the db to load trusted history
cert := certifiers.NewInquiring(chainID, seed, p,
certifiers.MissingProvider{})
cert := certifiers.NewInquiring(chainID, fc, p,
certifiers.NewMissingProvider())
return cert, nil
}
@ -55,40 +56,49 @@ func newDBProvider(store state.SimpleDB) *dbProvider {
var _ certifiers.Provider = &dbProvider{}
func (d *dbProvider) StoreSeed(seed certifiers.FullCommit) error {
func (d *dbProvider) StoreCommit(fc certifiers.FullCommit) error {
// TODO: don't duplicate data....
b := wire.BinaryBytes(seed)
d.byHash.Set(seed.Hash(), b)
d.byHeight.Set(uint64(seed.Height()), b)
b := wire.BinaryBytes(fc)
d.byHash.Set(fc.ValidatorsHash(), b)
d.byHeight.Set(uint64(fc.Height()), b)
return nil
}
func (d *dbProvider) GetByHeight(h int) (seed certifiers.FullCommit, err error) {
b, _ := d.byHeight.LTE(uint64(h))
func (d *dbProvider) LatestCommit() (fc certifiers.FullCommit, err error) {
b, _ := d.byHeight.Top()
if b == nil {
return seed, certifiers.ErrSeedNotFound()
return fc, certerr.ErrCommitNotFound()
}
err = wire.ReadBinaryBytes(b, &seed)
err = wire.ReadBinaryBytes(b, &fc)
return
}
func (d *dbProvider) GetByHash(hash []byte) (seed certifiers.FullCommit, err error) {
func (d *dbProvider) GetByHeight(h int) (fc certifiers.FullCommit, err error) {
b, _ := d.byHeight.LTE(uint64(h))
if b == nil {
return fc, certerr.ErrCommitNotFound()
}
err = wire.ReadBinaryBytes(b, &fc)
return
}
func (d *dbProvider) GetByHash(hash []byte) (fc certifiers.FullCommit, err error) {
b := d.byHash.Get(hash)
if b == nil {
return seed, certifiers.ErrSeedNotFound()
return fc, certerr.ErrCommitNotFound()
}
err = wire.ReadBinaryBytes(b, &seed)
err = wire.ReadBinaryBytes(b, &fc)
return
}
// GetExactHeight is like GetByHeight, but returns an error instead of
// closest match if there is no exact match
func (d *dbProvider) GetExactHeight(h int) (seed certifiers.FullCommit, err error) {
seed, err = d.GetByHeight(h)
func (d *dbProvider) GetExactHeight(h int) (fc certifiers.FullCommit, err error) {
fc, err = d.GetByHeight(h)
if err != nil {
return
}
if seed.Height() != h {
if fc.Height() != h {
err = ErrHeaderNotFound(h)
}
return

View File

@ -32,17 +32,17 @@ func init() {
// RegisterChainTx allows you to register a new chain on this blockchain
type RegisterChainTx struct {
Seed certifiers.FullCommit `json:"seed"`
Commit certifiers.FullCommit `json:"seed"`
}
// ChainID helps get the chain this tx refers to
func (r RegisterChainTx) ChainID() string {
return r.Seed.Header.ChainID
return r.Commit.Header.ChainID
}
// ValidateBasic makes sure this is consistent, without checking the sigs
func (r RegisterChainTx) ValidateBasic() error {
err := r.Seed.ValidateBasic(r.ChainID())
err := r.Commit.ValidateBasic(r.ChainID())
if err != nil {
err = ErrInvalidCommit(err)
}
@ -56,17 +56,17 @@ func (r RegisterChainTx) Wrap() sdk.Tx {
// UpdateChainTx updates the state of this chain
type UpdateChainTx struct {
Seed certifiers.FullCommit `json:"seed"`
Commit certifiers.FullCommit `json:"seed"`
}
// ChainID helps get the chain this tx refers to
func (u UpdateChainTx) ChainID() string {
return u.Seed.Header.ChainID
return u.Commit.Header.ChainID
}
// ValidateBasic makes sure this is consistent, without checking the sigs
func (u UpdateChainTx) ValidateBasic() error {
err := u.Seed.ValidateBasic(u.ChainID())
err := u.Commit.ValidateBasic(u.ChainID())
if err != nil {
err = ErrInvalidCommit(err)
}