Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable querying based on mempool status (only gRPC) #840

Merged
merged 5 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
"time"

"github.com/gogo/protobuf/proto"
abci "github.com/line/ostracon/abci/types"
ocproto "github.com/line/ostracon/proto/ostracon/types"
"google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"

abci "github.com/line/ostracon/abci/types"
ocproto "github.com/line/ostracon/proto/ostracon/types"

"github.com/line/lbm-sdk/codec"
snapshottypes "github.com/line/lbm-sdk/snapshots/types"
"github.com/line/lbm-sdk/telemetry"
Expand Down Expand Up @@ -920,3 +921,19 @@ func splitPath(requestPath string) (path []string) {

return path
}

// createQueryContext creates a new sdk.Context for a query, taking as args
// the block height and whether the query needs a proof or not.
func (app *BaseApp) createQueryContextWithCheckState() sdk.Context {

cacheMS := app.checkState.CacheMultiStore()

// branch the commit-multistore for safety
app.checkStateMtx.RLock()
ctx := sdk.NewContext(
cacheMS, app.checkState.ctx.BlockHeader(), true, app.logger,
).WithMinGasPrices(app.minGasPrices).WithBlockHeight(app.LastBlockHeight())
app.checkStateMtx.RUnlock()
jaeseung-bae marked this conversation as resolved.
Show resolved Hide resolved

return ctx
}
23 changes: 17 additions & 6 deletions baseapp/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
return nil, status.Error(codes.Internal, "unable to retrieve metadata")
}

var sdkCtx sdk.Context
// Get height header from the request context, if present.
var height int64

if heightHeaders := md.Get(grpctypes.GRPCBlockHeightHeader); len(heightHeaders) == 1 {
height, err = strconv.ParseInt(heightHeaders[0], 10, 64)
if err != nil {
Expand All @@ -43,13 +45,22 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
if err := checkNegativeHeight(height); err != nil {
return nil, err
}
}

// Create the sdk.Context. Passing false as 2nd arg, as we can't
// actually support proofs with gRPC right now.
sdkCtx, err := app.createQueryContext(height, false)
if err != nil {
return nil, err
// Create the sdk.Context. Passing false as 2nd arg, as we can't
// actually support proofs with gRPC right now.
sdkCtx, err = app.createQueryContext(height, false)
if err != nil {
return nil, err
}
} else if csHeaders := md.Get(grpctypes.GRPCCheckStateHeader); len(csHeaders) == 1 {
isCheck := csHeaders[0]
if isCheck != "on" {
return nil, sdkerrors.Wrapf(
sdkerrors.ErrInvalidRequest,
"Baseapp.RegisterGRPCServer: invalid checkState header %q: %v", grpctypes.GRPCCheckStateHeader, err)
}

sdkCtx = app.createQueryContextWithCheckState()
}

// Add relevant gRPC headers
Expand Down
3 changes: 3 additions & 0 deletions types/grpc/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ package grpc
const (
// GRPCBlockHeightHeader is the gRPC header for block height.
GRPCBlockHeightHeader = "x-cosmos-block-height"
// GRPCCheckStateHeader is the gRPC header for mempool state. Assign "on" to this header when you want to query checkState values.
// If you use both GRPCBlockHeightHeader and GRPCCheckStateHeader, GRPCCheckStateHeader would be ignored.
GRPCCheckStateHeader = "x-lbm-checkstate"
)