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.

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