Skip to content

Commit

Permalink
fix: check if cluster message is acknowledged
Browse files Browse the repository at this point in the history
  • Loading branch information
sherpalden committed Nov 27, 2024
1 parent 6cf21ac commit b61a2c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions relayer/chains/icon/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ var (
// Cluster Methods
MethodSubmitPacket = "submitPacket"
MethodClusterMsgReceived = "packetSubmitted"
MethodPacketAcknowledged = "packetAcknowledged"
MethodRecvMessageWithSignature = "recvMessageWithSignatures"
)
12 changes: 12 additions & 0 deletions relayer/chains/icon/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ func (p *Provider) ClusterMessageReceived(ctx context.Context, message *provider
return status == types.NewHexInt(1), err
}

// ClusterMessageAcknowledged checks if the message is acknowledged or not
func (p *Provider) ClusterMessageAcknowledged(ctx context.Context, message *providerTypes.Message) (bool, error) {
callParam := p.prepareCallParams(MethodClusterMsgReceived, p.cfg.Contracts[providerTypes.AggregationContract], map[string]interface{}{
"srcNetwork": message.Src,
"srcContractAddress": message.SrcConnAddress,
"srcSn": types.NewHexInt(message.Sn.Int64()),
})
var status types.HexInt
err := p.client.Call(callParam, &status)
return status == types.NewHexInt(1), err
}

// ReverseMessage reverts a message
func (p *Provider) RevertMessage(ctx context.Context, sn *big.Int) error {
params := map[string]interface{}{"sn": types.NewHexInt(sn.Int64())}
Expand Down
1 change: 1 addition & 0 deletions relayer/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ChainQuery interface {
type ClusterChainProvider interface {
SubmitClusterMessage(ctx context.Context, message *types.Message, callback types.TxResponseFunc) error
ClusterMessageReceived(ctx context.Context, message *types.Message) (bool, error)
ClusterMessageAcknowledged(ctx context.Context, message *types.Message) (bool, error)
}

type ClusterChainVerifier interface {
Expand Down
10 changes: 10 additions & 0 deletions relayer/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,16 @@ func (r *Relayer) processAcknowledgementMsg(ctx context.Context, message *types.
var messages []*types.Message
var err error
if clusterProvider, ok := iconChain.Provider.(provider.ClusterChainProvider); ok {
msgAcknowledged, err := clusterProvider.ClusterMessageAcknowledged(ctx, message.Message)
if err != nil {
dst.log.Error("error occured when checking cluster message acknowledged", zap.String("src", message.Src), zap.Uint64("sn", message.Sn.Uint64()), zap.Error(err))
message.ToggleProcessing()
return
}
if msgAcknowledged {
return
}

msgReceived, err := clusterProvider.ClusterMessageReceived(ctx, message.Message)
if err != nil {
dst.log.Error("error occured when checking cluster message received", zap.String("src", message.Src), zap.Uint64("sn", message.Sn.Uint64()), zap.Error(err))
Expand Down

0 comments on commit b61a2c8

Please sign in to comment.