Unverified Commit 8f564747 authored by Alexader's avatar Alexader Committed by GitHub

Merge pull request #17 from meshplus/feat/replace-go-plugin

feat(client): replace native go plugin mechanism with grpc plugin
parents f245bb5b b67da12b
......@@ -18,7 +18,7 @@ test-coverage:
## make fabric1.4: build fabric(1.4) client plugin
fabric1.4:
mkdir -p build
$(GO) build --buildmode=plugin -o build/fabric-client-1.4.so ./*.go
$(GO) build -o build/fabric-client-1.4 ./*.go
docker:
mkdir -p build
......@@ -31,4 +31,4 @@ fabric1.4-linux:
## make linter: Run golanci-lint
linter:
golangci-lint run
golangci-lint run
\ No newline at end of file
......@@ -10,6 +10,7 @@ import (
"github.com/Rican7/retry"
"github.com/Rican7/retry/strategy"
"github.com/golang/protobuf/proto"
"github.com/hashicorp/go-plugin"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
......@@ -19,14 +20,13 @@ import (
"github.com/hyperledger/fabric/common/util"
"github.com/meshplus/bitxhub-kit/log"
"github.com/meshplus/bitxhub-model/pb"
"github.com/meshplus/pier/pkg/model"
"github.com/meshplus/pier/pkg/plugins/client"
"github.com/meshplus/pier/pkg/plugins"
"github.com/sirupsen/logrus"
)
var logger = log.NewWithModule("client")
var _ client.Client = (*Client)(nil)
var _ plugins.Client = (*Client)(nil)
const (
GetInnerMetaMethod = "getInnerMeta" // get last index of each source chain executing tx
......@@ -57,14 +57,14 @@ type Client struct {
done chan bool
}
func NewClient(configPath, pierId string, extra []byte) (client.Client, error) {
func (c *Client) Initialize(configPath, pierId string, extra []byte) error {
eventC := make(chan *pb.IBTP)
fabricConfig, err := UnmarshalConfig(configPath)
if err != nil {
return nil, fmt.Errorf("unmarshal config for plugin :%w", err)
return fmt.Errorf("unmarshal config for plugin :%w", err)
}
c := &ContractMeta{
contractmeta := &ContractMeta{
EventFilter: fabricConfig.EventFilter,
Username: fabricConfig.Username,
CCID: fabricConfig.CCID,
......@@ -74,33 +74,33 @@ func NewClient(configPath, pierId string, extra []byte) (client.Client, error) {
m := make(map[string]uint64)
if err := json.Unmarshal(extra, &m); err != nil {
return nil, fmt.Errorf("unmarshal extra for plugin :%w", err)
return fmt.Errorf("unmarshal extra for plugin :%w", err)
}
if m == nil {
m = make(map[string]uint64)
}
mgh, err := newFabricHandler(c.EventFilter, eventC, pierId)
mgh, err := newFabricHandler(contractmeta.EventFilter, eventC, pierId)
if err != nil {
return nil, err
return err
}
done := make(chan bool)
csm, err := NewConsumer(configPath, c, mgh, done)
csm, err := NewConsumer(configPath, contractmeta, mgh, done)
if err != nil {
return nil, err
return err
}
return &Client{
consumer: csm,
eventC: eventC,
meta: c,
pierId: pierId,
name: fabricConfig.Name,
outMeta: m,
ticker: time.NewTicker(2 * time.Second),
done: done,
}, nil
c.consumer = csm
c.eventC = eventC
c.meta = contractmeta
c.pierId = pierId
c.name = fabricConfig.Name
c.outMeta = m
c.ticker = time.NewTicker(2 * time.Second)
c.done = done
return nil
}
func (c *Client) Start() error {
......@@ -225,9 +225,9 @@ func (c *Client) GetIBTP() chan *pb.IBTP {
return c.eventC
}
func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*model.PluginResponse, error) {
func (c *Client) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
pd := &pb.Payload{}
ret := &model.PluginResponse{}
ret := &pb.SubmitIBTPResponse{}
if err := pd.Unmarshal(ibtp.Payload); err != nil {
return ret, fmt.Errorf("ibtp payload unmarshal: %w", err)
}
......@@ -431,3 +431,15 @@ func (h *handler) HandleMessage(deliveries *fab.CCEvent, payload []byte) {
h.eventC <- e
}
}
func main() {
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: plugins.Handshake,
Plugins: map[string]plugin.Plugin{
plugins.PluginName: &plugins.AppchainGRPCPlugin{Impl: &Client{}},
},
GRPCServer: plugin.DefaultGRPCServer,
})
logger.Println("Plugin server down")
}
......@@ -29,5 +29,5 @@ peers = [
]
[appchain]
plugin = "fabric-client-1.4.so"
plugin = "fabric-client-1.4"
config = "fabric"
......@@ -7,40 +7,18 @@ require (
github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004
github.com/golang/protobuf v1.4.0
github.com/golangci/golangci-lint v1.23.0 // indirect
github.com/google/certificate-transparency-go v1.1.0 // indirect
github.com/hashicorp/go-plugin v1.3.0
github.com/hyperledger/fabric v2.0.1+incompatible
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
github.com/hyperledger/fabric-lib-go v1.0.0 // indirect
github.com/hyperledger/fabric-protos-go v0.0.0-20200330074707-cfe579e86986
github.com/hyperledger/fabric-sdk-go v1.0.0-alpha5
github.com/meshplus/bitxhub-kit v1.0.1-0.20200525112026-df2160653e23
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200608065824-2fbc63639e92
github.com/meshplus/pier v0.0.0-00010101000000-000000000000
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200707045101-18b88b80efb1
github.com/meshplus/pier v1.0.0-rc1.0.20200717044435-de24cfbef0f3
github.com/sirupsen/logrus v1.5.0
github.com/spf13/viper v1.6.1
)
replace github.com/golang/protobuf => github.com/golang/protobuf v1.3.2
replace google.golang.org/grpc => google.golang.org/grpc v1.27.1
replace gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.2.7
replace golang.org/x/net => golang.org/x/net v0.0.0-20200202094626-16171245cfb2
replace github.com/meshplus/pier => ../pier
replace golang.org/x/text => golang.org/x/text v0.3.0
replace golang.org/x/sys => golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f
replace github.com/spf13/afero => github.com/spf13/afero v1.1.2
replace github.com/spf13/pflag => github.com/spf13/pflag v1.0.5
replace github.com/pelletier/go-toml => github.com/pelletier/go-toml v1.2.0
replace github.com/spf13/jwalterweatherman => github.com/spf13/jwalterweatherman v1.0.0
replace github.com/mholt/archiver => github.com/mholt/archiver v0.0.0-20180417220235-e4ef56d48eb0
This diff is collapsed.
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