Skip to content

Commit 18bfb14

Browse files
Manav-AggarwalGanesha Upadhyaya
authored andcommitted
Deduplicate client generation (#1354)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Closes: #1324 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [x] New and updated code has appropriate documentation - [x] New and updated code has new and/or updated testing - [x] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced node structures with integrated RPC client support for improved interaction capabilities. - Streamlined client access with new initialization patterns and dedicated client retrieval methods. - **Refactor** - Reorganized client-related code for better clarity and maintainability. - Renamed and relocated client access functions to align with their respective node types. - **Documentation** - Updated function names and usage in documentation to reflect the new structure and methods. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1451090 commit 18bfb14

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

node/full.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/cometbft/cometbft/libs/service"
1919
corep2p "github.com/cometbft/cometbft/p2p"
2020
proxy "github.com/cometbft/cometbft/proxy"
21+
rpcclient "github.com/cometbft/cometbft/rpc/client"
2122
cmtypes "github.com/cometbft/cometbft/types"
2223

2324
"github.com/rollkit/rollkit/block"
@@ -70,6 +71,7 @@ type FullNode struct {
7071
mempoolIDs *mempoolIDs
7172
Store store.Store
7273
blockManager *block.Manager
74+
client rpcclient.Client
7375

7476
// Preserves cometBFT compatibility
7577
TxIndexer txindex.TxIndexer
@@ -167,6 +169,7 @@ func newFullNode(
167169

168170
node.BaseService = *service.NewBaseService(logger, "Node", node)
169171
node.p2pClient.SetTxValidator(node.newTxValidator())
172+
node.client = NewFullClient(node)
170173

171174
return node, nil
172175
}
@@ -301,6 +304,11 @@ func (n *FullNode) blockPublishLoop(ctx context.Context) {
301304
}
302305
}
303306

307+
// GetClient returns the RPC client for the full node.
308+
func (n *FullNode) GetClient() rpcclient.Client {
309+
return n.client
310+
}
311+
304312
// Cancel calls the underlying context's cancel function.
305313
func (n *FullNode) Cancel() {
306314
n.cancel()

node/full_client.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ var _ rpcclient.Client = &FullClient{}
4646
type FullClient struct {
4747
*cmtypes.EventBus
4848
config *config.RPCConfig
49-
50-
node *FullNode
49+
node *FullNode
5150
}
5251

5352
// NewFullClient returns Client working with given node.
@@ -59,14 +58,6 @@ func NewFullClient(node *FullNode) *FullClient {
5958
}
6059
}
6160

62-
// GetClient returns a new RPC client for the full node.
63-
//
64-
// TODO: should this be NewRPPCClient? Or should we add the client as a field of
65-
// the FullNode so that it is just created once?
66-
func (n *FullNode) GetClient() rpcclient.Client {
67-
return NewFullClient(n)
68-
}
69-
7061
// ABCIInfo returns basic information about application state.
7162
func (c *FullClient) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
7263
resInfo, err := c.appClient().Query().Info(ctx, proxy.RequestInfo)

node/light.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ type LightNode struct {
3131

3232
hSyncService *block.HeaderSyncService
3333

34+
client rpcclient.Client
35+
3436
ctx context.Context
3537
cancel context.CancelFunc
3638
}
3739

3840
// GetClient returns a new rpcclient for the light node
39-
// TODO: this should be renamed to NewRPCClient or some New variant since it is
40-
// creating a new item
4141
func (ln *LightNode) GetClient() rpcclient.Client {
42-
return NewLightClient(ln)
42+
return ln.client
4343
}
4444

4545
func newLightNode(
@@ -85,6 +85,8 @@ func newLightNode(
8585

8686
node.BaseService = *service.NewBaseService(logger, "LightNode", node)
8787

88+
node.client = NewLightClient(node)
89+
8890
return node, nil
8991
}
9092

0 commit comments

Comments
 (0)