diff --git a/internal/fetch/fetch.go b/internal/fetch/fetch.go index 929c2b8..355f64f 100644 --- a/internal/fetch/fetch.go +++ b/internal/fetch/fetch.go @@ -55,7 +55,7 @@ func ShouldFetchSnapshot( if localBaseSlot < remote[0].BaseSlot { advice = AdviceFetchFull return - } else if localBaseSlot == remote[0].BaseSlot { + } else if len(local) > 0 && localBaseSlot == remote[0].BaseSlot { for _, l := range local[0].Files { for _, r := range remote[0].Files { if l.BaseSlot == 0 && r.BaseSlot == 0 { diff --git a/internal/fetch/fetch_test.go b/internal/fetch/fetch_test.go index 68777cf..5bbad5c 100644 --- a/internal/fetch/fetch_test.go +++ b/internal/fetch/fetch_test.go @@ -49,7 +49,7 @@ func TestShouldFetchSnapshot(t *testing.T) { minAge: 500, maxAge: 10000, minSlot: 113456, - advice: AdviceFetch, + advice: AdviceFetchFull, }, { name: "LowSlotNumber", @@ -58,7 +58,7 @@ func TestShouldFetchSnapshot(t *testing.T) { minAge: 50, maxAge: 10000, minSlot: 0, - advice: AdviceFetch, + advice: AdviceFetchFull, }, { name: "Refresh", @@ -67,7 +67,7 @@ func TestShouldFetchSnapshot(t *testing.T) { minAge: 500, maxAge: 10000, minSlot: 113456, - advice: AdviceFetch, + advice: AdviceFetchFull, }, { name: "NotNewEnough", @@ -107,7 +107,8 @@ func fakeSnapshotInfo(slots []uint64) []*types.SnapshotInfo { infos := make([]*types.SnapshotInfo, len(slots)) for i, slot := range slots { infos[i] = &types.SnapshotInfo{ - Slot: slot, + Slot: slot, + BaseSlot: slot, } } return infos @@ -118,7 +119,8 @@ func fakeSnapshotSources(slots []uint64) []types.SnapshotSource { for i, slot := range slots { infos[i] = types.SnapshotSource{ SnapshotInfo: types.SnapshotInfo{ - Slot: slot, + Slot: slot, + BaseSlot: slot, }, } } diff --git a/internal/fetch/sidecar.go b/internal/fetch/sidecar.go index b8d186c..fb9a505 100644 --- a/internal/fetch/sidecar.go +++ b/internal/fetch/sidecar.go @@ -90,7 +90,7 @@ func (c *SidecarClient) ListSnapshots(ctx context.Context) (infos []*types.Snaps // The returned response is guaranteed to have a valid ContentLength. // The caller has the responsibility to close the response body even if the error is not nil. func (c *SidecarClient) StreamSnapshot(ctx context.Context, name string) (res *http.Response, err error) { - snapURL := "http://" + c.resty.HostURL + "/v1/snapshot/" + url.PathEscape(name) // TODO: Don't hardcode scheme + snapURL := c.resty.HostURL + "/v1/snapshot/" + url.PathEscape(name) // TODO: Don't hardcode scheme c.log.Info("Downloading snapshot", zap.String("snapshot_url", snapURL)) req, err := http.NewRequestWithContext(ctx, http.MethodGet, snapURL, nil) if err != nil { diff --git a/internal/integrationtest/sidecar_test.go b/internal/integrationtest/sidecar_test.go index fc794cd..fbff1db 100644 --- a/internal/integrationtest/sidecar_test.go +++ b/internal/integrationtest/sidecar_test.go @@ -39,6 +39,7 @@ import ( func TestSidecar(t *testing.T) { server, root := newSidecar(t, 100) defer server.Close() + fmt.Println("Server url", server.URL) client := fetch.NewSidecarClientWithOpts(server.URL, fetch.SidecarClientOpts{Resty: resty.NewWithClient(server.Client())}) @@ -51,6 +52,7 @@ func TestSidecar(t *testing.T) { []*types.SnapshotInfo{ { Slot: 100, + BaseSlot: 100, Hash: solana.MustHashFromBase58("7jMmeXZSNcWPrB2RsTdeXfXrsyW5c1BfPjqoLW2X5T7V"), TotalSize: 1, Files: []*types.SnapshotFile{ diff --git a/internal/integrationtest/tracker_test.go b/internal/integrationtest/tracker_test.go index c4b0a60..1ba698e 100644 --- a/internal/integrationtest/tracker_test.go +++ b/internal/integrationtest/tracker_test.go @@ -106,6 +106,7 @@ func TestTracker(t *testing.T) { { SnapshotInfo: types.SnapshotInfo{ Slot: 103, + BaseSlot: 103, Hash: solana.MustHashFromBase58("7w4zb1jh47zY5FPMPyRzDSmYf1CPirVP9LmTr5xWEs6X"), Files: []*types.SnapshotFile{ { @@ -122,6 +123,7 @@ func TestTracker(t *testing.T) { { SnapshotInfo: types.SnapshotInfo{ Slot: 102, + BaseSlot: 102, Hash: solana.MustHashFromBase58("7sAawX1cAHVpfZGNtUAYKX2KPzdd1uPUZUTaLteWX4SB"), Files: []*types.SnapshotFile{ { @@ -138,6 +140,7 @@ func TestTracker(t *testing.T) { { SnapshotInfo: types.SnapshotInfo{ Slot: 101, + BaseSlot: 101, Hash: solana.MustHashFromBase58("7oGBJ2HXGT17Fs9QNxu6RbH68z4rJxHZyc9gqhLWoFmq"), Files: []*types.SnapshotFile{ { @@ -154,6 +157,7 @@ func TestTracker(t *testing.T) { { SnapshotInfo: types.SnapshotInfo{ Slot: 100, + BaseSlot: 100, Hash: solana.MustHashFromBase58("7jMmeXZSNcWPrB2RsTdeXfXrsyW5c1BfPjqoLW2X5T7V"), Files: []*types.SnapshotFile{ { @@ -172,7 +176,7 @@ func TestTracker(t *testing.T) { } func newTracker(db *index.DB) *httptest.Server { - handler := tracker.NewHandler(db) + handler := tracker.NewHandler(db, "http://localhost:8899", 1000) gin.SetMode(gin.ReleaseMode) engine := gin.New() handler.RegisterHandlers(engine.Group("/v1")) diff --git a/internal/ledger/snapshot_test.go b/internal/ledger/snapshot_test.go index 9890f53..1acaf02 100644 --- a/internal/ledger/snapshot_test.go +++ b/internal/ledger/snapshot_test.go @@ -51,6 +51,7 @@ func TestListSnapshots(t *testing.T) { []*types.SnapshotInfo{ { Slot: 300, + BaseSlot: 100, Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"), TotalSize: 3, Files: []*types.SnapshotFile{ @@ -84,6 +85,7 @@ func TestListSnapshots(t *testing.T) { }, { Slot: 200, + BaseSlot: 100, Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"), TotalSize: 2, Files: []*types.SnapshotFile{ @@ -108,6 +110,7 @@ func TestListSnapshots(t *testing.T) { }, { Slot: 100, + BaseSlot: 100, Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"), TotalSize: 1, Files: []*types.SnapshotFile{ @@ -123,6 +126,7 @@ func TestListSnapshots(t *testing.T) { }, { Slot: 100, + BaseSlot: 50, Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"), TotalSize: 2, Files: []*types.SnapshotFile{ @@ -147,6 +151,7 @@ func TestListSnapshots(t *testing.T) { }, { Slot: 50, + BaseSlot: 50, Hash: solana.MustHashFromBase58("AvFf9oS8A8U78HdjT9YG2sTTThLHJZmhaMn2g8vkWYnr"), TotalSize: 1, Files: []*types.SnapshotFile{