Skip to content

Commit c93ddf2

Browse files
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 645ee90 commit c93ddf2

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"
@@ -71,6 +72,7 @@ type FullNode struct {
7172
mempoolIDs *mempoolIDs
7273
Store store.Store
7374
blockManager *block.Manager
75+
client rpcclient.Client
7476

7577
// Preserves cometBFT compatibility
7678
TxIndexer txindex.TxIndexer
@@ -168,6 +170,7 @@ func newFullNode(
168170

169171
node.BaseService = *service.NewBaseService(logger, "Node", node)
170172
node.p2pClient.SetTxValidator(node.newTxValidator())
173+
node.client = NewFullClient(node)
171174

172175
return node, nil
173176
}
@@ -302,6 +305,11 @@ func (n *FullNode) blockPublishLoop(ctx context.Context) {
302305
}
303306
}
304307

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

node/full_client.go

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

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

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