Commit 81e2537e authored by suyanlong's avatar suyanlong

Fixed bug

parent 3f382b79
Pipeline #8630 failed with stages
...@@ -2,6 +2,7 @@ package appchain ...@@ -2,6 +2,7 @@ package appchain
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
...@@ -115,17 +116,19 @@ func (a *appChain) applyInterchainIBTP(ibtp *pb.IBTP) (*pb.IBTP, error) { ...@@ -115,17 +116,19 @@ func (a *appChain) applyInterchainIBTP(ibtp *pb.IBTP) (*pb.IBTP, error) {
// execute interchain tx, and if execution failed, try to rollback // execute interchain tx, and if execution failed, try to rollback
response, err := a.client.SubmitIBTP(ibtp) response, err := a.client.SubmitIBTP(ibtp)
if err != nil { if err != nil {
entry.WithField("error", err).Panic("Submit ibtp") //entry.WithField("error", err).Panic("Submit ibtp")
entry.WithField("error", err)
return nil, err
} }
if response == nil || response.Result == nil { if response == nil || response.Result == nil {
entry.WithField("error", err).Panic("empty response") err := errors.New("empty response")
} entry.WithField("error", err)
return nil, err
} else {
if !response.Status { if !response.Status {
pd := &pb.Payload{} pd := &pb.Payload{}
if err := pd.Unmarshal(response.Result.Payload); err != nil { if err := pd.Unmarshal(response.Result.Payload); err != nil {
entry.Panic("Unmarshal payload") entry.WithField("error", "Unmarshal payload")
} }
entry.WithFields(logrus.Fields{ entry.WithFields(logrus.Fields{
...@@ -133,8 +136,8 @@ func (a *appChain) applyInterchainIBTP(ibtp *pb.IBTP) (*pb.IBTP, error) { ...@@ -133,8 +136,8 @@ func (a *appChain) applyInterchainIBTP(ibtp *pb.IBTP) (*pb.IBTP, error) {
"payload": pd, "payload": pd,
}).Warn("Get wrong response, need rollback on source chain") }).Warn("Get wrong response, need rollback on source chain")
} }
return response.Result, nil return response.Result, nil
}
} }
func (a *appChain) applyReceiptIBTP(ibtp *pb.IBTP) error { func (a *appChain) applyReceiptIBTP(ibtp *pb.IBTP) error {
...@@ -165,7 +168,7 @@ func (a *appChain) applyReceiptIBTP(ibtp *pb.IBTP) error { ...@@ -165,7 +168,7 @@ func (a *appChain) applyReceiptIBTP(ibtp *pb.IBTP) error {
return fmt.Errorf("execute callback tx: %w", err) return fmt.Errorf("execute callback tx: %w", err)
} }
return nil return nil
}, strategy.Wait(1*time.Second)); err != nil { }, strategy.Limit(3), strategy.Wait(1*time.Second)); err != nil {
a.logger.Errorf("Execution of callback function failed: %s", err.Error()) a.logger.Errorf("Execution of callback function failed: %s", err.Error())
} }
return nil return nil
...@@ -200,7 +203,7 @@ func (a *appChain) Rollback(ibtp *pb.IBTP, isSrcChain bool) { ...@@ -200,7 +203,7 @@ func (a *appChain) Rollback(ibtp *pb.IBTP, isSrcChain bool) {
return fmt.Errorf("execute callback tx: %w", err) return fmt.Errorf("execute callback tx: %w", err)
} }
return nil return nil
}, strategy.Wait(1*time.Second)); err != nil { }, strategy.Limit(3), strategy.Wait(1*time.Second)); err != nil {
a.logger.Errorf("Execution of callback function failed: %s", err.Error()) a.logger.Errorf("Execution of callback function failed: %s", err.Error())
} }
} }
...@@ -287,7 +290,7 @@ func (a *appChain) QueryIBTP(to string, id string) (*pb.IBTP, error) { ...@@ -287,7 +290,7 @@ func (a *appChain) QueryIBTP(to string, id string) (*pb.IBTP, error) {
} }
c <- e c <- e
return nil return nil
}, strategy.Wait(2*time.Second)); err != nil { }, strategy.Limit(3), strategy.Wait(2*time.Second)); err != nil {
panic(err) panic(err)
} }
...@@ -314,7 +317,7 @@ func (a *appChain) QueryOuterMeta() map[string]uint64 { ...@@ -314,7 +317,7 @@ func (a *appChain) QueryOuterMeta() map[string]uint64 {
return err return err
} }
return nil return nil
}, strategy.Wait(2*time.Second)); err != nil { }, strategy.Limit(3), strategy.Wait(2*time.Second)); err != nil {
panic(err) panic(err)
} }
......
...@@ -73,7 +73,7 @@ func (lite *HubLite) syncBlock() { ...@@ -73,7 +73,7 @@ func (lite *HubLite) syncBlock() {
} }
return nil return nil
}, strategy.Wait(1*time.Second)) }, strategy.Limit(3), strategy.Wait(1*time.Second))
if err != nil { if err != nil {
lite.logger.Panic(err) lite.logger.Panic(err)
} }
...@@ -91,7 +91,7 @@ func (lite *HubLite) getHeaderChannel() chan *pb.BlockHeader { ...@@ -91,7 +91,7 @@ func (lite *HubLite) getHeaderChannel() chan *pb.BlockHeader {
} }
return nil return nil
}, strategy.Wait(2*time.Second)); err != nil { }, strategy.Limit(3), strategy.Wait(2*time.Second)); err != nil {
panic(err) panic(err)
} }
......
...@@ -5,10 +5,11 @@ package pb ...@@ -5,10 +5,11 @@ package pb
import ( import (
fmt "fmt" fmt "fmt"
proto "github.com/gogo/protobuf/proto"
io "io" io "io"
math "math" math "math"
math_bits "math/bits" math_bits "math/bits"
proto "github.com/gogo/protobuf/proto"
) )
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
......
...@@ -43,7 +43,6 @@ func (m *IBTP) Category() IBTP_Category { ...@@ -43,7 +43,6 @@ func (m *IBTP) Category() IBTP_Category {
return IBTP_UNKNOWN return IBTP_UNKNOWN
} }
func (m *IBTP) ServicePair() string { func (m *IBTP) ServicePair() string {
return fmt.Sprintf("%s-%s", m.From, m.To) return fmt.Sprintf("%s-%s", m.From, m.To)
} }
...@@ -102,8 +101,3 @@ func ParseIBTPID(id string) (string, string, uint64, error) { ...@@ -102,8 +101,3 @@ func ParseIBTPID(id string) (string, string, uint64, error) {
func GenServicePair(from, to string) string { func GenServicePair(from, to string) string {
return fmt.Sprintf("%s-%s", from, to) return fmt.Sprintf("%s-%s", from, to)
} }
...@@ -5,10 +5,11 @@ package pb ...@@ -5,10 +5,11 @@ package pb
import ( import (
fmt "fmt" fmt "fmt"
proto "github.com/gogo/protobuf/proto"
io "io" io "io"
math "math" math "math"
math_bits "math/bits" math_bits "math/bits"
proto "github.com/gogo/protobuf/proto"
) )
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
......
...@@ -5,10 +5,11 @@ package pb ...@@ -5,10 +5,11 @@ package pb
import ( import (
fmt "fmt" fmt "fmt"
proto "github.com/gogo/protobuf/proto"
io "io" io "io"
math "math" math "math"
math_bits "math/bits" math_bits "math/bits"
proto "github.com/gogo/protobuf/proto"
) )
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
......
...@@ -5,10 +5,11 @@ package pb ...@@ -5,10 +5,11 @@ package pb
import ( import (
fmt "fmt" fmt "fmt"
proto "github.com/gogo/protobuf/proto"
io "io" io "io"
math "math" math "math"
math_bits "math/bits" math_bits "math/bits"
proto "github.com/gogo/protobuf/proto"
) )
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
......
...@@ -50,7 +50,7 @@ func (s *GRPCServer) GetIBTP(_ *pb.Empty, conn pb.AppchainPlugin_GetIBTPServer) ...@@ -50,7 +50,7 @@ func (s *GRPCServer) GetIBTP(_ *pb.Empty, conn pb.AppchainPlugin_GetIBTPServer)
return err return err
} }
return nil return nil
}, strategy.Wait(1*time.Second)); err != nil { }, strategy.Limit(3), strategy.Wait(1*time.Second)); err != nil {
logger.Error("Execution of plugin server sending ibtp failed", "error", err) logger.Error("Execution of plugin server sending ibtp failed", "error", err)
} }
} }
...@@ -202,7 +202,7 @@ func (g *GRPCClient) handleIBTPStream(conn pb.AppchainPlugin_GetIBTPClient, ibtp ...@@ -202,7 +202,7 @@ func (g *GRPCClient) handleIBTPStream(conn pb.AppchainPlugin_GetIBTPClient, ibtp
return err return err
} }
return nil return nil
}, strategy.Wait(1*time.Second)); err != nil { }, strategy.Limit(3), strategy.Wait(1*time.Second)); err != nil {
logger.Error("Execution of client recv failed", "error", err) logger.Error("Execution of client recv failed", "error", err)
} }
...@@ -217,7 +217,7 @@ func (g *GRPCClient) handleIBTPStream(conn pb.AppchainPlugin_GetIBTPClient, ibtp ...@@ -217,7 +217,7 @@ func (g *GRPCClient) handleIBTPStream(conn pb.AppchainPlugin_GetIBTPClient, ibtp
func (g *GRPCClient) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { func (g *GRPCClient) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
var err error var err error
response := &pb.SubmitIBTPResponse{} response := &pb.SubmitIBTPResponse{}
retry.Retry(func(attempt uint) error { err = retry.Retry(func(attempt uint) error {
response, err = g.client.SubmitIBTP(g.doneContext, ibtp) response, err = g.client.SubmitIBTP(g.doneContext, ibtp)
if err != nil { if err != nil {
logger.Error("submit ibtp to plugin server", logger.Error("submit ibtp to plugin server",
...@@ -226,9 +226,9 @@ func (g *GRPCClient) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) { ...@@ -226,9 +226,9 @@ func (g *GRPCClient) SubmitIBTP(ibtp *pb.IBTP) (*pb.SubmitIBTPResponse, error) {
return err return err
} }
return nil return nil
}, strategy.Wait(1*time.Second)) }, strategy.Limit(3), strategy.Wait(1*time.Second))
return response, nil return response, err
} }
func (g *GRPCClient) RollbackIBTP(ibtp *pb.IBTP, srcChain bool) (*pb.RollbackIBTPResponse, error) { func (g *GRPCClient) RollbackIBTP(ibtp *pb.IBTP, srcChain bool) (*pb.RollbackIBTPResponse, error) {
......
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