-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make file nit * base app set up * make file update * makefile nit * adding service test to e2e * lint * type fix * nit * unit test + readme (cherry picked from commit 7d8a695) # Conflicts: # Makefile # tests/integration/block_sdk_suite.go # testutils/utils.go
- Loading branch information
1 parent
863649c
commit 4d30a6c
Showing
14 changed files
with
1,295 additions
and
40 deletions.
There are no files selected for viewing
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
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,56 @@ | ||
# Block SDK Mempool Service | ||
|
||
The Block SDK mempool service is a service that allows you to query the current state of the application side mempool. | ||
|
||
## Usage | ||
|
||
The mempool service is a standard gRPC service that can be paired with http or grpc clients. | ||
|
||
### HTTP Clients | ||
|
||
To make requests to the mempool service using HTTP, you have to use the grpc-gateway defined on your application's server. This is usually hosted on port 1317. | ||
|
||
### gRPC Clients | ||
|
||
To query the mempool service using gRPC, you can use the Mempool `ServiceClient` defined in [types](./types/query.pb.go): | ||
|
||
```golang | ||
type serviceClient struct { | ||
cc grpc1.ClientConn | ||
} | ||
|
||
func NewServiceClient(cc grpc1.ClientConn) ServiceClient { | ||
return &serviceClient{cc} | ||
} | ||
|
||
func (c *serviceClient) GetTxDistribution(ctx context.Context, in *GetTxDistributionRequest, opts ...grpc.CallOption) (*GetTxDistributionResponse, error) { | ||
out := new(GetTxDistributionResponse) | ||
err := c.cc.Invoke(ctx, "/sdk.mempool.v1.Service/GetTxDistribution", in, out, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return out, nil | ||
} | ||
``` | ||
|
||
## Endpoints | ||
|
||
### GetTxDistribution | ||
|
||
GetTxDistribution returns the current distribution of transactions in the mempool. The response is a map of the lane name to the number of transactions in that lane. | ||
|
||
```golang | ||
type GetTxDistributionRequest struct {} | ||
|
||
type GetTxDistributionResponse struct { | ||
Distribution map[string]uint64 | ||
} | ||
``` | ||
|
||
### HTTP Requests | ||
|
||
To query the mempool service using HTTP, you can use the following endpoint: | ||
|
||
```bash | ||
curl http://localhost:1317/block-sdk/mempool/v1/distribution | ||
``` |
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,54 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
|
||
gogogrpc "github.com/cosmos/gogoproto/grpc" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
|
||
"github.com/skip-mev/block-sdk/block" | ||
"github.com/skip-mev/block-sdk/block/service/types" | ||
) | ||
|
||
var _ types.ServiceServer = (*QueryService)(nil) | ||
|
||
// QueryService defines the service used by the gRPC query server to query the | ||
// Block SDK mempool. | ||
type QueryService struct { | ||
types.UnimplementedServiceServer | ||
|
||
// mempool is the mempool instance to query. | ||
mempool block.Mempool | ||
} | ||
|
||
// NewQueryService creates a new QueryService instance. | ||
func NewQueryService(mempool block.Mempool) *QueryService { | ||
return &QueryService{ | ||
mempool: mempool, | ||
} | ||
} | ||
|
||
// GetTxDistribution returns the current distribution of transactions in the | ||
// mempool. | ||
func (s *QueryService) GetTxDistribution( | ||
_ context.Context, | ||
_ *types.GetTxDistributionRequest, | ||
) (*types.GetTxDistributionResponse, error) { | ||
distribution := s.mempool.GetTxDistribution() | ||
return &types.GetTxDistributionResponse{Distribution: distribution}, nil | ||
} | ||
|
||
// RegisterMempoolService registers the Block SDK mempool queries on the gRPC server. | ||
|
||
func RegisterMempoolService( | ||
server gogogrpc.Server, | ||
mempool block.Mempool, | ||
) { | ||
types.RegisterServiceServer(server, NewQueryService(mempool)) | ||
} | ||
|
||
// RegisterGRPCGatewayRoutes mounts the Block SDK mempool service's GRPC-gateway routes on the | ||
// given Mux. | ||
func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) { | ||
_ = types.RegisterServiceHandlerClient(context.Background(), mux, types.NewServiceClient(clientConn)) | ||
} |
Oops, something went wrong.