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.

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