Skip to content

Commit a473a04

Browse files
Ferret-sanGanesha Upadhyaya
andauthored
Use proxyApp instead of abciclient.Client in node clients (#779)
Closes: #744 --------- Co-authored-by: Ganesha Upadhyaya <gupadhyaya@Ganeshas-MacBook-Pro-2.local>
1 parent 42e7dcf commit a473a04

File tree

9 files changed

+58
-44
lines changed

9 files changed

+58
-44
lines changed

node/full.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
"github.com/libp2p/go-libp2p/core/crypto"
1313
"go.uber.org/multierr"
1414

15-
abciclient "github.com/tendermint/tendermint/abci/client"
1615
abci "github.com/tendermint/tendermint/abci/types"
1716
llcfg "github.com/tendermint/tendermint/config"
1817
"github.com/tendermint/tendermint/libs/log"
1918
"github.com/tendermint/tendermint/libs/service"
2019
corep2p "github.com/tendermint/tendermint/p2p"
20+
proxy "github.com/tendermint/tendermint/proxy"
2121
tmtypes "github.com/tendermint/tendermint/types"
2222

2323
"github.com/rollkit/rollkit/block"
@@ -53,8 +53,8 @@ var _ Node = &FullNode{}
5353
// It connects all the components and orchestrates their work.
5454
type FullNode struct {
5555
service.BaseService
56-
eventBus *tmtypes.EventBus
57-
appClient abciclient.Client
56+
eventBus *tmtypes.EventBus
57+
proxyApp proxy.AppConns
5858

5959
genesis *tmtypes.GenesisDoc
6060
// cache of chunked genesis data.
@@ -94,18 +94,24 @@ func newFullNode(
9494
conf config.NodeConfig,
9595
p2pKey crypto.PrivKey,
9696
signingKey crypto.PrivKey,
97-
appClient abciclient.Client,
97+
clientCreator proxy.ClientCreator,
9898
genesis *tmtypes.GenesisDoc,
9999
logger log.Logger,
100100
) (*FullNode, error) {
101+
proxyApp := proxy.NewAppConns(clientCreator)
102+
proxyApp.SetLogger(logger.With("module", "proxy"))
103+
if err := proxyApp.Start(); err != nil {
104+
return nil, fmt.Errorf("error starting proxy app connections: %v", err)
105+
}
106+
101107
eventBus := tmtypes.NewEventBus()
102108
eventBus.SetLogger(logger.With("module", "events"))
103109
if err := eventBus.Start(); err != nil {
104110
return nil, err
105111
}
106112

107-
var baseKV ds.TxnDatastore
108113
var err error
114+
var baseKV ds.TxnDatastore
109115
if conf.RootDir == "" && conf.DBPath == "" { // this is used for testing
110116
logger.Info("WARNING: working in in-memory mode")
111117
baseKV, err = store.NewDefaultInMemoryKVStore()
@@ -140,12 +146,12 @@ func newFullNode(
140146
return nil, err
141147
}
142148

143-
mp := mempoolv1.NewTxMempool(logger, llcfg.DefaultMempoolConfig(), appClient, 0)
149+
mp := mempoolv1.NewTxMempool(logger, llcfg.DefaultMempoolConfig(), proxyApp.Mempool(), 0)
144150
mpIDs := newMempoolIDs()
145151
mp.EnableTxsAvailable()
146152

147153
doneBuildingChannel := make(chan struct{})
148-
blockManager, err := block.NewManager(signingKey, conf.BlockManagerConfig, genesis, s, mp, appClient, dalc, eventBus, logger.With("module", "BlockManager"), doneBuildingChannel)
154+
blockManager, err := block.NewManager(signingKey, conf.BlockManagerConfig, genesis, s, mp, proxyApp.Consensus(), dalc, eventBus, logger.With("module", "BlockManager"), doneBuildingChannel)
149155
if err != nil {
150156
return nil, fmt.Errorf("BlockManager initialization error: %w", err)
151157
}
@@ -158,7 +164,7 @@ func newFullNode(
158164
ctx, cancel := context.WithCancel(ctx)
159165

160166
node := &FullNode{
161-
appClient: appClient,
167+
proxyApp: proxyApp,
162168
eventBus: eventBus,
163169
genesis: genesis,
164170
conf: conf,
@@ -249,6 +255,7 @@ func (n *FullNode) fraudProofPublishLoop(ctx context.Context) {
249255

250256
// OnStart is a part of Service interface.
251257
func (n *FullNode) OnStart() error {
258+
252259
n.Logger.Info("starting P2P client")
253260
err := n.P2P.Start(n.ctx)
254261
if err != nil {
@@ -319,8 +326,8 @@ func (n *FullNode) EventBus() *tmtypes.EventBus {
319326
}
320327

321328
// AppClient returns ABCI proxy connections to communicate with application.
322-
func (n *FullNode) AppClient() abciclient.Client {
323-
return n.appClient
329+
func (n *FullNode) AppClient() proxy.AppConns {
330+
return n.proxyApp
324331
}
325332

326333
// newTxValidator creates a pubsub validator that uses the node's mempool to check the

node/full_client.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"sort"
88
"time"
99

10-
abcicli "github.com/tendermint/tendermint/abci/client"
1110
abci "github.com/tendermint/tendermint/abci/types"
1211
"github.com/tendermint/tendermint/config"
1312
tmbytes "github.com/tendermint/tendermint/libs/bytes"
@@ -67,7 +66,7 @@ func (n *FullNode) GetClient() rpcclient.Client {
6766

6867
// ABCIInfo returns basic information about application state.
6968
func (c *FullClient) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
70-
resInfo, err := c.appClient().InfoSync(proxy.RequestInfo)
69+
resInfo, err := c.appClient().Query().InfoSync(proxy.RequestInfo)
7170
if err != nil {
7271
return nil, err
7372
}
@@ -81,7 +80,7 @@ func (c *FullClient) ABCIQuery(ctx context.Context, path string, data tmbytes.He
8180

8281
// ABCIQueryWithOptions queries for data from application.
8382
func (c *FullClient) ABCIQueryWithOptions(ctx context.Context, path string, data tmbytes.HexBytes, opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
84-
resQuery, err := c.appClient().QuerySync(abci.RequestQuery{
83+
resQuery, err := c.appClient().Query().QuerySync(abci.RequestQuery{
8584
Path: path,
8685
Data: data,
8786
Height: opts.Height,
@@ -788,7 +787,7 @@ func (c *FullClient) UnconfirmedTxs(ctx context.Context, limitPtr *int) (*ctypes
788787
//
789788
// If valid, the tx is automatically added to the mempool.
790789
func (c *FullClient) CheckTx(ctx context.Context, tx tmtypes.Tx) (*ctypes.ResultCheckTx, error) {
791-
res, err := c.appClient().CheckTxSync(abci.RequestCheckTx{Tx: tx})
790+
res, err := c.appClient().Mempool().CheckTxSync(abci.RequestCheckTx{Tx: tx})
792791
if err != nil {
793792
return nil, err
794793
}
@@ -844,7 +843,7 @@ func (c *FullClient) resubscribe(subscriber string, q tmpubsub.Query) tmtypes.Su
844843
}
845844
}
846845

847-
func (c *FullClient) appClient() abcicli.Client {
846+
func (c *FullClient) appClient() proxy.AppConns {
848847
return c.node.AppClient()
849848
}
850849

node/full_client_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515

1616
"github.com/libp2p/go-libp2p/core/crypto"
1717
"github.com/libp2p/go-libp2p/core/peer"
18-
abcicli "github.com/tendermint/tendermint/abci/client"
1918
abci "github.com/tendermint/tendermint/abci/types"
2019
tconfig "github.com/tendermint/tendermint/config"
2120
tmcrypto "github.com/tendermint/tendermint/crypto"
@@ -25,6 +24,7 @@ import (
2524
"github.com/tendermint/tendermint/libs/log"
2625
"github.com/tendermint/tendermint/p2p"
2726
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
27+
"github.com/tendermint/tendermint/proxy"
2828
tmtypes "github.com/tendermint/tendermint/types"
2929
"github.com/tendermint/tendermint/version"
3030

@@ -119,7 +119,7 @@ func TestGenesisChunked(t *testing.T) {
119119
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
120120
privKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)
121121
signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)
122-
n, _ := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock"}, privKey, signingKey, abcicli.NewLocalClient(nil, mockApp), genDoc, log.TestingLogger())
122+
n, _ := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock"}, privKey, signingKey, proxy.NewLocalClientCreator(mockApp), genDoc, log.TestingLogger())
123123

124124
rpc := NewFullClient(n)
125125

@@ -435,7 +435,7 @@ func TestTx(t *testing.T) {
435435
BlockManagerConfig: config.BlockManagerConfig{
436436
BlockTime: 1 * time.Second, // blocks must be at least 1 sec apart for adjacent headers to get verified correctly
437437
}},
438-
key, signingKey, abcicli.NewLocalClient(nil, mockApp),
438+
key, signingKey, proxy.NewLocalClientCreator(mockApp),
439439
&tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators},
440440
log.TestingLogger())
441441
require.NoError(err)
@@ -692,7 +692,7 @@ func TestValidatorSetHandling(t *testing.T) {
692692
},
693693
signingKey,
694694
signingKey,
695-
abcicli.NewLocalClient(nil, apps[i]),
695+
proxy.NewLocalClientCreator(apps[i]),
696696
&tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators},
697697
log.TestingLogger(),
698698
)
@@ -858,7 +858,7 @@ func getRPC(t *testing.T) (*mocks.Application, *FullClient) {
858858
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
859859
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
860860
signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)
861-
node, err := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, abcicli.NewLocalClient(nil, app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
861+
node, err := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
862862
require.NoError(err)
863863
require.NotNil(node)
864864

@@ -939,7 +939,7 @@ func TestMempool2Nodes(t *testing.T) {
939939
BlockManagerConfig: config.BlockManagerConfig{
940940
BlockTime: 1 * time.Second,
941941
},
942-
}, key1, signingKey1, abcicli.NewLocalClient(nil, app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
942+
}, key1, signingKey1, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
943943
require.NoError(err)
944944
require.NotNil(node1)
945945

@@ -949,7 +949,7 @@ func TestMempool2Nodes(t *testing.T) {
949949
ListenAddress: "/ip4/127.0.0.1/tcp/9002",
950950
Seeds: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.Pretty(),
951951
},
952-
}, key2, signingKey2, abcicli.NewLocalClient(nil, app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
952+
}, key2, signingKey2, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test"}, log.TestingLogger())
953953
require.NoError(err)
954954
require.NotNil(node1)
955955

@@ -1034,7 +1034,7 @@ func TestStatus(t *testing.T) {
10341034
},
10351035
key,
10361036
signingKey,
1037-
abcicli.NewLocalClient(nil, app),
1037+
proxy.NewLocalClientCreator(app),
10381038
&tmtypes.GenesisDoc{
10391039
ChainID: "test",
10401040
Validators: genesisValidators,
@@ -1134,7 +1134,7 @@ func TestFutureGenesisTime(t *testing.T) {
11341134
BlockTime: 200 * time.Millisecond,
11351135
}},
11361136
key, signingKey,
1137-
abcicli.NewLocalClient(nil, mockApp),
1137+
proxy.NewLocalClientCreator(mockApp),
11381138
&tmtypes.GenesisDoc{
11391139
ChainID: "test",
11401140
InitialHeight: 1,

node/full_node_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
"github.com/libp2p/go-libp2p/core/peer"
1818
"github.com/stretchr/testify/mock"
1919
"github.com/stretchr/testify/require"
20-
abcicli "github.com/tendermint/tendermint/abci/client"
2120
abci "github.com/tendermint/tendermint/abci/types"
2221
"github.com/tendermint/tendermint/libs/log"
22+
"github.com/tendermint/tendermint/proxy"
2323
tmtypes "github.com/tendermint/tendermint/types"
2424

2525
"github.com/rollkit/rollkit/config"
@@ -51,7 +51,7 @@ func TestAggregatorMode(t *testing.T) {
5151
BlockTime: 1 * time.Second,
5252
NamespaceID: types.NamespaceID{1, 2, 3, 4, 5, 6, 7, 8},
5353
}
54-
node, err := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: blockManagerConfig}, key, signingKey, abcicli.NewLocalClient(nil, app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
54+
node, err := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: blockManagerConfig}, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
5555
require.NoError(err)
5656
require.NotNil(node)
5757

@@ -157,7 +157,7 @@ func TestLazyAggregator(t *testing.T) {
157157
Aggregator: true,
158158
BlockManagerConfig: blockManagerConfig,
159159
LazyAggregator: true,
160-
}, key, signingKey, abcicli.NewLocalClient(nil, app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
160+
}, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
161161
assert.False(node.IsRunning())
162162
assert.NoError(err)
163163
err = node.Start()
@@ -545,7 +545,7 @@ func createNode(ctx context.Context, n int, isMalicious bool, aggregator bool, d
545545
},
546546
keys[n],
547547
signingKey,
548-
abcicli.NewLocalClient(nil, app),
548+
proxy.NewLocalClientCreator(app),
549549
&tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators},
550550
log.TestingLogger().With("node", n))
551551
require.NoError(err)

node/full_node_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212

1313
"github.com/libp2p/go-libp2p/core/crypto"
1414
"github.com/libp2p/go-libp2p/core/peer"
15-
abcicli "github.com/tendermint/tendermint/abci/client"
1615
abci "github.com/tendermint/tendermint/abci/types"
1716
"github.com/tendermint/tendermint/libs/log"
17+
"github.com/tendermint/tendermint/proxy"
1818
"github.com/tendermint/tendermint/types"
1919

2020
"github.com/rollkit/rollkit/config"
@@ -31,7 +31,7 @@ func TestStartup(t *testing.T) {
3131
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
3232
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
3333
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
34-
node, err := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, abcicli.NewLocalClient(nil, app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
34+
node, err := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
3535
require.NoError(err)
3636
require.NotNil(node)
3737

@@ -57,7 +57,7 @@ func TestMempoolDirectly(t *testing.T) {
5757
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
5858
anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
5959

60-
node, err := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, abcicli.NewLocalClient(nil, app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
60+
node, err := newFullNode(context.Background(), config.NodeConfig{DALayer: "mock"}, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger())
6161
require.NoError(err)
6262
require.NotNil(node)
6363

node/header_exchange.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
"github.com/celestiaorg/go-header"
1010
goheaderp2p "github.com/celestiaorg/go-header/p2p"
1111
goheaderstore "github.com/celestiaorg/go-header/store"
12-
"github.com/celestiaorg/go-header/sync"
13-
goheadersync "github.com/celestiaorg/go-header/sync"
12+
sync "github.com/celestiaorg/go-header/sync"
1413
ds "github.com/ipfs/go-datastore"
1514
pubsub "github.com/libp2p/go-libp2p-pubsub"
1615
"github.com/libp2p/go-libp2p/core/host"
@@ -145,7 +144,7 @@ func (hExService *HeaderExchangeService) Start() error {
145144
return fmt.Errorf("error while starting exchange: %w", err)
146145
}
147146

148-
if hExService.syncer, err = newSyncer(hExService.ex, hExService.headerStore, hExService.sub, goheadersync.WithBlockTime(hExService.conf.BlockTime)); err != nil {
147+
if hExService.syncer, err = newSyncer(hExService.ex, hExService.headerStore, hExService.sub, sync.WithBlockTime(hExService.conf.BlockTime)); err != nil {
149148
return err
150149
}
151150

@@ -229,7 +228,7 @@ func newSyncer(
229228
ex header.Exchange[*types.SignedHeader],
230229
store header.Store[*types.SignedHeader],
231230
sub header.Subscriber[*types.SignedHeader],
232-
opt goheadersync.Options,
231+
opt sync.Options,
233232
) (*sync.Syncer[*types.SignedHeader], error) {
234233
return sync.NewSyncer[*types.SignedHeader](ex, store, sub, opt)
235234
}

node/light.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66

77
ds "github.com/ipfs/go-datastore"
88
"github.com/libp2p/go-libp2p/core/crypto"
9-
abciclient "github.com/tendermint/tendermint/abci/client"
109
abci "github.com/tendermint/tendermint/abci/types"
1110
"github.com/tendermint/tendermint/libs/log"
1211
"github.com/tendermint/tendermint/libs/service"
12+
proxy "github.com/tendermint/tendermint/proxy"
1313
rpcclient "github.com/tendermint/tendermint/rpc/client"
1414
tmtypes "github.com/tendermint/tendermint/types"
1515
"go.uber.org/multierr"
@@ -26,7 +26,7 @@ type LightNode struct {
2626

2727
P2P *p2p.Client
2828

29-
app abciclient.Client
29+
proxyApp proxy.AppConns
3030

3131
hExService *HeaderExchangeService
3232

@@ -42,10 +42,17 @@ func newLightNode(
4242
ctx context.Context,
4343
conf config.NodeConfig,
4444
p2pKey crypto.PrivKey,
45-
appClient abciclient.Client,
45+
clientCreator proxy.ClientCreator,
4646
genesis *tmtypes.GenesisDoc,
4747
logger log.Logger,
4848
) (*LightNode, error) {
49+
// Create the proxyApp and establish connections to the ABCI app (consensus, mempool, query).
50+
proxyApp := proxy.NewAppConns(clientCreator)
51+
proxyApp.SetLogger(logger.With("module", "proxy"))
52+
if err := proxyApp.Start(); err != nil {
53+
return nil, fmt.Errorf("error starting proxy app connections: %v", err)
54+
}
55+
4956
datastore, err := openDatastore(conf, logger)
5057
if err != nil {
5158
return nil, err
@@ -64,7 +71,7 @@ func newLightNode(
6471

6572
node := &LightNode{
6673
P2P: client,
67-
app: appClient,
74+
proxyApp: proxyApp,
6875
hExService: headerExchangeService,
6976
cancel: cancel,
7077
ctx: ctx,
@@ -124,7 +131,7 @@ func (ln *LightNode) newFraudProofValidator() p2p.GossipValidator {
124131
return false
125132
}
126133

127-
resp, err := ln.app.VerifyFraudProofSync(abci.RequestVerifyFraudProof{
134+
resp, err := ln.proxyApp.Consensus().VerifyFraudProofSync(abci.RequestVerifyFraudProof{
128135
FraudProof: &fraudProof,
129136
ExpectedValidAppHash: fraudProof.ExpectedValidAppHash,
130137
})

0 commit comments

Comments
 (0)