diff --git a/cmd-rpc-server-car-getTransaction.go b/cmd-rpc-server-car-getTransaction.go index 5540b694..29ec8340 100644 --- a/cmd-rpc-server-car-getTransaction.go +++ b/cmd-rpc-server-car-getTransaction.go @@ -288,6 +288,10 @@ func adaptTransactionMetaToExpectedOutput(m map[string]any) map[string]any { if !ok { continue } + // If doesn't have `index`, then set it to 0 + if _, ok := innerInstruction["index"]; !ok { + innerInstruction["index"] = 0 + } instructionsAny, ok := innerInstruction["instructions"] if !ok { continue diff --git a/http-range.go b/http-range.go index c66e6a0b..591d0d88 100644 --- a/http-range.go +++ b/http-range.go @@ -9,6 +9,8 @@ import ( "path/filepath" "strings" "time" + + "github.com/goware/urlx" ) type ReaderAtCloser interface { @@ -71,10 +73,15 @@ func remoteHTTPFileAsIoReaderAt(ctx context.Context, url string) (ReaderAtCloser contentLength: contentLength, client: newHTTPClient(), } + parsedURL, err := urlx.Parse(url) + if err != nil { + return nil, err + } + name := filepath.Base(parsedURL.Path) rc := NewRangeCache( contentLength, - filepath.Base(url), + name, func(p []byte, off int64) (n int, err error) { return remoteReadAt(rr.client, rr.url, p, off) }) diff --git a/multiepoch-getBlock.go b/multiepoch-getBlock.go index 33a08ef8..18650314 100644 --- a/multiepoch-getBlock.go +++ b/multiepoch-getBlock.go @@ -125,16 +125,25 @@ func (multi *MultiEpoch) handleGetBlock(ctx context.Context, conn *requestContex } idealEntrySize := uint64(36190) - maybeOffsetOfLastEntry := parentOffset - idealEntrySize - length += idealEntrySize + var start uint64 + if parentIsInPreviousEpoch { + start = parentOffset + } else { + if parentOffset > idealEntrySize { + start = parentOffset - idealEntrySize + } else { + start = parentOffset + } + length += idealEntrySize + } - klog.Infof("prefetching CAR: start=%d length=%d (parent_offset=%d)", maybeOffsetOfLastEntry, length, parentOffset) - carSection, err := epochHandler.ReadAtFromCar(ctx, maybeOffsetOfLastEntry, length) + klog.Infof("prefetching CAR: start=%d length=%d (parent_offset=%d)", start, length, parentOffset) + carSection, err := epochHandler.ReadAtFromCar(ctx, start, length) if err != nil { return err } dr := bytes.NewReader(carSection) - { + if !parentIsInPreviousEpoch { dr.Seek(int64(idealEntrySize), io.SeekStart) } br := bufio.NewReader(dr) @@ -154,7 +163,7 @@ func (multi *MultiEpoch) handleGetBlock(ctx context.Context, conn *requestContex if errors.Is(err, io.EOF) { break } - return err + return fmt.Errorf("failed to read node: %w", err) } if gotCid.Equals(blockCid) { break @@ -285,7 +294,17 @@ func (multi *MultiEpoch) handleGetBlock(ctx context.Context, conn *requestContex rewardsAsArray := m["rewards"].([]any) for _, reward := range rewardsAsArray { rewardAsMap := reward.(map[string]any) - rewardAsMap["commission"] = nil + if _, ok := rewardAsMap["commission"]; !ok { + rewardAsMap["commission"] = nil + } + // if the commission field is a string, convert it to a float + if asString, ok := rewardAsMap["commission"].(string); ok { + rewardAsMap["commission"] = asFloat(asString) + } + // if no lamports field, add it and set it to 0 + if _, ok := rewardAsMap["lamports"]; !ok { + rewardAsMap["lamports"] = uint64(0) + } // if it has a post_balance field, convert it to postBalance if _, ok := rewardAsMap["post_balance"]; ok { @@ -433,6 +452,15 @@ func (multi *MultiEpoch) handleGetBlock(ctx context.Context, conn *requestContex return nil, nil } +func asFloat(s string) float64 { + var f float64 + _, err := fmt.Sscanf(s, "%f", &f) + if err != nil { + panic(err) + } + return f +} + func mergeTxNodeSlices(slices [][]*ipldbindcode.Transaction) []*ipldbindcode.Transaction { var out []*ipldbindcode.Transaction for _, slice := range slices { diff --git a/range-cache_test.go b/range-cache_test.go index 2fd91fac..794e0a9e 100644 --- a/range-cache_test.go +++ b/range-cache_test.go @@ -13,9 +13,12 @@ func TestCache(t *testing.T) { v := []byte("hello") full := append(v, []byte(" world")...) rd := bytes.NewReader(full) - rc := NewRangeCache(int64(len(full)), func(p []byte, off int64) (n int, err error) { - return rd.ReadAt(p, off) - }) + rc := NewRangeCache( + int64(len(full)), + "test", + func(p []byte, off int64) (n int, err error) { + return rd.ReadAt(p, off) + }) { { diff --git a/solana-block-rewards/rewards.go b/solana-block-rewards/rewards.go index 846d53aa..8bbd2024 100644 --- a/solana-block-rewards/rewards.go +++ b/solana-block-rewards/rewards.go @@ -1,8 +1,8 @@ package solanablockrewards import ( - "github.com/golang/protobuf/proto" "github.com/rpcpool/yellowstone-faithful/third_party/solana_proto/confirmed_block" + "google.golang.org/protobuf/proto" ) func ParseRewards(buf []byte) (*confirmed_block.Rewards, error) {