Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skip validation if peer is known #2491

Merged
merged 10 commits into from
Sep 15, 2021
Merged

feat: skip validation if peer is known #2491

merged 10 commits into from
Sep 15, 2021

Conversation

istae
Copy link
Member

@istae istae commented Sep 10, 2021

This change is Reviewable

@acud
Copy link
Member

acud commented Sep 11, 2021

@istae just a suggestion, but we might also want not to check the same peer twice, in case the result was a negative. for this we can reuse the LRU cache used in the chainsync PR, to basically cache the results (true/false) for an address - no entry means we didn't try, false means unreachable (dont retry) and true means reachable. having an upper bound of addresses in the cache would mean we could potentially retry after a while (but it should be well into the thousands range).

i would also consider not to have this validation on the bootnode at all since it does not actively dial

Copy link
Contributor

@mrekucci mrekucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @istae)


pkg/hive/hive.go, line 268 at r1 (raw file):

		// if peer exists already, skip validation
		if _, err := s.addressBook.Get(swarm.NewAddress(p.Overlay)); err == nil {

The errors thrown by the Get method should be handled (at least logged).

Copy link
Contributor

@aloknerurkar aloknerurkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is happening a lot, I would also suggest an LRU cache here to speed it up more as this is going to disk every time.

@istae istae force-pushed the hive-addressbook-check branch from 442b315 to 4dcdeef Compare September 13, 2021 12:00
@istae istae requested a review from mrekucci September 13, 2021 12:38
@istae istae changed the title fix: skip validation if peer is known feat: skip validation if peer is known Sep 13, 2021
pkg/hive/hive.go Outdated
@@ -39,6 +40,8 @@ const (
maxBatchSize = 30
pingTimeout = time.Second * 5 // time to wait for ping to succeed
batchValidationTimeout = 5 * time.Minute // prevent lock contention on peer validation
cacheSize = 25000
cachePrefix = 4 // enough bytes (32 bits) to uniquely identify a peer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure if this is strictly needed. even when keeping 25k addresses in memory, the total overhead is around 800kb.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I increased the cache size to 100,000 and kept the cachePrefix, it's best if cache is big for hive.

pkg/hive/hive.go Outdated
return
}
if s.bootnode {
for _, p := range peers.Peers {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what is the desirable outcome here. this basically means - if we are a bootnode we persist every peer we get over discovery. if anything, we should not persist any node which we are not connected to

Copy link
Member Author

@istae istae Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because bootnodes do not dial, the newest commit discards the received peers without validating or persisting them. thanks.

pkg/hive/hive.go Outdated
if err == nil {
continue
} else {
s.logger.Errorf("hive: addressbook %v", err)
Copy link
Member

@acud acud Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means that you return an error here if the peer is not in the address book, so you basically print an error for every peer you don't know

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrekucci's request was that we should at least log it, but I agree, logging here is does not add much value.

@mrekucci mrekucci requested a review from acud September 14, 2021 08:45
Copy link
Contributor

@mrekucci mrekucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 4 unresolved discussions (waiting on @acud and @istae)

@istae istae added the ready for review The PR is ready to be reviewed label Sep 14, 2021
pkg/hive/hive.go Outdated Show resolved Hide resolved
pkg/hive/hive.go Outdated Show resolved Hide resolved
@istae istae requested a review from acud September 14, 2021 11:51
pkg/hive/hive.go Outdated
err error
)

if !bootnode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is fine to initialize this even in bootnode mode. the cache size is negligible when empty, and we don't risk any panics on bootnodes

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@istae istae merged commit fb8a54a into master Sep 15, 2021
@istae istae deleted the hive-addressbook-check branch September 15, 2021 08:08
@acud acud added this to the v1.2.0 milestone Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull-request ready for review The PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants