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.

99 lines
2.8 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package proxy
  2. import (
  3. "github.com/pkg/errors"
  4. "github.com/tendermint/tendermint/libs/service"
  5. )
  6. //-----------------------------
  7. // Tendermint's interface to the application consists of multiple connections
  8. type AppConns interface {
  9. service.Service
  10. Mempool() AppConnMempool
  11. Consensus() AppConnConsensus
  12. Query() AppConnQuery
  13. }
  14. func NewAppConns(clientCreator ClientCreator) AppConns {
  15. return NewMultiAppConn(clientCreator)
  16. }
  17. //-----------------------------
  18. // multiAppConn implements AppConns
  19. // a multiAppConn is made of a few appConns (mempool, consensus, query)
  20. // and manages their underlying abci clients
  21. // TODO: on app restart, clients must reboot together
  22. type multiAppConn struct {
  23. service.BaseService
  24. mempoolConn *appConnMempool
  25. consensusConn *appConnConsensus
  26. queryConn *appConnQuery
  27. clientCreator ClientCreator
  28. }
  29. // Make all necessary abci connections to the application
  30. func NewMultiAppConn(clientCreator ClientCreator) *multiAppConn {
  31. multiAppConn := &multiAppConn{
  32. clientCreator: clientCreator,
  33. }
  34. multiAppConn.BaseService = *service.NewBaseService(nil, "multiAppConn", multiAppConn)
  35. return multiAppConn
  36. }
  37. // Returns the mempool connection
  38. func (app *multiAppConn) Mempool() AppConnMempool {
  39. return app.mempoolConn
  40. }
  41. // Returns the consensus Connection
  42. func (app *multiAppConn) Consensus() AppConnConsensus {
  43. return app.consensusConn
  44. }
  45. // Returns the query Connection
  46. func (app *multiAppConn) Query() AppConnQuery {
  47. return app.queryConn
  48. }
  49. func (app *multiAppConn) OnStart() error {
  50. // query connection
  51. querycli, err := app.clientCreator.NewABCIClient()
  52. if err != nil {
  53. return errors.Wrap(err, "Error creating ABCI client (query connection)")
  54. }
  55. querycli.SetLogger(app.Logger.With("module", "abci-client", "connection", "query"))
  56. if err := querycli.Start(); err != nil {
  57. return errors.Wrap(err, "Error starting ABCI client (query connection)")
  58. }
  59. app.queryConn = NewAppConnQuery(querycli)
  60. // mempool connection
  61. memcli, err := app.clientCreator.NewABCIClient()
  62. if err != nil {
  63. return errors.Wrap(err, "Error creating ABCI client (mempool connection)")
  64. }
  65. memcli.SetLogger(app.Logger.With("module", "abci-client", "connection", "mempool"))
  66. if err := memcli.Start(); err != nil {
  67. return errors.Wrap(err, "Error starting ABCI client (mempool connection)")
  68. }
  69. app.mempoolConn = NewAppConnMempool(memcli)
  70. // consensus connection
  71. concli, err := app.clientCreator.NewABCIClient()
  72. if err != nil {
  73. return errors.Wrap(err, "Error creating ABCI client (consensus connection)")
  74. }
  75. concli.SetLogger(app.Logger.With("module", "abci-client", "connection", "consensus"))
  76. if err := concli.Start(); err != nil {
  77. return errors.Wrap(err, "Error starting ABCI client (consensus connection)")
  78. }
  79. app.consensusConn = NewAppConnConsensus(concli)
  80. return nil
  81. }