-
Notifications
You must be signed in to change notification settings - Fork 759
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
Client Discovery Improvements #3120
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
421c2a4
Client: add explicit discovery startup logging
holgerd77 d895157
Client: add bootnodes format hint on CLI option help
holgerd77 8cfaf36
Client: add option to pass in bootnode.txt file to --bootnodes CLI pa…
holgerd77 8d2c3b5
Client: replace goerli -> holesky in list with networks with activate…
holgerd77 a25f217
Devp2p: add new confirmed-peer mechanism for a more fine grained peer…
holgerd77 bb0de66
Devp2p: add test setup for DPT, initialization, bootstrap(), addPeer(…
holgerd77 b9a655c
Client: make onlyConfirmed exception for mainnet (since most peers ar…
holgerd77 57b90c6
Devp2p: increase network resilience for the case that no initial conf…
holgerd77 02cfaba
Devp2p: remove peer from confirmed peers list when being removed from…
holgerd77 0196597
Fix tests
holgerd77 69f7351
Client: add missing bootnode.txt test file
holgerd77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
enode://abc@127.0.0.1:30303 | ||
enode://abc@127.0.0.1:30304 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { hexToBytes } from '@ethereumjs/util' | ||
import { afterEach, assert, describe, expect, it, vi } from 'vitest' | ||
|
||
import { DPT } from '../src/dpt/index.js' | ||
|
||
import type { PeerInfo } from '../src/types.js' | ||
|
||
describe('DPT', () => { | ||
afterEach(() => { | ||
vi.restoreAllMocks() | ||
}) | ||
|
||
const privateKey1 = hexToBytes( | ||
'0x012e930448c53e0b73edbbbc433e8a741e978cda79be2be039905f538d6247c2' | ||
) | ||
|
||
const peers: PeerInfo[] = [] | ||
|
||
for (let i = 1; i <= 5; i++) { | ||
const id = new Uint8Array([i]) | ||
const address = '127.0.0.1' | ||
const udpPort = 5000 + i | ||
const peer: PeerInfo = { | ||
id, | ||
address, | ||
udpPort, | ||
} | ||
peers.push(peer) | ||
} | ||
|
||
class Server { | ||
ping() {} | ||
findneighbours() {} | ||
destroy() {} | ||
} | ||
|
||
it('should initialize and add peers', async () => { | ||
const dpt = new DPT(privateKey1, {}) | ||
dpt['_server'] = new Server() as any | ||
assert.equal(dpt['_dnsAddr'], '8.8.8.8', 'should initialize with default values') | ||
|
||
dpt['_server'].ping = vi.fn().mockResolvedValue(peers[0]) | ||
await dpt.bootstrap(peers[0]) | ||
assert.equal(dpt.numPeers(), 1, 'should add peer on bootstrap()') | ||
|
||
// Attention! Not all peers are called by default in refresh() | ||
// (take into account on test design) | ||
const spy = vi.spyOn(dpt['_server'], 'findneighbours') | ||
await dpt.refresh() | ||
expect(spy).toHaveBeenCalledTimes(1) | ||
|
||
dpt['_server'].ping = vi.fn().mockResolvedValue(peers[1]) | ||
await dpt.addPeer(peers[1]) | ||
assert.equal(dpt.numPeers(), 2, 'should add another peer on addPeer()') | ||
|
||
assert.equal( | ||
dpt.getClosestPeers(peers[0].id!).length, | ||
2, | ||
'should return all peers on getClosestPeers()' | ||
) | ||
|
||
dpt.destroy() | ||
}) | ||
|
||
it('should only call to confirmed peers on activated flag', async () => { | ||
const dpt = new DPT(privateKey1, { onlyConfirmed: true }) | ||
dpt['_server'] = new Server() as any | ||
|
||
dpt['_server'].ping = vi.fn().mockResolvedValue(peers[0]) | ||
await dpt.addPeer(peers[0]) | ||
|
||
const spy = vi.spyOn(dpt['_server'], 'findneighbours') | ||
await dpt.refresh() | ||
expect( | ||
spy, | ||
'call findneighbours on unconfirmed if no confirmed peers yet' | ||
).toHaveBeenCalledTimes(1) | ||
|
||
dpt['_refreshIntervalSelectionCounter'] = 0 | ||
dpt.confirmPeer('01') | ||
await dpt.refresh() | ||
expect(spy, 'call findneighbours on confirmed').toHaveBeenCalledTimes(2) | ||
|
||
dpt['_server'].ping = vi.fn().mockResolvedValue(peers[1]) | ||
await dpt.addPeer(peers[1]) | ||
assert.equal( | ||
dpt.getClosestPeers(peers[0].id!).length, | ||
1, | ||
'should not return unconfirmed on getClosestPeers()' | ||
) | ||
|
||
dpt.confirmPeer('02') | ||
assert.equal( | ||
dpt.getClosestPeers(peers[0].id!).length, | ||
2, | ||
'should return confirmed on getClosestPeers()' | ||
) | ||
|
||
dpt.removePeer(peers[1]) | ||
assert.equal( | ||
dpt.getClosestPeers(peers[0].id!).length, | ||
1, | ||
'should work after peers being removed' | ||
) | ||
|
||
dpt.destroy() | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peers are never removed from
_confirmedPeers
, so at some point we cannot confirm new peers since the set is full? Should the peer id be removed onremovePeer
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was the lazy version assuming a very slow growth. But removing on
removePeer
definitely make sense, will add. 👍