Skip to content

Commit

Permalink
fix: enforce connection id check
Browse files Browse the repository at this point in the history
  • Loading branch information
sherpalden committed Jun 11, 2024
1 parent e480bba commit 3bcad15
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 8 additions & 0 deletions relayer/chains/sui/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ func (p *Provider) parseMessagesFromEvents(events []types.EventResponse) ([]rela
for _, ev := range events {
msg, err := p.parseMessageFromEvent(ev)
if err != nil {
if err.Error() == types.ConnectionIDMismatchError {
continue
}
return nil, err
}

p.log.Info("Detected event log: ",
zap.Uint64("checkpoint", msg.MessageHeight),
zap.String("event-type", msg.EventType),
Expand Down Expand Up @@ -134,6 +138,10 @@ func (p *Provider) parseMessageFromEvent(ev types.EventResponse) (*relayertypes.
if err := json.Unmarshal(eventBytes, &emitEvent); err != nil {
return nil, err
}
if emitEvent.ConnectionID != p.cfg.ConnectionID {
return nil, fmt.Errorf(types.ConnectionIDMismatchError)
}

sn, err := strconv.Atoi(emitEvent.Sn)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/sui/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
ModuleMockDapp = "mock_dapp"
ModuleXcallManager = "xcall_manager"
ModuleAssetManager = "asset_manager"
ModuleBalancedDollar = "balanced_dollar"
ModuleBalancedDollar = "balanced_dollar_crosschain"

suiCurrencyDenom = "SUI"
suiBaseFee = 1000
Expand Down
9 changes: 6 additions & 3 deletions relayer/chains/sui/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const (
XcallContract = "xcall"
ConnectionContract = "connection"

ConnectionIDMismatchError = "connection_id_mismatch_error"

QUERY_MAX_RESULT_LIMIT = 50
)

Expand Down Expand Up @@ -66,9 +68,10 @@ type SuiMultiGetTransactionBlocksRequest struct {
}

type EmitEvent struct {
Sn string `json:"conn_sn"`
Msg []byte `json:"msg"`
To string `json:"to"`
Sn string `json:"conn_sn"`
Msg []byte `json:"msg"`
To string `json:"to"`
ConnectionID string `json:"connection_id"`
}

type CallMsgEvent struct {
Expand Down

0 comments on commit 3bcad15

Please sign in to comment.