Skip to content

feat: reduce rpc complexity #69

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

Merged
merged 9 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/cosmos/cosmos-sdk v0.50.13
github.com/cosmos/gogoproto v1.7.0
github.com/go-kit/kit v0.13.0
github.com/gorilla/rpc v1.2.1
github.com/hashicorp/go-metrics v0.5.4
github.com/ipfs/go-datastore v0.8.2
github.com/rollkit/rollkit v0.14.2-0.20250422111549-9f2f92ea5c6e
Expand Down Expand Up @@ -108,7 +107,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.3
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,6 @@ github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/rpc v1.2.1 h1:yC+LMV5esttgpVvNORL/xX4jvTTEUE30UZhZ5JF7K9k=
github.com/gorilla/rpc v1.2.1/go.mod h1:uNpOihAlF5xRFLuTYhfR0yfCTm0WTQSQttkMSptRfGk=
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
Expand Down
5 changes: 5 additions & 0 deletions pkg/p2p/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package p2p

import "errors"

var ErrNotReady = errors.New("tx gossiper is not ready")
41 changes: 41 additions & 0 deletions pkg/rpc/core/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package core

import (
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/bytes"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
rpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types"
)

// ABCIQuery queries the application for some information.
// More: https://docs.cometbft.com/v0.37/rpc/#/ABCI/abci_query
func ABCIQuery(
ctx *rpctypes.Context,
path string,
data bytes.HexBytes,
height int64,
prove bool,
) (*ctypes.ResultABCIQuery, error) {
resp, err := env.Adapter.App.Query(ctx.Context(), &abci.RequestQuery{
Data: data,
Path: path,
})
if err != nil {
return nil, err
}
Comment on lines +19 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add nil check for environment before use

The function directly accesses the global env variable without checking if it's been initialized. This could lead to nil pointer panics if SetEnvironment hasn't been called.

func ABCIQuery(
	ctx *rpctypes.Context,
	path string,
	data bytes.HexBytes,
	height int64,
	prove bool,
) (*ctypes.ResultABCIQuery, error) {
+	if env == nil {
+		return nil, errors.New("rpc environment not initialized")
+	}
+	
	resp, err := env.Adapter.App.Query(ctx.Context(), &abci.RequestQuery{
		Data: data,
		Path: path,
	})
	if err != nil {
		return nil, err
	}
	return &ctypes.ResultABCIQuery{
		Response: *resp,
	}, nil
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
resp, err := env.Adapter.App.Query(ctx.Context(), &abci.RequestQuery{
Data: data,
Path: path,
})
if err != nil {
return nil, err
}
func ABCIQuery(
ctx *rpctypes.Context,
path string,
data bytes.HexBytes,
height int64,
prove bool,
) (*ctypes.ResultABCIQuery, error) {
if env == nil {
return nil, errors.New("rpc environment not initialized")
}
resp, err := env.Adapter.App.Query(ctx.Context(), &abci.RequestQuery{
Data: data,
Path: path,
})
if err != nil {
return nil, err
}
return &ctypes.ResultABCIQuery{
Response: *resp,
}, nil
}

return &ctypes.ResultABCIQuery{
Response: *resp,
}, nil
Comment on lines +12 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Unused parameters and missing validation in ABCIQuery

The function declares height and prove parameters but doesn't use them in the actual query. There's also no input validation.

Two issues need to be addressed:

  1. Utilize the unused parameters or remove them to avoid confusion
  2. Add basic validation for inputs
func ABCIQuery(
	ctx *rpctypes.Context,
	path string,
	data bytes.HexBytes,
	height int64,
	prove bool,
) (*ctypes.ResultABCIQuery, error) {
+	// Validate inputs
+	if height < 0 {
+		return nil, fmt.Errorf("height cannot be negative: %d", height)
+	}
+
	resp, err := env.Adapter.App.Query(ctx.Context(), &abci.RequestQuery{
		Data: data,
		Path: path,
+		Height: height,
+		Prove: prove,
	})
	if err != nil {
		return nil, err
	}
	return &ctypes.ResultABCIQuery{
		Response: *resp,
	}, nil
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func ABCIQuery(
ctx *rpctypes.Context,
path string,
data bytes.HexBytes,
height int64,
prove bool,
) (*ctypes.ResultABCIQuery, error) {
resp, err := env.Adapter.App.Query(ctx.Context(), &abci.RequestQuery{
Data: data,
Path: path,
})
if err != nil {
return nil, err
}
return &ctypes.ResultABCIQuery{
Response: *resp,
}, nil
func ABCIQuery(
ctx *rpctypes.Context,
path string,
data bytes.HexBytes,
height int64,
prove bool,
) (*ctypes.ResultABCIQuery, error) {
// Validate inputs
if height < 0 {
return nil, fmt.Errorf("height cannot be negative: %d", height)
}
resp, err := env.Adapter.App.Query(ctx.Context(), &abci.RequestQuery{
Data: data,
Path: path,
Height: height,
Prove: prove,
})
if err != nil {
return nil, err
}
return &ctypes.ResultABCIQuery{
Response: *resp,
}, nil
}

}

// ABCIInfo gets some info about the application.
// More: https://docs.cometbft.com/v0.37/rpc/#/ABCI/abci_info
func ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) {
info, err := env.Adapter.App.Info(&abci.RequestInfo{})
if err != nil {
return nil, err
}
return &ctypes.ResultABCIInfo{
Response: *info,
}, nil
}
Loading