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
+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