forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abci: Add relaxed local client synchronization models (cometbft#1141)
* proxy: Remove "unsynchronized" local client creator Signed-off-by: Thane Thomson <[email protected]> * proxy: Expand client creator interface Expand the `ClientCreator` interface to allow the caller to explicitly specify the "connection" whose client they are creating. This potentially gives greater control over the concurrency model employed in each type of connection. Signed-off-by: Thane Thomson <[email protected]> * abci/client: Clarify NewLocalClient description Signed-off-by: Thane Thomson <[email protected]> * proxy: Add connection-synchronized local client creator Analogous to the old "unsynchronized" local client creator. Signed-off-by: Thane Thomson <[email protected]> * abci/client: Add unsynchronized local client Signed-off-by: Thane Thomson <[email protected]> * proxy: Add consensus-synchronized local client creator Signed-off-by: Thane Thomson <[email protected]> * proxy: Fix mock configuration in test Signed-off-by: Thane Thomson <[email protected]> * Add changelog entries Signed-off-by: Thane Thomson <[email protected]> * Remove changelog entry - no longer necessary Signed-off-by: Thane Thomson <[email protected]> * proxy: Add unsynchronized local client creator Signed-off-by: Thane Thomson <[email protected]> * changelog: Add entry for unsync local client creator Signed-off-by: Thane Thomson <[email protected]> * Update 1141-abci-unsync-proxy.md Co-authored-by: Adi Seredinschi <[email protected]> --------- Signed-off-by: Thane Thomson <[email protected]> Co-authored-by: Adi Seredinschi <[email protected]>
- Loading branch information
Showing
14 changed files
with
484 additions
and
57 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
.changelog/unreleased/breaking-changes/1141-abci-advanced-proxy.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- `[proxy]` Expand `ClientCreator` interface to allow | ||
for per-"connection" control of client creation | ||
([\#1141](https://github.com/cometbft/cometbft/pull/1141)) |
4 changes: 4 additions & 0 deletions
4
.changelog/v0.38.0/improvements/1141-abci-consensus-syncd-proxy.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- `[abci/client]` Add consensus-synchronized local client creator, | ||
which only imposes a mutex on the consensus "connection", leaving | ||
the concurrency of all other "connections" up to the application | ||
([\#1141](https://github.com/cometbft/cometbft/pull/1141)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- `[abci/client]` Add fully unsynchronized local client creator, which | ||
imposes no mutexes on the application, leaving all handling of concurrency up | ||
to the application ([\#1141](https://github.com/cometbft/cometbft/pull/1141)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package abcicli | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
types "github.com/cometbft/cometbft/abci/types" | ||
"github.com/cometbft/cometbft/libs/service" | ||
) | ||
|
||
type unsyncLocalClient struct { | ||
service.BaseService | ||
|
||
types.Application | ||
|
||
mtx sync.Mutex | ||
Callback | ||
} | ||
|
||
var _ Client = (*unsyncLocalClient)(nil) | ||
|
||
// NewUnsyncLocalClient creates a local client, which wraps the application | ||
// interface that Comet as the client will call to the application as the | ||
// server. | ||
// | ||
// This differs from [NewLocalClient] in that it returns a client that only | ||
// maintains a mutex over the callback used by CheckTxAsync and not over the | ||
// application, leaving it up to the proxy to handle all concurrency. If the | ||
// proxy does not impose any concurrency restrictions, it is then left up to | ||
// the application to implement its own concurrency for the relevant group of | ||
// calls. | ||
func NewUnsyncLocalClient(app types.Application) Client { | ||
cli := &unsyncLocalClient{ | ||
Application: app, | ||
} | ||
cli.BaseService = *service.NewBaseService(nil, "unsyncLocalClient", cli) | ||
return cli | ||
} | ||
|
||
func (app *unsyncLocalClient) SetResponseCallback(cb Callback) { | ||
app.mtx.Lock() | ||
app.Callback = cb | ||
app.mtx.Unlock() | ||
} | ||
|
||
func (app *unsyncLocalClient) CheckTxAsync(ctx context.Context, req *types.RequestCheckTx) (*ReqRes, error) { | ||
res, err := app.Application.CheckTx(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return app.callback( | ||
types.ToRequestCheckTx(req), | ||
types.ToResponseCheckTx(res), | ||
), nil | ||
} | ||
|
||
func (app *unsyncLocalClient) callback(req *types.Request, res *types.Response) *ReqRes { | ||
app.Callback(req, res) | ||
rr := newLocalReqRes(req, res) | ||
rr.callbackInvoked = true | ||
return rr | ||
} | ||
|
||
//------------------------------------------------------- | ||
|
||
func (app *unsyncLocalClient) Error() error { | ||
return nil | ||
} | ||
|
||
func (app *unsyncLocalClient) Flush(context.Context) error { | ||
return nil | ||
} | ||
|
||
func (app *unsyncLocalClient) Echo(_ context.Context, msg string) (*types.ResponseEcho, error) { | ||
return &types.ResponseEcho{Message: msg}, nil | ||
} | ||
|
||
func (app *unsyncLocalClient) Info(ctx context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) { | ||
return app.Application.Info(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) CheckTx(ctx context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) { | ||
return app.Application.CheckTx(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) Query(ctx context.Context, req *types.RequestQuery) (*types.ResponseQuery, error) { | ||
return app.Application.Query(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) Commit(ctx context.Context, req *types.RequestCommit) (*types.ResponseCommit, error) { | ||
return app.Application.Commit(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) InitChain(ctx context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) { | ||
return app.Application.InitChain(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) ListSnapshots(ctx context.Context, req *types.RequestListSnapshots) (*types.ResponseListSnapshots, error) { | ||
return app.Application.ListSnapshots(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) OfferSnapshot(ctx context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) { | ||
return app.Application.OfferSnapshot(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) LoadSnapshotChunk(ctx context.Context, | ||
req *types.RequestLoadSnapshotChunk, | ||
) (*types.ResponseLoadSnapshotChunk, error) { | ||
return app.Application.LoadSnapshotChunk(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) ApplySnapshotChunk(ctx context.Context, | ||
req *types.RequestApplySnapshotChunk, | ||
) (*types.ResponseApplySnapshotChunk, error) { | ||
return app.Application.ApplySnapshotChunk(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) PrepareProposal(ctx context.Context, req *types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) { | ||
return app.Application.PrepareProposal(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) ProcessProposal(ctx context.Context, req *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) { | ||
return app.Application.ProcessProposal(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) ExtendVote(ctx context.Context, req *types.RequestExtendVote) (*types.ResponseExtendVote, error) { | ||
return app.Application.ExtendVote(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) VerifyVoteExtension(ctx context.Context, req *types.RequestVerifyVoteExtension) (*types.ResponseVerifyVoteExtension, error) { | ||
return app.Application.VerifyVoteExtension(ctx, req) | ||
} | ||
|
||
func (app *unsyncLocalClient) FinalizeBlock(ctx context.Context, req *types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) { | ||
return app.Application.FinalizeBlock(ctx, req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.