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.

66 lines
2.1 KiB

  1. // Package node provides a high level wrapper around tendermint services.
  2. package node
  3. import (
  4. "fmt"
  5. abciclient "github.com/tendermint/tendermint/abci/client"
  6. "github.com/tendermint/tendermint/config"
  7. "github.com/tendermint/tendermint/libs/log"
  8. "github.com/tendermint/tendermint/libs/service"
  9. "github.com/tendermint/tendermint/privval"
  10. "github.com/tendermint/tendermint/types"
  11. )
  12. // NewDefault constructs a tendermint node service for use in go
  13. // process that host their own process-local tendermint node. This is
  14. // equivalent to running tendermint in it's own process communicating
  15. // to an external ABCI application.
  16. func NewDefault(conf *config.Config, logger log.Logger) (service.Service, error) {
  17. return newDefaultNode(conf, logger)
  18. }
  19. // New constructs a tendermint node. The ClientCreator makes it
  20. // possible to construct an ABCI application that runs in the same
  21. // process as the tendermint node. The final option is a pointer to a
  22. // Genesis document: if the value is nil, the genesis document is read
  23. // from the file specified in the config, and otherwise the node uses
  24. // value of the final argument.
  25. func New(conf *config.Config,
  26. logger log.Logger,
  27. cf abciclient.Creator,
  28. gen *types.GenesisDoc,
  29. ) (service.Service, error) {
  30. nodeKey, err := types.LoadOrGenNodeKey(conf.NodeKeyFile())
  31. if err != nil {
  32. return nil, fmt.Errorf("failed to load or gen node key %s: %w", conf.NodeKeyFile(), err)
  33. }
  34. var genProvider genesisDocProvider
  35. switch gen {
  36. case nil:
  37. genProvider = defaultGenesisDocProviderFunc(conf)
  38. default:
  39. genProvider = func() (*types.GenesisDoc, error) { return gen, nil }
  40. }
  41. switch conf.Mode {
  42. case config.ModeFull, config.ModeValidator:
  43. pval, err := privval.LoadOrGenFilePV(conf.PrivValidator.KeyFile(), conf.PrivValidator.StateFile())
  44. if err != nil {
  45. return nil, err
  46. }
  47. return makeNode(conf,
  48. pval,
  49. nodeKey,
  50. cf,
  51. genProvider,
  52. config.DefaultDBProvider,
  53. logger)
  54. case config.ModeSeed:
  55. return makeSeedNode(conf, config.DefaultDBProvider, nodeKey, genProvider, logger)
  56. default:
  57. return nil, fmt.Errorf("%q is not a valid mode", conf.Mode)
  58. }
  59. }