From 7ae767d3adc7b89e7ac730cc47053495585c3ce4 Mon Sep 17 00:00:00 2001 From: Truong Ma Phi Date: Sat, 14 Aug 2021 12:03:19 +0700 Subject: [PATCH 1/4] fix: retry on skiptransaction error --- btp/btp.go | 2 ++ chain/error.go | 36 +++++++++++++++++++++++++++++++----- chain/icon/sender.go | 2 ++ chain/icon/type.go | 1 + 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/btp/btp.go b/btp/btp.go index ecd5c912..a3732d66 100644 --- a/btp/btp.go +++ b/btp/btp.go @@ -448,6 +448,8 @@ func (b *BTP) updateResult(rm *chain.RelayMessage, segment *chain.Segment) (err segment.GetResultParam = nil case chain.BMCRevertUnauthorized: segment.GetResultParam = nil + case chain.ICONSkipTransaction: + segment.GetResultParam = nil default: b.log.Panicf("fail to GetResult GetResultParam:%v ErrorCoder:%+v", segment.GetResultParam, ec) } diff --git a/chain/error.go b/chain/error.go index 58a16547..805ece78 100644 --- a/chain/error.go +++ b/chain/error.go @@ -31,11 +31,12 @@ var ( ) const ( - CodeBTP errors.Code = 0 - CodeBMC errors.Code = 10 - CodeBMV errors.Code = 25 - CodeBSH errors.Code = 40 - CodeReserved errors.Code = 55 + CodeBTP errors.Code = 0 + CodeBMC errors.Code = 10 + CodeBMV errors.Code = 25 + CodeBSH errors.Code = 40 + CodeReserved errors.Code = 55 + CodeRetryable errors.Code = 1000 ) const ( @@ -100,6 +101,31 @@ var ( } ) +const ( + GenericRetryable = CodeRetryable + iota + ICONSkipTransaction +) + +var ( + RetrybleCodeNames = map[errors.Code]string{ + GenericRetryable: "GenericRetryable", + ICONSkipTransaction: "ICONSkipTransaction", + } +) + +func NewRetryable(code int) error { + c := errors.Code(code) + if c >= CodeRetryable { + var msg string + var ok bool + if msg, ok = RetrybleCodeNames[c]; !ok { + msg = fmt.Sprintf("Retryable[%d]", c) + } + return errors.NewBase(c, msg) + } + return nil +} + func NewRevertError(code int) error { c := errors.Code(code) if c >= CodeBTP { diff --git a/chain/icon/sender.go b/chain/icon/sender.go index 5aa8e839..995f0aeb 100644 --- a/chain/icon/sender.go +++ b/chain/icon/sender.go @@ -602,6 +602,8 @@ func mapErrorWithTransactionResult(txr *TransactionResult, err error) error { if fc < ResultStatusFailureCodeRevert || fc > ResultStatusFailureCodeEnd { err = fmt.Errorf("failure with code:%s, message:%s", txr.Failure.CodeValue, txr.Failure.MessageValue) + } else if fc == ResultStatusSkipTransaction { + err = chain.NewRetryable(int(chain.ICONSkipTransaction)) } else { err = chain.NewRevertError(int(fc - ResultStatusFailureCodeRevert)) } diff --git a/chain/icon/type.go b/chain/icon/type.go index 1e926851..e562838b 100644 --- a/chain/icon/type.go +++ b/chain/icon/type.go @@ -58,6 +58,7 @@ const ( const ( ResultStatusSuccess = "0x1" + ResultStatusSkipTransaction = 14 ResultStatusFailureCodeRevert = 32 ResultStatusFailureCodeEnd = 99 ) From a06df1191e1e342aef57706dc984f67d58e36e17 Mon Sep 17 00:00:00 2001 From: Truong Ma Phi Date: Fri, 20 Aug 2021 14:26:33 +0700 Subject: [PATCH 2/4] fix: add a delay in the last fragmentation in RelayMessage --- chain/icon/sender.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/chain/icon/sender.go b/chain/icon/sender.go index 995f0aeb..3f7525bc 100644 --- a/chain/icon/sender.go +++ b/chain/icon/sender.go @@ -50,12 +50,13 @@ type SenderOptions struct { } type sender struct { - c *Client - src chain.BtpAddress - dst chain.BtpAddress - w Wallet - l log.Logger - opt SenderOptions + c *Client + src chain.BtpAddress + dst chain.BtpAddress + w Wallet + l log.Logger + opt SenderOptions + iconBlockInterval int } func (s *sender) newTransactionParam(prev string, rm *RelayMessage) (*TransactionParam, error) { @@ -351,10 +352,10 @@ func (s *sender) sendFragmentations(tps []*TransactionParam, idxs []int) (chain. if err != nil { s.l.Panicf("sendFragmentations: fails result %+v error%+v", grp, err) } - // TODO use (finalizelatency * blockinterval / appropriateratio) * time.Second - time.Sleep(time.Duration(s.FinalizeLatency()) * time.Second) } + // Only last fragmnetation need this + time.Sleep(time.Duration(s.FinalizeLatency()*s.iconBlockInterval) * time.Second) s.l.Tracef("sendFragmentations: end") return grp, err } @@ -500,6 +501,7 @@ func (s *sender) GetStatus() (*chain.BMCLinkStatus, error) { ls.RxHeightSrc, err = bs.RxHeightSrc.Value() ls.BlockIntervalSrc, err = bs.BlockIntervalSrc.Int() ls.BlockIntervalDst, err = bs.BlockIntervalDst.Int() + s.iconBlockInterval = ls.BlockIntervalDst return ls, nil } From 5f92bbd3e47f35553c35e0516ac9f0d519d06be2 Mon Sep 17 00:00:00 2001 From: Truong Ma Phi Date: Mon, 23 Aug 2021 14:44:38 +0700 Subject: [PATCH 3/4] fix: remove redundant sleep --- chain/icon/sender.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/chain/icon/sender.go b/chain/icon/sender.go index 3f7525bc..c6ca9451 100644 --- a/chain/icon/sender.go +++ b/chain/icon/sender.go @@ -354,8 +354,6 @@ func (s *sender) sendFragmentations(tps []*TransactionParam, idxs []int) (chain. } } - // Only last fragmnetation need this - time.Sleep(time.Duration(s.FinalizeLatency()*s.iconBlockInterval) * time.Second) s.l.Tracef("sendFragmentations: end") return grp, err } From e0047c57d8a8abd13e4066eeec9ce6b83b6f0f44 Mon Sep 17 00:00:00 2001 From: Truong Ma Phi Date: Mon, 23 Aug 2021 14:48:50 +0700 Subject: [PATCH 4/4] refactor: remove redundant field in Sender --- chain/icon/sender.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/chain/icon/sender.go b/chain/icon/sender.go index c6ca9451..a6bfd84f 100644 --- a/chain/icon/sender.go +++ b/chain/icon/sender.go @@ -50,13 +50,12 @@ type SenderOptions struct { } type sender struct { - c *Client - src chain.BtpAddress - dst chain.BtpAddress - w Wallet - l log.Logger - opt SenderOptions - iconBlockInterval int + c *Client + src chain.BtpAddress + dst chain.BtpAddress + w Wallet + l log.Logger + opt SenderOptions } func (s *sender) newTransactionParam(prev string, rm *RelayMessage) (*TransactionParam, error) { @@ -499,7 +498,6 @@ func (s *sender) GetStatus() (*chain.BMCLinkStatus, error) { ls.RxHeightSrc, err = bs.RxHeightSrc.Value() ls.BlockIntervalSrc, err = bs.BlockIntervalSrc.Int() ls.BlockIntervalDst, err = bs.BlockIntervalDst.Int() - s.iconBlockInterval = ls.BlockIntervalDst return ls, nil }