Skip to content

chore: reduce external dependencies by removing 13 packages#518

Open
icellan wants to merge 8 commits intomainfrom
chore/reduce-external-dependencies
Open

chore: reduce external dependencies by removing 13 packages#518
icellan wants to merge 8 commits intomainfrom
chore/reduce-external-dependencies

Conversation

@icellan
Copy link
Contributor

@icellan icellan commented Feb 19, 2026

Summary

Reduce the external dependency footprint by removing 13 packages from go.mod (473 → 460 lines, go.sum 1395 → 1361 lines). All replacements use either Go stdlib, existing dependencies already in the project, or small internalized implementations.

Motivation

The primary driver was ordishs/go-utils, which was imported in 43 files but pulled in heavy transitive dependencies:

  • uber/jaeger-client-go — deprecated OpenTracing/Jaeger client (teranode uses OpenTelemetry, never called InitGlobalTracer)
  • go.uber.org/atomic — redundant with sync/atomic since Go 1.19
  • uber/jaeger-lib — transitive dep of jaeger-client-go

The go-utils library itself only provided a handful of simple utility functions (ReverseAndHexEncodeSlice, SafeSend, ExpiringMap) that are trivial to implement locally. Internalizing these eliminated the entire jaeger/uber dependency chain.

libsv/go-p2p was only used for test fixture constants (TX1Raw, TX1RawBytes) in 4 test files — inlined as local constants.

Changes by category

Stdlib replacements (zero-risk)

Removed Replacement Files
kpango/fastime time.Now().UnixMilli() 1
golang.org/x/exp/rand crypto/rand 1
golang.org/x/exp/constraints + custom max func builtin max (Go 1.21+) 1
golang.org/x/exp/slices stdlib slices 1
go.uber.org/atomic sync/atomic 2
json-iterator/go encoding/json 1
gocarina/gocsv encoding/csv 1

Consolidation (removed duplicates)

Removed Kept Files
patrickmn/go-cache jellydator/ttlcache/v3 (already in deps) 1
cespare/xxhash v1 cespare/xxhash/v2 (already in deps) 2

Internalized from ordishs/go-utils

What New location Lines
expiringmap.ExpiringMap util/expiringmap/ 178
safemap.Safemap util/safemap/ 101
ReverseAndHexEncodeSlice, DecodeAndReverseHexString, ReverseSlice util/reverse_hex.go 51
SafeSend[T] util/safe_send.go 23
FormatComma (replaced dustin/go-humanize) util/format_comma.go 19
Logger interface switched to existing ulogger.Logger 1

Test fixture inlining

Removed What Files
libsv/go-p2p test.TX1Raw, TX1Hash, TX2RawBytes etc. inlined as local constants 4
joho/godotenv replaced with 20-line loadEnvFile() 1

Dependencies fully removed from go.mod

Direct: kpango/fastime, cespare/xxhash v1, gocarina/gocsv, ordishs/go-utils, libsv/go-p2p, patrickmn/go-cache

Indirect (no longer needed): uber/jaeger-client-go, uber/jaeger-lib, go.uber.org/atomic, golang.org/x/exp, joho/godotenv, dustin/go-humanize, json-iterator/go

Test plan

  • go build ./... passes
  • make lint passes (0 issues)
  • make test passes (pre-existing TestImprovedCache_OverfillGenerationStats failure fixed — bound was too tight for hash distribution variance)
  • go mod tidy is clean
  • No direct imports of removed packages remain: grep -r 'ordishs/go-utils\|libsv/go-p2p' --include='*.go' returns nothing

Remove direct dependency on ordishs/go-utils, libsv/go-p2p, and 11
other external packages by replacing them with stdlib equivalents or
small internal implementations.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2026

🤖 Claude Code Review

Status: Complete

Current Review:

This PR successfully reduces 13 external dependencies by internalizing simple utilities and using stdlib replacements. The internalized code quality is good with proper cleanup patterns.

Unresolved Issue:

  • Goroutine leak in RPC handlers - The ttlcache started at services/rpc/handlers.go:69 is never stopped, causing a background goroutine leak during RPC server shutdown.

Previously Fixed (verified):

  • ✅ ExpiringMap goroutine cleanup implemented
  • ✅ SafeSend timer leak fixed with proper cleanup

@icellan icellan self-assigned this Feb 19, 2026
icellan and others added 2 commits February 19, 2026 12:43
Add Stop() method and use time.NewTicker with a select loop to
prevent goroutine leaks from the background cleanup routine.
icellan and others added 3 commits February 19, 2026 12:57
Call Stop() on every ExpiringMap during service shutdown and test
cleanup to prevent goroutine leaks from background ticker routines.

Production code: added to S3.Close(), SyncManager.Stop(),
SubtreeValidation.Stop(), BlockValidation (new StopCaches method),
Orphanage (new Stop method), UTXOSetCache, ExpiringConcurrentCache.

Test code: added defer/t.Cleanup Stop() calls at all creation sites.
- Remove rpcCallCache.Stop() from RPCServer.Stop() since the cache is
  a package-level global whose lifetime outlives individual servers.
  Calling Stop() twice on ttlcache deadlocks.
- Add nil guards for orphanage and invalidSubtreeDeDuplicateMap in
  subtreevalidation Server.Stop() since tests may not initialize them.
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
66.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants