Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
fixing pruning time issues + node crashing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Apr 18, 2024
1 parent e60ba10 commit 3291b66
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jprov/server/file_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
40 changes: 40 additions & 0 deletions jprov/server/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"strconv"
"time"

query "github.com/cosmos/cosmos-sdk/types/query"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3291b66

Please sign in to comment.