-
Notifications
You must be signed in to change notification settings - Fork 20.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
panic: invalid argument to Int63n (light mainnet node) #21820
Labels
Comments
@zsfelfoldi repro: diff --git a/les/utils/weighted_select_test.go b/les/utils/weighted_select_test.go
index 3e1c0ad987..c5913ed9d7 100644
--- a/les/utils/weighted_select_test.go
+++ b/les/utils/weighted_select_test.go
@@ -66,3 +66,12 @@ func TestWeightedRandomSelect(t *testing.T) {
testFn(100000)
testFn(1000000)
}
+
+// TestOOB tests values which doesn't fit in int64
+func TestOOB(t *testing.T) {
+ w := NewWeightedRandomSelect(func(i interface{}) uint64 {
+ return 5
+ })
+ w.root.sumWeight = uint64(0xffffffffffffffee)
+ w.Choose()
+} It's easy to just fix by just making it ceiling to |
Thanks for reporting, @joeytwiddle |
@zsfelfoldi actually, the later diff --git a/les/utils/weighted_select.go b/les/utils/weighted_select.go
index d6db3c0e65..15f6eae5e3 100644
--- a/les/utils/weighted_select.go
+++ b/les/utils/weighted_select.go
@@ -17,6 +17,7 @@
package utils
import (
+ "math"
"math/rand"
)
@@ -83,6 +84,9 @@ func (w *WeightedRandomSelect) Choose() WrsItem {
if w.root.sumWeight == 0 {
return nil
}
+ if int64(w.root.sumWeight) < 0{
+ w.root.sumWeight = math.MaxInt64
+ }
val := uint64(rand.Int63n(int64(w.root.sumWeight)))
choice, lastWeight := w.root.choose(val)
weight := w.wfn(choice) |
Or perhaps even better: diff --git a/les/utils/weighted_select.go b/les/utils/weighted_select.go
index d6db3c0e65..d5169dbbfd 100644
--- a/les/utils/weighted_select.go
+++ b/les/utils/weighted_select.go
@@ -83,7 +83,7 @@ func (w *WeightedRandomSelect) Choose() WrsItem {
if w.root.sumWeight == 0 {
return nil
}
- val := uint64(rand.Int63n(int64(w.root.sumWeight)))
+ val := rand.Uint64() % w.root.sumWeight
choice, lastWeight := w.root.choose(val)
weight := w.wfn(choice)
if weight != lastWeight {
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
System information
Geth version: geth-linux-amd64-1.9.23-8c2f2715 but also observed in 1.9.22
OS & Version: Amazon Linux 4.14.193-149.317.amzn2.x86_64
Go version: go1.13.14 linux/amd64
Actual behaviour
It runs ok for a while, but then crashes with:
Steps to reproduce the behaviour
I'm running a light geth node on mainnet with:
Possibly relevant, I am also running a light testnet node on the same machine, and have not yet experienced the same problem. (Although that node struggles to find peers, so that could be the reason.)
(Note to self: I have now wiped the config folder and restarted, to see if that helps.)
The text was updated successfully, but these errors were encountered: