Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions relayer/chainreader/indexer/events_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type EventsIndexerApi interface {
Start(ctx context.Context) error
SyncAllEvents(ctx context.Context) error
SyncEvent(ctx context.Context, selector *client.EventSelector) error
AddEventSelector(ctx context.Context, selector *client.EventSelector) error
Ready() error
Close() error
}
Expand Down Expand Up @@ -414,6 +415,24 @@ eventLoop:
return nil
}

func (eIndexer *EventsIndexer) AddEventSelector(ctx context.Context, selector *client.EventSelector) error {
if selector == nil {
return fmt.Errorf("unspecified selector for AddEventSelector call")
}

// check if the event selector is already tracked, if not add it to the list
if !eIndexer.isEventSelectorAdded(*selector) {
eIndexer.configMutex.Lock()
// Double-check after acquiring write lock (avoid race with concurrent adds)
if !eIndexer.isEventSelectorAddedLocked(*selector) {
eIndexer.eventConfigurations = append(eIndexer.eventConfigurations, selector)
}
eIndexer.configMutex.Unlock()
}

return nil
}

// IsEventSelectorAdded checks if a specific event selector has already been included in the list of events to sync
func (eIndexer *EventsIndexer) isEventSelectorAdded(eConfig client.EventSelector) bool {
eIndexer.configMutex.RLock()
Expand Down
45 changes: 33 additions & 12 deletions relayer/chainreader/indexer/transactions_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewTransactionsIndexer(
executionEventKey: "ExecutionStateChanged",
configEventModuleKey: "ocr3_base",
configEventKey: "ConfigSet",
executeFunctions: []string{"finish_execute"},
executeFunctions: []string{"init_execute", "ccip_receive", "finish_execute"},
Copy link
Member

Choose a reason for hiding this comment

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

We should include token transfer processing, is it release_or_mint?

eventConfigs: eventConfigs,
eventPkgReady: make(chan struct{}),
}
Expand Down Expand Up @@ -329,28 +329,49 @@ func (tIndexer *TransactionsIndexer) syncTransmitterTransactions(ctx context.Con
continue
}

if moveAbort.Location.Module.Address != tIndexer.eventPackageId {
tIndexer.logger.Debugw("Skipping transaction with different package address",
"transmitter", transmitter, "packageAddress", moveAbort.Location.Module.Address)
includesValidPackage := false
includesValidModule := false

continue
}
// Check if any of the transaction's commands match with the expected package and module
for _, raw := range transactionRecord.Transaction.Data.Transaction.Transactions {
if moveCall := models.MoveCall(raw); moveCall != nil {
packageID := moveCall.Package
moduleName := moveCall.Module

if moveAbort.Location.Module.Name != moduleKey {
tIndexer.logger.Debugw("Skipping transaction with different module",
"transmitter", transmitter, "module", moveAbort.Location.Module.Name)
if packageID == tIndexer.eventPackageId {
includesValidPackage = true
}

if moduleName == moduleKey {
includesValidModule = true
}
}
}

// NOTE: The check below does not guarantee that a malicious (known) transmitter is not sending a failed PTB
// with the expected package and module. However, it is considered as the worst case scenario simply involves
// creating an event record with a failure state against an digest that is not checked.
if !includesValidPackage || !includesValidModule {
tIndexer.logger.Warnw(
"Expected package and module not found in commands of failed PTB originating from known transmitter",
"transmitter", transmitter,
"digest", transactionRecord.Digest,
)
continue
}

if moveAbort.Location.FunctionName == nil || !slices.Contains(tIndexer.executeFunctions, *moveAbort.Location.FunctionName) {
tIndexer.logger.Debugw("Skipping transaction for non-execute function",
"transmitter", transmitter, "location", moveAbort.Location)
tIndexer.logger.Debugw("Skipping transaction for failed function against a non-configured function name",
"transmitter", transmitter,
"location", moveAbort.Location,
"functionName", *moveAbort.Location.FunctionName,
"digest", transactionRecord.Digest,
)

continue
}

// we always get the report from the init_execute function call (index 0), the "finish_execute" function call
// We always get the report from the init_execute function call (index 0), the "finish_execute" function call
// does not contain an argument which contains the report
// NOTE: we assume that init_execute (which contains the report) is always the first command in the PTB
commandIndex := uint64(0)
Expand Down
16 changes: 15 additions & 1 deletion relayer/chainreader/reader/chainreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,21 @@ func (s *suiChainReader) Bind(ctx context.Context, bindings []pkgtypes.BoundCont

// If the "OffRamp" package/module is now bound, set the offramp package ID for the tx indexer
if pkg, err := s.packageResolver.ResolvePackageAddress(offrampName); err == nil {
// Get the latest package ID for the offramp module
// Add the ocr3_base ConfigSet event selector explicitly to the indexer since the transaction indexer depends on it.
// This avoids requiring the QueryKey call to be made in the transaction indexer to get the ocr3_base ConfigSet event
// in the case that it's not already configured / indexed.
addEventSelectorErr := s.indexer.GetEventIndexer().AddEventSelector(ctx, &client.EventSelector{
Package: pkg,
Module: "ocr3_base",
Event: "ConfigSet",
})

if addEventSelectorErr != nil {
s.logger.Warnw("Failed to add ocr3_base ConfigSet event selector to indexer", "error", err)
}

// Get the latest package ID for the offramp module. The transaction indexer watches the latest package ID for the offramp module
// to capture failed transactions.
latestPackageID, err := s.client.GetLatestPackageId(ctx, pkg, "offramp")
if err != nil {
s.logger.Warnw("Failed to get latest package ID for OffRamp", "error", err)
Expand Down
Loading