github.com/vipernet-xyz/tendermint-core@v0.32.0/proxy/multi_app_conn.go (about)

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