feat: gRPC mempool service (#275)

* make file nit

* base app set up

* make file update

* makefile nit

* adding service test to e2e

* lint

* type fix

* nit

* unit test + readme
This commit is contained in:
David Terpay
2023-12-08 13:33:58 -05:00
committed by GitHub
parent 56eeeb3ea2
commit 7d8a6956a7
14 changed files with 1280 additions and 39 deletions
+19
View File
@@ -44,6 +44,7 @@ import (
"github.com/skip-mev/block-sdk/abci"
"github.com/skip-mev/block-sdk/block"
"github.com/skip-mev/block-sdk/block/base"
service "github.com/skip-mev/block-sdk/block/service"
"github.com/skip-mev/block-sdk/lanes/mev"
auctionkeeper "github.com/skip-mev/block-sdk/x/auction/keeper"
blocksdkkeeper "github.com/skip-mev/block-sdk/x/blocksdk/keeper"
@@ -385,13 +386,31 @@ func (app *TestApp) SimulationManager() *module.SimulationManager {
// RegisterAPIRoutes registers all application module routes with the provided
// API server.
func (app *TestApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
// Register the base app API routes.
app.App.RegisterAPIRoutes(apiSvr, apiConfig)
// Register the Block SDK mempool API routes.
service.RegisterGRPCGatewayRoutes(apiSvr.ClientCtx, apiSvr.GRPCGatewayRouter)
// register swagger API in app.go so that other applications can override easily
if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil {
panic(err)
}
}
// RegisterTxService implements the Application.RegisterTxService method.
func (app *TestApp) RegisterTxService(clientCtx client.Context) {
// Register the base app transaction service.
app.App.RegisterTxService(clientCtx)
// Register the Block SDK mempool transaction service.
mempool, ok := app.App.Mempool().(block.Mempool)
if !ok {
panic("mempool is not a block.Mempool")
}
service.RegisterMempoolService(app.GRPCQueryRouter(), mempool)
}
// GetMaccPerms returns a copy of the module account permissions
//
// NOTE: This is solely to be used for testing purposes.
+16
View File
@@ -12,6 +12,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/skip-mev/block-sdk/lanes/base"
"github.com/skip-mev/block-sdk/lanes/free"
interchaintest "github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
@@ -121,6 +123,12 @@ func (s *IntegrationTestSuite) TestQueryParams() {
require.NoError(s.T(), params.Validate())
}
func (s *IntegrationTestSuite) TestMempoolService() {
resp, err := QueryMempool(s.T(), s.chain)
s.Require().NoError(err)
s.Require().Len(resp.Distribution, 3)
}
// TestValidBids tests the execution of various valid auction bids. There are a few
// invariants that are tested:
//
@@ -1298,6 +1306,10 @@ func (s *IntegrationTestSuite) TestNetwork() {
s.BroadcastTxs(context.Background(), s.chain.(*cosmos.CosmosChain), []Tx{normalTx})
}
}
resp, err := QueryMempool(s.T(), s.chain)
s.NoError(err)
s.Require().True(resp.Distribution[base.LaneName] > 0)
}
}
})
@@ -1322,6 +1334,10 @@ func (s *IntegrationTestSuite) TestNetwork() {
s.BroadcastTxs(context.Background(), s.chain.(*cosmos.CosmosChain), []Tx{freeTx})
}
}
resp, err := QueryMempool(s.T(), s.chain)
s.NoError(err)
s.Require().True(resp.Distribution[free.LaneName] > 0)
}
}
})
+13
View File
@@ -37,6 +37,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
servicetypes "github.com/skip-mev/block-sdk/block/service/types"
auctiontypes "github.com/skip-mev/block-sdk/x/auction/types"
)
@@ -367,6 +368,18 @@ func QueryValidators(t *testing.T, chain *cosmos.CosmosChain) []sdk.ValAddress {
return addrs
}
// QueryMempool queries the mempool of the given chain
func QueryMempool(t *testing.T, chain ibc.Chain) (*servicetypes.GetTxDistributionResponse, error) {
// get grpc client of the node
grpcAddr := chain.GetHostGRPCAddress()
cc, err := grpc.Dial(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err)
client := servicetypes.NewServiceClient(cc)
return client.GetTxDistribution(context.Background(), &servicetypes.GetTxDistributionRequest{})
}
// QueryAccountBalance queries a given account's balance on the chain
func QueryAccountBalance(t *testing.T, chain ibc.Chain, address, denom string) int64 {
// cast the chain to a cosmos-chain