You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.5 KiB

  1. package proxy
  2. import (
  3. cmn "github.com/tendermint/tendermint/libs/common"
  4. dbm "github.com/tendermint/tendermint/libs/db"
  5. log "github.com/tendermint/tendermint/libs/log"
  6. "github.com/tendermint/tendermint/lite"
  7. lclient "github.com/tendermint/tendermint/lite/client"
  8. )
  9. func NewVerifier(chainID, rootDir string, client lclient.SignStatusClient, logger log.Logger) (*lite.DynamicVerifier, error) {
  10. logger = logger.With("module", "lite/proxy")
  11. logger.Info("lite/proxy/NewVerifier()...", "chainID", chainID, "rootDir", rootDir, "client", client)
  12. memProvider := lite.NewDBProvider("trusted.mem", dbm.NewMemDB()).SetLimit(10)
  13. lvlProvider := lite.NewDBProvider("trusted.lvl", dbm.NewDB("trust-base", dbm.LevelDBBackend, rootDir))
  14. trust := lite.NewMultiProvider(
  15. memProvider,
  16. lvlProvider,
  17. )
  18. source := lclient.NewProvider(chainID, client)
  19. cert := lite.NewDynamicVerifier(chainID, trust, source)
  20. cert.SetLogger(logger) // Sets logger recursively.
  21. // TODO: Make this more secure, e.g. make it interactive in the console?
  22. _, err := trust.LatestFullCommit(chainID, 1, 1<<63-1)
  23. if err != nil {
  24. logger.Info("lite/proxy/NewVerifier found no trusted full commit, initializing from source from height 1...")
  25. fc, err := source.LatestFullCommit(chainID, 1, 1)
  26. if err != nil {
  27. return nil, cmn.ErrorWrap(err, "fetching source full commit @ height 1")
  28. }
  29. err = trust.SaveFullCommit(fc)
  30. if err != nil {
  31. return nil, cmn.ErrorWrap(err, "saving full commit to trusted")
  32. }
  33. }
  34. return cert, nil
  35. }