Add logs to lite/*; Fix rpc status to return consensus height, not blockstore height

This commit is contained in:
Jae Kwon
2018-06-26 16:52:38 -07:00
parent 7f4498f8b1
commit 37ef5485b4
15 changed files with 174 additions and 68 deletions

View File

@ -3,33 +3,39 @@ package proxy
import (
"github.com/tendermint/tendermint/lite"
lclient "github.com/tendermint/tendermint/lite/client"
cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db"
log "github.com/tendermint/tmlibs/log"
)
func GetCertifier(chainID, rootDir string, client lclient.SignStatusClient) (*lite.InquiringCertifier, error) {
func NewCertifier(chainID, rootDir string, client lclient.SignStatusClient, logger log.Logger) (*lite.InquiringCertifier, error) {
logger = logger.With("module", "lite/proxy")
logger.Info("lite/proxy/NewCertifier()...", "chainID", chainID, "rootDir", rootDir, "client", client)
memProvider := lite.NewDBProvider("trusted.mem", dbm.NewMemDB()).SetLimit(10)
lvlProvider := lite.NewDBProvider("trusted.lvl", dbm.NewDB("trust-base", dbm.LevelDBBackend, rootDir))
trust := lite.NewMultiProvider(
lite.NewDBProvider(dbm.NewMemDB()).SetLimit(10),
lite.NewDBProvider(dbm.NewDB("trust-base", dbm.LevelDBBackend, rootDir)),
memProvider,
lvlProvider,
)
source := lclient.NewProvider(chainID, client)
cert := lite.NewInquiringCertifier(chainID, trust, source)
cert.SetLogger(logger) // Sets logger recursively.
// TODO: Make this more secure, e.g. make it interactive in the console?
_, err := trust.LatestFullCommit(chainID, 1, 1<<63-1)
if err != nil {
logger.Info("lite/proxy/NewCertifier found no trusted full commit, initializing from source from height 1...")
fc, err := source.LatestFullCommit(chainID, 1, 1)
if err != nil {
return nil, err
return nil, cmn.ErrorWrap(err, "fetching source full commit @ height 1")
}
err = trust.SaveFullCommit(fc)
if err != nil {
return nil, err
return nil, cmn.ErrorWrap(err, "saving full commit to trusted")
}
}
cert, err := lite.NewInquiringCertifier(chainID, trust, source)
if err != nil {
return nil, err
}
return cert, nil
}

View File

@ -89,33 +89,49 @@ func (w Wrapper) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlock
// Block returns an entire block and verifies all signatures
func (w Wrapper) Block(height *int64) (*ctypes.ResultBlock, error) {
r, err := w.Client.Block(height)
resBlock, err := w.Client.Block(height)
if err != nil {
return nil, err
}
// get a checkpoint to verify from
res, err := w.Commit(height)
resCommit, err := w.Commit(height)
if err != nil {
return nil, err
}
sh := res.SignedHeader
sh := resCommit.SignedHeader
// now verify
err = ValidateBlockMeta(r.BlockMeta, sh)
err = ValidateBlockMeta(resBlock.BlockMeta, sh)
if err != nil {
return nil, err
}
err = ValidateBlock(r.Block, sh)
err = ValidateBlock(resBlock.Block, sh)
if err != nil {
return nil, err
}
return r, nil
return resBlock, nil
}
// Commit downloads the Commit and certifies it with the lite.
//
// This is the foundation for all other verification in this module
func (w Wrapper) Commit(height *int64) (*ctypes.ResultCommit, error) {
if height == nil {
resStatus, err := w.Client.Status()
if err != nil {
return nil, err
}
// NOTE: If resStatus.CatchingUp, there is a race
// condition where the validator set for the next height
// isn't available until some time after the blockstore
// has height h on the remote node. This isn't an issue
// once the node has caught up, and a syncing node likely
// won't have this issue esp with the implementation we
// have here, but we may have to address this at some
// point.
height = new(int64)
*height = resStatus.SyncInfo.LatestBlockHeight
}
rpcclient.WaitForHeight(w.Client, *height, nil)
res, err := w.Client.Commit(height)
// if we got it, then certify it