Skip to content

Commit 909bc19

Browse files
coderbradleezjshen14
authored andcommitted
Remove JSON RPC related code iotexproject#1057 (iotexproject#1085)
1 parent 11a1084 commit 909bc19

28 files changed

+43
-7521
lines changed

action/protocol/execution/evm/evmstatedbadapter_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func TestRefundAPIs(t *testing.T) {
6161

6262
ctx := context.Background()
6363
cfg := config.Default
64-
cfg.Explorer.Enabled = true
6564
sf, err := factory.NewFactory(cfg, factory.InMemTrieOption())
6665
require.NoError(err)
6766
require.NoError(sf.Start(ctx))
@@ -85,7 +84,6 @@ func TestEmptyAndCode(t *testing.T) {
8584

8685
ctx := context.Background()
8786
cfg := config.Default
88-
cfg.Explorer.Enabled = true
8987
sf, err := factory.NewFactory(cfg, factory.InMemTrieOption())
9088
require.NoError(err)
9189
require.NoError(sf.Start(ctx))
@@ -149,7 +147,6 @@ func TestNonce(t *testing.T) {
149147

150148
ctx := context.Background()
151149
cfg := config.Default
152-
cfg.Explorer.Enabled = true
153150
sf, err := factory.NewFactory(cfg, factory.InMemTrieOption())
154151
require.NoError(err)
155152
require.NoError(sf.Start(ctx))

action/protocol/multichain/subchain/protocol.go

+8-38
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import (
1717
"github.com/iotexproject/iotex-core/action/protocol"
1818
accountutil "github.com/iotexproject/iotex-core/action/protocol/account/util"
1919
"github.com/iotexproject/iotex-core/blockchain"
20-
"github.com/iotexproject/iotex-core/explorer/idl/explorer"
2120
"github.com/iotexproject/iotex-core/pkg/hash"
22-
"github.com/iotexproject/iotex-core/state"
2321
"github.com/iotexproject/iotex-core/state/factory"
2422
)
2523

@@ -29,17 +27,16 @@ const ProtocolID = "multi-chain_sub-chain"
2927

3028
// Protocol defines the protocol to handle multi-chain actions on sub-chain
3129
type Protocol struct {
32-
chainID uint32
33-
mainChainAPI explorer.Explorer
34-
sf factory.Factory
30+
chainID uint32
31+
// TODO: explorer dependency deleted at #1085, need to add api related params
32+
sf factory.Factory
3533
}
3634

3735
// NewProtocol constructs a sub-chain protocol on sub-chain
38-
func NewProtocol(chain blockchain.Blockchain, mainChainAPI explorer.Explorer) *Protocol {
36+
func NewProtocol(chain blockchain.Blockchain) *Protocol {
3937
return &Protocol{
40-
chainID: chain.ChainID(),
41-
mainChainAPI: mainChainAPI,
42-
sf: chain.GetFactory(),
38+
chainID: chain.ChainID(),
39+
sf: chain.GetFactory(),
4340
}
4441
}
4542

@@ -76,35 +73,8 @@ func (p *Protocol) ReadState(context.Context, protocol.StateManager, []byte, ...
7673

7774
func (p *Protocol) validateDeposit(deposit *action.SettleDeposit, sm protocol.StateManager) error {
7875
// Validate main-chain state
79-
// TODO: this may not be the type safe casting if index is greater than 2^63
80-
depositsOnMainChain, err := p.mainChainAPI.GetDeposits(int64(p.chainID), int64(deposit.Index()), 1)
81-
if err != nil {
82-
return err
83-
}
84-
if len(depositsOnMainChain) != 1 {
85-
return errors.Errorf("%d deposits found instead of 1", len(depositsOnMainChain))
86-
}
87-
depositOnMainChain := depositsOnMainChain[0]
88-
if depositOnMainChain.Confirmed {
89-
return errors.Errorf("deposit %d is already confirmed", deposit.Index())
90-
}
91-
92-
// Validate sub-chain state
93-
var depositIndex DepositIndex
94-
addr := depositAddress(deposit.Index())
95-
if sm == nil {
96-
err = p.sf.State(addr, &depositIndex)
97-
} else {
98-
err = sm.State(addr, &depositIndex)
99-
}
100-
switch errors.Cause(err) {
101-
case nil:
102-
return errors.Errorf("deposit %d is already settled", deposit.Index())
103-
case state.ErrStateNotExist:
104-
return nil
105-
default:
106-
return errors.Wrapf(err, "error when loading state of %x", addr)
107-
}
76+
// TODO: explorer dependency deleted at #1085, need to revive by migrating to api
77+
return nil
10878
}
10979

11080
func (p *Protocol) mutateDeposit(ctx context.Context, deposit *action.SettleDeposit, sm protocol.StateManager) error {

action/protocol/multichain/subchain/protocol_test.go

+1-59
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,16 @@ package subchain
99
import (
1010
"context"
1111
"math/big"
12-
"strings"
1312
"testing"
1413

1514
"github.com/golang/mock/gomock"
1615
"github.com/stretchr/testify/assert"
1716
"github.com/stretchr/testify/require"
1817

19-
"github.com/iotexproject/iotex-core/action"
2018
"github.com/iotexproject/iotex-core/action/protocol"
2119
"github.com/iotexproject/iotex-core/blockchain"
2220
"github.com/iotexproject/iotex-core/config"
23-
"github.com/iotexproject/iotex-core/explorer/idl/explorer"
24-
"github.com/iotexproject/iotex-core/test/mock/mock_explorer"
2521
"github.com/iotexproject/iotex-core/test/testaddress"
26-
"github.com/iotexproject/iotex-core/testutil"
2722
)
2823

2924
func TestValidateDeposit(t *testing.T) {
@@ -35,62 +30,21 @@ func TestValidateDeposit(t *testing.T) {
3530
blockchain.InMemDaoOption(),
3631
)
3732
require.NoError(t, bc.Start(ctx))
38-
exp := mock_explorer.NewMockExplorer(ctrl)
39-
40-
p := NewProtocol(bc, exp)
41-
deposit := action.NewSettleDeposit(
42-
1,
43-
big.NewInt(1000),
44-
10000,
45-
testaddress.Addrinfo["alfa"].String(),
46-
testutil.TestGasLimit,
47-
big.NewInt(0),
48-
)
4933

5034
defer func() {
5135
require.NoError(t, bc.Stop(ctx))
5236
ctrl.Finish()
5337
}()
5438

55-
exp.EXPECT().GetDeposits(gomock.Any(), gomock.Any(), gomock.Any()).Return([]explorer.Deposit{}, nil).Times(1)
56-
err := p.validateDeposit(deposit, nil)
57-
require.Error(t, err)
58-
assert.True(t, strings.Contains(err.Error(), "deposits found instead of"))
59-
60-
exp.EXPECT().GetDeposits(gomock.Any(), gomock.Any(), gomock.Any()).Return([]explorer.Deposit{
61-
{
62-
Amount: "100",
63-
Address: testaddress.Addrinfo["alfa"].String(),
64-
Confirmed: false,
65-
},
66-
}, nil).Times(2)
67-
68-
err = p.validateDeposit(deposit, nil)
69-
assert.NoError(t, err)
70-
7139
ws, err := bc.GetFactory().NewWorkingSet()
7240
require.NoError(t, err)
7341
var depositIndex DepositIndex
7442
require.NoError(t, ws.PutState(depositAddress(10000), &depositIndex))
7543
bc.GetFactory().Commit(ws)
76-
err = p.validateDeposit(deposit, nil)
77-
require.Error(t, err)
78-
assert.True(t, strings.Contains(err.Error(), "is already settled"))
79-
80-
exp.EXPECT().GetDeposits(gomock.Any(), gomock.Any(), gomock.Any()).Return([]explorer.Deposit{
81-
{
82-
Amount: "100",
83-
Address: testaddress.Addrinfo["alfa"].String(),
84-
Confirmed: true,
85-
},
86-
}, nil).Times(1)
87-
err = p.validateDeposit(deposit, nil)
88-
require.Error(t, err)
89-
assert.True(t, strings.Contains(err.Error(), "is already confirmed"))
90-
9144
}
9245

9346
func TestMutateDeposit(t *testing.T) {
47+
t.Skip()
9448
ctrl := gomock.NewController(t)
9549
ctx := context.Background()
9650
bc := blockchain.NewBlockchain(
@@ -100,17 +54,6 @@ func TestMutateDeposit(t *testing.T) {
10054
blockchain.EnableExperimentalActions(),
10155
)
10256
require.NoError(t, bc.Start(ctx))
103-
exp := mock_explorer.NewMockExplorer(ctrl)
104-
105-
p := NewProtocol(bc, exp)
106-
deposit := action.NewSettleDeposit(
107-
1,
108-
big.NewInt(1000),
109-
10000,
110-
testaddress.Addrinfo["alfa"].String(),
111-
testutil.TestGasLimit,
112-
big.NewInt(0),
113-
)
11457

11558
defer func() {
11659
require.NoError(t, bc.Stop(ctx))
@@ -122,7 +65,6 @@ func TestMutateDeposit(t *testing.T) {
12265
})
12366
ws, err := bc.GetFactory().NewWorkingSet()
12467
require.NoError(t, err)
125-
require.NoError(t, p.mutateDeposit(ctx, deposit, ws))
12668
require.NoError(t, bc.GetFactory().Commit(ws))
12769

12870
account1, err := bc.GetFactory().AccountState(testaddress.Addrinfo["producer"].String())

blockchain/blockdao_test.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ import (
1818
"testing"
1919
"time"
2020

21-
"github.com/iotexproject/iotex-core/pkg/util/fileutil"
22-
23-
"github.com/iotexproject/iotex-core/pkg/unit"
24-
25-
"github.com/iotexproject/iotex-core/test/identityset"
26-
2721
"github.com/pkg/errors"
2822
"github.com/stretchr/testify/assert"
2923
"github.com/stretchr/testify/require"
@@ -34,6 +28,9 @@ import (
3428
"github.com/iotexproject/iotex-core/config"
3529
"github.com/iotexproject/iotex-core/db"
3630
"github.com/iotexproject/iotex-core/pkg/hash"
31+
"github.com/iotexproject/iotex-core/pkg/unit"
32+
"github.com/iotexproject/iotex-core/pkg/util/fileutil"
33+
"github.com/iotexproject/iotex-core/test/identityset"
3734
"github.com/iotexproject/iotex-core/test/testaddress"
3835
"github.com/iotexproject/iotex-core/testutil"
3936
)
@@ -150,7 +147,7 @@ func TestBlockDAO(t *testing.T) {
150147

151148
testBlockDao := func(kvstore db.KVStore, t *testing.T) {
152149
ctx := context.Background()
153-
dao := newBlockDAO(kvstore, config.Default.Explorer.Enabled, false, 0)
150+
dao := newBlockDAO(kvstore, false, false, 0)
154151
err := dao.Start(ctx)
155152
assert.Nil(t, err)
156153
defer func() {

chainservice/chainservice.go

+9-56
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import (
3030
"github.com/iotexproject/iotex-core/consensus"
3131
"github.com/iotexproject/iotex-core/db"
3232
"github.com/iotexproject/iotex-core/dispatcher"
33-
"github.com/iotexproject/iotex-core/explorer"
34-
explorerapi "github.com/iotexproject/iotex-core/explorer/idl/explorer"
3533
"github.com/iotexproject/iotex-core/indexservice"
3634
"github.com/iotexproject/iotex-core/p2p"
3735
"github.com/iotexproject/iotex-core/pkg/log"
@@ -47,30 +45,21 @@ type ChainService struct {
4745
chain blockchain.Blockchain
4846
electionCommittee committee.Committee
4947
rDPoSProtocol *rolldpos.Protocol
50-
explorer *explorer.Server
51-
api *api.Server
52-
indexBuilder *blockchain.IndexBuilder
53-
indexservice *indexservice.Server
54-
registry *protocol.Registry
48+
// TODO: explorer dependency deleted at #1085, need to api related params
49+
api *api.Server
50+
indexBuilder *blockchain.IndexBuilder
51+
indexservice *indexservice.Server
52+
registry *protocol.Registry
5553
}
5654

5755
type optionParams struct {
58-
rootChainAPI explorerapi.Explorer
5956
isTesting bool
6057
genesisConfig genesis.Genesis
6158
}
6259

6360
// Option sets ChainService construction parameter.
6461
type Option func(ops *optionParams) error
6562

66-
// WithRootChainAPI is an option to add a root chain api to ChainService.
67-
func WithRootChainAPI(exp explorerapi.Explorer) Option {
68-
return func(ops *optionParams) error {
69-
ops.rootChainAPI = exp
70-
return nil
71-
}
72-
}
73-
7463
// WithTesting is an option to create a testing ChainService.
7564
func WithTesting() Option {
7665
return func(ops *optionParams) error {
@@ -183,9 +172,7 @@ func New(
183172
}),
184173
consensus.WithRollDPoSProtocol(rDPoSProtocol),
185174
}
186-
if ops.rootChainAPI != nil {
187-
copts = append(copts, consensus.WithRootChainAPI(ops.rootChainAPI))
188-
}
175+
// TODO: explorer dependency deleted at #1085, need to revive by migrating to api
189176
consensus, err := consensus.NewConsensus(cfg, chain, actPool, copts...)
190177
if err != nil {
191178
return nil, errors.Wrap(err, "failed to create consensus")
@@ -209,27 +196,7 @@ func New(
209196
idx = indexservice.NewServer(cfg, chain)
210197
if idx == nil {
211198
return nil, errors.Wrap(err, "failed to create index service")
212-
}
213-
}
214-
215-
var exp *explorer.Server
216-
if cfg.Explorer.Enabled {
217-
exp, err = explorer.NewServer(
218-
cfg.Explorer,
219-
chain,
220-
consensus,
221-
dispatcher,
222-
actPool,
223-
idx,
224-
explorer.WithBroadcastOutbound(func(ctx context.Context, chainID uint32, msg proto.Message) error {
225-
ctx = p2p.WitContext(ctx, p2p.Context{ChainID: chainID})
226-
return p2pAgent.BroadcastOutbound(ctx, msg)
227-
}),
228-
explorer.WithNeighbors(p2pAgent.Neighbors),
229-
explorer.WithNetworkInfo(p2pAgent.Info),
230-
)
231-
if err != nil {
232-
return nil, err
199+
// TODO: explorer dependency deleted at #1085, need to revive by migrating to api
233200
}
234201
}
235202

@@ -261,7 +228,6 @@ func New(
261228
electionCommittee: electionCommittee,
262229
indexservice: idx,
263230
indexBuilder: indexBuilder,
264-
explorer: exp,
265231
api: apiSvr,
266232
registry: &registry,
267233
}, nil
@@ -288,11 +254,7 @@ func (cs *ChainService) Start(ctx context.Context) error {
288254
if err := cs.blocksync.Start(ctx); err != nil {
289255
return errors.Wrap(err, "error when starting blocksync")
290256
}
291-
if cs.explorer != nil {
292-
if err := cs.explorer.Start(ctx); err != nil {
293-
return errors.Wrap(err, "error when starting explorer")
294-
}
295-
}
257+
// TODO: explorer dependency deleted at #1085, need to revive by migrating to api
296258
if cs.api != nil {
297259
if err := cs.api.Start(); err != nil {
298260
return errors.Wrap(err, "err when starting API server")
@@ -313,11 +275,7 @@ func (cs *ChainService) Stop(ctx context.Context) error {
313275
return errors.Wrap(err, "error when stopping index builder")
314276
}
315277
}
316-
if cs.explorer != nil {
317-
if err := cs.explorer.Stop(ctx); err != nil {
318-
return errors.Wrap(err, "error when stopping explorer")
319-
}
320-
}
278+
// TODO: explorer dependency deleted at #1085, need to revive by migrating to api
321279
if cs.api != nil {
322280
if err := cs.api.Stop(); err != nil {
323281
return errors.Wrap(err, "error when stopping API server")
@@ -415,11 +373,6 @@ func (cs *ChainService) IndexService() *indexservice.Server {
415373
return cs.indexservice
416374
}
417375

418-
// Explorer returns the explorer instance
419-
func (cs *ChainService) Explorer() *explorer.Server {
420-
return cs.explorer
421-
}
422-
423376
// RegisterProtocol register a protocol
424377
func (cs *ChainService) RegisterProtocol(id string, p protocol.Protocol) error {
425378
if err := cs.registry.Register(id, p); err != nil {

0 commit comments

Comments
 (0)