Skip to content

Commit

Permalink
feat: add pool for bxh adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
roxie-23 committed Jan 13, 2023
1 parent 266d25e commit c866f17
Show file tree
Hide file tree
Showing 27 changed files with 747 additions and 460 deletions.
1 change: 1 addition & 0 deletions config/pier.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ title = "Pier"
quorum = 2
bitxhub_id = "1356"
enable_offchain_transmission = false
grpc_pool_size = 16
save_path = ""
[mode.direct]
gas_limit = 0x5f5e100
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/fatih/color v1.9.0
github.com/fsnotify/fsnotify v1.4.9
github.com/gobuffalo/packd v1.0.1
github.com/gobuffalo/packr v1.30.1
github.com/gobuffalo/packr/v2 v2.8.3
github.com/golang/mock v1.6.0
github.com/google/btree v1.0.0
Expand All @@ -21,11 +20,12 @@ require (
github.com/libp2p/go-libp2p-core v0.6.1
github.com/meshplus/bitxhub-core v1.3.1-0.20221216095518-2b59e2647227
github.com/meshplus/bitxhub-kit v1.2.1-0.20220412092457-5836414df781
github.com/meshplus/bitxhub-model v1.2.1-0.20230103095329-f8638b97544e
github.com/meshplus/go-bitxhub-client v1.4.1-0.20220412093230-11ca79f069fc
github.com/meshplus/bitxhub-model v1.20.2-0.20230113083618-3407ac676767
github.com/meshplus/go-bitxhub-client v1.4.1-0.20221118022536-c821301838c8
github.com/meshplus/go-lightp2p v0.0.0-20221205091217-47f605aa3067
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.3.0
github.com/otiai10/copy v1.9.0
github.com/pelletier/go-toml v1.9.3
github.com/sirupsen/logrus v1.8.1
github.com/spf13/viper v1.8.1
Expand Down
104 changes: 77 additions & 27 deletions go.sum

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions internal/adapt/appchain_adapter/Ibtp_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,32 @@ func (a *AppchainAdapter) listenIBTPBatch() {
"Froms": req.Froms,
"indexs": req.Indexs,
"serviceIDs": req.ServiceIDs,
"batchSize": len(req.Froms),
"ibtpTypes": req.IbtpTypes,
"Contents": req.Contents,
"proofs": req.Proofs,
"isEncrypt": req.IsEncrypted,
"batchSize": len(req.Froms),
}).Info("start submit ibtpBatch")

now := time.Now()
response, err := a.client.SubmitIBTPBatch(
_, err = a.client.SubmitIBTPBatch(
req.Froms, req.Indexs, req.ServiceIDs, req.IbtpTypes, req.Contents, req.Proofs, req.IsEncrypted)
if err != nil {
a.logger.WithFields(logrus.Fields{"Froms": req.Froms, "indexs": req.Indexs,
"serviceIDs": req.ServiceIDs, "proofs": req.Proofs, "err": err}).Errorf("SubmitIBTPBatch err")
continue
}

if !response.Status {
a.logger.Errorf("fail to send ibtp: %s",
response.Message)
}
//if !response.Status {
// a.logger.Errorf("fail to send ibtp: %s",
// response.Message)
//}

a.logger.WithFields(logrus.Fields{
"time": time.Since(now),
"batchSize": len(req.Froms),
"indexs": req.Indexs,
"ibtpTypes": req.IbtpTypes,
"time": time.Since(now),
}).Info("appchain adapter submit ibtp batch success")

// release instance after clean it
Expand Down
16 changes: 9 additions & 7 deletions internal/adapt/appchain_adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (a *AppchainAdapter) Stop() error {
func (a *AppchainAdapter) ID() string {
return fmt.Sprintf("%s", a.appchainID)
}

func (a *AppchainAdapter) Name() string {
return fmt.Sprintf("appchain:%s", a.appchainID)
}
Expand Down Expand Up @@ -231,16 +232,13 @@ func (a *AppchainAdapter) SendIBTP(ibtp *pb.IBTP) error {
// solidity broker cannot get detailed error info
return &adapt.SendIbtpError{
Err: fmt.Sprintf("fail to send ibtp %s with type %v: %v", ibtp.ID(), ibtp.Type, err),
Status: adapt.Other_Error,
Status: adapt.OtherError,
}
}

var genFailReceipt bool
if !res.Status {
err := &adapt.SendIbtpError{Err: fmt.Sprintf("fail to send ibtp %s with type %v: %s", ibtp.ID(), ibtp.Type, res.Message)}
if strings.Contains(res.Message, "invalid multi-signature") {
err.Status = adapt.Proof_Invalid
}
if a.config.Mode.Type == repo.DirectMode &&
(strings.Contains(res.Message, DirectSrcRegisterErr) ||
strings.Contains(res.Message, DirectDestAuditErr)) {
Expand All @@ -249,9 +247,9 @@ func (a *AppchainAdapter) SendIBTP(ibtp *pb.IBTP) error {
if genFailReceipt {
ibtp.Type = pb.IBTP_RECEIPT_FAILURE
a.ibtpC <- ibtp
err.Status = adapt.Other_Error
err.Status = adapt.OtherError
} else {
err.Status = adapt.Other_Error
err.Status = adapt.OtherError
}
return err
}
Expand Down Expand Up @@ -411,10 +409,14 @@ func (a *AppchainAdapter) MonitorUpdatedMeta() chan *[]byte {
return nil
}

func (a *AppchainAdapter) SendUpdatedMeta(byte []byte) error {
func (a *AppchainAdapter) SendUpdatedMeta(_ []byte) error {
return nil
}

func (a *AppchainAdapter) InitIbtpPool(_, _ string, _ pb.IBTP_Category, _ uint64) {
return
}

func (a *AppchainAdapter) handlePayload(ibtp *pb.IBTP, encrypt bool) (*pb.IBTP, *pb.Payload, error) {
pd := pb.Payload{}
if err := pd.Unmarshal(ibtp.Payload); err != nil {
Expand Down
Loading

0 comments on commit c866f17

Please sign in to comment.