Skip to content

Commit

Permalink
Fixing Peer Discovery
Browse files Browse the repository at this point in the history
This has plagued expanse for YEARS. Finally took the time to fix it.
  • Loading branch information
chrisfranko committed Nov 18, 2023
1 parent 9a92497 commit f58cd2d
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cmd/devp2p/internal/ethtest/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *Suite) dial66() (*Conn, error) {
if err != nil {
return nil, fmt.Errorf("dial failed: %v", err)
}
conn.caps = append(conn.caps, p2p.Cap{Name: "eth", Version: 66})
conn.caps = append(conn.caps, p2p.Cap{Name: "exp", Version: 66})
conn.ourHighestProtoVersion = 66
return conn, nil
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func (c *Conn) handshake() error {
}
c.negotiateEthProtocol(msg.Caps)
if c.negotiatedProtoVersion == 0 {
return fmt.Errorf("unexpected eth protocol version")
return fmt.Errorf("unexpected exp protocol version")
}
return nil
default:
Expand All @@ -144,7 +144,7 @@ func (c *Conn) handshake() error {
func (c *Conn) negotiateEthProtocol(caps []p2p.Cap) {
var highestEthVersion uint
for _, capability := range caps {
if capability.Name != "eth" {
if capability.Name != "exp" {
continue
}
if capability.Version > highestEthVersion && capability.Version <= c.ourHighestProtoVersion {
Expand Down
4 changes: 2 additions & 2 deletions cmd/devp2p/internal/v4test/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func newTestEnv(remote string, listen1, listen2 string) *testenv {
ip = net.ParseIP("127.0.0.1")
}
if tcpPort = node.TCP(); tcpPort == 0 {
tcpPort = 30303
tcpPort = 42786
}
if udpPort = node.TCP(); udpPort == 0 {
udpPort = 30303
udpPort = 42786
}
node = enode.NewV4(node.Pubkey(), ip, tcpPort, udpPort)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/devp2p/nodesetcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func snapFilter(args []string) (nodeFilter, error) {
var snap struct {
Tail []rlp.RawValue `rlp:"tail"`
}
return n.N.Load(enr.WithEntry("snap", &snap)) == nil
return n.N.Load(enr.WithEntry("xsnap", &snap)) == nil
}
return f, nil
}
2 changes: 1 addition & 1 deletion eth/downloader/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ type peerSet struct {
func newPeerSet() *peerSet {
return &peerSet{
peers: make(map[string]*peerConnection),
rates: msgrate.NewTrackers(log.New("proto", "eth")),
rates: msgrate.NewTrackers(log.New("proto", "exp")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (h *handler) unregisterPeer(id string) {
return
}
// Remove the `eth` peer if it exists
logger.Debug("Removing Ethereum peer", "snap", peer.snapExt != nil)
logger.Debug("Removing Ethereum peer", "xsnap", peer.snapExt != nil)

// Remove the `snap` extension if it exists
if peer.snapExt != nil {
Expand Down
2 changes: 1 addition & 1 deletion eth/peerset.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (

// errSnapWithoutEth is returned if a peer attempts to connect only on the
// snap protocol without advertizing the eth main protocol.
errSnapWithoutEth = errors.New("peer connected on snap without compatible eth support")
errSnapWithoutEth = errors.New("peer connected on snap without compatible exp support")
)

// peerSet represents the collection of active peers currently participating in
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/snap/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (

// ProtocolName is the official short name of the `snap` protocol used during
// devp2p capability negotiation.
const ProtocolName = "snap"
const ProtocolName = "xsnap"

// ProtocolVersions are the supported versions of the `snap` protocol (first
// is primary).
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/snap/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func NewSyncer(db ethdb.KeyValueStore) *Syncer {
peers: make(map[string]SyncPeer),
peerJoin: new(event.Feed),
peerDrop: new(event.Feed),
rates: msgrate.NewTrackers(log.New("proto", "snap")),
rates: msgrate.NewTrackers(log.New("proto", "xsnap")),
update: make(chan struct{}, 1),

accountIdlers: make(map[string]struct{}),
Expand Down
2 changes: 1 addition & 1 deletion les/enr_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ethEntry struct {
Tail []rlp.RawValue `rlp:"tail"`
}

func (ethEntry) ENRKey() string { return "eth" }
func (ethEntry) ENRKey() string { return "exp" }

// setupDiscovery creates the node discovery source for the eth protocol.
func (eth *LightEthereum) setupDiscovery() (enode.Iterator, error) {
Expand Down

0 comments on commit f58cd2d

Please sign in to comment.