Skip to content

Commit 741d320

Browse files
committed
Fixed event attribute query expressions
1 parent 18ec337 commit 741d320

File tree

2 files changed

+65
-17
lines changed

2 files changed

+65
-17
lines changed

pkg/solana/ccip/chainaccessor/event.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ var eventFilterConfigMap = map[string]map[string]filterConfig{
100100
},
101101
}
102102

103+
// Map of event name to offchain attribute to its subkey index for querying the LogPoller
104+
// Corresponds to the indexed fields in the eventFilterConfigMap above
105+
var eventFilterSubkeyIndexMap = map[string]map[string]uint64 {
106+
consts.EventNameCCIPMessageSent: {
107+
consts.EventAttributeSourceChain: 0,
108+
consts.EventAttributeDestChain: 1,
109+
consts.EventAttributeSequenceNumber: 2,
110+
},
111+
consts.EventNameExecutionStateChanged: {
112+
consts.EventAttributeSourceChain: 0,
113+
consts.EventAttributeSequenceNumber: 1,
114+
consts.EventAttributeState: 2,
115+
},
116+
}
117+
103118
// bindContractEvent binds contract events to the logpoller for monitoring blockchain events.
104119
// This operation is idempotent - if the same address exists, it performs no operation;
105120
// if the address is changed, it updates to the new address, overwriting the existing one;
@@ -457,7 +472,7 @@ func (a *SolanaAccessor) processPriceUpdates(priceUpdates ccip_offramp.PriceUpda
457472
return updates, nil
458473
}
459474

460-
func createExecutedMessagesKeyFilter(rangesPerChain map[ccipocr3.ChainSelector][]ccipocr3.SeqNumRange) (query.KeyFilter, uint64) {
475+
func createExecutedMessagesKeyFilter(rangesPerChain map[ccipocr3.ChainSelector][]ccipocr3.SeqNumRange) (query.KeyFilter, uint64, error) {
461476
var chainExpressions []query.Expression
462477
var countSqNrs uint64
463478
// final query should look like
@@ -492,20 +507,30 @@ func createExecutedMessagesKeyFilter(rangesPerChain map[ccipocr3.ChainSelector][
492507
}
493508
extendedQuery := query.Or(chainExpressions...)
494509

510+
attributeIndexes, ok := eventFilterSubkeyIndexMap[consts.EventNameExecutionStateChanged]
511+
if !ok {
512+
return query.KeyFilter{}, 0, fmt.Errorf("failed to find attribute indexes for event %s", consts.EventNameExecutionStateChanged)
513+
}
514+
stateAttributeIndex, ok := attributeIndexes[consts.EventAttributeState]
515+
if !ok {
516+
return query.KeyFilter{}, 0, fmt.Errorf("failed to find index for attribute %s for event %s", consts.EventAttributeState, consts.EventNameExecutionStateChanged)
517+
}
518+
// We don't need to wait for an execute state changed event to be finalized
519+
// before we optimistically mark a message as executed.
520+
subKeyFilter, err := logpoller.NewEventBySubKeyFilter(stateAttributeIndex, []primitives.ValueComparator{{Value: 0, Operator: primitives.Gt}},)
521+
if err != nil {
522+
return query.KeyFilter{}, 0, fmt.Errorf("failed to build event sub key filter for state attribute: %w", err)
523+
}
524+
495525
keyFilter := query.KeyFilter{
496526
Key: consts.EventNameExecutionStateChanged,
497527
Expressions: []query.Expression{
498528
extendedQuery,
499-
// We don't need to wait for an execute state changed event to be finalized
500-
// before we optimistically mark a message as executed.
501-
query.Comparator(consts.EventAttributeState, primitives.ValueComparator{
502-
Value: 0, // > 0 corresponds to: IN_PROGRESS, SUCCESS, FAILURE
503-
Operator: primitives.Gt,
504-
}),
529+
subKeyFilter,
505530
query.Confidence(primitives.Finalized),
506531
},
507532
}
508-
return keyFilter, countSqNrs
533+
return keyFilter, countSqNrs, nil
509534
}
510535

511536
func (a *SolanaAccessor) processExecutionStateChangesEvents(logs []logpollertypes.Log, nonEmptyRangesPerChain map[ccipocr3.ChainSelector][]ccipocr3.SeqNumRange) (map[ccipocr3.ChainSelector][]ccipocr3.SeqNum, error) {

pkg/solana/ccip/chainaccessor/solana_accessor.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,23 @@ func (a *SolanaAccessor) MsgsBetweenSeqNums(ctx context.Context, dest ccipocr3.C
223223
return nil, fmt.Errorf("OnRamp not bound: %w", err)
224224
}
225225

226+
attributeIndexes, ok := eventFilterSubkeyIndexMap[consts.EventNameCCIPMessageSent]
227+
if !ok {
228+
return nil, fmt.Errorf("failed to find attribute indexes for event %s", consts.EventNameCCIPMessageSent)
229+
}
230+
destChainAttributeIndex, ok := attributeIndexes[consts.EventAttributeDestChain]
231+
if !ok {
232+
return nil, fmt.Errorf("failed to find index for attribute %s for event %s", consts.EventAttributeDestChain, consts.EventNameCCIPMessageSent)
233+
}
234+
subKeyFilter, err := logpoller.NewEventBySubKeyFilter(destChainAttributeIndex, []primitives.ValueComparator{{Value: dest, Operator: primitives.Eq}},)
235+
if err != nil {
236+
return nil, fmt.Errorf("failed to build event sub key filter for dest chain attribute: %w", err)
237+
}
238+
226239
expressions := []query.Expression{
227240
logpoller.NewAddressFilter(onrampAddr),
228241
logpoller.NewEventSigFilter(logpollertypes.NewEventSignatureFromName(consts.EventNameCCIPMessageSent)),
229-
query.Comparator(consts.EventAttributeDestChain, primitives.ValueComparator{
230-
Value: dest,
231-
Operator: primitives.Eq,
232-
}),
242+
subKeyFilter,
233243
query.Comparator(consts.EventAttributeSequenceNumber, primitives.ValueComparator{
234244
Value: seqNumRange.Start(),
235245
Operator: primitives.Gte,
@@ -285,13 +295,23 @@ func (a *SolanaAccessor) LatestMessageTo(ctx context.Context, dest ccipocr3.Chai
285295
return 0, fmt.Errorf("OnRamp not bound: %w", err)
286296
}
287297

298+
attributeIndexes, ok := eventFilterSubkeyIndexMap[consts.EventNameCCIPMessageSent]
299+
if !ok {
300+
return 0, fmt.Errorf("failed to find attribute indexes for event %s", consts.EventNameCCIPMessageSent)
301+
}
302+
destChainAttributeIndex, ok := attributeIndexes[consts.EventAttributeDestChain]
303+
if !ok {
304+
return 0, fmt.Errorf("failed to find index for attribute %s for event %s", consts.EventAttributeDestChain, consts.EventNameCCIPMessageSent)
305+
}
306+
subKeyFilter, err := logpoller.NewEventBySubKeyFilter(destChainAttributeIndex, []primitives.ValueComparator{{Value: dest, Operator: primitives.Eq}},)
307+
if err != nil {
308+
return 0, fmt.Errorf("failed to build event sub key filter for dest chain attribute: %w", err)
309+
}
310+
288311
expressions := []query.Expression{
289312
logpoller.NewAddressFilter(onrampAddr),
290313
logpoller.NewEventSigFilter(logpollertypes.NewEventSignatureFromName(consts.EventNameCCIPMessageSent)),
291-
query.Comparator(consts.EventAttributeDestChain, primitives.ValueComparator{
292-
Value: dest,
293-
Operator: primitives.Eq,
294-
}),
314+
subKeyFilter,
295315
query.Confidence(primitives.Finalized),
296316
}
297317

@@ -486,7 +506,10 @@ func (a *SolanaAccessor) ExecutedMessages(ctx context.Context, ranges map[ccipoc
486506
}
487507
}
488508

489-
keyFilter, countSqNrs := createExecutedMessagesKeyFilter(nonEmptyRangesPerChain)
509+
keyFilter, countSqNrs, err := createExecutedMessagesKeyFilter(nonEmptyRangesPerChain)
510+
if err != nil {
511+
return nil, fmt.Errorf("failed to build key filter for executed messages: %w", err)
512+
}
490513
if countSqNrs == 0 {
491514
a.lggr.Debugw("no sequence numbers to query", "nonEmptyRangesPerChain", nonEmptyRangesPerChain)
492515
return nil, nil

0 commit comments

Comments
 (0)