-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: check eth events indexed in range #12728
Changes from 2 commits
d0d52b5
9f824d1
1bcf220
17ab3d3
37c3f85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -256,6 +256,8 @@ func (si *SqliteIndexer) checkTipsetIndexedStatus(ctx context.Context, f *EventF | |||||
|
||||||
return xerrors.Errorf("failed to get tipset key cid by height: %w", err) | ||||||
} | ||||||
case f.MinHeight >= 0 && f.MaxHeight >= 0 && f.MinHeight != f.MaxHeight: | ||||||
return si.checkRangeIndexedStatus(ctx, f) | ||||||
default: | ||||||
// This function distinguishes between two scenarios: | ||||||
// 1. Missing events: The requested tipset is not present in the Index (an error condition). | ||||||
|
@@ -280,6 +282,39 @@ func (si *SqliteIndexer) checkTipsetIndexedStatus(ctx context.Context, f *EventF | |||||
return ErrNotFound // Tipset is not indexed | ||||||
} | ||||||
|
||||||
func (si *SqliteIndexer) checkRangeIndexedStatus(ctx context.Context, f *EventFilter) error { | ||||||
startCid, err := si.getTipsetKeyCidByHeight(ctx, f.MinHeight) | ||||||
if err != nil { | ||||||
if errors.Is(err, ErrNotFound) { | ||||||
// Null round for the start of the range is acceptable | ||||||
return nil | ||||||
} | ||||||
return xerrors.Errorf("failed to get tipset key cid for start height: %w", err) | ||||||
} | ||||||
|
||||||
endCid, err := si.getTipsetKeyCidByHeight(ctx, f.MaxHeight) | ||||||
if err != nil { | ||||||
if errors.Is(err, ErrNotFound) { | ||||||
// Check if the range ends in the future | ||||||
head := si.cs.GetHeaviestTipSet() | ||||||
if head == nil || f.MaxHeight > head.Height() { | ||||||
return xerrors.Errorf("range end is in the future: %w", err) | ||||||
} | ||||||
return ErrNotFound // End is unindexed | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're back in the null round case, I think that we should walk backward to find the first non-null lower than Basically: let's contract the range if the edges contain null rounds, walk inward until we find a min and max that are not null rounds. Be careful not to iterate beyond the other bound (don't increment from Min beyond the Max value, and don't decrement from Max beyond the Min value). The special case is when there are only null rounds between them, don't error, just return. There's another special case of contracting to min==max, you could easily do an |
||||||
} | ||||||
return xerrors.Errorf("failed to get tipset key cid for end height: %w", err) | ||||||
} | ||||||
|
||||||
if exists, err := si.isTipsetIndexed(ctx, startCid); err != nil || !exists { | ||||||
return xerrors.Errorf("start tipset not indexed: %w", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
if exists, err := si.isTipsetIndexed(ctx, endCid); err != nil || !exists { | ||||||
return xerrors.Errorf("end tipset not indexed: %w", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
// getTipsetKeyCidByHeight retrieves the tipset key CID for a given height. | ||||||
func (si *SqliteIndexer) getTipsetKeyCidByHeight(ctx context.Context, height abi.ChainEpoch) ([]byte, error) { | ||||||
ts, err := si.cs.GetTipsetByHeight(ctx, height, nil, false) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the
ErrNotFound
case, I'd like it to increment by1
until it finds one <=MaxHeight
that's not a null round.In the special case where there are only null rounds between
MinHeight
andMaxHeight
, pretend that it's indexed and don't return an error, they'll just get no results.So you'll need a loop here, and a local copy of
f.MinHeight
to increment.