From 16b16052141bc54429bb0fc68a3da193b6e39723 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Tue, 13 Feb 2024 14:05:23 -0800 Subject: [PATCH] worker: remove context value interaction recorder --- worker/host.go | 4 +++- worker/interactions.go | 8 -------- worker/worker.go | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/worker/host.go b/worker/host.go index fcaac0cf1..2aa97d57a 100644 --- a/worker/host.go +++ b/worker/host.go @@ -55,6 +55,7 @@ type ( logger *zap.SugaredLogger transportPool *transportPoolV3 priceTables *priceTables + interactionRecorder HostInteractionRecorder } ) @@ -76,6 +77,7 @@ func (w *worker) Host(hk types.PublicKey, fcid types.FileContractID, siamuxAddr accountKey: w.accounts.deriveAccountKey(hk), transportPool: w.transportPoolV3, priceTables: w.priceTables, + interactionRecorder: w.hostInteractionRecorder, } } @@ -196,7 +198,7 @@ func (h *host) FetchPriceTable(ctx context.Context, rev *types.FileContractRevis fetchPT := func(paymentFn PriceTablePaymentFunc) (hpt hostdb.HostPriceTable, err error) { err = h.transportPool.withTransportV3(ctx, h.hk, h.siamuxAddr, func(ctx context.Context, t *transportV3) (err error) { hpt, err = RPCPriceTable(ctx, t, paymentFn) - HostInteractionRecorderFromContext(ctx).RecordPriceTableUpdate(hostdb.PriceTableUpdate{ + h.interactionRecorder.RecordPriceTableUpdate(hostdb.PriceTableUpdate{ HostKey: h.hk, Success: isSuccessfulInteraction(err), Timestamp: time.Now(), diff --git a/worker/interactions.go b/worker/interactions.go index 70629c1f0..a011cc0d4 100644 --- a/worker/interactions.go +++ b/worker/interactions.go @@ -42,14 +42,6 @@ var ( _ HostInteractionRecorder = (*hostInteractionRecorder)(nil) ) -func HostInteractionRecorderFromContext(ctx context.Context) HostInteractionRecorder { - ir, ok := ctx.Value(keyInteractionRecorder).(HostInteractionRecorder) - if !ok { - panic("no interaction recorder attached to the context") // developer error - } - return ir -} - func interactionMiddleware(ir HostInteractionRecorder, routes map[string]jape.Handler) map[string]jape.Handler { for route, handler := range routes { routes[route] = jape.Adapt(func(h http.Handler) http.Handler { diff --git a/worker/worker.go b/worker/worker.go index b917960d4..c76329aeb 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -342,7 +342,7 @@ func (w *worker) rhpPriceTableHandler(jc jape.Context) { var err error var hpt hostdb.HostPriceTable defer func() { - HostInteractionRecorderFromContext(ctx).RecordPriceTableUpdate(hostdb.PriceTableUpdate{ + w.hostInteractionRecorder.RecordPriceTableUpdate(hostdb.PriceTableUpdate{ HostKey: rptr.HostKey, Success: isSuccessfulInteraction(err), Timestamp: time.Now(), @@ -1442,7 +1442,7 @@ func (w *worker) scanHost(ctx context.Context, hostKey types.PublicKey, hostIP s } // record host scan - HostInteractionRecorderFromContext(ctx).RecordHostScan(hostdb.HostScan{ + w.hostInteractionRecorder.RecordHostScan(hostdb.HostScan{ HostKey: hostKey, Success: isSuccessfulInteraction(err), Timestamp: time.Now(),