mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 05:46:32 +00:00
abci: modify Client interface and socket client (#5673)
`abci.Client`:
- Sync and Async methods now accept a context for cancellation
* grpc client uses context to cancel both Sync and Async requests
* local client ignores context parameter
* socket client uses context to cancel Sync requests and to drop Async requests before sending them if context was cancelled prior to that
- Async methods return an error
* socket client returns an error immediately if queue is full for Async requests
* local client always returns nil error
* grpc client returns an error if context was cancelled before we got response or the receiving queue had a space for response (do not confuse with the sending queue from the socket client)
- specify clients semantics in [doc.go](https://raw.githubusercontent.com/tendermint/tendermint/27112fffa62276bc016d56741f686f0f77931748/abci/client/doc.go)
`mempool.TxInfo`
- add optional `Context` to `TxInfo`, which can be used to cancel `CheckTx` request
Closes #5190
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -223,7 +224,7 @@ func (blockExec *BlockExecutor) Commit(
|
||||
}
|
||||
|
||||
// Commit block, get hash back
|
||||
res, err := blockExec.proxyApp.CommitSync()
|
||||
res, err := blockExec.proxyApp.CommitSync(context.Background())
|
||||
if err != nil {
|
||||
blockExec.logger.Error(
|
||||
"Client error during proxyAppConn.CommitSync",
|
||||
@@ -297,18 +298,22 @@ func execBlockOnProxyApp(
|
||||
byzVals = append(byzVals, evidence.ABCI()...)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Begin block
|
||||
var err error
|
||||
pbh := block.Header.ToProto()
|
||||
if pbh == nil {
|
||||
return nil, errors.New("nil header")
|
||||
}
|
||||
abciResponses.BeginBlock, err = proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{
|
||||
Hash: block.Hash(),
|
||||
Header: *pbh,
|
||||
LastCommitInfo: commitInfo,
|
||||
ByzantineValidators: byzVals,
|
||||
})
|
||||
abciResponses.BeginBlock, err = proxyAppConn.BeginBlockSync(
|
||||
ctx,
|
||||
abci.RequestBeginBlock{
|
||||
Hash: block.Hash(),
|
||||
Header: *pbh,
|
||||
LastCommitInfo: commitInfo,
|
||||
ByzantineValidators: byzVals,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("Error in proxyAppConn.BeginBlock", "err", err)
|
||||
return nil, err
|
||||
@@ -316,14 +321,14 @@ func execBlockOnProxyApp(
|
||||
|
||||
// Run txs of block.
|
||||
for _, tx := range block.Txs {
|
||||
proxyAppConn.DeliverTxAsync(abci.RequestDeliverTx{Tx: tx})
|
||||
if err := proxyAppConn.Error(); err != nil {
|
||||
_, err = proxyAppConn.DeliverTxAsync(ctx, abci.RequestDeliverTx{Tx: tx})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// End block.
|
||||
abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(abci.RequestEndBlock{Height: block.Height})
|
||||
abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(ctx, abci.RequestEndBlock{Height: block.Height})
|
||||
if err != nil {
|
||||
logger.Error("Error in proxyAppConn.EndBlock", "err", err)
|
||||
return nil, err
|
||||
@@ -537,7 +542,7 @@ func ExecCommitBlock(
|
||||
return nil, err
|
||||
}
|
||||
// Commit block, get hash back
|
||||
res, err := appConnConsensus.CommitSync()
|
||||
res, err := appConnConsensus.CommitSync(context.Background())
|
||||
if err != nil {
|
||||
logger.Error("Client error during proxyAppConn.CommitSync", "err", res)
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user