You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

776 lines
22 KiB

9 years ago
9 years ago
5 years ago
5 years ago
9 years ago
9 years ago
8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
8 years ago
8 years ago
8 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
p2p: fix infinite loop in addrbook (#3232) * failing test * fix infinite loop in addrbook There are cases where we only have a small number of addresses marked good ("old"), but the selection mechanism keeps trying to select more of these addresses, and hence ends up in an infinite loop. Here we fix this to only try and select such "old" addresses if we have enough of them. Note this means, if we don't have enough of them, we may return more "new" addresses than otherwise expected by the newSelectionBias. This whole GetSelectionWithBias method probably needs to be rewritten, but this is a quick fix for the issue. * changelog * fix infinite loop if not enough new addrs * fix another potential infinite loop if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items (a.nOld > len(oldBucketToAddrsMap) false) * Revert "fix another potential infinite loop" This reverts commit 146540c1125597162bd89820d611f6531f5e5e4b. * check num addresses instead of buckets, new test * fixed the int division * add slack to bias % in test, lint fixes * Added checks for selection content in test * test cleanup * Apply suggestions from code review Co-Authored-By: ebuchman <ethan@coinculture.info> * address review comments * change after Anton's review comments * use the same docker image we use for testing when building a binary for localnet * switch back to circleci classic * more review comments * more review comments * refactor addrbook_test * build linux binary inside docker in attempt to fix ``` --> Running dep + make build-linux GOOS=linux GOARCH=amd64 make build make[1]: Entering directory `/home/circleci/.go_workspace/src/github.com/tendermint/tendermint' CGO_ENABLED=0 go build -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=`git rev-parse --short=8 HEAD`" -tags 'tendermint' -o build/tendermint ./cmd/tendermint/ p2p/pex/addrbook.go:373:13: undefined: math.Round ``` * change dir from /usr to /go * use concrete Go version for localnet binary * check for nil addresses just to be sure
6 years ago
  1. package pex
  2. import (
  3. "encoding/hex"
  4. "fmt"
  5. "io/ioutil"
  6. "math"
  7. mrand "math/rand"
  8. "net"
  9. "os"
  10. "testing"
  11. "time"
  12. "github.com/stretchr/testify/assert"
  13. "github.com/stretchr/testify/require"
  14. "github.com/tendermint/tendermint/libs/log"
  15. tmmath "github.com/tendermint/tendermint/libs/math"
  16. tmrand "github.com/tendermint/tendermint/libs/rand"
  17. "github.com/tendermint/tendermint/p2p"
  18. )
  19. // FIXME These tests should not rely on .(*addrBook) assertions
  20. func TestAddrBookPickAddress(t *testing.T) {
  21. fname := createTempFileName(t, "addrbook_test")
  22. // 0 addresses
  23. book := NewAddrBook(fname, true)
  24. book.SetLogger(log.TestingLogger())
  25. assert.Zero(t, book.Size())
  26. addr := book.PickAddress(50)
  27. assert.Nil(t, addr, "expected no address")
  28. randAddrs := randNetAddressPairs(t, 1)
  29. addrSrc := randAddrs[0]
  30. err := book.AddAddress(addrSrc.addr, addrSrc.src)
  31. require.NoError(t, err)
  32. // pick an address when we only have new address
  33. addr = book.PickAddress(0)
  34. assert.NotNil(t, addr, "expected an address")
  35. addr = book.PickAddress(50)
  36. assert.NotNil(t, addr, "expected an address")
  37. addr = book.PickAddress(100)
  38. assert.NotNil(t, addr, "expected an address")
  39. // pick an address when we only have old address
  40. book.MarkGood(addrSrc.addr.ID)
  41. addr = book.PickAddress(0)
  42. assert.NotNil(t, addr, "expected an address")
  43. addr = book.PickAddress(50)
  44. assert.NotNil(t, addr, "expected an address")
  45. // in this case, nNew==0 but we biased 100% to new, so we return nil
  46. addr = book.PickAddress(100)
  47. assert.Nil(t, addr, "did not expected an address")
  48. }
  49. func TestAddrBookSaveLoad(t *testing.T) {
  50. fname := createTempFileName(t, "addrbook_test")
  51. // 0 addresses
  52. book := NewAddrBook(fname, true)
  53. book.SetLogger(log.TestingLogger())
  54. book.Save()
  55. book = NewAddrBook(fname, true)
  56. book.SetLogger(log.TestingLogger())
  57. err := book.Start()
  58. require.NoError(t, err)
  59. assert.True(t, book.Empty())
  60. // 100 addresses
  61. randAddrs := randNetAddressPairs(t, 100)
  62. for _, addrSrc := range randAddrs {
  63. err := book.AddAddress(addrSrc.addr, addrSrc.src)
  64. require.NoError(t, err)
  65. }
  66. assert.Equal(t, 100, book.Size())
  67. book.Save()
  68. book = NewAddrBook(fname, true)
  69. book.SetLogger(log.TestingLogger())
  70. err = book.Start()
  71. require.NoError(t, err)
  72. assert.Equal(t, 100, book.Size())
  73. }
  74. func TestAddrBookLookup(t *testing.T) {
  75. fname := createTempFileName(t, "addrbook_test")
  76. randAddrs := randNetAddressPairs(t, 100)
  77. book := NewAddrBook(fname, true)
  78. book.SetLogger(log.TestingLogger())
  79. for _, addrSrc := range randAddrs {
  80. addr := addrSrc.addr
  81. src := addrSrc.src
  82. err := book.AddAddress(addr, src)
  83. require.NoError(t, err)
  84. ka := book.HasAddress(addr)
  85. assert.True(t, ka, "Expected to find KnownAddress %v but wasn't there.", addr)
  86. }
  87. }
  88. func TestAddrBookPromoteToOld(t *testing.T) {
  89. fname := createTempFileName(t, "addrbook_test")
  90. randAddrs := randNetAddressPairs(t, 100)
  91. book := NewAddrBook(fname, true)
  92. book.SetLogger(log.TestingLogger())
  93. for _, addrSrc := range randAddrs {
  94. err := book.AddAddress(addrSrc.addr, addrSrc.src)
  95. require.NoError(t, err)
  96. }
  97. // Attempt all addresses.
  98. for _, addrSrc := range randAddrs {
  99. book.MarkAttempt(addrSrc.addr)
  100. }
  101. // Promote half of them
  102. for i, addrSrc := range randAddrs {
  103. if i%2 == 0 {
  104. book.MarkGood(addrSrc.addr.ID)
  105. }
  106. }
  107. // TODO: do more testing :)
  108. selection := book.GetSelection()
  109. t.Logf("selection: %v", selection)
  110. if len(selection) > book.Size() {
  111. t.Errorf("selection could not be bigger than the book")
  112. }
  113. selection = book.GetSelectionWithBias(30)
  114. t.Logf("selection: %v", selection)
  115. if len(selection) > book.Size() {
  116. t.Errorf("selection with bias could not be bigger than the book")
  117. }
  118. assert.Equal(t, book.Size(), 100, "expecting book size to be 100")
  119. }
  120. func TestAddrBookHandlesDuplicates(t *testing.T) {
  121. fname := createTempFileName(t, "addrbook_test")
  122. book := NewAddrBook(fname, true)
  123. book.SetLogger(log.TestingLogger())
  124. randAddrs := randNetAddressPairs(t, 100)
  125. differentSrc := randIPv4Address(t)
  126. for _, addrSrc := range randAddrs {
  127. err := book.AddAddress(addrSrc.addr, addrSrc.src)
  128. require.NoError(t, err)
  129. err = book.AddAddress(addrSrc.addr, addrSrc.src) // duplicate
  130. require.NoError(t, err)
  131. err = book.AddAddress(addrSrc.addr, differentSrc) // different src
  132. require.NoError(t, err)
  133. }
  134. assert.Equal(t, 100, book.Size())
  135. }
  136. type netAddressPair struct {
  137. addr *p2p.NetAddress
  138. src *p2p.NetAddress
  139. }
  140. func randNetAddressPairs(t *testing.T, n int) []netAddressPair {
  141. randAddrs := make([]netAddressPair, n)
  142. for i := 0; i < n; i++ {
  143. randAddrs[i] = netAddressPair{addr: randIPv4Address(t), src: randIPv4Address(t)}
  144. }
  145. return randAddrs
  146. }
  147. func randIPv4Address(t *testing.T) *p2p.NetAddress {
  148. for {
  149. ip := fmt.Sprintf("%v.%v.%v.%v",
  150. mrand.Intn(254)+1,
  151. mrand.Intn(255),
  152. mrand.Intn(255),
  153. mrand.Intn(255),
  154. )
  155. port := mrand.Intn(65535-1) + 1
  156. id := p2p.NodeID(hex.EncodeToString(tmrand.Bytes(p2p.NodeIDByteLength)))
  157. idAddr := p2p.IDAddressString(id, fmt.Sprintf("%v:%v", ip, port))
  158. addr, err := p2p.NewNetAddressString(idAddr)
  159. assert.Nil(t, err, "error generating rand network address")
  160. if addr.Routable() {
  161. return addr
  162. }
  163. }
  164. }
  165. func TestAddrBookRemoveAddress(t *testing.T) {
  166. fname := createTempFileName(t, "addrbook_test")
  167. book := NewAddrBook(fname, true)
  168. book.SetLogger(log.TestingLogger())
  169. addr := randIPv4Address(t)
  170. err := book.AddAddress(addr, addr)
  171. require.NoError(t, err)
  172. assert.Equal(t, 1, book.Size())
  173. book.RemoveAddress(addr)
  174. assert.Equal(t, 0, book.Size())
  175. nonExistingAddr := randIPv4Address(t)
  176. book.RemoveAddress(nonExistingAddr)
  177. assert.Equal(t, 0, book.Size())
  178. }
  179. func TestAddrBookGetSelectionWithOneMarkedGood(t *testing.T) {
  180. // create a book with 10 addresses, 1 good/old and 9 new
  181. book, _ := createAddrBookWithMOldAndNNewAddrs(t, 1, 9)
  182. addrs := book.GetSelectionWithBias(biasToSelectNewPeers)
  183. assert.NotNil(t, addrs)
  184. assertMOldAndNNewAddrsInSelection(t, 1, 9, addrs, book)
  185. }
  186. func TestAddrBookGetSelectionWithOneNotMarkedGood(t *testing.T) {
  187. // create a book with 10 addresses, 9 good/old and 1 new
  188. book, _ := createAddrBookWithMOldAndNNewAddrs(t, 9, 1)
  189. addrs := book.GetSelectionWithBias(biasToSelectNewPeers)
  190. assert.NotNil(t, addrs)
  191. assertMOldAndNNewAddrsInSelection(t, 9, 1, addrs, book)
  192. }
  193. func TestAddrBookGetSelectionReturnsNilWhenAddrBookIsEmpty(t *testing.T) {
  194. book, _ := createAddrBookWithMOldAndNNewAddrs(t, 0, 0)
  195. addrs := book.GetSelectionWithBias(biasToSelectNewPeers)
  196. assert.Nil(t, addrs)
  197. }
  198. func TestAddrBookGetSelection(t *testing.T) {
  199. fname := createTempFileName(t, "addrbook_test")
  200. book := NewAddrBook(fname, true)
  201. book.SetLogger(log.TestingLogger())
  202. // 1) empty book
  203. assert.Empty(t, book.GetSelection())
  204. // 2) add one address
  205. addr := randIPv4Address(t)
  206. err := book.AddAddress(addr, addr)
  207. require.NoError(t, err)
  208. assert.Equal(t, 1, len(book.GetSelection()))
  209. assert.Equal(t, addr, book.GetSelection()[0])
  210. // 3) add a bunch of addresses
  211. randAddrs := randNetAddressPairs(t, 100)
  212. for _, addrSrc := range randAddrs {
  213. err := book.AddAddress(addrSrc.addr, addrSrc.src)
  214. require.NoError(t, err)
  215. }
  216. // check there is no duplicates
  217. addrs := make(map[string]*p2p.NetAddress)
  218. selection := book.GetSelection()
  219. for _, addr := range selection {
  220. if dup, ok := addrs[addr.String()]; ok {
  221. t.Fatalf("selection %v contains duplicates %v", selection, dup)
  222. }
  223. addrs[addr.String()] = addr
  224. }
  225. if len(selection) > book.Size() {
  226. t.Errorf("selection %v could not be bigger than the book", selection)
  227. }
  228. }
  229. func TestAddrBookGetSelectionWithBias(t *testing.T) {
  230. const biasTowardsNewAddrs = 30
  231. fname := createTempFileName(t, "addrbook_test")
  232. book := NewAddrBook(fname, true)
  233. book.SetLogger(log.TestingLogger())
  234. // 1) empty book
  235. selection := book.GetSelectionWithBias(biasTowardsNewAddrs)
  236. assert.Empty(t, selection)
  237. // 2) add one address
  238. addr := randIPv4Address(t)
  239. err := book.AddAddress(addr, addr)
  240. require.NoError(t, err)
  241. selection = book.GetSelectionWithBias(biasTowardsNewAddrs)
  242. assert.Equal(t, 1, len(selection))
  243. assert.Equal(t, addr, selection[0])
  244. // 3) add a bunch of addresses
  245. randAddrs := randNetAddressPairs(t, 100)
  246. for _, addrSrc := range randAddrs {
  247. err := book.AddAddress(addrSrc.addr, addrSrc.src)
  248. require.NoError(t, err)
  249. }
  250. // check there is no duplicates
  251. addrs := make(map[string]*p2p.NetAddress)
  252. selection = book.GetSelectionWithBias(biasTowardsNewAddrs)
  253. for _, addr := range selection {
  254. if dup, ok := addrs[addr.String()]; ok {
  255. t.Fatalf("selection %v contains duplicates %v", selection, dup)
  256. }
  257. addrs[addr.String()] = addr
  258. }
  259. if len(selection) > book.Size() {
  260. t.Fatalf("selection %v could not be bigger than the book", selection)
  261. }
  262. // 4) mark 80% of the addresses as good
  263. randAddrsLen := len(randAddrs)
  264. for i, addrSrc := range randAddrs {
  265. if int((float64(i)/float64(randAddrsLen))*100) >= 20 {
  266. book.MarkGood(addrSrc.addr.ID)
  267. }
  268. }
  269. selection = book.GetSelectionWithBias(biasTowardsNewAddrs)
  270. // check that ~70% of addresses returned are good
  271. good := 0
  272. for _, addr := range selection {
  273. if book.IsGood(addr) {
  274. good++
  275. }
  276. }
  277. got, expected := int((float64(good)/float64(len(selection)))*100), 100-biasTowardsNewAddrs
  278. // compute some slack to protect against small differences due to rounding:
  279. slack := int(math.Round(float64(100) / float64(len(selection))))
  280. if got > expected+slack {
  281. t.Fatalf(
  282. "got more good peers (%% got: %d, %% expected: %d, number of good addrs: %d, total: %d)",
  283. got,
  284. expected,
  285. good,
  286. len(selection),
  287. )
  288. }
  289. if got < expected-slack {
  290. t.Fatalf(
  291. "got fewer good peers (%% got: %d, %% expected: %d, number of good addrs: %d, total: %d)",
  292. got,
  293. expected,
  294. good,
  295. len(selection),
  296. )
  297. }
  298. }
  299. func TestAddrBookHasAddress(t *testing.T) {
  300. fname := createTempFileName(t, "addrbook_test")
  301. book := NewAddrBook(fname, true)
  302. book.SetLogger(log.TestingLogger())
  303. addr := randIPv4Address(t)
  304. err := book.AddAddress(addr, addr)
  305. require.NoError(t, err)
  306. assert.True(t, book.HasAddress(addr))
  307. book.RemoveAddress(addr)
  308. assert.False(t, book.HasAddress(addr))
  309. }
  310. func testCreatePrivateAddrs(t *testing.T, numAddrs int) ([]*p2p.NetAddress, []string) {
  311. t.Helper()
  312. addrs := make([]*p2p.NetAddress, numAddrs)
  313. for i := 0; i < numAddrs; i++ {
  314. addrs[i] = randIPv4Address(t)
  315. }
  316. private := make([]string, numAddrs)
  317. for i, addr := range addrs {
  318. private[i] = string(addr.ID)
  319. }
  320. return addrs, private
  321. }
  322. func TestBanBadPeers(t *testing.T) {
  323. fname := createTempFileName(t, "addrbook_test")
  324. book := NewAddrBook(fname, true)
  325. book.SetLogger(log.TestingLogger())
  326. addr := randIPv4Address(t)
  327. _ = book.AddAddress(addr, addr)
  328. book.MarkBad(addr, 1*time.Second)
  329. // addr should not reachable
  330. assert.False(t, book.HasAddress(addr))
  331. assert.True(t, book.IsBanned(addr))
  332. err := book.AddAddress(addr, addr)
  333. // book should not add address from the blacklist
  334. assert.Error(t, err)
  335. time.Sleep(1 * time.Second)
  336. book.ReinstateBadPeers()
  337. // address should be reinstated in the new bucket
  338. assert.EqualValues(t, 1, book.Size())
  339. assert.True(t, book.HasAddress(addr))
  340. assert.False(t, book.IsGood(addr))
  341. }
  342. func TestAddrBookEmpty(t *testing.T) {
  343. fname := createTempFileName(t, "addrbook_test")
  344. book := NewAddrBook(fname, true)
  345. book.SetLogger(log.TestingLogger())
  346. // Check that empty book is empty
  347. require.True(t, book.Empty())
  348. // Check that book with our address is empty
  349. book.AddOurAddress(randIPv4Address(t))
  350. require.True(t, book.Empty())
  351. // Check that book with private addrs is empty
  352. _, privateIds := testCreatePrivateAddrs(t, 5)
  353. book.AddPrivateIDs(privateIds)
  354. require.True(t, book.Empty())
  355. // Check that book with address is not empty
  356. err := book.AddAddress(randIPv4Address(t), randIPv4Address(t))
  357. require.NoError(t, err)
  358. require.False(t, book.Empty())
  359. }
  360. func TestPrivatePeers(t *testing.T) {
  361. fname := createTempFileName(t, "addrbook_test")
  362. book := NewAddrBook(fname, true)
  363. book.SetLogger(log.TestingLogger())
  364. addrs, private := testCreatePrivateAddrs(t, 10)
  365. book.AddPrivateIDs(private)
  366. // private addrs must not be added
  367. for _, addr := range addrs {
  368. err := book.AddAddress(addr, addr)
  369. if assert.Error(t, err) {
  370. _, ok := err.(ErrAddrBookPrivate)
  371. assert.True(t, ok)
  372. }
  373. }
  374. // addrs coming from private peers must not be added
  375. err := book.AddAddress(randIPv4Address(t), addrs[0])
  376. if assert.Error(t, err) {
  377. _, ok := err.(ErrAddrBookPrivateSrc)
  378. assert.True(t, ok)
  379. }
  380. }
  381. func testAddrBookAddressSelection(t *testing.T, bookSize int) {
  382. // generate all combinations of old (m) and new addresses
  383. for nBookOld := 0; nBookOld <= bookSize; nBookOld++ {
  384. nBookNew := bookSize - nBookOld
  385. dbgStr := fmt.Sprintf("book of size %d (new %d, old %d)", bookSize, nBookNew, nBookOld)
  386. // create book and get selection
  387. book, _ := createAddrBookWithMOldAndNNewAddrs(t, nBookOld, nBookNew)
  388. addrs := book.GetSelectionWithBias(biasToSelectNewPeers)
  389. assert.NotNil(t, addrs, "%s - expected a non-nil selection", dbgStr)
  390. nAddrs := len(addrs)
  391. assert.NotZero(t, nAddrs, "%s - expected at least one address in selection", dbgStr)
  392. // check there's no nil addresses
  393. for _, addr := range addrs {
  394. if addr == nil {
  395. t.Fatalf("%s - got nil address in selection %v", dbgStr, addrs)
  396. }
  397. }
  398. // XXX: shadowing
  399. nOld, nNew := countOldAndNewAddrsInSelection(addrs, book)
  400. // Given:
  401. // n - num new addrs, m - num old addrs
  402. // k - num new addrs expected in the beginning (based on bias %)
  403. // i=min(n, max(k,r-m)), aka expNew
  404. // j=min(m, r-i), aka expOld
  405. //
  406. // We expect this layout:
  407. // indices: 0...i-1 i...i+j-1
  408. // addresses: N0..Ni-1 O0..Oj-1
  409. //
  410. // There is at least one partition and at most three.
  411. var (
  412. k = percentageOfNum(biasToSelectNewPeers, nAddrs)
  413. expNew = tmmath.MinInt(nNew, tmmath.MaxInt(k, nAddrs-nBookOld))
  414. expOld = tmmath.MinInt(nOld, nAddrs-expNew)
  415. )
  416. // Verify that the number of old and new addresses are as expected
  417. if nNew != expNew {
  418. t.Fatalf("%s - expected new addrs %d, got %d", dbgStr, expNew, nNew)
  419. }
  420. if nOld != expOld {
  421. t.Fatalf("%s - expected old addrs %d, got %d", dbgStr, expOld, nOld)
  422. }
  423. // Verify that the order of addresses is as expected
  424. // Get the sequence types and lengths of the selection
  425. seqLens, seqTypes, err := analyseSelectionLayout(book, addrs)
  426. assert.NoError(t, err, "%s", dbgStr)
  427. // Build a list with the expected lengths of partitions and another with the expected types, e.g.:
  428. // expSeqLens = [10, 22], expSeqTypes = [1, 2]
  429. // means we expect 10 new (type 1) addresses followed by 22 old (type 2) addresses.
  430. var expSeqLens []int
  431. var expSeqTypes []int
  432. switch {
  433. case expOld == 0: // all new addresses
  434. expSeqLens = []int{nAddrs}
  435. expSeqTypes = []int{1}
  436. case expNew == 0: // all old addresses
  437. expSeqLens = []int{nAddrs}
  438. expSeqTypes = []int{2}
  439. case nAddrs-expNew-expOld == 0: // new addresses, old addresses
  440. expSeqLens = []int{expNew, expOld}
  441. expSeqTypes = []int{1, 2}
  442. }
  443. assert.Equal(t, expSeqLens, seqLens,
  444. "%s - expected sequence lengths of old/new %v, got %v",
  445. dbgStr, expSeqLens, seqLens)
  446. assert.Equal(t, expSeqTypes, seqTypes,
  447. "%s - expected sequence types (1-new, 2-old) was %v, got %v",
  448. dbgStr, expSeqTypes, seqTypes)
  449. }
  450. }
  451. func TestMultipleAddrBookAddressSelection(t *testing.T) {
  452. // test books with smaller size, < N
  453. const N = 32
  454. for bookSize := 1; bookSize < N; bookSize++ {
  455. testAddrBookAddressSelection(t, bookSize)
  456. }
  457. // Test for two books with sizes from following ranges
  458. ranges := [...][]int{{33, 100}, {100, 175}}
  459. bookSizes := make([]int, 0, len(ranges))
  460. for _, r := range ranges {
  461. bookSizes = append(bookSizes, mrand.Intn(r[1]-r[0])+r[0])
  462. }
  463. t.Logf("Testing address selection for the following book sizes %v\n", bookSizes)
  464. for _, bookSize := range bookSizes {
  465. testAddrBookAddressSelection(t, bookSize)
  466. }
  467. }
  468. func TestAddrBookAddDoesNotOverwriteOldIP(t *testing.T) {
  469. fname := createTempFileName(t, "addrbook_test")
  470. // This test creates adds a peer to the address book and marks it good
  471. // It then attempts to override the peer's IP, by adding a peer with the same ID
  472. // but different IP. We distinguish the IP's by "RealIP" and "OverrideAttemptIP"
  473. peerID := "678503e6c8f50db7279c7da3cb9b072aac4bc0d5"
  474. peerRealIP := "1.1.1.1:26656"
  475. peerOverrideAttemptIP := "2.2.2.2:26656"
  476. SrcAddr := "b0dd378c3fbc4c156cd6d302a799f0d2e4227201@159.89.121.174:26656"
  477. // There is a chance that AddAddress will ignore the new peer its given.
  478. // So we repeat trying to override the peer several times,
  479. // to ensure we aren't in a case that got probabilistically ignored
  480. numOverrideAttempts := 10
  481. peerRealAddr, err := p2p.NewNetAddressString(peerID + "@" + peerRealIP)
  482. require.Nil(t, err)
  483. peerOverrideAttemptAddr, err := p2p.NewNetAddressString(peerID + "@" + peerOverrideAttemptIP)
  484. require.Nil(t, err)
  485. src, err := p2p.NewNetAddressString(SrcAddr)
  486. require.Nil(t, err)
  487. book := NewAddrBook(fname, true)
  488. book.SetLogger(log.TestingLogger())
  489. err = book.AddAddress(peerRealAddr, src)
  490. require.Nil(t, err)
  491. book.MarkAttempt(peerRealAddr)
  492. book.MarkGood(peerRealAddr.ID)
  493. // Double check that adding a peer again doesn't error
  494. err = book.AddAddress(peerRealAddr, src)
  495. require.Nil(t, err)
  496. // Try changing ip but keeping the same node id. (change 1.1.1.1 to 2.2.2.2)
  497. // This should just be ignored, and not error.
  498. for i := 0; i < numOverrideAttempts; i++ {
  499. err = book.AddAddress(peerOverrideAttemptAddr, src)
  500. require.Nil(t, err)
  501. }
  502. // Now check that the IP was not overridden.
  503. // This is done by sampling several peers from addr book
  504. // and ensuring they all have the correct IP.
  505. // In the expected functionality, this test should only have 1 Peer, hence will pass.
  506. for i := 0; i < numOverrideAttempts; i++ {
  507. selection := book.GetSelection()
  508. for _, addr := range selection {
  509. require.Equal(t, addr.IP, peerRealAddr.IP)
  510. }
  511. }
  512. }
  513. func TestAddrBookGroupKey(t *testing.T) {
  514. // non-strict routability
  515. testCases := []struct {
  516. name string
  517. ip string
  518. expKey string
  519. }{
  520. // IPv4 normal.
  521. {"ipv4 normal class a", "12.1.2.3", "12.1.0.0"},
  522. {"ipv4 normal class b", "173.1.2.3", "173.1.0.0"},
  523. {"ipv4 normal class c", "196.1.2.3", "196.1.0.0"},
  524. // IPv6/IPv4 translations.
  525. {"ipv6 rfc3964 with ipv4 encap", "2002:0c01:0203::", "12.1.0.0"},
  526. {"ipv6 rfc4380 toredo ipv4", "2001:0:1234::f3fe:fdfc", "12.1.0.0"},
  527. {"ipv6 rfc6052 well-known prefix with ipv4", "64:ff9b::0c01:0203", "12.1.0.0"},
  528. {"ipv6 rfc6145 translated ipv4", "::ffff:0:0c01:0203", "12.1.0.0"},
  529. // Tor.
  530. {"ipv6 tor onioncat", "fd87:d87e:eb43:1234::5678", "tor:2"},
  531. {"ipv6 tor onioncat 2", "fd87:d87e:eb43:1245::6789", "tor:2"},
  532. {"ipv6 tor onioncat 3", "fd87:d87e:eb43:1345::6789", "tor:3"},
  533. // IPv6 normal.
  534. {"ipv6 normal", "2602:100::1", "2602:100::"},
  535. {"ipv6 normal 2", "2602:0100::1234", "2602:100::"},
  536. {"ipv6 hurricane electric", "2001:470:1f10:a1::2", "2001:470:1000::"},
  537. {"ipv6 hurricane electric 2", "2001:0470:1f10:a1::2", "2001:470:1000::"},
  538. }
  539. for i, tc := range testCases {
  540. nip := net.ParseIP(tc.ip)
  541. key := groupKeyFor(p2p.NewNetAddressIPPort(nip, 26656), false)
  542. assert.Equal(t, tc.expKey, key, "#%d", i)
  543. }
  544. // strict routability
  545. testCases = []struct {
  546. name string
  547. ip string
  548. expKey string
  549. }{
  550. // Local addresses.
  551. {"ipv4 localhost", "127.0.0.1", "local"},
  552. {"ipv6 localhost", "::1", "local"},
  553. {"ipv4 zero", "0.0.0.0", "local"},
  554. {"ipv4 first octet zero", "0.1.2.3", "local"},
  555. // Unroutable addresses.
  556. {"ipv4 invalid bcast", "255.255.255.255", "unroutable"},
  557. {"ipv4 rfc1918 10/8", "10.1.2.3", "unroutable"},
  558. {"ipv4 rfc1918 172.16/12", "172.16.1.2", "unroutable"},
  559. {"ipv4 rfc1918 192.168/16", "192.168.1.2", "unroutable"},
  560. {"ipv6 rfc3849 2001:db8::/32", "2001:db8::1234", "unroutable"},
  561. {"ipv4 rfc3927 169.254/16", "169.254.1.2", "unroutable"},
  562. {"ipv6 rfc4193 fc00::/7", "fc00::1234", "unroutable"},
  563. {"ipv6 rfc4843 2001:10::/28", "2001:10::1234", "unroutable"},
  564. {"ipv6 rfc4862 fe80::/64", "fe80::1234", "unroutable"},
  565. }
  566. for i, tc := range testCases {
  567. nip := net.ParseIP(tc.ip)
  568. key := groupKeyFor(p2p.NewNetAddressIPPort(nip, 26656), true)
  569. assert.Equal(t, tc.expKey, key, "#%d", i)
  570. }
  571. }
  572. func assertMOldAndNNewAddrsInSelection(t *testing.T, m, n int, addrs []*p2p.NetAddress, book *addrBook) {
  573. nOld, nNew := countOldAndNewAddrsInSelection(addrs, book)
  574. assert.Equal(t, m, nOld, "old addresses")
  575. assert.Equal(t, n, nNew, "new addresses")
  576. }
  577. func createTempFileName(t *testing.T, prefix string) string {
  578. t.Helper()
  579. f, err := ioutil.TempFile("", prefix)
  580. if err != nil {
  581. panic(err)
  582. }
  583. fname := f.Name()
  584. if err := f.Close(); err != nil {
  585. t.Fatal(err)
  586. }
  587. t.Cleanup(func() { _ = os.Remove(fname) })
  588. return fname
  589. }
  590. func createAddrBookWithMOldAndNNewAddrs(t *testing.T, nOld, nNew int) (book *addrBook, fname string) {
  591. t.Helper()
  592. fname = createTempFileName(t, "addrbook_test")
  593. book = NewAddrBook(fname, true).(*addrBook)
  594. book.SetLogger(log.TestingLogger())
  595. assert.Zero(t, book.Size())
  596. randAddrs := randNetAddressPairs(t, nOld)
  597. for _, addr := range randAddrs {
  598. err := book.AddAddress(addr.addr, addr.src)
  599. require.NoError(t, err)
  600. book.MarkGood(addr.addr.ID)
  601. }
  602. randAddrs = randNetAddressPairs(t, nNew)
  603. for _, addr := range randAddrs {
  604. err := book.AddAddress(addr.addr, addr.src)
  605. require.NoError(t, err)
  606. }
  607. return
  608. }
  609. func countOldAndNewAddrsInSelection(addrs []*p2p.NetAddress, book *addrBook) (nOld, nNew int) {
  610. for _, addr := range addrs {
  611. if book.IsGood(addr) {
  612. nOld++
  613. } else {
  614. nNew++
  615. }
  616. }
  617. return
  618. }
  619. // Analyze the layout of the selection specified by 'addrs'
  620. // Returns:
  621. // - seqLens - the lengths of the sequences of addresses of same type
  622. // - seqTypes - the types of sequences in selection
  623. func analyseSelectionLayout(book *addrBook, addrs []*p2p.NetAddress) (seqLens, seqTypes []int, err error) {
  624. // address types are: 0 - nil, 1 - new, 2 - old
  625. var (
  626. prevType = 0
  627. currentSeqLen = 0
  628. )
  629. for _, addr := range addrs {
  630. addrType := 0
  631. if book.IsGood(addr) {
  632. addrType = 2
  633. } else {
  634. addrType = 1
  635. }
  636. if addrType != prevType && prevType != 0 {
  637. seqLens = append(seqLens, currentSeqLen)
  638. seqTypes = append(seqTypes, prevType)
  639. currentSeqLen = 0
  640. }
  641. currentSeqLen++
  642. prevType = addrType
  643. }
  644. seqLens = append(seqLens, currentSeqLen)
  645. seqTypes = append(seqTypes, prevType)
  646. return
  647. }