From 7e73b0683f0ba77fe32b6c115dc2a55b7933890a Mon Sep 17 00:00:00 2001 From: LexLuthr Date: Thu, 30 Mar 2023 12:57:23 +0530 Subject: [PATCH 1/6] log insert --- retrievalmarket/rtvllog/retrieval_log.go | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/retrievalmarket/rtvllog/retrieval_log.go b/retrievalmarket/rtvllog/retrieval_log.go index 7d51140cf..640ce22a5 100644 --- a/retrievalmarket/rtvllog/retrieval_log.go +++ b/retrievalmarket/rtvllog/retrieval_log.go @@ -2,6 +2,7 @@ package rtvllog import ( "context" + "fmt" "sync" "time" @@ -58,6 +59,34 @@ func (r *RetrievalLog) OnQueryEvent(evt retrievalmarket.ProviderQueryEvent) { "status", evt.Response.Status, "msg", evt.Response.Message, "err", evt.Error) + + // Log failures to DB + if evt.Error != nil { + st := &RetrievalDealState{ + Status: fmt.Sprintf("failed to respond to the query: %s", evt.Error.Error()), + UnsealPrice: evt.Response.UnsealPrice, + Message: evt.Response.Message, + } + r.db.Insert(r.ctx, st) + } else { + if evt.Response.Status == retrievalmarket.QueryResponseUnavailable { + st := &RetrievalDealState{ + Status: "retrieval query offer was unavailable", + UnsealPrice: evt.Response.UnsealPrice, + Message: evt.Response.Message, + } + r.db.Insert(r.ctx, st) + } + + if evt.Response.Status == retrievalmarket.QueryResponseError { + st := &RetrievalDealState{ + Status: "retrieval query offer errored", + UnsealPrice: evt.Response.UnsealPrice, + Message: evt.Response.Message, + } + r.db.Insert(r.ctx, st) + } + } } // Called when there is a validation event. From 67947330a1c982dd0d490944b5b39b34d12ef486 Mon Sep 17 00:00:00 2001 From: LexLuthr Date: Tue, 4 Apr 2023 22:45:49 +0530 Subject: [PATCH 2/6] fix display error --- retrievalmarket/rtvllog/db.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/retrievalmarket/rtvllog/db.go b/retrievalmarket/rtvllog/db.go index 6c8a156db..8f70b149c 100644 --- a/retrievalmarket/rtvllog/db.go +++ b/retrievalmarket/rtvllog/db.go @@ -227,7 +227,8 @@ func (d *RetrievalLogDB) list(ctx context.Context, offset int, limit int, where dealState.PayloadCID, err = cid.Parse(payloadCid.String) if err != nil { - return nil, fmt.Errorf("parsing payload cid '%s': %w", payloadCid.String, err) + //return nil, fmt.Errorf("parsing payload cid '%s': %w", payloadCid.String, err) + dealState.PayloadCID = cid.Undef } if pieceCid.Valid && pieceCid.String != "" { From 8d7c43600cf19f8b068f7fe113e379b3ae82d58a Mon Sep 17 00:00:00 2001 From: LexLuthr Date: Tue, 4 Apr 2023 23:18:19 +0530 Subject: [PATCH 3/6] refactor code --- retrievalmarket/rtvllog/retrieval_log.go | 34 +++++++++++------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/retrievalmarket/rtvllog/retrieval_log.go b/retrievalmarket/rtvllog/retrieval_log.go index 640ce22a5..f1b8b5c0f 100644 --- a/retrievalmarket/rtvllog/retrieval_log.go +++ b/retrievalmarket/rtvllog/retrieval_log.go @@ -61,32 +61,28 @@ func (r *RetrievalLog) OnQueryEvent(evt retrievalmarket.ProviderQueryEvent) { "err", evt.Error) // Log failures to DB + st := &RetrievalDealState{ + UnsealPrice: evt.Response.UnsealPrice, + Message: evt.Response.Message, + } if evt.Error != nil { - st := &RetrievalDealState{ - Status: fmt.Sprintf("failed to respond to the query: %s", evt.Error.Error()), - UnsealPrice: evt.Response.UnsealPrice, - Message: evt.Response.Message, - } - r.db.Insert(r.ctx, st) + st.Status = fmt.Sprintf("failed to respond to the query: %s", evt.Error.Error()) } else { if evt.Response.Status == retrievalmarket.QueryResponseUnavailable { - st := &RetrievalDealState{ - Status: "retrieval query offer was unavailable", - UnsealPrice: evt.Response.UnsealPrice, - Message: evt.Response.Message, - } - r.db.Insert(r.ctx, st) + st.Status = "retrieval query offer was unavailable" } - if evt.Response.Status == retrievalmarket.QueryResponseError { - st := &RetrievalDealState{ - Status: "retrieval query offer errored", - UnsealPrice: evt.Response.UnsealPrice, - Message: evt.Response.Message, - } - r.db.Insert(r.ctx, st) + st.Status = "retrieval query offer errored" } } + if st.Status != "" { + r.dbUpdate(func() { + err := r.db.Insert(r.ctx, st) + if err != nil { + log.Errorw("failed to update retrieval deal logger db", "err", err) + } + }) + } } // Called when there is a validation event. From 8c0451094bcbd46a168f8138bc96a167a46ca881 Mon Sep 17 00:00:00 2001 From: LexLuthr Date: Wed, 5 Apr 2023 14:00:20 +0530 Subject: [PATCH 4/6] shorten status strings --- retrievalmarket/rtvllog/retrieval_log.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/retrievalmarket/rtvllog/retrieval_log.go b/retrievalmarket/rtvllog/retrieval_log.go index f1b8b5c0f..a787a3fb3 100644 --- a/retrievalmarket/rtvllog/retrieval_log.go +++ b/retrievalmarket/rtvllog/retrieval_log.go @@ -2,7 +2,6 @@ package rtvllog import ( "context" - "fmt" "sync" "time" @@ -66,13 +65,13 @@ func (r *RetrievalLog) OnQueryEvent(evt retrievalmarket.ProviderQueryEvent) { Message: evt.Response.Message, } if evt.Error != nil { - st.Status = fmt.Sprintf("failed to respond to the query: %s", evt.Error.Error()) + st.Status = evt.Error.Error() } else { if evt.Response.Status == retrievalmarket.QueryResponseUnavailable { - st.Status = "retrieval query offer was unavailable" + st.Status = "unavailable" } if evt.Response.Status == retrievalmarket.QueryResponseError { - st.Status = "retrieval query offer errored" + st.Status = "errored" } } if st.Status != "" { From f61e8e5c1c647ae0e6d5e88bf8d78c931e20b674 Mon Sep 17 00:00:00 2001 From: LexLuthr Date: Wed, 5 Apr 2023 14:06:59 +0530 Subject: [PATCH 5/6] remove comment --- retrievalmarket/rtvllog/db.go | 1 - 1 file changed, 1 deletion(-) diff --git a/retrievalmarket/rtvllog/db.go b/retrievalmarket/rtvllog/db.go index 8f70b149c..a1b25d214 100644 --- a/retrievalmarket/rtvllog/db.go +++ b/retrievalmarket/rtvllog/db.go @@ -227,7 +227,6 @@ func (d *RetrievalLogDB) list(ctx context.Context, offset int, limit int, where dealState.PayloadCID, err = cid.Parse(payloadCid.String) if err != nil { - //return nil, fmt.Errorf("parsing payload cid '%s': %w", payloadCid.String, err) dealState.PayloadCID = cid.Undef } From 8298a4aca624f9b36dcde63978a2827aafb1bed1 Mon Sep 17 00:00:00 2001 From: LexLuthr Date: Wed, 5 Apr 2023 15:20:18 +0530 Subject: [PATCH 6/6] apply suggestion --- retrievalmarket/rtvllog/retrieval_log.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/retrievalmarket/rtvllog/retrieval_log.go b/retrievalmarket/rtvllog/retrieval_log.go index a787a3fb3..c1f27e350 100644 --- a/retrievalmarket/rtvllog/retrieval_log.go +++ b/retrievalmarket/rtvllog/retrieval_log.go @@ -65,7 +65,10 @@ func (r *RetrievalLog) OnQueryEvent(evt retrievalmarket.ProviderQueryEvent) { Message: evt.Response.Message, } if evt.Error != nil { - st.Status = evt.Error.Error() + st.Status = "Failed" + if evt.Response.Message == "" { + st.Message = evt.Error.Error() + } } else { if evt.Response.Status == retrievalmarket.QueryResponseUnavailable { st.Status = "unavailable"