|
@ -2,7 +2,6 @@ package proxy |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
"errors" |
|
|
|
|
|
"fmt" |
|
|
"fmt" |
|
|
"os" |
|
|
"os" |
|
|
"syscall" |
|
|
"syscall" |
|
@ -67,7 +66,7 @@ type multiAppConn struct { |
|
|
// of reasonable lifecycle witout needing an explicit stop method.
|
|
|
// of reasonable lifecycle witout needing an explicit stop method.
|
|
|
type stoppableClient interface { |
|
|
type stoppableClient interface { |
|
|
abciclient.Client |
|
|
abciclient.Client |
|
|
Stop() error |
|
|
|
|
|
|
|
|
Stop() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// NewMultiAppConn makes all necessary abci connections to the application.
|
|
|
// NewMultiAppConn makes all necessary abci connections to the application.
|
|
@ -81,53 +80,42 @@ func NewMultiAppConn(clientCreator abciclient.Creator, logger log.Logger, metric |
|
|
return multiAppConn |
|
|
return multiAppConn |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *multiAppConn) Mempool() AppConnMempool { |
|
|
|
|
|
return app.mempoolConn |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (app *multiAppConn) Consensus() AppConnConsensus { |
|
|
|
|
|
return app.consensusConn |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (app *multiAppConn) Query() AppConnQuery { |
|
|
|
|
|
return app.queryConn |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (app *multiAppConn) Snapshot() AppConnSnapshot { |
|
|
|
|
|
return app.snapshotConn |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (app *multiAppConn) Mempool() AppConnMempool { return app.mempoolConn } |
|
|
|
|
|
func (app *multiAppConn) Consensus() AppConnConsensus { return app.consensusConn } |
|
|
|
|
|
func (app *multiAppConn) Query() AppConnQuery { return app.queryConn } |
|
|
|
|
|
func (app *multiAppConn) Snapshot() AppConnSnapshot { return app.snapshotConn } |
|
|
|
|
|
|
|
|
func (app *multiAppConn) OnStart(ctx context.Context) error { |
|
|
func (app *multiAppConn) OnStart(ctx context.Context) error { |
|
|
c, err := app.abciClientFor(ctx, connQuery) |
|
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
defer func() { |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
app.stopAllClients() |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
app.queryConnClient, err = app.abciClientFor(ctx, connQuery) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
app.queryConnClient = c.(stoppableClient) |
|
|
|
|
|
app.queryConn = NewAppConnQuery(c, app.metrics) |
|
|
|
|
|
|
|
|
app.queryConn = NewAppConnQuery(app.queryConnClient, app.metrics) |
|
|
|
|
|
|
|
|
c, err = app.abciClientFor(ctx, connSnapshot) |
|
|
|
|
|
|
|
|
app.snapshotConnClient, err = app.abciClientFor(ctx, connSnapshot) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
app.stopAllClients() |
|
|
|
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
app.snapshotConnClient = c.(stoppableClient) |
|
|
|
|
|
app.snapshotConn = NewAppConnSnapshot(c, app.metrics) |
|
|
|
|
|
|
|
|
app.snapshotConn = NewAppConnSnapshot(app.snapshotConnClient, app.metrics) |
|
|
|
|
|
|
|
|
c, err = app.abciClientFor(ctx, connMempool) |
|
|
|
|
|
|
|
|
app.mempoolConnClient, err = app.abciClientFor(ctx, connMempool) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
app.stopAllClients() |
|
|
|
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
app.mempoolConnClient = c.(stoppableClient) |
|
|
|
|
|
app.mempoolConn = NewAppConnMempool(c, app.metrics) |
|
|
|
|
|
|
|
|
app.mempoolConn = NewAppConnMempool(app.mempoolConnClient, app.metrics) |
|
|
|
|
|
|
|
|
c, err = app.abciClientFor(ctx, connConsensus) |
|
|
|
|
|
|
|
|
app.consensusConnClient, err = app.abciClientFor(ctx, connConsensus) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
app.stopAllClients() |
|
|
|
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
app.consensusConnClient = c.(stoppableClient) |
|
|
|
|
|
app.consensusConn = NewAppConnConsensus(c, app.metrics) |
|
|
|
|
|
|
|
|
app.consensusConn = NewAppConnConsensus(app.consensusConnClient, app.metrics) |
|
|
|
|
|
|
|
|
// Kill Tendermint if the ABCI application crashes.
|
|
|
// Kill Tendermint if the ABCI application crashes.
|
|
|
app.startWatchersForClientErrorToKillTendermint(ctx) |
|
|
app.startWatchersForClientErrorToKillTendermint(ctx) |
|
@ -135,9 +123,7 @@ func (app *multiAppConn) OnStart(ctx context.Context) error { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *multiAppConn) OnStop() { |
|
|
|
|
|
app.stopAllClients() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (app *multiAppConn) OnStop() { app.stopAllClients() } |
|
|
|
|
|
|
|
|
func (app *multiAppConn) startWatchersForClientErrorToKillTendermint(ctx context.Context) { |
|
|
func (app *multiAppConn) startWatchersForClientErrorToKillTendermint(ctx context.Context) { |
|
|
// this function starts a number of threads (per abci client)
|
|
|
// this function starts a number of threads (per abci client)
|
|
@ -154,12 +140,10 @@ func (app *multiAppConn) startWatchersForClientErrorToKillTendermint(ctx context |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type op struct { |
|
|
|
|
|
|
|
|
for _, client := range []struct { |
|
|
connClient stoppableClient |
|
|
connClient stoppableClient |
|
|
name string |
|
|
name string |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, client := range []op{ |
|
|
|
|
|
|
|
|
}{ |
|
|
{ |
|
|
{ |
|
|
connClient: app.consensusConnClient, |
|
|
connClient: app.consensusConnClient, |
|
|
name: connConsensus, |
|
|
name: connConsensus, |
|
@ -190,47 +174,36 @@ func (app *multiAppConn) startWatchersForClientErrorToKillTendermint(ctx context |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *multiAppConn) stopAllClients() { |
|
|
func (app *multiAppConn) stopAllClients() { |
|
|
if app.consensusConnClient != nil { |
|
|
|
|
|
if err := app.consensusConnClient.Stop(); err != nil { |
|
|
|
|
|
if !errors.Is(err, service.ErrAlreadyStopped) { |
|
|
|
|
|
app.logger.Error("error while stopping consensus client", "error", err) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if app.mempoolConnClient != nil { |
|
|
|
|
|
if err := app.mempoolConnClient.Stop(); err != nil { |
|
|
|
|
|
if !errors.Is(err, service.ErrAlreadyStopped) { |
|
|
|
|
|
app.logger.Error("error while stopping mempool client", "error", err) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if app.queryConnClient != nil { |
|
|
|
|
|
if err := app.queryConnClient.Stop(); err != nil { |
|
|
|
|
|
if !errors.Is(err, service.ErrAlreadyStopped) { |
|
|
|
|
|
app.logger.Error("error while stopping query client", "error", err) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if app.snapshotConnClient != nil { |
|
|
|
|
|
if err := app.snapshotConnClient.Stop(); err != nil { |
|
|
|
|
|
if !errors.Is(err, service.ErrAlreadyStopped) { |
|
|
|
|
|
app.logger.Error("error while stopping snapshot client", "error", err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for _, client := range []stoppableClient{ |
|
|
|
|
|
app.consensusConnClient, |
|
|
|
|
|
app.mempoolConnClient, |
|
|
|
|
|
app.queryConnClient, |
|
|
|
|
|
app.snapshotConnClient, |
|
|
|
|
|
} { |
|
|
|
|
|
if client != nil { |
|
|
|
|
|
client.Stop() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (app *multiAppConn) abciClientFor(ctx context.Context, conn string) (abciclient.Client, error) { |
|
|
|
|
|
|
|
|
func (app *multiAppConn) abciClientFor(ctx context.Context, conn string) (stoppableClient, error) { |
|
|
c, err := app.clientCreator(app.logger.With( |
|
|
c, err := app.clientCreator(app.logger.With( |
|
|
"module", "abci-client", |
|
|
"module", "abci-client", |
|
|
"connection", conn)) |
|
|
"connection", conn)) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, fmt.Errorf("error creating ABCI client (%s connection): %w", conn, err) |
|
|
return nil, fmt.Errorf("error creating ABCI client (%s connection): %w", conn, err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if err := c.Start(ctx); err != nil { |
|
|
if err := c.Start(ctx); err != nil { |
|
|
return nil, fmt.Errorf("error starting ABCI client (%s connection): %w", conn, err) |
|
|
return nil, fmt.Errorf("error starting ABCI client (%s connection): %w", conn, err) |
|
|
} |
|
|
} |
|
|
return c, nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client, ok := c.(stoppableClient) |
|
|
|
|
|
if !ok { |
|
|
|
|
|
return nil, fmt.Errorf("%T is not a stoppable client", c) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return client, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func kill() error { |
|
|
func kill() error { |
|
|