Unverified Commit 4e3c0b70 authored by jiuhuche120's avatar jiuhuche120 Committed by GitHub

Merge pull request #35 from meshplus/fix/rollback-index

fix(*): rollback ibtp index when ibtp failed on bitxhub
parents 0d6dfd49 d5bbc931
......@@ -455,6 +455,56 @@ func (c *Client) CommitCallback(ibtp *pb.IBTP) error {
return nil
}
// @ibtp is the original ibtp merged from this appchain
func (c *Client) RollbackIBTP(ibtp *pb.IBTP, isSrcChain bool) (*pb.RollbackIBTPResponse, error) {
ret := &pb.RollbackIBTPResponse{}
pd := &pb.Payload{}
if err := pd.Unmarshal(ibtp.Payload); err != nil {
return nil, fmt.Errorf("ibtp payload unmarshal: %w", err)
}
content := &pb.Content{}
if err := content.Unmarshal(pd.Content); err != nil {
return ret, fmt.Errorf("ibtp content unmarshal: %w", err)
}
// only support rollback for interchainCharge
if content.Func != "interchainCharge" {
return nil, nil
}
callFunc := CallFunc{
Func: content.Rollback,
Args: content.ArgsRb,
}
bizData, err := json.Marshal(callFunc)
if err != nil {
return ret, err
}
// pb.IBTP_RESPONSE indicates it is to update callback counter
_, resp, err := c.InvokeInterchain(ibtp.To, ibtp.Index, content.SrcContractId, pb.IBTP_RESPONSE, bizData)
if err != nil {
return nil, fmt.Errorf("invoke interchain for ibtp %s to call %s: %w", ibtp.ID(), content.Rollback, err)
}
ret.Status = resp.OK
ret.Message = resp.Message
return ret, nil
}
func (c *Client) IncreaseInMeta(original *pb.IBTP) (*pb.IBTP, error) {
ibtp, err := c.generateCallback(original, nil, nil, false)
if err != nil {
return nil, err
}
_, _, err = c.InvokeIndexUpdate(original.From, original.Index, original.Category())
if err != nil {
logger.Error("update in meta", "ibtp_id", original.ID(), "error", err.Error())
}
return ibtp, nil
}
func (c *Client) GetReceipt(ibtp *pb.IBTP) (*pb.IBTP, error) {
result, err := c.GetInMessage(ibtp.From, ibtp.Index)
if err != nil {
......
......@@ -6,25 +6,22 @@ require (
github.com/OneOfOne/xxhash v1.2.5 // indirect
github.com/Rican7/retry v0.1.0
github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/meshplus/bitxid v0.0.0-20210331074321-62187b1145f5
github.com/cloudflare/cfssl v0.0.0-20190409034051-768cd563887f
github.com/elastic/gosigar v0.8.1-0.20180330100440-37f05ff46ffa // indirect
github.com/ethereum/go-ethereum v1.9.18 // indirect
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/golang/protobuf v1.4.0
github.com/golang/protobuf v1.4.3
github.com/google/certificate-transparency-go v1.1.0 // indirect
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
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 v1.0.0-rc2 // indirect
github.com/meshplus/bitxhub-kit v1.1.2-0.20201203072410-8a0383a6870d
github.com/meshplus/bitxhub-model v1.1.2-0.20210312014622-c3ad532b64ad
github.com/meshplus/pier v1.5.1-0.20210312103925-148435c71325
github.com/sirupsen/logrus v1.6.0
github.com/spf13/viper v1.6.1
github.com/meshplus/bitxhub-model v1.2.1-0.20210524073042-f243c2fee25b
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a
github.com/meshplus/pier v1.7.1-0.20210524093640-1337e0a53318
github.com/spf13/viper v1.7.0
sigs.k8s.io/yaml v1.2.0 // indirect
)
......@@ -32,4 +29,6 @@ replace (
github.com/go-kit/kit => github.com/go-kit/kit v0.8.0
github.com/golang/protobuf => github.com/golang/protobuf v1.3.2
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/protobuf => google.golang.org/protobuf v1.21.0
)
This source diff could not be displayed because it is too large. You can view the blob instead.
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