Commit 1c8c5a8d authored by mdj33's avatar mdj33 Committed by vipwzw

paracross adapt multi grpc ip

parent f942309a
...@@ -16,16 +16,17 @@ import ( ...@@ -16,16 +16,17 @@ import (
//"github.com/33cn/chain33/common" //"github.com/33cn/chain33/common"
"encoding/hex" "encoding/hex"
"github.com/33cn/chain33/client/api"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto" "github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/merkle" "github.com/33cn/chain33/common/merkle"
"github.com/33cn/chain33/queue" "github.com/33cn/chain33/queue"
"github.com/33cn/chain33/rpc/grpcclient"
drivers "github.com/33cn/chain33/system/consensus" drivers "github.com/33cn/chain33/system/consensus"
cty "github.com/33cn/chain33/system/dapp/coins/types" cty "github.com/33cn/chain33/system/dapp/coins/types"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
paracross "github.com/33cn/plugin/plugin/dapp/paracross/types" paracross "github.com/33cn/plugin/plugin/dapp/paracross/types"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types" pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"google.golang.org/grpc"
) )
const ( const (
...@@ -59,9 +60,9 @@ func init() { ...@@ -59,9 +60,9 @@ func init() {
type client struct { type client struct {
*drivers.BaseClient *drivers.BaseClient
conn *grpc.ClientConn
grpcClient types.Chain33Client grpcClient types.Chain33Client
paraClient paracross.ParacrossClient paraClient paracross.ParacrossClient
execAPI api.ExecutorAPI
isCaughtUp bool isCaughtUp bool
commitMsgClient *commitMsgClient commitMsgClient *commitMsgClient
authAccount string authAccount string
...@@ -122,20 +123,22 @@ func New(cfg *types.Consensus, sub []byte) queue.Module { ...@@ -122,20 +123,22 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
plog.Debug("New Para consensus client") plog.Debug("New Para consensus client")
msgRecvOp := grpc.WithMaxMsgSize(grpcRecSize) //msgRecvOp := grpc.WithMaxMsgSize(grpcRecSize)
conn, err := grpc.Dial(grpcSite, grpc.WithInsecure(), msgRecvOp) //conn, err := grpc.Dial(grpcSite, grpc.WithInsecure(), msgRecvOp)
//if err != nil {
// panic(err)
//}
//_ = types.NewChain33Client(conn)
//grpcClient := types.NewChain33Client(conn)
grpcCli, err := grpcclient.NewMainChainClient(grpcSite)
if err != nil { if err != nil {
panic(err) panic(err)
} }
grpcClient := types.NewChain33Client(conn)
paraCli := paracross.NewParacrossClient(conn)
para := &client{ para := &client{
BaseClient: c, BaseClient: c,
conn: conn, grpcClient: grpcCli,
grpcClient: grpcClient,
paraClient: paraCli,
authAccount: subcfg.AuthAccount, authAccount: subcfg.AuthAccount,
privateKey: priKey, privateKey: priKey,
isCaughtUp: false, isCaughtUp: false,
...@@ -166,7 +169,6 @@ func (client *client) Close() { ...@@ -166,7 +169,6 @@ func (client *client) Close() {
client.BaseClient.Close() client.BaseClient.Close()
close(client.commitMsgClient.quit) close(client.commitMsgClient.quit)
client.wg.Wait() client.wg.Wait()
client.conn.Close()
plog.Info("consensus para closed") plog.Info("consensus para closed")
} }
...@@ -189,6 +191,8 @@ func (client *client) InitBlock() { ...@@ -189,6 +191,8 @@ func (client *client) InitBlock() {
panic(err) panic(err)
} }
client.execAPI = api.New(client.BaseClient.GetAPI(), client.grpcClient)
block, err := client.RequestLastBlock() block, err := client.RequestLastBlock()
if err != nil { if err != nil {
panic(err) panic(err)
......
...@@ -475,14 +475,26 @@ out: ...@@ -475,14 +475,26 @@ out:
isSync = true isSync = true
} }
ret, err := client.paraClient.paraClient.GetTitle(context.Background(), //ret, err := client.paraClient.paraClient.GetTitle(context.Background(),
&types.ReqString{Data: types.GetTitle()}) // &types.ReqString{Data: types.GetTitle()})
var req types.ChainExecutor
req.Driver = "paracross"
req.FuncName = "GetTitle"
req.Param = types.Encode(&types.ReqString{Data: types.GetTitle()})
ret, err := client.paraClient.grpcClient.QueryChain(context.Background(), &req)
if err != nil { if err != nil {
plog.Error("getConsensusHeight ", "err", err.Error()) plog.Error("getConsensusHeight ", "err", err.Error())
continue continue
} }
if !ret.GetIsOk() {
plog.Info("getConsensusHeight", "error", ret.GetMsg())
continue
}
var result pt.ParacrossStatus
types.Decode(ret.Msg, &result)
consensusRst <- ret consensusRst <- &result
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment