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.

117 lines
3.4 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
8 years ago
  1. package proxy
  2. import (
  3. "fmt"
  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. Snapshot() AppConnSnapshot
  14. }
  15. func NewAppConns(clientCreator ClientCreator) AppConns {
  16. return NewMultiAppConn(clientCreator)
  17. }
  18. //-----------------------------
  19. // multiAppConn implements AppConns
  20. // a multiAppConn is made of a few appConns (mempool, consensus, query)
  21. // and manages their underlying abci clients
  22. // TODO: on app restart, clients must reboot together
  23. type multiAppConn struct {
  24. service.BaseService
  25. mempoolConn AppConnMempool
  26. consensusConn AppConnConsensus
  27. queryConn AppConnQuery
  28. snapshotConn AppConnSnapshot
  29. clientCreator ClientCreator
  30. }
  31. // Make all necessary abci connections to the application
  32. func NewMultiAppConn(clientCreator ClientCreator) AppConns {
  33. multiAppConn := &multiAppConn{
  34. clientCreator: clientCreator,
  35. }
  36. multiAppConn.BaseService = *service.NewBaseService(nil, "multiAppConn", multiAppConn)
  37. return multiAppConn
  38. }
  39. // Returns the mempool connection
  40. func (app *multiAppConn) Mempool() AppConnMempool {
  41. return app.mempoolConn
  42. }
  43. // Returns the consensus Connection
  44. func (app *multiAppConn) Consensus() AppConnConsensus {
  45. return app.consensusConn
  46. }
  47. // Returns the query Connection
  48. func (app *multiAppConn) Query() AppConnQuery {
  49. return app.queryConn
  50. }
  51. // Returns the snapshot Connection
  52. func (app *multiAppConn) Snapshot() AppConnSnapshot {
  53. return app.snapshotConn
  54. }
  55. func (app *multiAppConn) OnStart() error {
  56. // query connection
  57. querycli, err := app.clientCreator.NewABCIClient()
  58. if err != nil {
  59. return fmt.Errorf("error creating ABCI client (query connection): %w", err)
  60. }
  61. querycli.SetLogger(app.Logger.With("module", "abci-client", "connection", "query"))
  62. if err := querycli.Start(); err != nil {
  63. return fmt.Errorf("error starting ABCI client (query connection): %w", err)
  64. }
  65. app.queryConn = NewAppConnQuery(querycli)
  66. // snapshot connection
  67. snapshotcli, err := app.clientCreator.NewABCIClient()
  68. if err != nil {
  69. return fmt.Errorf("error creating ABCI client (snapshot connection): %w", err)
  70. }
  71. snapshotcli.SetLogger(app.Logger.With("module", "abci-client", "connection", "snapshot"))
  72. if err := snapshotcli.Start(); err != nil {
  73. return fmt.Errorf("error starting ABCI client (snapshot connection): %w", err)
  74. }
  75. app.snapshotConn = NewAppConnSnapshot(snapshotcli)
  76. // mempool connection
  77. memcli, err := app.clientCreator.NewABCIClient()
  78. if err != nil {
  79. return fmt.Errorf("error creating ABCI client (mempool connection): %w", err)
  80. }
  81. memcli.SetLogger(app.Logger.With("module", "abci-client", "connection", "mempool"))
  82. if err := memcli.Start(); err != nil {
  83. return fmt.Errorf("error starting ABCI client (mempool connection): %w", err)
  84. }
  85. app.mempoolConn = NewAppConnMempool(memcli)
  86. // consensus connection
  87. concli, err := app.clientCreator.NewABCIClient()
  88. if err != nil {
  89. return fmt.Errorf("error creating ABCI client (consensus connection): %w", err)
  90. }
  91. concli.SetLogger(app.Logger.With("module", "abci-client", "connection", "consensus"))
  92. if err := concli.Start(); err != nil {
  93. return fmt.Errorf("error starting ABCI client (consensus connection): %w", err)
  94. }
  95. app.consensusConn = NewAppConnConsensus(concli)
  96. return nil
  97. }