This document enumerates actionable tasks for the AI code-generation agent. Follow these instructions exactly when producing code. Each task is bite-sized and intended to be completed in sequence (or small batches) while continually running go vet, golangci-lint, and unit tests.
- Language: Go 1.23+ with
go mod&go worksetup already in repo. - Style:
goimports,gofumpt; idiomatic Go, small funcs, descriptive names. - Logging: Use
zerolog(already indirect via metfin) with structured JSON. - DB Access: MongoDB driver with context timeouts; use upsert for idempotency.
- Testing:
testingpkg +stretchr/testify. Every new package needs tests. - Metrics:
prometheus/client_golang– histogram/bucket best-practice. - Config: All runtime config through env vars; parse once at startup.
- Error Handling: Wrap errors with
%w; never ignore errors. - Concurrency: Avoid goroutine leaks; use
errgroup.Groupand contexts.
- Create
config/config.gothat reads env vars into a struct, validates, and exposesLoad() (Config, error). - Include slice
[]string RPCEndpointsand intsMinWorkers,MaxWorkers.
internal/logger/logger.go– returns a configuredzerolog.Logger.internal/metrics/metrics.go– declares Prometheus metrics listed in README.cmd/mercon/main.go– wire config, logger, metrics HTTP server (/metrics,/ready).
- Package
internal/queuewith wrapper aroundgo-redisv9. - Implement methods:
PopWallet(ctx) (string, error) // ZPOPMIN PushWallet(ctx, addr string, priority float64) error SetInFlight(ctx, addr, worker string) error RemoveInFlight(ctx, addr string) error GetProgress(ctx, addr string) (string, error) SetProgress(ctx, addr, sig string) error
- Use the existing
core/databasepackage for MongoDB connection. Mercon should calldatabase.InitMongoDB(cfg)once and reusedatabase.GetMongoDatabase(). - No new DB connection code inside Mercon.
- Use the existing
core/models/mongo_raw_models.gofor MongoDB document models with time-partitioned collections. - Collections are created automatically with proper indexes.
-
internal/worker/manager.go- Accepts Config, Queue, MongoDB, RPC pool.
- Maintains slice
[]*Worker. - Tick every 30 s → adjust worker count.
-
internal/worker/worker.go- Holds
id,rpcClient,queue,mongodb. - Implements
Start(ctx); useerrgroupinside for batching loop.
- Holds
internal/rpc/pool.go– round-robin[]*http.Client+ endpoint URL.- Each call wrapped with rate-limiter (
golang.org/x/time/rate).
internal/rpc/fetch.go–FetchTx(ctx, sig string) (*RpcTx, error)with retries.
- Implement helpers in
core/rawchain/mongo_insert.gothat insert transactions + sub-records using MongoDB bulk operations with upsert; Mercon imports this package. No MongoDB models live inside Mercon.
- Add bulk insertion optimizations for MongoDB.
- Benchmark with 10k tx; ensure optimal MongoDB performance.
- Auto-create next month collections as needed.
- Re-use existing code under
core/parsersvia thin adapter. - Add MongoDB collections for analytics data.
- Create models inside
core/models:Swap(generic SPL swaps)TokenTransfer
- Add MongoDB indexes for analytics collections.
- Mercon worker uses these core models for inserts; no analytics structs in Mercon.
- Implement exponential back-off utility (
internal/backoff/backoff.go). - Cool-down RPC endpoints after repeated 429s.
- Watchdog goroutine that re-queues stuck wallets: if
wallet_inflight.{wallet}.start_timeolder thanXmin, push back to queue. - Graceful shutdown: on SIGTERM stop accepting wallets, finish current batch, flush metrics.
- VIP wallet priority (
queue.PushWalletwith lower score). - CLI tool (
cmd/merctl) to enqueue/check wallets. - Multi-instance advisory lock using
Redlockif multiple binaries run.
- Unit test coverage ≥ 70 % for all new packages.
go vet&golangci-lint runclean.- Can scrape 100 wallets (avg 5 k tx each) on 4-core VPS in < 2 hours.
- Prometheus metrics visible; Grafana dashboard JSON loads without error.
Do not edit this plan via Finder/Explorer. Use pull-requests with explicit task references (Phase X.Y). Tick boxes in README's checklist when tasks merge.