Skip to content

Commit

Permalink
Fix tx fetch (#94)
Browse files Browse the repository at this point in the history
* Improve logs

* Fix ts search in epochs
  • Loading branch information
gagliardetto authored Mar 4, 2024
1 parent 2ad5b9b commit 66de97f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
38 changes: 11 additions & 27 deletions multiepoch-getTransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (multi *MultiEpoch) findEpochNumberFromSignature(ctx context.Context, sig s
return epochs[0], nil
}

// Linear search:
numbers := multi.GetEpochNumbers()
// sort from highest to lowest:
sort.Slice(numbers, func(i, j int) bool {
Expand All @@ -48,37 +47,22 @@ func (multi *MultiEpoch) findEpochNumberFromSignature(ctx context.Context, sig s

buckets := multi.getAllBucketteers()

found := make([]uint64, 0)
startedSearchingCandidatesAt := time.Now()
for _, epochNumber := range numbers {
bucket, ok := buckets[epochNumber]
if !ok {
continue
}
if has, err := bucket.Has(sig); err != nil {
return 0, fmt.Errorf("failed to check if signature exists in bucket: %w", err)
} else if has {
found = append(found, epochNumber)
}
}
klog.V(4).Infof(
"Searched %d epochs in %s, and found %d candidate epochs for signature %s: %v",
len(numbers),
time.Since(startedSearchingCandidatesAt),
len(found),
sig,
found,
)

if len(found) == 0 {
return 0, ErrNotFound
}

// Search all epochs in parallel:
wg := NewFirstResponse(ctx, multi.options.EpochSearchConcurrency)
for i := range numbers {
epochNumber := numbers[i]
wg.Spawn(func() (any, error) {
bucket, ok := buckets[epochNumber]
if !ok {
return nil, nil
}
has, err := bucket.Has(sig)
if err != nil {
return 0, fmt.Errorf("failed to check if signature exists in bucket: %w", err)
}
if !has {
return nil, nil
}
epoch, err := multi.GetEpoch(epochNumber)
if err != nil {
return nil, fmt.Errorf("failed to get epoch %d: %w", epochNumber, err)
Expand Down
3 changes: 1 addition & 2 deletions split-car-fetcher/remote-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"net/http"
"path/filepath"
"time"

"github.com/goware/urlx"
Expand Down Expand Up @@ -35,7 +34,7 @@ func NewRemoteHTTPFileAsIoReaderAt(ctx context.Context, url string) (ReaderAtClo
if err != nil {
return nil, 0, err
}
name := filepath.Base(parsedURL.Path)
name := parsedURL.Path

rc := rangecache.NewRangeCache(
contentLength,
Expand Down

0 comments on commit 66de97f

Please sign in to comment.