From 1b7bec230d6d83a7849e75b5d6104b6dba92f33c Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 20 Oct 2017 20:50:22 +0200 Subject: [PATCH] make install works --- client/commands/query/get.go | 1 - modules/ibc/handler.go | 14 +++++----- modules/ibc/provider.go | 52 +++++++++++++++++++++--------------- modules/ibc/tx.go | 12 ++++----- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/client/commands/query/get.go b/client/commands/query/get.go index f597cd8bb..7ffc1c1f5 100644 --- a/client/commands/query/get.go +++ b/client/commands/query/get.go @@ -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" diff --git a/modules/ibc/handler.go b/modules/ibc/handler.go index 63bebc3ed..66c9b16cb 100644 --- a/modules/ibc/handler.go +++ b/modules/ibc/handler.go @@ -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 } diff --git a/modules/ibc/provider.go b/modules/ibc/provider.go index 7dc2302fe..712b6ee81 100644 --- a/modules/ibc/provider.go +++ b/modules/ibc/provider.go @@ -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 diff --git a/modules/ibc/tx.go b/modules/ibc/tx.go index 83eb17eb3..eae5a38f9 100644 --- a/modules/ibc/tx.go +++ b/modules/ibc/tx.go @@ -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) }