From 3291b66b8768d572a97687241f6a72b11966f092 Mon Sep 17 00:00:00 2001 From: marston Date: Thu, 18 Apr 2024 11:55:48 -0400 Subject: [PATCH] fixing pruning time issues + node crashing issues --- jprov/server/file_server.go | 2 +- jprov/server/query.go | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/jprov/server/file_server.go b/jprov/server/file_server.go index 76f5c31..8b3b91f 100644 --- a/jprov/server/file_server.go +++ b/jprov/server/file_server.go @@ -235,7 +235,7 @@ func (f *FileServer) Init() error { } func (f *FileServer) RecollectActiveDeals() error { - queryActiveDeals, err := f.QueryMyActiveDeals() + queryActiveDeals, err := f.QueryOnlyMyActiveDeals() if err != nil { return err } diff --git a/jprov/server/query.go b/jprov/server/query.go index bc4c2e2..3f02693 100644 --- a/jprov/server/query.go +++ b/jprov/server/query.go @@ -2,6 +2,7 @@ package server import ( "strconv" + "time" query "github.com/cosmos/cosmos-sdk/types/query" @@ -73,6 +74,45 @@ func (f *FileServer) QueryAllActiveDeals() ([]storageTypes.ActiveDeals, error) { return activeDeals, nil } +func (f *FileServer) QueryOnlyMyActiveDeals() ([]storageTypes.ActiveDeals, error) { + req := storageTypes.QueryAllActiveDealsRequest{ + Pagination: &query.PageRequest{CountTotal: true}, + } + + activeDeals := make([]storageTypes.ActiveDeals, 0) + + resp, err := f.queryClient.ActiveDealsAll(f.cmd.Context(), &req) + if err != nil { + return nil, err + } + + for _, a := range resp.ActiveDeals { + if a.Provider == f.provider.Address { + activeDeals = append(activeDeals, a) + } + } + + for len(resp.Pagination.GetNextKey()) != 0 { + req = storageTypes.QueryAllActiveDealsRequest{ + Pagination: &query.PageRequest{Key: resp.Pagination.GetNextKey()}, + } + + r, err := f.queryClient.ActiveDealsAll(f.cmd.Context(), &req) + if err != nil { + time.Sleep(time.Second * 60) // we wait for a full minute if the request fails and try again + continue + } + resp = r // we only update the pagination key if the request was successful + for _, a := range resp.ActiveDeals { + if a.Provider == f.provider.Address { + activeDeals = append(activeDeals, a) + } + } + } + + return activeDeals, nil +} + func filterMyActiveDeals(activeDeals []storageTypes.ActiveDeals, provider string) []storageTypes.ActiveDeals { if activeDeals == nil { return nil