From 304cd4a693bb571629d3579b46e0a7686260cbee Mon Sep 17 00:00:00 2001 From: Debendra Oli Date: Tue, 9 Jul 2024 15:00:43 +0545 Subject: [PATCH 1/3] add: sleep when there is mempool error --- relayer/chains/wasm/consts.go | 4 ++++ relayer/chains/wasm/tx.go | 20 +++----------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/relayer/chains/wasm/consts.go b/relayer/chains/wasm/consts.go index 788f1b7f0..7aa098f28 100644 --- a/relayer/chains/wasm/consts.go +++ b/relayer/chains/wasm/consts.go @@ -1,5 +1,7 @@ package wasm +import "time" + const ( // External methods MethodCreateClient = "create_client" @@ -36,3 +38,5 @@ const ( const ( ContractAddressSizeMinusPrefix = 59 ) + +var MempoolFullWaitTime = time.Second * 30 diff --git a/relayer/chains/wasm/tx.go b/relayer/chains/wasm/tx.go index 124ca9a77..ce51518ec 100644 --- a/relayer/chains/wasm/tx.go +++ b/relayer/chains/wasm/tx.go @@ -151,7 +151,6 @@ func (pc *WasmProviderConfig) SignMode() signing.SignMode { } func (ap *WasmProvider) NewClientState(dstChainID string, dstIBCHeader provider.IBCHeader, dstTrustingPeriod, dstUbdPeriod time.Duration, allowUpdateAfterExpiry, allowUpdateAfterMisbehaviour bool) (ibcexported.ClientState, error) { - return &itm.ClientState{ ChainId: dstChainID, TrustLevel: &itm.Fraction{Numerator: light.DefaultTrustLevel.Numerator, Denominator: light.DefaultTrustLevel.Denominator}, @@ -198,7 +197,6 @@ func (ap *WasmProvider) MsgSubmitMisbehaviour(clientID string, misbehaviour ibce } func (ap *WasmProvider) ValidatePacket(msgTransfer provider.PacketInfo, latest provider.LatestBlock) error { - if msgTransfer.Sequence == 0 { return errors.New("refusing to relay packet with sequence: 0") } @@ -215,7 +213,6 @@ func (ap *WasmProvider) ValidatePacket(msgTransfer provider.PacketInfo, latest p revisionNumber := 0 latestClientTypesHeight := clienttypes.NewHeight(uint64(revisionNumber), latest.Height) if !msgTransfer.TimeoutHeight.IsZero() && latestClientTypesHeight.GTE(msgTransfer.TimeoutHeight) { - return provider.NewTimeoutHeightError(latest.Height, msgTransfer.TimeoutHeight.RevisionHeight) } // latestTimestamp := uint64(latest.Time.UnixNano()) @@ -230,7 +227,6 @@ func (ap *WasmProvider) PacketCommitment(ctx context.Context, msgTransfer provid packetCommitmentResponse, err := ap.QueryPacketCommitment( ctx, int64(height), msgTransfer.SourceChannel, msgTransfer.SourcePort, msgTransfer.Sequence, ) - if err != nil { return provider.PacketProof{}, err } @@ -252,9 +248,7 @@ func (ap *WasmProvider) PacketAcknowledgement(ctx context.Context, msgRecvPacket } func (ap *WasmProvider) PacketReceipt(ctx context.Context, msgTransfer provider.PacketInfo, height uint64) (provider.PacketProof, error) { - packetReceiptResponse, err := ap.QueryPacketReceipt(ctx, int64(height), msgTransfer.DestChannel, msgTransfer.DestPort, msgTransfer.Sequence) - if err != nil { return provider.PacketProof{}, err } @@ -308,7 +302,6 @@ func (ap *WasmProvider) MsgAcknowledgement(msgRecvPacket provider.PacketInfo, pr Signer: signer, } return ap.NewWasmContractMessage(MethodAcknowledgePacket, params) - } func (ap *WasmProvider) MsgTimeout(msgTransfer provider.PacketInfo, proof provider.PacketProof) (provider.RelayerMessage, error) { @@ -381,7 +374,6 @@ func (ap *WasmProvider) MsgConnectionOpenInit(info provider.ConnectionInfo, proo } return ap.NewWasmContractMessage(MethodConnectionOpenInit, params) - } func (ap *WasmProvider) MsgConnectionOpenTry(msgOpenInit provider.ConnectionInfo, proof provider.ConnectionProof) (provider.RelayerMessage, error) { @@ -416,7 +408,6 @@ func (ap *WasmProvider) MsgConnectionOpenTry(msgOpenInit provider.ConnectionInfo } return ap.NewWasmContractMessage(MethodConnectionOpenTry, params) - } func (ap *WasmProvider) MsgConnectionOpenAck(msgOpenTry provider.ConnectionInfo, proof provider.ConnectionProof) (provider.RelayerMessage, error) { @@ -633,7 +624,6 @@ func (ap *WasmProvider) MsgUpdateClient(clientID string, dstHeader ibcexported.C } return ap.NewWasmContractMessage(MethodUpdateClient, params) - } func (ap *WasmProvider) QueryICQWithProof(ctx context.Context, msgType string, request []byte, height uint64) (provider.ICQProof, error) { @@ -760,7 +750,6 @@ func (ap *WasmProvider) SendCustomMessage(ctx context.Context, contract string, } return rlyResp, true, callbackErr - } func (ap *WasmProvider) SendTransactionCosmWasm( @@ -849,6 +838,9 @@ func (ap *WasmProvider) SendMessagesToMempool( if err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, true); err != nil { if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) { ap.handleAccountSequenceMismatchError(err) + } else if strings.Contains(err.Error(), sdkerrors.ErrMempoolIsFull.Error()) { + ap.log.Info("Mempool is full, retrying in 15 second") + time.Sleep(MempoolFullWaitTime) } } return err @@ -868,11 +860,9 @@ func (ap *WasmProvider) SendMessagesToMempool( } return nil - } func (ap *WasmProvider) LogFailedTx(res *provider.RelayerTxResponse, err error, msgs []provider.RelayerMessage) { - fields := []zapcore.Field{zap.String("chain_id", ap.ChainId())} // if res != nil { // channels := getChannelsIfPresent(res.Events) @@ -945,7 +935,6 @@ func (ap *WasmProvider) LogSuccessTx(res *sdk.TxResponse, msgs []provider.Relaye "Successful transaction", fields..., ) - } // getFeePayer returns the bech32 address of the fee payer of a transaction. @@ -968,7 +957,6 @@ func getFeePayer(tx *txtypes.Tx) string { default: return firstMsg.GetSigners()[0].String() } - } func (ap *WasmProvider) sdkError(codespace string, code uint32) error { @@ -1361,10 +1349,8 @@ func (cc *WasmProvider) QueryABCI(ctx context.Context, req abci.RequestQuery) (a } func (cc *WasmProvider) handleAccountSequenceMismatchError(err error) { - clientCtx := cc.ClientContext() _, seq, err := cc.ClientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, clientCtx.GetFromAddress()) - // sequences := numRegex.FindAllString(err.Error(), -1) // if len(sequences) != 2 { // return From 03b81ae336efc0656220829c6c530097fe3fa917 Mon Sep 17 00:00:00 2001 From: Debendra Oli Date: Tue, 9 Jul 2024 15:48:17 +0545 Subject: [PATCH 2/3] rf: use retry delay rather sleep --- relayer/chains/wasm/consts.go | 4 ---- relayer/chains/wasm/tx.go | 8 +++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/relayer/chains/wasm/consts.go b/relayer/chains/wasm/consts.go index 7aa098f28..788f1b7f0 100644 --- a/relayer/chains/wasm/consts.go +++ b/relayer/chains/wasm/consts.go @@ -1,7 +1,5 @@ package wasm -import "time" - const ( // External methods MethodCreateClient = "create_client" @@ -38,5 +36,3 @@ const ( const ( ContractAddressSizeMinusPrefix = 59 ) - -var MempoolFullWaitTime = time.Second * 30 diff --git a/relayer/chains/wasm/tx.go b/relayer/chains/wasm/tx.go index ce51518ec..0db71ca5b 100644 --- a/relayer/chains/wasm/tx.go +++ b/relayer/chains/wasm/tx.go @@ -52,6 +52,7 @@ var ( rtyAttNum = uint(5) rtyAtt = retry.Attempts(rtyAttNum) rtyDel = retry.Delay(time.Millisecond * 400) + memPoolDel = retry.Delay(time.Second * 30) rtyErr = retry.LastErrorOnly(true) numRegex = regexp.MustCompile("[0-9]+") defaultBroadcastWaitTimeout = 10 * time.Minute @@ -834,17 +835,18 @@ func (ap *WasmProvider) SendMessagesToMempool( } if msg.Type() == MethodUpdateClient { + delay := retry.Delay(time.Millisecond * time.Duration(ap.PCfg.BlockInterval)) if err := retry.Do(func() error { if err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, true); err != nil { if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) { ap.handleAccountSequenceMismatchError(err) } else if strings.Contains(err.Error(), sdkerrors.ErrMempoolIsFull.Error()) { - ap.log.Info("Mempool is full, retrying in 15 second") - time.Sleep(MempoolFullWaitTime) + ap.log.Info("Mempool is full, retrying later with increased delay") + delay = memPoolDel } } return err - }, retry.Context(ctx), rtyAtt, retry.Delay(time.Millisecond*time.Duration(ap.PCfg.BlockInterval)), rtyErr); err != nil { + }, retry.Context(ctx), rtyAtt, delay, rtyErr); err != nil { ap.log.Error("Failed to update client", zap.Any("Message", msg)) return err } From 12add3be269e868090d42113501e7c71a9922fd4 Mon Sep 17 00:00:00 2001 From: Debendra Oli Date: Tue, 9 Jul 2024 18:45:43 +0545 Subject: [PATCH 3/3] rf: unlimited retry for update client --- relayer/chains/wasm/tx.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/relayer/chains/wasm/tx.go b/relayer/chains/wasm/tx.go index 0db71ca5b..797f2401c 100644 --- a/relayer/chains/wasm/tx.go +++ b/relayer/chains/wasm/tx.go @@ -836,6 +836,7 @@ func (ap *WasmProvider) SendMessagesToMempool( if msg.Type() == MethodUpdateClient { delay := retry.Delay(time.Millisecond * time.Duration(ap.PCfg.BlockInterval)) + retryAttempt := rtyAtt if err := retry.Do(func() error { if err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, true); err != nil { if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) { @@ -843,10 +844,11 @@ func (ap *WasmProvider) SendMessagesToMempool( } else if strings.Contains(err.Error(), sdkerrors.ErrMempoolIsFull.Error()) { ap.log.Info("Mempool is full, retrying later with increased delay") delay = memPoolDel + retryAttempt = retry.Attempts(0) } } return err - }, retry.Context(ctx), rtyAtt, delay, rtyErr); err != nil { + }, retry.Context(ctx), retryAttempt, delay, rtyErr); err != nil { ap.log.Error("Failed to update client", zap.Any("Message", msg)) return err }