abciclient

package
v0.35.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2022 License: Apache-2.0 Imports: 16 Imported by: 263

Documentation

Overview

Package abciclient provides an ABCI implementation in Go.

There are 3 clients available:

  1. socket (unix or TCP)
  2. local (in memory)
  3. gRPC

## Socket client

async: the client maintains an internal buffer of a fixed size. when the buffer becomes full, all Async calls will return an error immediately.

sync: the client blocks on 1) enqueuing the Sync request 2) enqueuing the Flush requests 3) waiting for the Flush response

## Local client

async: global mutex is locked during each call (meaning it's not really async!) sync: global mutex is locked during each call

## gRPC client

async: gRPC is synchronous, but an internal buffer of a fixed size is used to store responses and later call callbacks (separate goroutine per response).

sync: waits for all Async calls to complete (essentially what Flush does in the socket client) and calls Sync method.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(*types.Request, *types.Response)

type Client

type Client interface {
	service.Service

	SetResponseCallback(Callback)
	Error() error

	// Asynchronous requests
	FlushAsync(context.Context) (*ReqRes, error)
	EchoAsync(ctx context.Context, msg string) (*ReqRes, error)
	InfoAsync(context.Context, types.RequestInfo) (*ReqRes, error)
	DeliverTxAsync(context.Context, types.RequestDeliverTx) (*ReqRes, error)
	CheckTxAsync(context.Context, types.RequestCheckTx) (*ReqRes, error)
	QueryAsync(context.Context, types.RequestQuery) (*ReqRes, error)
	CommitAsync(context.Context) (*ReqRes, error)
	InitChainAsync(context.Context, types.RequestInitChain) (*ReqRes, error)
	BeginBlockAsync(context.Context, types.RequestBeginBlock) (*ReqRes, error)
	EndBlockAsync(context.Context, types.RequestEndBlock) (*ReqRes, error)
	ListSnapshotsAsync(context.Context, types.RequestListSnapshots) (*ReqRes, error)
	OfferSnapshotAsync(context.Context, types.RequestOfferSnapshot) (*ReqRes, error)
	LoadSnapshotChunkAsync(context.Context, types.RequestLoadSnapshotChunk) (*ReqRes, error)
	ApplySnapshotChunkAsync(context.Context, types.RequestApplySnapshotChunk) (*ReqRes, error)

	// Synchronous requests
	FlushSync(context.Context) error
	EchoSync(ctx context.Context, msg string) (*types.ResponseEcho, error)
	InfoSync(context.Context, types.RequestInfo) (*types.ResponseInfo, error)
	DeliverTxSync(context.Context, types.RequestDeliverTx) (*types.ResponseDeliverTx, error)
	CheckTxSync(context.Context, types.RequestCheckTx) (*types.ResponseCheckTx, error)
	QuerySync(context.Context, types.RequestQuery) (*types.ResponseQuery, error)
	CommitSync(context.Context) (*types.ResponseCommit, error)
	InitChainSync(context.Context, types.RequestInitChain) (*types.ResponseInitChain, error)
	BeginBlockSync(context.Context, types.RequestBeginBlock) (*types.ResponseBeginBlock, error)
	EndBlockSync(context.Context, types.RequestEndBlock) (*types.ResponseEndBlock, error)
	ListSnapshotsSync(context.Context, types.RequestListSnapshots) (*types.ResponseListSnapshots, error)
	OfferSnapshotSync(context.Context, types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error)
	LoadSnapshotChunkSync(context.Context, types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error)
	ApplySnapshotChunkSync(context.Context, types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error)
}

Client defines an interface for an ABCI client.

All `Async` methods return a `ReqRes` object and an error. All `Sync` methods return the appropriate protobuf ResponseXxx struct and an error.

NOTE these are client errors, eg. ABCI socket connectivity issues. Application-related errors are reflected in response via ABCI error codes and logs.

func NewClient

func NewClient(addr, transport string, mustConnect bool) (client Client, err error)

NewClient returns a new ABCI client of the specified transport type. It returns an error if the transport is not "socket" or "grpc"

func NewGRPCClient

func NewGRPCClient(addr string, mustConnect bool) Client

NewGRPCClient creates a gRPC client, which will connect to addr upon the start. Note Client#Start returns an error if connection is unsuccessful and mustConnect is true.

GRPC calls are synchronous, but some callbacks expect to be called asynchronously (eg. the mempool expects to be able to lock to remove bad txs from cache). To accommodate, we finish each call in its own go-routine, which is expensive, but easy - if you want something better, use the socket protocol! maybe one day, if people really want it, we use grpc streams, but hopefully not :D

func NewLocalClient

func NewLocalClient(mtx *tmsync.Mutex, app types.Application) Client

NewLocalClient creates a local client, which will be directly calling the methods of the given app.

Both Async and Sync methods ignore the given context.Context parameter.

func NewSocketClient

func NewSocketClient(addr string, mustConnect bool) Client

NewSocketClient creates a new socket client, which connects to a given address. If mustConnect is true, the client will return an error upon start if it fails to connect.

type Creator added in v0.35.0

type Creator func() (Client, error)

Creator creates new ABCI clients.

func NewLocalCreator added in v0.35.0

func NewLocalCreator(app types.Application) Creator

NewLocalCreator returns a Creator for the given app, which will be running locally.

func NewRemoteCreator added in v0.35.0

func NewRemoteCreator(addr, transport string, mustConnect bool) Creator

NewRemoteCreator returns a Creator for the given address (e.g. "192.168.0.1") and transport (e.g. "tcp"). Set mustConnect to true if you want the client to connect before reporting success.

type ReqRes

type ReqRes struct {
	*types.Request
	*sync.WaitGroup
	*types.Response // Not set atomically, so be sure to use WaitGroup.
	// contains filtered or unexported fields
}

func NewReqRes

func NewReqRes(req *types.Request) *ReqRes

func (*ReqRes) GetCallback

func (r *ReqRes) GetCallback() func(*types.Response)

GetCallback returns the configured callback of the ReqRes object which may be nil. Note, it is not safe to concurrently call this in cases where it is marked done and SetCallback is called before calling GetCallback as that will invoke the callback twice and create a potential race condition.

ref: https://github.com/tendermint/tendermint/issues/5439

func (*ReqRes) InvokeCallback added in v0.34.8

func (r *ReqRes) InvokeCallback()

InvokeCallback invokes a thread-safe execution of the configured callback if non-nil.

func (*ReqRes) SetCallback

func (r *ReqRes) SetCallback(cb func(res *types.Response))

Sets sets the callback. If reqRes is already done, it will call the cb immediately. Note, reqRes.cb should not change if reqRes.done and only one callback is supported.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL