Skip to content

Commit cc11462

Browse files
authored
Prioritize eth/68 by default (#7463)
Set `DefaultConfig.ProtocolVersion` to [68, 67, 66] instead of [67, 68]. See ethereum/hive#776
1 parent d9abfd8 commit cc11462

File tree

12 files changed

+146
-147
lines changed

12 files changed

+146
-147
lines changed

cmd/observer/observer/handshake.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
libcommon "github.com/ledgerwatch/erigon-lib/common"
13+
"github.com/ledgerwatch/erigon-lib/direct"
1314

1415
"github.com/ledgerwatch/erigon/common"
1516
"github.com/ledgerwatch/erigon/core/forkid"
@@ -239,11 +240,10 @@ func makeOurHelloMessage(myPrivateKey *ecdsa.PrivateKey) HelloMessage {
239240
clientID := common.MakeName("observer", version)
240241

241242
caps := []p2p.Cap{
242-
{Name: eth.ProtocolName, Version: 63},
243-
{Name: eth.ProtocolName, Version: 64},
244-
{Name: eth.ProtocolName, Version: 65},
245-
{Name: eth.ProtocolName, Version: eth.ETH66},
246-
{Name: eth.ProtocolName, Version: eth.ETH67},
243+
{Name: eth.ProtocolName, Version: direct.ETH65},
244+
{Name: eth.ProtocolName, Version: direct.ETH66},
245+
{Name: eth.ProtocolName, Version: direct.ETH67},
246+
{Name: eth.ProtocolName, Version: direct.ETH68},
247247
}
248248

249249
return HelloMessage{

cmd/observer/observer/handshake_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"context"
55
"testing"
66

7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
10+
"github.com/ledgerwatch/erigon-lib/direct"
11+
712
"github.com/ledgerwatch/erigon/crypto"
8-
"github.com/ledgerwatch/erigon/eth/protocols/eth"
913
"github.com/ledgerwatch/erigon/p2p/enode"
1014
"github.com/ledgerwatch/erigon/params"
11-
"github.com/stretchr/testify/assert"
12-
"github.com/stretchr/testify/require"
1315
)
1416

1517
func TestHandshake(t *testing.T) {
@@ -31,6 +33,6 @@ func TestHandshake(t *testing.T) {
3133
assert.Contains(t, hello.ClientID, "erigon")
3234

3335
require.NotNil(t, status)
34-
assert.Equal(t, uint32(eth.ETH66), status.ProtocolVersion)
36+
assert.Equal(t, uint32(direct.ETH66), status.ProtocolVersion)
3537
assert.Equal(t, uint64(1), status.NetworkID)
3638
}

cmd/sentry/sentry/eth_handshake_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ import (
55
"testing"
66

77
"github.com/holiman/uint256"
8+
"github.com/stretchr/testify/assert"
9+
810
libcommon "github.com/ledgerwatch/erigon-lib/common"
11+
"github.com/ledgerwatch/erigon-lib/direct"
912
"github.com/ledgerwatch/erigon-lib/gointerfaces"
1013
proto_sentry "github.com/ledgerwatch/erigon-lib/gointerfaces/sentry"
11-
"github.com/stretchr/testify/assert"
1214

1315
"github.com/ledgerwatch/erigon/core/forkid"
1416
"github.com/ledgerwatch/erigon/eth/protocols/eth"
1517
"github.com/ledgerwatch/erigon/params"
1618
)
1719

1820
func TestCheckPeerStatusCompatibility(t *testing.T) {
19-
var version uint = eth.ETH66
21+
var version uint = direct.ETH66
2022
networkID := params.MainnetChainConfig.ChainID.Uint64()
2123
goodReply := eth.StatusPacket{
2224
ProtocolVersion: uint32(version),
@@ -52,14 +54,14 @@ func TestCheckPeerStatusCompatibility(t *testing.T) {
5254
})
5355
t.Run("version mismatch min", func(t *testing.T) {
5456
reply := goodReply
55-
reply.ProtocolVersion = eth.ETH66 - 1
57+
reply.ProtocolVersion = direct.ETH66 - 1
5658
err := checkPeerStatusCompatibility(&reply, &status, version, version)
5759
assert.NotNil(t, err)
5860
assert.Contains(t, err.Error(), "version is less")
5961
})
6062
t.Run("version mismatch max", func(t *testing.T) {
6163
reply := goodReply
62-
reply.ProtocolVersion = eth.ETH66 + 1
64+
reply.ProtocolVersion = direct.ETH66 + 1
6365
err := checkPeerStatusCompatibility(&reply, &status, version, version)
6466
assert.NotNil(t, err)
6567
assert.Contains(t, err.Error(), "version is more")

cmd/sentry/sentry/sentry_grpc_server.go

Lines changed: 70 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ import (
1818
"syscall"
1919
"time"
2020

21+
"github.com/ledgerwatch/log/v3"
22+
"google.golang.org/grpc"
23+
"google.golang.org/grpc/health"
24+
"google.golang.org/grpc/health/grpc_health_v1"
25+
"google.golang.org/protobuf/types/known/emptypb"
26+
2127
libcommon "github.com/ledgerwatch/erigon-lib/common"
2228
"github.com/ledgerwatch/erigon-lib/common/datadir"
2329
"github.com/ledgerwatch/erigon-lib/common/dir"
30+
"github.com/ledgerwatch/erigon-lib/direct"
2431
"github.com/ledgerwatch/erigon-lib/gointerfaces"
2532
"github.com/ledgerwatch/erigon-lib/gointerfaces/grpcutil"
2633
proto_sentry "github.com/ledgerwatch/erigon-lib/gointerfaces/sentry"
2734
proto_types "github.com/ledgerwatch/erigon-lib/gointerfaces/types"
28-
"github.com/ledgerwatch/log/v3"
29-
"google.golang.org/grpc"
30-
"google.golang.org/grpc/health"
31-
"google.golang.org/grpc/health/grpc_health_v1"
32-
"google.golang.org/protobuf/types/known/emptypb"
3335

3436
"github.com/ledgerwatch/erigon/cmd/utils"
3537
"github.com/ledgerwatch/erigon/common/debug"
@@ -414,7 +416,7 @@ func runPeer(
414416
}
415417
send(eth.ToProto[protocol][msg.Code], peerID, b)
416418
case eth.GetNodeDataMsg:
417-
if protocol >= eth.ETH67 {
419+
if protocol >= direct.ETH67 {
418420
msg.Discard()
419421
return fmt.Errorf("unexpected GetNodeDataMsg from %s in eth/%d", peerID, protocol)
420422
}
@@ -558,75 +560,67 @@ func NewGrpcServer(ctx context.Context, dialCandidates func() enode.Iterator, re
558560
logger: logger,
559561
}
560562

561-
protocols := []uint{protocol}
562-
if protocol == eth.ETH67 {
563-
protocols = append(protocols, eth.ETH66)
563+
var disc enode.Iterator
564+
if dialCandidates != nil {
565+
disc = dialCandidates()
564566
}
565-
566-
for _, p := range protocols {
567-
protocol := p
568-
var disc enode.Iterator
569-
if dialCandidates != nil {
570-
disc = dialCandidates()
571-
}
572-
ss.Protocols = append(ss.Protocols, p2p.Protocol{
573-
Name: eth.ProtocolName,
574-
Version: protocol,
575-
Length: 17,
576-
DialCandidates: disc,
577-
Run: func(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
578-
peerID := peer.Pubkey()
579-
printablePeerID := hex.EncodeToString(peerID[:])[:20]
580-
if ss.getPeer(peerID) != nil {
581-
logger.Trace("[p2p] peer already has connection", "peerId", printablePeerID)
582-
return nil
583-
}
584-
logger.Trace("[p2p] start with peer", "peerId", printablePeerID)
585-
586-
peerInfo := NewPeerInfo(peer, rw)
587-
peerInfo.protocol = protocol
588-
defer peerInfo.Close()
589-
590-
defer ss.GoodPeers.Delete(peerID)
591-
err := handShake(ctx, ss.GetStatus(), peerID, rw, protocol, protocol, func(bestHash libcommon.Hash) error {
592-
ss.GoodPeers.Store(peerID, peerInfo)
593-
ss.sendNewPeerToClients(gointerfaces.ConvertHashToH512(peerID))
594-
return ss.startSync(ctx, bestHash, peerID)
595-
})
596-
if err != nil {
597-
if errors.Is(err, NetworkIdMissmatchErr) || errors.Is(err, io.EOF) || errors.Is(err, p2p.ErrShuttingDown) {
598-
logger.Trace("[p2p] Handshake failure", "peer", printablePeerID, "err", err)
599-
} else {
600-
logger.Debug("[p2p] Handshake failure", "peer", printablePeerID, "err", err)
601-
}
602-
return fmt.Errorf("[p2p]handshake to peer %s: %w", printablePeerID, err)
603-
}
604-
logger.Trace("[p2p] Received status message OK", "peerId", printablePeerID, "name", peer.Name())
605-
606-
err = runPeer(
607-
ctx,
608-
peerID,
609-
protocol,
610-
rw,
611-
peerInfo,
612-
ss.send,
613-
ss.hasSubscribers,
614-
logger,
615-
) // runPeer never returns a nil error
616-
logger.Trace("[p2p] error while running peer", "peerId", printablePeerID, "err", err)
617-
ss.sendGonePeerToClients(gointerfaces.ConvertHashToH512(peerID))
567+
ss.Protocols = append(ss.Protocols, p2p.Protocol{
568+
Name: eth.ProtocolName,
569+
Version: protocol,
570+
Length: 17,
571+
DialCandidates: disc,
572+
Run: func(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
573+
peerID := peer.Pubkey()
574+
printablePeerID := hex.EncodeToString(peerID[:])[:20]
575+
if ss.getPeer(peerID) != nil {
576+
logger.Trace("[p2p] peer already has connection", "peerId", printablePeerID)
618577
return nil
619-
},
620-
NodeInfo: func() interface{} {
621-
return readNodeInfo()
622-
},
623-
PeerInfo: func(peerID [64]byte) interface{} {
624-
// TODO: remember handshake reply per peer ID and return eth-related Status info (see ethPeerInfo in geth)
625-
return nil
626-
},
627-
//Attributes: []enr.Entry{eth.CurrentENREntry(chainConfig, genesisHash, headHeight)},
628-
})
629-
}
578+
}
579+
logger.Trace("[p2p] start with peer", "peerId", printablePeerID)
580+
581+
peerInfo := NewPeerInfo(peer, rw)
582+
peerInfo.protocol = protocol
583+
defer peerInfo.Close()
584+
585+
defer ss.GoodPeers.Delete(peerID)
586+
err := handShake(ctx, ss.GetStatus(), peerID, rw, protocol, protocol, func(bestHash libcommon.Hash) error {
587+
ss.GoodPeers.Store(peerID, peerInfo)
588+
ss.sendNewPeerToClients(gointerfaces.ConvertHashToH512(peerID))
589+
return ss.startSync(ctx, bestHash, peerID)
590+
})
591+
if err != nil {
592+
if errors.Is(err, NetworkIdMissmatchErr) || errors.Is(err, io.EOF) || errors.Is(err, p2p.ErrShuttingDown) {
593+
logger.Trace("[p2p] Handshake failure", "peer", printablePeerID, "err", err)
594+
} else {
595+
logger.Debug("[p2p] Handshake failure", "peer", printablePeerID, "err", err)
596+
}
597+
return fmt.Errorf("[p2p]handshake to peer %s: %w", printablePeerID, err)
598+
}
599+
logger.Trace("[p2p] Received status message OK", "peerId", printablePeerID, "name", peer.Name())
600+
601+
err = runPeer(
602+
ctx,
603+
peerID,
604+
protocol,
605+
rw,
606+
peerInfo,
607+
ss.send,
608+
ss.hasSubscribers,
609+
logger,
610+
) // runPeer never returns a nil error
611+
logger.Trace("[p2p] error while running peer", "peerId", printablePeerID, "err", err)
612+
ss.sendGonePeerToClients(gointerfaces.ConvertHashToH512(peerID))
613+
return nil
614+
},
615+
NodeInfo: func() interface{} {
616+
return readNodeInfo()
617+
},
618+
PeerInfo: func(peerID [64]byte) interface{} {
619+
// TODO: remember handshake reply per peer ID and return eth-related Status info (see ethPeerInfo in geth)
620+
return nil
621+
},
622+
//Attributes: []enr.Entry{eth.CurrentENREntry(chainConfig, genesisHash, headHeight)},
623+
})
630624

631625
return ss
632626
}
@@ -934,11 +928,11 @@ func (ss *GrpcServer) SendMessageToAll(ctx context.Context, req *proto_sentry.Ou
934928
func (ss *GrpcServer) HandShake(context.Context, *emptypb.Empty) (*proto_sentry.HandShakeReply, error) {
935929
reply := &proto_sentry.HandShakeReply{}
936930
switch ss.Protocols[0].Version {
937-
case eth.ETH66:
931+
case direct.ETH66:
938932
reply.Protocol = proto_sentry.Protocol_ETH66
939-
case eth.ETH67:
933+
case direct.ETH67:
940934
reply.Protocol = proto_sentry.Protocol_ETH67
941-
case eth.ETH68:
935+
case direct.ETH68:
942936
reply.Protocol = proto_sentry.Protocol_ETH68
943937
}
944938
return reply, nil

cmd/sentry/sentry/sentry_grpc_server_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ import (
77
"time"
88

99
"github.com/holiman/uint256"
10+
"github.com/stretchr/testify/require"
11+
1012
"github.com/ledgerwatch/erigon-lib/chain"
1113
libcommon "github.com/ledgerwatch/erigon-lib/common"
14+
"github.com/ledgerwatch/erigon-lib/direct"
1215
"github.com/ledgerwatch/erigon-lib/gointerfaces"
1316
proto_sentry "github.com/ledgerwatch/erigon-lib/gointerfaces/sentry"
1417
"github.com/ledgerwatch/erigon-lib/kv"
1518
"github.com/ledgerwatch/erigon-lib/kv/memdb"
16-
"github.com/ledgerwatch/erigon/core"
17-
"github.com/ledgerwatch/erigon/core/types"
18-
"github.com/stretchr/testify/require"
1919

20+
"github.com/ledgerwatch/erigon/core"
2021
"github.com/ledgerwatch/erigon/core/forkid"
2122
"github.com/ledgerwatch/erigon/core/rawdb"
22-
"github.com/ledgerwatch/erigon/eth/protocols/eth"
23+
"github.com/ledgerwatch/erigon/core/types"
2324
"github.com/ledgerwatch/erigon/p2p"
2425
)
2526

@@ -55,7 +56,7 @@ func testSentryServer(db kv.Getter, genesis *types.Genesis, genesisHash libcommo
5556

5657
// Tests that peers are correctly accepted (or rejected) based on the advertised
5758
// fork IDs in the protocol handshake.
58-
func TestForkIDSplit66(t *testing.T) { testForkIDSplit(t, eth.ETH66) }
59+
func TestForkIDSplit66(t *testing.T) { testForkIDSplit(t, direct.ETH66) }
5960

6061
func testForkIDSplit(t *testing.T, protocol uint) {
6162
var (

cmd/sentry/sentry/sentry_multi_client.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import (
1313

1414
"github.com/c2h5oh/datasize"
1515
"github.com/holiman/uint256"
16+
"github.com/ledgerwatch/log/v3"
17+
"google.golang.org/grpc"
18+
"google.golang.org/grpc/backoff"
19+
"google.golang.org/grpc/credentials/insecure"
20+
"google.golang.org/grpc/keepalive"
21+
"google.golang.org/protobuf/types/known/emptypb"
22+
1623
"github.com/ledgerwatch/erigon-lib/chain"
1724
libcommon "github.com/ledgerwatch/erigon-lib/common"
1825
"github.com/ledgerwatch/erigon-lib/common/dbg"
@@ -23,12 +30,6 @@ import (
2330
proto_types "github.com/ledgerwatch/erigon-lib/gointerfaces/types"
2431
"github.com/ledgerwatch/erigon-lib/kv"
2532
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
26-
"github.com/ledgerwatch/log/v3"
27-
"google.golang.org/grpc"
28-
"google.golang.org/grpc/backoff"
29-
"google.golang.org/grpc/credentials/insecure"
30-
"google.golang.org/grpc/keepalive"
31-
"google.golang.org/protobuf/types/known/emptypb"
3233

3334
"github.com/ledgerwatch/erigon/consensus"
3435
"github.com/ledgerwatch/erigon/core/forkid"
@@ -68,8 +69,8 @@ func (cs *MultiClient) RecvUploadMessageLoop(
6869
wg *sync.WaitGroup,
6970
) {
7071
ids := []proto_sentry.MessageId{
71-
eth.ToProto[eth.ETH66][eth.GetBlockBodiesMsg],
72-
eth.ToProto[eth.ETH66][eth.GetReceiptsMsg],
72+
eth.ToProto[direct.ETH66][eth.GetBlockBodiesMsg],
73+
eth.ToProto[direct.ETH66][eth.GetReceiptsMsg],
7374
}
7475
streamFactory := func(streamCtx context.Context, sentry direct.SentryClient) (sentryMessageStream, error) {
7576
return sentry.Messages(streamCtx, &proto_sentry.MessagesRequest{Ids: ids}, grpc.WaitForReady(true))
@@ -84,7 +85,7 @@ func (cs *MultiClient) RecvUploadHeadersMessageLoop(
8485
wg *sync.WaitGroup,
8586
) {
8687
ids := []proto_sentry.MessageId{
87-
eth.ToProto[eth.ETH66][eth.GetBlockHeadersMsg],
88+
eth.ToProto[direct.ETH66][eth.GetBlockHeadersMsg],
8889
}
8990
streamFactory := func(streamCtx context.Context, sentry direct.SentryClient) (sentryMessageStream, error) {
9091
return sentry.Messages(streamCtx, &proto_sentry.MessagesRequest{Ids: ids}, grpc.WaitForReady(true))
@@ -99,10 +100,10 @@ func (cs *MultiClient) RecvMessageLoop(
99100
wg *sync.WaitGroup,
100101
) {
101102
ids := []proto_sentry.MessageId{
102-
eth.ToProto[eth.ETH66][eth.BlockHeadersMsg],
103-
eth.ToProto[eth.ETH66][eth.BlockBodiesMsg],
104-
eth.ToProto[eth.ETH66][eth.NewBlockHashesMsg],
105-
eth.ToProto[eth.ETH66][eth.NewBlockMsg],
103+
eth.ToProto[direct.ETH66][eth.BlockHeadersMsg],
104+
eth.ToProto[direct.ETH66][eth.BlockBodiesMsg],
105+
eth.ToProto[direct.ETH66][eth.NewBlockHashesMsg],
106+
eth.ToProto[direct.ETH66][eth.NewBlockMsg],
106107
}
107108
streamFactory := func(streamCtx context.Context, sentry direct.SentryClient) (sentryMessageStream, error) {
108109
return sentry.Messages(streamCtx, &proto_sentry.MessagesRequest{Ids: ids}, grpc.WaitForReady(true))

0 commit comments

Comments
 (0)