Commit 1c94ed9d authored by harrylee's avatar harrylee

ajust for sidecar-client-fabric

parent d359a25a
# Pier Client Fabric # Sidecar Client Fabric
Pier-client-fabric is the plugin implementation for fabric blockchain. Sidecar-client-fabric is the plugin implementation for fabric blockchain.
## How to build ## How to build
...@@ -11,7 +11,7 @@ make fabric1.4 ...@@ -11,7 +11,7 @@ make fabric1.4
``` ```
This will create a `build` directory under the project path and generate a `fabric-client-1.4.so` inside the `build`. This will create a `build` directory under the project path and generate a `fabric-client-1.4.so` inside the `build`.
This `.so` file will be used by [Pier](https://github.com/meshplus/pier). This `.so` file will be used by [Sidecar](https://gitlab.33.cn/link33/sidecar).
## Usage ## Usage
......
...@@ -20,8 +20,8 @@ import ( ...@@ -20,8 +20,8 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/client/ledger" "github.com/hyperledger/fabric-sdk-go/pkg/client/ledger"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab" "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric/common/util" "github.com/hyperledger/fabric/common/util"
"github.com/meshplus/bitxhub-model/pb" "gitlab.33.cn/link33/sidecar/model/pb"
"github.com/meshplus/pier/pkg/plugins" "gitlab.33.cn/link33/sidecar/pkg/plugins"
) )
var ( var (
...@@ -73,7 +73,15 @@ type CallFunc struct { ...@@ -73,7 +73,15 @@ type CallFunc struct {
Func string `json:"func"` Func string `json:"func"`
Args [][]byte `json:"args"` Args [][]byte `json:"args"`
} }
func (c *Client) Kill() {
}
func (c *Client) Exited() bool {
return true
}
func (c *Client) Bind(kern plugins.Kernel) {
}
func (c *Client) Initialize(configPath, appchainID string, extra []byte) error { func (c *Client) Initialize(configPath, appchainID string, extra []byte) error {
eventC := make(chan *pb.IBTP) eventC := make(chan *pb.IBTP)
config, err := UnmarshalConfig(configPath) config, err := UnmarshalConfig(configPath)
...@@ -151,7 +159,7 @@ func (c *Client) polling() { ...@@ -151,7 +159,7 @@ func (c *Client) polling() {
ID: srcChainServiceID, ID: srcChainServiceID,
InterchainCounter: make(map[string]uint64), InterchainCounter: make(map[string]uint64),
ReceiptCounter: make(map[string]uint64), ReceiptCounter: make(map[string]uint64),
SourceInterchainCounter: make(map[string]uint64), //SourceInterchainCounter: make(map[string]uint64),
SourceReceiptCounter: make(map[string]uint64), SourceReceiptCounter: make(map[string]uint64),
} }
c.serviceMeta[srcChainServiceID] = meta c.serviceMeta[srcChainServiceID] = meta
...@@ -232,6 +240,23 @@ func (c *Client) Name() string { ...@@ -232,6 +240,23 @@ func (c *Client) Name() string {
func (c *Client) Type() string { func (c *Client) Type() string {
return FabricType return FabricType
} }
//TODO ID等同于链ID
func (c *Client) ID() string {
request := channel.Request{
ChaincodeID: c.meta.CCID,
Fcn: GetChainId,
}
response, err := c.consumer.ChannelClient.Execute(request)
if err != nil || response.Payload == nil {
return ""
}
chainIds := strings.Split(string(response.Payload), "-")
if len(chainIds) != 2 {
return ""
}
return fmt.Sprintf("%s:%s", chainIds[0], chainIds[1])
}
func (c *Client) GetIBTP() chan *pb.IBTP { func (c *Client) GetIBTP() chan *pb.IBTP {
return c.eventC return c.eventC
...@@ -269,7 +294,7 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -269,7 +294,7 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
if ibtp.Category() == pb.IBTP_RESPONSE && content.Func == "" || ibtp.Type == pb.IBTP_ROLLBACK { if ibtp.Category() == pb.IBTP_RESPONSE && content.Func == "" || ibtp.Type == pb.IBTP_ROLLBACK {
logger.Info("InvokeIndexUpdate", "ibtp", ibtp.ID()) logger.Info("InvokeIndexUpdate", "ibtp", ibtp.ID())
_, resp, err := c.InvokeIndexUpdate(srcChainServiceID, ibtp.Index, serviceID, ibtp.Category()) _, resp, err := c.InvokeIndexUpdate(srcChainServiceID, ibtp.Nonce, serviceID, ibtp.Category())
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -296,13 +321,13 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -296,13 +321,13 @@ func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
ret.Status = false ret.Status = false
ret.Message = fmt.Sprintf("marshal ibtp %s func %s and args: %s", ibtp.ID(), callFunc.Func, err.Error()) ret.Message = fmt.Sprintf("marshal ibtp %s func %s and args: %s", ibtp.ID(), callFunc.Func, err.Error())
res, _, err := c.InvokeIndexUpdate(srcChainServiceID, ibtp.Index, serviceID, ibtp.Category()) res, _, err := c.InvokeIndexUpdate(srcChainServiceID, ibtp.Nonce, serviceID, ibtp.Category())
if err != nil { if err != nil {
return nil, err return nil, err
} }
chResp = res chResp = res
} else { } else {
res, resp, err := c.InvokeInterchain(srcChainServiceID, ibtp.Index, serviceID, uint64(ibtp.Category()), bizData) res, resp, err := c.InvokeInterchain(srcChainServiceID, ibtp.Nonce, serviceID, uint64(ibtp.Category()), bizData)
if err != nil { if err != nil {
return nil, fmt.Errorf("invoke interchain for ibtp %s to call %s: %w", ibtp.ID(), content.Func, err) return nil, fmt.Errorf("invoke interchain for ibtp %s to call %s: %w", ibtp.ID(), content.Func, err)
} }
...@@ -525,7 +550,7 @@ func (c *Client) RollbackIBTP(ibtp *pb.IBTP, isSrcChain bool) (*pb.RollbackIBTPR ...@@ -525,7 +550,7 @@ func (c *Client) RollbackIBTP(ibtp *pb.IBTP, isSrcChain bool) (*pb.RollbackIBTPR
} }
// pb.IBTP_RESPONSE indicates it is to update callback counter // pb.IBTP_RESPONSE indicates it is to update callback counter
_, resp, err := c.InvokeInterchain(srcChainServiceID, ibtp.Index, serviceID, reqType, bizData) _, resp, err := c.InvokeInterchain(srcChainServiceID, ibtp.Nonce, serviceID, reqType, bizData)
if err != nil { if err != nil {
return nil, fmt.Errorf("invoke interchain for ibtp %s to call %s: %w", ibtp.ID(), content.Rollback, err) return nil, fmt.Errorf("invoke interchain for ibtp %s to call %s: %w", ibtp.ID(), content.Rollback, err)
} }
...@@ -545,7 +570,7 @@ func (c *Client) IncreaseInMeta(original *pb.IBTP) (*pb.IBTP, error) { ...@@ -545,7 +570,7 @@ func (c *Client) IncreaseInMeta(original *pb.IBTP) (*pb.IBTP, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
_, _, err = c.InvokeIndexUpdate(original.From, original.Index, serviceID, original.Category()) _, _, err = c.InvokeIndexUpdate(original.From, original.Nonce, serviceID, original.Category())
if err != nil { if err != nil {
logger.Error("update in meta", "ibtp_id", original.ID(), "error", err.Error()) logger.Error("update in meta", "ibtp_id", original.ID(), "error", err.Error())
} }
...@@ -553,7 +578,8 @@ func (c *Client) IncreaseInMeta(original *pb.IBTP) (*pb.IBTP, error) { ...@@ -553,7 +578,8 @@ func (c *Client) IncreaseInMeta(original *pb.IBTP) (*pb.IBTP, error) {
} }
func (c *Client) GetReceipt(ibtp *pb.IBTP) (*pb.IBTP, error) { func (c *Client) GetReceipt(ibtp *pb.IBTP) (*pb.IBTP, error) {
result, err := c.GetInMessage(ibtp.ServicePair(), ibtp.Index) //TODO 这里有问题Pair := fmt.Sprintf("%s-%s-%d", m.From, m.To, m.Nonce)
result, err := c.GetInMessage(genServicePair(ibtp.From,ibtp.To), ibtp.Nonce)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"strings" "strings"
"github.com/cloudflare/cfssl/log" "github.com/cloudflare/cfssl/log"
"github.com/meshplus/bitxhub-model/pb" "gitlab.33.cn/link33/sidecar/model/pb"
) )
type Event struct { type Event struct {
...@@ -27,9 +27,10 @@ func (ev *Event) Convert2IBTP(timeoutHeight int64, ibtpType pb.IBTP_Type) *pb.IB ...@@ -27,9 +27,10 @@ func (ev *Event) Convert2IBTP(timeoutHeight int64, ibtpType pb.IBTP_Type) *pb.IB
return &pb.IBTP{ return &pb.IBTP{
From: ev.SrcFullID, From: ev.SrcFullID,
To: ev.DstFullID, To: ev.DstFullID,
Index: ev.Index, Nonce: ev.Index,
Type: ibtpType, Type: ibtpType,
TimeoutHeight: timeoutHeight, //FIXME 这个版本暂时没有设置超时时间
//TimeoutHeight: timeoutHeight,
Payload: pd, Payload: pd,
} }
} }
......
...@@ -6,6 +6,7 @@ require ( ...@@ -6,6 +6,7 @@ require (
github.com/Knetic/govaluate v3.0.0+incompatible // indirect github.com/Knetic/govaluate v3.0.0+incompatible // indirect
github.com/Shopify/sarama v1.29.1 // indirect github.com/Shopify/sarama v1.29.1 // indirect
github.com/fsouza/go-dockerclient v1.7.3 // indirect github.com/fsouza/go-dockerclient v1.7.3 // indirect
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/hashicorp/go-version v1.3.0 // indirect github.com/hashicorp/go-version v1.3.0 // indirect
github.com/hyperledger/fabric v1.4.3 github.com/hyperledger/fabric v1.4.3
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
module github.com/meshplus/pier-client-fabric module gitlab.33.cn/link33/sidecar-client-fabric
go 1.13 go 1.13
require ( require (
github.com/Knetic/govaluate v3.0.0+incompatible // indirect
github.com/Rican7/retry v0.1.0 github.com/Rican7/retry v0.1.0
github.com/VividCortex/gohistogram v1.0.0 // indirect github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/golang/protobuf v1.5.2 github.com/golang/protobuf v1.5.2
github.com/google/certificate-transparency-go v1.1.0 // indirect github.com/google/certificate-transparency-go v1.1.0 // indirect
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
...@@ -17,9 +15,8 @@ require ( ...@@ -17,9 +15,8 @@ require (
github.com/hyperledger/fabric-lib-go v1.0.0 // indirect github.com/hyperledger/fabric-lib-go v1.0.0 // indirect
github.com/hyperledger/fabric-protos-go v0.0.0-20201028172056-a3136dde2354 github.com/hyperledger/fabric-protos-go v0.0.0-20201028172056-a3136dde2354
github.com/hyperledger/fabric-sdk-go v1.0.0-alpha5 github.com/hyperledger/fabric-sdk-go v1.0.0-alpha5
github.com/meshplus/bitxhub-model v1.2.1-0.20210805064451-03258148acad
github.com/meshplus/pier v1.11.1-0.20210809064238-de527e06d443
github.com/spf13/viper v1.7.0 github.com/spf13/viper v1.7.0
gitlab.33.cn/link33/sidecar v0.0.0-20211028080238-67f4248825bb
) )
replace ( replace (
...@@ -27,4 +24,5 @@ replace ( ...@@ -27,4 +24,5 @@ replace (
github.com/golang/protobuf => github.com/golang/protobuf v1.3.2 github.com/golang/protobuf => github.com/golang/protobuf v1.3.2
github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.3 github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.3
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884 google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884
google.golang.org/grpc => google.golang.org/grpc v1.26.0
) )
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,7 +3,7 @@ package main ...@@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/meshplus/bitxhub-model/pb" "gitlab.33.cn/link33/sidecar/model/pb"
) )
func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool) (result *pb.IBTP, err error) { func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool) (result *pb.IBTP, err error) {
...@@ -52,7 +52,7 @@ func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool) ...@@ -52,7 +52,7 @@ func (c *Client) generateCallback(original *pb.IBTP, args [][]byte, status bool)
return &pb.IBTP{ return &pb.IBTP{
From: original.From, From: original.From,
To: original.To, To: original.To,
Index: original.Index, Nonce: original.Nonce,
Type: typ, Type: typ,
Proof: original.Proof, Proof: original.Proof,
Payload: pdb, Payload: pdb,
......
...@@ -10,17 +10,17 @@ linux-amd64) ...@@ -10,17 +10,17 @@ linux-amd64)
print_blue "Compile for linux/amd64" print_blue "Compile for linux/amd64"
# docker pull golang:1.13 # docker pull golang:1.13
docker run -t \ docker run -t \
-v $2/../pier:/code/pier \ -v $2/../sidecar:/code/sidecar \
-v $2:/code/pier-client-fabric \ -v $2:/code/sidecar-client-fabric \
-v ~/.ssh:/root/.ssh \ -v ~/.ssh:/root/.ssh \
-v ~/.gitconfig:/root/.gitconfig \ -v ~/.gitconfig:/root/.gitconfig \
-v $GOPATH/pkg/mod:$GOPATH/pkg/mod \ -v $GOPATH/pkg/mod:$GOPATH/pkg/mod \
pier-ubuntu/compile \ pier-ubuntu/compile \
/bin/bash -c "go env -w GO111MODULE=on && /bin/bash -c "go env -w GO111MODULE=on &&
go env -w GOPROXY=https://goproxy.cn,direct && go env -w GOPROXY=https://goproxy.cn,direct &&
cd /code/pier-client-fabric && cd /code/sidecar-client-fabric &&
make fabric1.4 && make fabric1.4 &&
mv /code/pier-client-fabric/build/fabric-client-1.4.so /code/pier-client-fabric/build/fabric-client-1.4-linux.so" mv /code/sidecar-client-fabric/build/fabric-client-1.4.so /code/sidecar-client-fabric/build/fabric-client-1.4-linux.so"
;; ;;
*) *)
print_red "Other architectures are not supported yet" print_red "Other architectures are not supported yet"
......
...@@ -3,6 +3,6 @@ set -e ...@@ -3,6 +3,6 @@ set -e
APPCHAIN_NAME=$1 APPCHAIN_NAME=$1
pier --repo=/root/.pier appchain register --name=${APPCHAIN_NAME} --type=fabric --validators=/root/.pier/fabric/fabric.validators --desc="appchain for test" --version=1.4.3 sidecar --repo=/root/.sidecar appchain register --name=${APPCHAIN_NAME} --type=fabric --validators=/root/.sidecar/fabric/fabric.validators --desc="appchain for test" --version=1.4.3
pier --repo=/root/.pier rule deploy --path=/root/.pier/validating.wasm sidecar --repo=/root/.sidecar rule deploy --path=/root/.sidecar/validating.wasm
pier --repo=/root/.pier start sidecar --repo=/root/.sidecar start
\ No newline at end of file \ No newline at end of file
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