From 888d4b7be698a871a69852ce865ecafc598c6ff4 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Wed, 6 Aug 2025 19:17:51 +0800 Subject: [PATCH 1/2] p2p: using math.MaxInt32 in go std lib --- p2p/msgrate/msgrate.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/p2p/msgrate/msgrate.go b/p2p/msgrate/msgrate.go index de1a3177db0..5e7df81dbb8 100644 --- a/p2p/msgrate/msgrate.go +++ b/p2p/msgrate/msgrate.go @@ -171,8 +171,7 @@ func (t *Tracker) Capacity(kind uint64, targetRTT time.Duration) int { // roundCapacity gives the integer value of a capacity. // The result fits int32, and is guaranteed to be positive. func roundCapacity(cap float64) int { - const maxInt32 = float64(1<<31 - 1) - return int(math.Min(maxInt32, math.Max(1, math.Ceil(cap)))) + return int(math.Min(math.MaxInt32, math.Max(1, math.Ceil(cap)))) } // Update modifies the peer's capacity values for a specific data type with a new From cdf534bfb2e43389430efb5a59e13e47e4fe258e Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 7 Aug 2025 16:12:29 +0200 Subject: [PATCH 2/2] Update msgrate.go --- p2p/msgrate/msgrate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/msgrate/msgrate.go b/p2p/msgrate/msgrate.go index 5e7df81dbb8..7702256ed4c 100644 --- a/p2p/msgrate/msgrate.go +++ b/p2p/msgrate/msgrate.go @@ -171,7 +171,7 @@ func (t *Tracker) Capacity(kind uint64, targetRTT time.Duration) int { // roundCapacity gives the integer value of a capacity. // The result fits int32, and is guaranteed to be positive. func roundCapacity(cap float64) int { - return int(math.Min(math.MaxInt32, math.Max(1, math.Ceil(cap)))) + return int(min(math.MaxInt32, max(1, math.Ceil(cap)))) } // Update modifies the peer's capacity values for a specific data type with a new