Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: seperate updateclient and other messages in archway #87

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion relayer/chains/archway/helper_debug_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func jsonDumpDataFile(filename string, bufs interface{}) {
os.Exit(1)
}

fmt.Printf("Successfully created or appended JSON in %s", filename)
fmt.Printf("Successfully created or appended JSON in %s \n", filename)
}

func readExistingData(filename string, opPointer interface{}) error {
Expand Down
3 changes: 1 addition & 2 deletions relayer/chains/archway/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cosmos/gogoproto/proto"
"github.com/cosmos/relayer/v2/relayer/chains/archway/types"
"github.com/cosmos/relayer/v2/relayer/provider"
"go.uber.org/zap"
)

type WasmContractMessage struct {
Expand Down Expand Up @@ -37,7 +36,7 @@ func (ap *ArchwayProvider) NewWasmContractMessage(method string, m codec.ProtoMa
if err != nil {
return nil, err
}
ap.log.Debug("Archway Constructed message ", zap.String("MethodName", method), zap.Any("Message", types.NewHexBytes(protoMsg)))
// ap.log.Debug("Archway Constructed message ", zap.String("MethodName", method), zap.Any("Message", types.NewHexBytes(protoMsg)))

msgParam, err := types.GenerateTxnParams(method, types.NewHexBytes(protoMsg))

Expand Down
4 changes: 4 additions & 0 deletions relayer/chains/archway/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ func (ac *ArchwayProvider) Codec() Codec {
return ac.Cdc
}

func (ap *ArchwayProvider) ClientContext() client.Context {
return ap.ClientCtx
}

func (ap *ArchwayProvider) updateNextAccountSequence(seq uint64) {
if seq > ap.nextAccountSeq {
ap.nextAccountSeq = seq
Expand Down
57 changes: 29 additions & 28 deletions relayer/chains/archway/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ func (ap *ArchwayProvider) ValidatePacket(msgTransfer provider.PacketInfo, lates
revisionNumber := 0
latestClientTypesHeight := clienttypes.NewHeight(uint64(revisionNumber), latest.Height)
if !msgTransfer.TimeoutHeight.IsZero() && latestClientTypesHeight.GTE(msgTransfer.TimeoutHeight) {
fmt.Println("packet timeout failed finally ", msgTransfer.TimeoutHeight)

return provider.NewTimeoutHeightError(latest.Height, msgTransfer.TimeoutHeight.RevisionHeight)
}
// latestTimestamp := uint64(latest.Time.UnixNano())
Expand Down Expand Up @@ -299,7 +301,8 @@ func (ap *ArchwayProvider) MsgRecvPacket(msgTransfer provider.PacketInfo, proof
}

params := &chantypes.MsgRecvPacket{
Packet: msgTransfer.Packet(),
Packet: msgTransfer.Packet(),
// Packet: chantypes.Packet{}, //TODO: just to check packet timeout
ProofCommitment: proof.Proof,
ProofHeight: proof.ProofHeight,
Signer: signer,
Expand Down Expand Up @@ -716,10 +719,6 @@ func (ap *ArchwayProvider) SendMessages(ctx context.Context, msgs []provider.Rel
return rlyResp, true, callbackErr
}

func (ap *ArchwayProvider) ClientContext() client.Context {
return ap.ClientCtx
}

func (ap *ArchwayProvider) SendMessagesToMempool(
ctx context.Context,
msgs []provider.RelayerMessage,
Expand All @@ -737,37 +736,34 @@ func (ap *ArchwayProvider) SendMessagesToMempool(
return err
}

var sdkMsgs []sdk.Msg
for _, msg := range msgs {

if msg == nil {
ap.log.Debug("One of the message is nil")
ap.log.Debug("One of the message of archway")
continue
}

archwayMsg, ok := msg.(*WasmContractMessage)
if !ok {
return fmt.Errorf("Invalid ArchwayMsg")
return fmt.Errorf("Archway Message is not valid %s", archwayMsg.Type())
}

sdkMsgs = append(sdkMsgs, archwayMsg.Msg)
}

if err != nil {

ap.log.Debug("error when dumping message")

}
txBytes, sequence, err := ap.buildMessages(cliCtx, factory, archwayMsg.Msg)
if err != nil {
return err
}
ap.updateNextAccountSequence(sequence + 1)

txBytes, sequence, err := ap.buildMessages(cliCtx, factory, sdkMsgs...)
if err != nil {
return err
if msg.Type() == MethodUpdateClient {
err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, true)
if err != nil {
return fmt.Errorf("Archway: failed during updateClient ")
}
continue
}
ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, false)
}

// updating the next sequence number
ap.updateNextAccountSequence(sequence + 1)

return ap.BroadcastTx(cliCtx, txBytes, msgs, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback)
return nil

}

Expand Down Expand Up @@ -844,8 +840,6 @@ func (ap *ArchwayProvider) LogSuccessTx(res *sdk.TxResponse, msgs []provider.Rel
fields...,
)

// uncomment for saving msg
SaveMsgToFile(ArchwayDebugMessagePath, msgs)
}

// getFeePayer returns the bech32 address of the fee payer of a transaction.
Expand Down Expand Up @@ -973,6 +967,7 @@ func (ap *ArchwayProvider) BroadcastTx(
asyncCtx context.Context, // context for async wait for block inclusion after successful tx broadcast
asyncTimeout time.Duration, // timeout for waiting for block inclusion
asyncCallback func(*provider.RelayerTxResponse, error), // callback for success/fail of the wait for block inclusion
shouldWait bool,
) error {
res, err := clientCtx.BroadcastTx(txBytes)
// log submitted txn
Expand Down Expand Up @@ -1011,6 +1006,9 @@ func (ap *ArchwayProvider) BroadcastTx(
zap.String("txHash", res.TxHash),
)

if shouldWait {
ap.waitForTx(asyncCtx, hexTx, msgs, asyncTimeout, asyncCallback)
}
go ap.waitForTx(asyncCtx, hexTx, msgs, asyncTimeout, asyncCallback)
return nil
}
Expand Down Expand Up @@ -1038,7 +1036,7 @@ func (ap *ArchwayProvider) waitForTx(
waitTimeout time.Duration,
callback func(*provider.RelayerTxResponse, error),
) {
res, err := ap.waitForBlockInclusion(ctx, txHash, waitTimeout)
res, err := ap.waitForTxResult(ctx, txHash, waitTimeout)
if err != nil {
ap.log.Error("Failed to wait for block inclusion", zap.Error(err))
if callback != nil {
Expand All @@ -1047,6 +1045,9 @@ func (ap *ArchwayProvider) waitForTx(
return
}

//uncomment for saving msg
SaveMsgToFile(ArchwayDebugMessagePath, msgs)

rlyResp := &provider.RelayerTxResponse{
Height: res.Height,
TxHash: res.TxHash,
Expand Down Expand Up @@ -1079,7 +1080,7 @@ func (ap *ArchwayProvider) waitForTx(
ap.LogSuccessTx(res, msgs)
}

func (ap *ArchwayProvider) waitForBlockInclusion(
func (ap *ArchwayProvider) waitForTxResult(
ctx context.Context,
txHash []byte,
waitTimeout time.Duration,
Expand Down
7 changes: 3 additions & 4 deletions relayer/chains/icon/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"

"github.com/cosmos/relayer/v2/relayer/provider"
"go.uber.org/zap"
)

const defaultStepLimit = 13610920010
Expand All @@ -15,11 +14,11 @@ type IconMessage struct {
}

func (im *IconMessage) Type() string {
return "icon"
return im.Method
}

func (im *IconMessage) MsgBytes() ([]byte, error) {
return json.Marshal(im)
return json.Marshal(im.Params)
}

func (icp *IconProvider) NewIconMessage(msg interface{}, method string) provider.RelayerMessage {
Expand All @@ -29,7 +28,7 @@ func (icp *IconProvider) NewIconMessage(msg interface{}, method string) provider
Method: method,
}

icp.log.Debug("Icon Message ", zap.String("method", method), zap.Any("message ", msg))
// icp.log.Debug("Icon Message ", zap.String("method", method), zap.Any("message ", msg))

return im
}
2 changes: 1 addition & 1 deletion relayer/processor/path_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (

// If the message was assembled successfully, but sending the message failed,
// how many blocks should pass before retrying.
blocksToRetrySendAfter = 1
blocksToRetrySendAfter = 2

// How many times to retry sending a message before giving up on it.
maxMessageSendRetries = 5
Expand Down