Skip to content

Commit

Permalink
worker: remove context value interaction recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger authored and ChrisSchinnerl committed Feb 14, 2024
1 parent 96a697a commit 16b1605
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
4 changes: 3 additions & 1 deletion worker/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type (
logger *zap.SugaredLogger
transportPool *transportPoolV3
priceTables *priceTables
interactionRecorder HostInteractionRecorder
}
)

Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 0 additions & 8 deletions worker/interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 16b1605

Please sign in to comment.