Skip to content
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
9 changes: 6 additions & 3 deletions relayer/chainreader/indexer/transactions_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,14 @@ func (tIndexer *TransactionsIndexer) syncTransmitterTransactions(ctx context.Con
executionStateChanged := map[string]any{
"source_chain_selector": fmt.Sprintf("%d", sourceChainSelector),
"sequence_number": fmt.Sprintf("%d", execReport.Message.Header.SequenceNumber),
"message_id": execReport.Message.Header.MessageID,
"message_hash": messageHash[:],
"state": uint8(3), // 3 = FAILURE
// The conversion to []any is needed to avoid the default Go DB SDK behaviour of converting the byte slice to encoded base64 string.
"message_id": codec.BytesToAnySlice(execReport.Message.Header.MessageID),
"message_hash": codec.BytesToAnySlice(messageHash[:]),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we decode these values first?

base64.StdEncoding.DecodeString(messageId)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are already []byte or [32]byte not strings. The issue here is that when inserting them as those types, the DB SDK auto-converts it to base64, all we're doing here is going from []byte to []any to match the JSON-friendly types that are inserted with regular events (comes from parsedJson).

This conversion effectively tells the DB SDK, we want to insert this slice as-is.

"state": uint8(3), // 3 = FAILURE
}

tIndexer.logger.Debugw("About to insert synthetic ExecutionStateChanged event", "executionStateChanged", executionStateChanged)

// normalize keys
executionStateChanged = common.ConvertMapKeysToCamelCase(executionStateChanged).(map[string]any)

Expand Down
28 changes: 24 additions & 4 deletions relayer/chainreader/indexer/transactions_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/hex"
"fmt"
"os"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -226,7 +227,16 @@ func TestTransactionsIndexer(t *testing.T) {
pollingInterval := 4 * time.Second
syncTimeout := 3 * time.Second

type OfframpExecutionStateChanged struct {
SourceChainSelector uint64 `json:"sourceChainSelector"`
SequenceNumber uint64 `json:"sequenceNumber"`
MessageId string `json:"messageId"`
MessageHash string `json:"messageHash"`
State int `json:"state"`
}

readerConfig := config.ChainReaderConfig{
IsLoopPlugin: false,
Modules: map[string]*config.ChainReaderModule{
"OffRamp": {
Name: "offramp",
Expand All @@ -240,6 +250,7 @@ func TestTransactionsIndexer(t *testing.T) {
Module: "offramp",
Event: "ExecutionStateChanged",
},
ExpectedEventType: &OfframpExecutionStateChanged{},
},
"SourceChainConfigSet": {
Name: "offramp",
Expand Down Expand Up @@ -277,7 +288,6 @@ func TestTransactionsIndexer(t *testing.T) {
},
},
},
IsLoopPlugin: false,
EventsIndexer: config.EventsIndexerConfig{
PollingInterval: pollingInterval,
SyncTimeout: syncTimeout,
Expand Down Expand Up @@ -354,15 +364,16 @@ func TestTransactionsIndexer(t *testing.T) {

// helper: returns true if at least one event with the given key exists for the contract
hasEvent := func(contract types.BoundContract, key string) bool {
events, err := cReader.QueryKey(ctx, contract, query.KeyFilter{Key: key}, query.LimitAndSort{}, &database.EventRecord{})
dataType := map[string]any{}
events, err := cReader.QueryKey(ctx, contract, query.KeyFilter{Key: key}, query.LimitAndSort{}, &dataType)
if err != nil {
log.Errorw("Error querying events", "contract", contract.Name, "key", key, "error", err)
return false
}
found := len(events) > 0

if found {
log.Debugw("Event found")
log.Debugw("Event found (hasEvent)", "events", events)
} else {
log.Debugw("Event not found", events)
}
Expand All @@ -380,7 +391,7 @@ func TestTransactionsIndexer(t *testing.T) {
found := len(events) > 0

if found {
log.Debugw("Event found")
log.Debugw("Event found (hasEventDBOnlyCheck)", "events", events)
} else {
log.Debugw("Event not found", events)
}
Expand Down Expand Up @@ -450,6 +461,15 @@ func TestTransactionsIndexer(t *testing.T) {
require.Eventually(t, func() bool {
return hasEvent(boundContracts[0], "ExecutionStateChanged")
}, 90*time.Second, 5*time.Second)

events, err := cReader.QueryKey(ctx, boundContracts[0], query.KeyFilter{Key: "ExecutionStateChanged"}, query.LimitAndSort{}, &OfframpExecutionStateChanged{})
require.NoError(t, err)
require.NotEmpty(t, events)

executionStateChanged := events[0].Data.(*OfframpExecutionStateChanged)

require.True(t, strings.HasPrefix(executionStateChanged.MessageId, "0x"))
Copy link
Copy Markdown
Member

@RodrigoAD RodrigoAD Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check the exact messageId? Same with messageHash

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we could parse reportStr and decode the report it has to get the actual message ID. It's not necessary imo.

The check just needs to verify that the type was read correctly. Given that it's a new contract being published, we can be fairly certain it's the same event we're looking for.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the exact messageId value check here: #301

require.True(t, strings.HasPrefix(executionStateChanged.MessageHash, "0x"))
})
}

Expand Down
8 changes: 8 additions & 0 deletions relayer/codec/type_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,3 +765,11 @@ func UnifiedTypeConverterHook(from, to reflect.Type, data any) (any, error) {
// Use the global converter
return getDefaultTypeConverter().Convert(from, to, data)
}

func BytesToAnySlice(b []byte) []any {
result := make([]any, len(b))
for i, v := range b {
result[i] = v
}
return result
}
Loading