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.

48 lines
1.5 KiB

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