diff --git a/core/commands/provide.go b/core/commands/provide.go index ba2be7d7b..1bc99c5fd 100644 --- a/core/commands/provide.go +++ b/core/commands/provide.go @@ -373,8 +373,8 @@ NOTES: // Queues if all || queues || brief { sectionTitle(1, "Queues") - formatLine(1, "%sProvide queue: %s CIDs, %s regions", indent, humanNumber(s.Sweep.Queues.PendingKeyProvides), humanNumber(s.Sweep.Queues.PendingRegionProvides)) - formatLine(1, "%sReprovide queue: %s regions", indent, humanNumber(s.Sweep.Queues.PendingRegionReprovides)) + formatLine(1, "%sProvide queue: %s CIDs, %s regions", indent, humanSI(s.Sweep.Queues.PendingKeyProvides, 1), humanSI(s.Sweep.Queues.PendingRegionProvides, 1)) + formatLine(1, "%sReprovide queue: %s regions", indent, humanSI(s.Sweep.Queues.PendingRegionReprovides, 1)) addBlankLine(1) } @@ -414,12 +414,12 @@ NOTES: sectionTitle(0, "Network") formatLine(0, "%sAvg record holders: %s", indent, humanFloatOrNA(s.Sweep.Network.AvgHolders)) if !brief { - formatLine(0, "%sPeers swept: %s", indent, humanNumber(s.Sweep.Network.Peers)) + formatLine(0, "%sPeers swept: %s", indent, humanInt(s.Sweep.Network.Peers)) formatLine(0, "%sFull keyspace coverage: %t", indent, s.Sweep.Network.CompleteKeyspaceCoverage) if s.Sweep.Network.Peers > 0 { - formatLine(0, "%sReachable peers: %s (%s%%)", indent, humanNumber(s.Sweep.Network.Reachable), humanNumber(100*s.Sweep.Network.Reachable/s.Sweep.Network.Peers)) + formatLine(0, "%sReachable peers: %s (%s%%)", indent, humanInt(s.Sweep.Network.Reachable), humanNumber(100*s.Sweep.Network.Reachable/s.Sweep.Network.Peers)) } else { - formatLine(0, "%sReachable peers: %s", indent, humanNumber(s.Sweep.Network.Reachable)) + formatLine(0, "%sReachable peers: %s", indent, humanInt(s.Sweep.Network.Reachable)) } formatLine(0, "%sAvg region size: %s", indent, humanFloatOrNA(s.Sweep.Network.AvgRegionSize)) formatLine(0, "%sReplication factor: %s", indent, humanNumber(s.Sweep.Network.ReplicationFactor)) @@ -431,8 +431,8 @@ NOTES: if all || operations || brief { sectionTitle(1, "Operations") // Ongoing operations - formatLine(1, "%sOngoing provides: %s CIDs, %s regions", indent, humanNumber(s.Sweep.Operations.Ongoing.KeyProvides), humanNumber(s.Sweep.Operations.Ongoing.RegionProvides)) - formatLine(1, "%sOngoing reprovides: %s CIDs, %s regions", indent, humanNumber(s.Sweep.Operations.Ongoing.KeyReprovides), humanNumber(s.Sweep.Operations.Ongoing.RegionReprovides)) + formatLine(1, "%sOngoing provides: %s CIDs, %s regions", indent, humanSI(s.Sweep.Operations.Ongoing.KeyProvides, 1), humanSI(s.Sweep.Operations.Ongoing.RegionProvides, 1)) + formatLine(1, "%sOngoing reprovides: %s CIDs, %s regions", indent, humanSI(s.Sweep.Operations.Ongoing.KeyReprovides, 1), humanSI(s.Sweep.Operations.Ongoing.RegionReprovides, 1)) // Past operations summary formatLine(1, "%sTotal CIDs provided: %s", indent, humanNumber(s.Sweep.Operations.Past.KeysProvided)) if !brief { @@ -464,21 +464,21 @@ NOTES: if compactMode { specifyWorkers = "" } - formatLine(0, "%sActive%s: %s / %s (max)", indent, specifyWorkers, humanNumber(s.Sweep.Workers.Active), humanFull(float64(s.Sweep.Workers.Max), 0)) + formatLine(0, "%sActive%s: %s / %s (max)", indent, specifyWorkers, humanInt(s.Sweep.Workers.Active), humanInt(s.Sweep.Workers.Max)) if brief { // Brief mode - show condensed worker info formatLine(0, "%sPeriodic%s: %s active, %s available, %s queued", indent, specifyWorkers, - humanNumber(s.Sweep.Workers.ActivePeriodic), humanNumber(availablePeriodic), humanNumber(s.Sweep.Workers.QueuedPeriodic)) + humanInt(s.Sweep.Workers.ActivePeriodic), humanInt(availablePeriodic), humanInt(s.Sweep.Workers.QueuedPeriodic)) formatLine(0, "%sBurst%s: %s active, %s available, %s queued\n", indent, specifyWorkers, - humanNumber(s.Sweep.Workers.ActiveBurst), humanNumber(availableBurst), humanNumber(s.Sweep.Workers.QueuedBurst)) + humanInt(s.Sweep.Workers.ActiveBurst), humanInt(availableBurst), humanInt(s.Sweep.Workers.QueuedBurst)) } else { - formatLine(0, "%sFree%s: %s", indent, specifyWorkers, humanNumber(availableFreeWorkers)) + formatLine(0, "%sFree%s: %s", indent, specifyWorkers, humanInt(availableFreeWorkers)) formatLine(0, "%s %-14s %-9s %s", indent, "Workers stats:", "Periodic", "Burst") - formatLine(0, "%s %-14s %-9s %s", indent, "Active:", humanNumber(s.Sweep.Workers.ActivePeriodic), humanNumber(s.Sweep.Workers.ActiveBurst)) - formatLine(0, "%s %-14s %-9s %s", indent, "Dedicated:", humanNumber(s.Sweep.Workers.DedicatedPeriodic), humanNumber(s.Sweep.Workers.DedicatedBurst)) - formatLine(0, "%s %-14s %-9s %s", indent, "Available:", humanNumber(availablePeriodic), humanNumber(availableBurst)) - formatLine(0, "%s %-14s %-9s %s", indent, "Queued:", humanNumber(s.Sweep.Workers.QueuedPeriodic), humanNumber(s.Sweep.Workers.QueuedBurst)) - formatLine(0, "%sMax connections/worker: %s", indent, humanNumber(s.Sweep.Workers.MaxProvideConnsPerWorker)) + formatLine(0, "%s %-14s %-9s %s", indent, "Active:", humanInt(s.Sweep.Workers.ActivePeriodic), humanInt(s.Sweep.Workers.ActiveBurst)) + formatLine(0, "%s %-14s %-9s %s", indent, "Dedicated:", humanInt(s.Sweep.Workers.DedicatedPeriodic), humanInt(s.Sweep.Workers.DedicatedBurst)) + formatLine(0, "%s %-14s %-9s %s", indent, "Available:", humanInt(availablePeriodic), humanInt(availableBurst)) + formatLine(0, "%s %-14s %-9s %s", indent, "Queued:", humanInt(s.Sweep.Workers.QueuedPeriodic), humanInt(s.Sweep.Workers.QueuedBurst)) + formatLine(0, "%sMax connections/worker: %s", indent, humanInt(s.Sweep.Workers.MaxProvideConnsPerWorker)) addBlankLine(0) } } @@ -563,11 +563,15 @@ func humanFloatOrNA(val float64) string { return humanFull(val, 1) } -func humanSI(val float64, decimals int) string { - v, unit := humanize.ComputeSI(val) +func humanSI[T constraints.Float | constraints.Integer](val T, decimals int) string { + v, unit := humanize.ComputeSI(float64(val)) return fmt.Sprintf("%s%s", humanFull(v, decimals), unit) } +func humanInt[T constraints.Integer](val T) string { + return humanFull(float64(val), 0) +} + func humanFull(val float64, decimals int) string { return humanize.CommafWithDigits(val, decimals) } diff --git a/core/node/provider.go b/core/node/provider.go index a948b1588..64ec1bc93 100644 --- a/core/node/provider.go +++ b/core/node/provider.go @@ -554,6 +554,9 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option { } reprovideAlert := fx.Invoke(func(lc fx.Lifecycle, in alertInput) { prov := extractSweepingProvider(in.Provider) + if prov == nil { + return + } var ( cancel context.CancelFunc @@ -562,9 +565,6 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option { lc.Append(fx.Hook{ OnStart: func(ctx context.Context) error { - if prov == nil { - return nil - } gcCtx, c := context.WithCancel(context.Background()) cancel = c go func() {