Skip to content

Commit

Permalink
Merge branch 'main' into dk/commit-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkouv authored Nov 5, 2024
2 parents a1e0e17 + fa3a001 commit c3882af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
3 changes: 2 additions & 1 deletion pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ const (
const (
EventAttributeSequenceNumber = "SequenceNumber"
EventAttributeSourceChain = "SourceChain"
EventAttributeDestChain = "destChain"
EventAttributeDestChain = "DestChain"
EventAttributeState = "State"
)

// Dedicated filters
Expand Down
62 changes: 32 additions & 30 deletions pkg/reader/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (r *ccipChainReader) CommitReportsGTETimestamp(
query.KeyFilter{
Key: consts.EventNameCommitReportAccepted,
Expressions: []query.Expression{
query.Timestamp(uint64(ts.Unix()), primitives.Gte),
query.Confidence(primitives.Finalized),
},
},
Expand All @@ -150,15 +151,6 @@ func (r *ccipChainReader) CommitReportsGTETimestamp(
return nil, fmt.Errorf("unexpected type %T while expecting a commit report", item)
}

valid := item.Timestamp >= uint64(ts.Unix())
if !valid {
r.lggr.Debugw("commit report too old, skipping", "report", ev, "item", item,
"destChain", dest,
"ts", ts,
"limit", limit)
continue
}

r.lggr.Debugw("processing commit report", "report", ev, "item", item)

merkleRoots := make([]cciptypes.MerkleRootChain, 0, len(ev.MerkleRoots))
Expand Down Expand Up @@ -245,6 +237,21 @@ func (r *ccipChainReader) ExecutedMessageRanges(
query.KeyFilter{
Key: consts.EventNameExecutionStateChanged,
Expressions: []query.Expression{
query.Comparator(consts.EventAttributeSourceChain, primitives.ValueComparator{
Value: source,
Operator: primitives.Eq,
}),
query.Comparator(consts.EventAttributeSequenceNumber, primitives.ValueComparator{
Value: seqNumRange.Start(),
Operator: primitives.Gte,
}, primitives.ValueComparator{
Value: seqNumRange.End(),
Operator: primitives.Lte,
}),
query.Comparator(consts.EventAttributeState, primitives.ValueComparator{
Value: 0,
Operator: primitives.Gt,
}),
query.Confidence(primitives.Finalized),
},
},
Expand All @@ -263,17 +270,6 @@ func (r *ccipChainReader) ExecutedMessageRanges(
if !ok {
return nil, fmt.Errorf("failed to cast %T to executionStateChangedEvent", item.Data)
}

// todo: filter via the query
valid := stateChange.SourceChainSelector == source &&
stateChange.SequenceNumber >= seqNumRange.Start() &&
stateChange.SequenceNumber <= seqNumRange.End() &&
stateChange.State > 0
if !valid {
r.lggr.Debugw("skipping invalid state change", "stateChange", stateChange)
continue
}

executed = append(executed, cciptypes.NewSeqNumRange(stateChange.SequenceNumber, stateChange.SequenceNumber))
}

Expand Down Expand Up @@ -353,6 +349,21 @@ func (r *ccipChainReader) MsgsBetweenSeqNums(
query.KeyFilter{
Key: consts.EventNameCCIPMessageSent,
Expressions: []query.Expression{
query.Comparator(consts.EventAttributeSourceChain, primitives.ValueComparator{
Value: sourceChainSelector,
Operator: primitives.Eq,
}),
query.Comparator(consts.EventAttributeDestChain, primitives.ValueComparator{
Value: r.destChain,
Operator: primitives.Eq,
}),
query.Comparator(consts.EventAttributeSequenceNumber, primitives.ValueComparator{
Value: seqNumRange.Start(),
Operator: primitives.Gte,
}, primitives.ValueComparator{
Value: seqNumRange.End(),
Operator: primitives.Lte,
}),
query.Confidence(primitives.Finalized),
},
},
Expand Down Expand Up @@ -380,17 +391,8 @@ func (r *ccipChainReader) MsgsBetweenSeqNums(
return nil, fmt.Errorf("failed to cast %v to Message", item.Data)
}

// todo: filter via the query
valid := msg.Message.Header.SourceChainSelector == sourceChainSelector &&
msg.Message.Header.DestChainSelector == r.destChain &&
msg.Message.Header.SequenceNumber >= seqNumRange.Start() &&
msg.Message.Header.SequenceNumber <= seqNumRange.End()

msg.Message.Header.OnRamp = onRampAddress

if valid {
msgs = append(msgs, msg.Message.ToMessage())
}
msgs = append(msgs, msg.Message.ToMessage())
}

r.lggr.Infow("decoded messages between sequence numbers", "msgs", msgs,
Expand Down

0 comments on commit c3882af

Please sign in to comment.