diff --git a/cmd/sentry/commands/sentry.go b/cmd/sentry/commands/sentry.go index 0a99fc7b2b7f94a1d576f96d58402dcc19b58833..e2b171cf86daa8b32ded163cf2d6a63a8ee60be6 100644 --- a/cmd/sentry/commands/sentry.go +++ b/cmd/sentry/commands/sentry.go @@ -41,7 +41,7 @@ func init() { `) rootCmd.Flags().IntVar(&port, "port", 30303, "p2p port number") rootCmd.Flags().StringVar(&sentryAddr, "sentry.api.addr", "localhost:9091", "grpc addresses") - rootCmd.Flags().StringVar(&protocol, "p2p.protocol", "eth66", "eth65|eth66") + rootCmd.Flags().StringVar(&protocol, "p2p.protocol", "eth66", "eth66") rootCmd.Flags().StringSliceVar(&staticPeers, "staticpeers", []string{}, "static peer list [enode]") rootCmd.Flags().StringSliceVar(&discoveryDNS, utils.DNSDiscoveryFlag.Name, []string{}, utils.DNSDiscoveryFlag.Usage) rootCmd.Flags().BoolVar(&nodiscover, utils.NoDiscoverFlag.Name, false, utils.NoDiscoverFlag.Usage) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3ef6e34af7bcf0f4770e16e836f2b64f620c5ccd..c995404ab298d363380a69e52e3e3ef19ffbb3a6 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -407,11 +407,6 @@ var ( Usage: "Network listening port", Value: 30303, } - ListenPort65Flag = cli.IntFlag{ - Name: "p2p.eth65.port", - Usage: "ETH65 Network listening port", - Value: 30304, - } SentryAddrFlag = cli.StringFlag{ Name: "sentry.api.addr", Usage: "comma separated sentry addresses '<host>:<port>,<host>:<port>'", @@ -756,9 +751,6 @@ func setListenAddress(ctx *cli.Context, cfg *p2p.Config) { if ctx.GlobalIsSet(ListenPortFlag.Name) { cfg.ListenAddr = fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortFlag.Name)) } - if ctx.GlobalIsSet(ListenPort65Flag.Name) { - cfg.ListenAddr65 = fmt.Sprintf(":%d", ctx.GlobalInt(ListenPort65Flag.Name)) - } if ctx.GlobalIsSet(SentryAddrFlag.Name) { cfg.SentryAddr = SplitAndTrim(ctx.GlobalString(SentryAddrFlag.Name)) } diff --git a/eth/protocols/eth/handler.go b/eth/protocols/eth/handler.go index 8466099c038d805b6f9fae5102963a840336aad5..2ea885e4131c4652815b9c52ec196afd2948cf4f 100644 --- a/eth/protocols/eth/handler.go +++ b/eth/protocols/eth/handler.go @@ -163,25 +163,6 @@ type Decoder interface { Time() time.Time } -var eth65 = map[uint64]msgHandler{ - // old 64 messages - GetBlockHeadersMsg: handleGetBlockHeaders, - BlockHeadersMsg: handleBlockHeaders, - GetBlockBodiesMsg: handleGetBlockBodies, - BlockBodiesMsg: handleBlockBodies, - GetNodeDataMsg: handleGetNodeData, - NodeDataMsg: handleNodeData, - GetReceiptsMsg: handleGetReceipts, - ReceiptsMsg: handleReceipts, - NewBlockHashesMsg: handleNewBlockhashes, - NewBlockMsg: handleNewBlock, - TransactionsMsg: handleTransactions, - // New eth65 messages - NewPooledTransactionHashesMsg: handleNewPooledTransactionHashes, - GetPooledTransactionsMsg: handleGetPooledTransactions, - PooledTransactionsMsg: handlePooledTransactions, -} - var eth66 = map[uint64]msgHandler{ // eth64 announcement messages (no id) NewBlockHashesMsg: handleNewBlockhashes, @@ -215,10 +196,7 @@ func handleMessage(backend Backend, peer *Peer) error { } defer msg.Discard() - var handlers = eth65 - if peer.Version() >= ETH66 { - handlers = eth66 - } + handlers := eth66 if handler := handlers[msg.Code]; handler != nil { return handler(backend, msg, peer) diff --git a/eth/protocols/eth/handler_test.go b/eth/protocols/eth/handler_test.go index cfcf5a0d66f018a918c85d04a084a64f18d8422e..888bb0c18b96eb9bb085c80d1ac47b131a500d7d 100644 --- a/eth/protocols/eth/handler_test.go +++ b/eth/protocols/eth/handler_test.go @@ -17,10 +17,7 @@ package eth_test import ( - "context" - "math" "math/big" - "math/rand" "testing" "github.com/holiman/uint256" @@ -32,7 +29,6 @@ import ( "github.com/ledgerwatch/erigon/core/types" "github.com/ledgerwatch/erigon/crypto" "github.com/ledgerwatch/erigon/eth/protocols/eth" - "github.com/ledgerwatch/erigon/p2p" "github.com/ledgerwatch/erigon/p2p/enode" "github.com/ledgerwatch/erigon/params" "github.com/ledgerwatch/erigon/rlp" @@ -134,266 +130,6 @@ func (b *testBackend) GetBlockHashesFromHash(tx kv.Tx, hash common.Hash, max uin return chain } -// Tests that block headers can be retrieved from a remote chain based on user queries. -func TestGetBlockHeaders64(t *testing.T) { testGetBlockHeaders(t, 64) } -func TestGetBlockHeaders65(t *testing.T) { testGetBlockHeaders(t, 65) } - -func testGetBlockHeaders(t *testing.T, protocol uint) { - backend := newTestBackend(t, eth.MaxHeadersServe+15) - tx, err := backend.db.BeginRw(context.Background()) - require.NoError(t, err) - defer tx.Rollback() - - peer, _ := newTestPeer("peer", protocol, backend) - defer peer.close() - - // Create a "random" unknown hash for testing - var unknown common.Hash - for i := range unknown { - unknown[i] = byte(i) - } - getBlockHash := func(n uint64) common.Hash { - h, _ := rawdb.ReadCanonicalHash(tx, n) - return h - - } - // Create a batch of tests for various scenarios - limit := uint64(eth.MaxHeadersServe) - tests := []struct { - query *eth.GetBlockHeadersPacket // The query to execute for header retrieval - expect []common.Hash // The hashes of the block whose headers are expected - }{ - // A single random block should be retrievable by hash and number too - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Hash: getBlockHash(limit / 2)}, Amount: 1}, - []common.Hash{getBlockHash(limit / 2)}, - }, { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: limit / 2}, Amount: 1}, - []common.Hash{getBlockHash(limit / 2)}, - }, - // Multiple headers should be retrievable in both directions - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: limit / 2}, Amount: 3}, - []common.Hash{ - getBlockHash(limit / 2), - getBlockHash(limit/2 + 1), - getBlockHash(limit/2 + 2), - }, - }, { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: limit / 2}, Amount: 3, Reverse: true}, - []common.Hash{ - getBlockHash(limit / 2), - getBlockHash(limit/2 - 1), - getBlockHash(limit/2 - 2), - }, - }, - // Multiple headers with skip lists should be retrievable - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: limit / 2}, Skip: 3, Amount: 3}, - []common.Hash{ - getBlockHash(limit / 2), - getBlockHash(limit/2 + 4), - getBlockHash(limit/2 + 8), - }, - }, { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: limit / 2}, Skip: 3, Amount: 3, Reverse: true}, - []common.Hash{ - getBlockHash(limit / 2), - getBlockHash(limit/2 - 4), - getBlockHash(limit/2 - 8), - }, - }, - // The chain endpoints should be retrievable - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: 0}, Amount: 1}, - []common.Hash{getBlockHash(0)}, - }, { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: rawdb.ReadCurrentHeader(tx).Number.Uint64()}, Amount: 1}, - []common.Hash{rawdb.ReadCurrentHeader(tx).Hash()}, - }, - // Ensure protocol limits are honored - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: rawdb.ReadCurrentHeader(tx).Number.Uint64() - 1}, Amount: limit + 10, Reverse: true}, - backend.GetBlockHashesFromHash(tx, rawdb.ReadCurrentHeader(tx).Hash(), limit), - }, - // Check that requesting more than available is handled gracefully - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: rawdb.ReadCurrentHeader(tx).Number.Uint64() - 4}, Skip: 3, Amount: 3}, - []common.Hash{ - getBlockHash(rawdb.ReadCurrentHeader(tx).Number.Uint64() - 4), - getBlockHash(rawdb.ReadCurrentHeader(tx).Number.Uint64()), - }, - }, { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: 4}, Skip: 3, Amount: 3, Reverse: true}, - []common.Hash{ - getBlockHash(4), - getBlockHash(0), - }, - }, - // Check that requesting more than available is handled gracefully, even if mid skip - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: rawdb.ReadCurrentHeader(tx).Number.Uint64() - 4}, Skip: 2, Amount: 3}, - []common.Hash{ - getBlockHash(rawdb.ReadCurrentHeader(tx).Number.Uint64() - 4), - getBlockHash(rawdb.ReadCurrentHeader(tx).Number.Uint64() - 1), - }, - }, { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: 4}, Skip: 2, Amount: 3, Reverse: true}, - []common.Hash{ - getBlockHash(4), - getBlockHash(1), - }, - }, - // Check a corner case where requesting more can iterate past the endpoints - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: 2}, Amount: 5, Reverse: true}, - []common.Hash{ - getBlockHash(2), - getBlockHash(1), - getBlockHash(0), - }, - }, - // Check a corner case where skipping overflow loops back into the chain start - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Hash: getBlockHash(3)}, Amount: 2, Reverse: false, Skip: math.MaxUint64 - 1}, - []common.Hash{ - getBlockHash(3), - }, - }, - // Check a corner case where skipping overflow loops back to the same header - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Hash: getBlockHash(1)}, Amount: 2, Reverse: false, Skip: math.MaxUint64}, - []common.Hash{ - getBlockHash(1), - }, - }, - // Check that non existing headers aren't returned - { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Hash: unknown}, Amount: 1}, - []common.Hash{}, - }, { - ð.GetBlockHeadersPacket{Origin: eth.HashOrNumber{Number: rawdb.ReadCurrentHeader(tx).Number.Uint64() + 1}, Amount: 1}, - []common.Hash{}, - }, - } - // Run each of the tests and verify the results against the chain - for i, tt := range tests { - // Collect the headers to expect in the response - var headers []*types.Header - for _, hash := range tt.expect { - h, _ := rawdb.ReadHeaderByHash(tx, hash) - - headers = append(headers, h) - } - // Send the hash request and verify the response - if err := p2p.Send(peer.app, eth.GetBlockHeadersMsg, tt.query); err != nil { - t.Fatal(err) - } - if err := p2p.ExpectMsg(peer.app, eth.BlockHeadersMsg, headers); err != nil { - t.Errorf("test %d: headers mismatch: %v", i, err) - } - // If the test used number origins, repeat with hashes as the too - if tt.query.Origin.Hash == (common.Hash{}) { - if origin := rawdb.ReadHeaderByNumber(tx, tt.query.Origin.Number); origin != nil { - tt.query.Origin.Hash, tt.query.Origin.Number = origin.Hash(), 0 - - if err := p2p.Send(peer.app, eth.GetBlockHeadersMsg, tt.query); err != nil { - t.Fatal(err) - } - if err := p2p.ExpectMsg(peer.app, eth.BlockHeadersMsg, headers); err != nil { - t.Errorf("test %d: headers mismatch: %v", i, err) - } - } - } - } -} - -// Tests that block contents can be retrieved from a remote chain based on their hashes. -func TestGetBlockBodies64(t *testing.T) { testGetBlockBodies(t, 64) } -func TestGetBlockBodies65(t *testing.T) { testGetBlockBodies(t, 65) } - -func testGetBlockBodies(t *testing.T, protocol uint) { - backend := newTestBackend(t, eth.MaxBodiesServe+15) - tx, err := backend.db.BeginRw(context.Background()) - require.NoError(t, err) - defer tx.Rollback() - - peer, _ := newTestPeer("peer", protocol, backend) - defer peer.close() - - block1 := rawdb.ReadHeaderByNumber(tx, 1) - block10 := rawdb.ReadHeaderByNumber(tx, 10) - block100 := rawdb.ReadHeaderByNumber(tx, 100) - - // Create a batch of tests for various scenarios - limit := eth.MaxBodiesServe - tests := []struct { - random int // Number of blocks to fetch randomly from the chain - explicit []common.Hash // Explicitly requested blocks - available []bool // Availability of explicitly requested blocks - expected int // Total number of existing blocks to expect - }{ - {1, nil, nil, 1}, // A single random block should be retrievable - {10, nil, nil, 10}, // Multiple random blocks should be retrievable - {limit, nil, nil, limit}, // The maximum possible blocks should be retrievable - {limit + 1, nil, nil, limit}, // No more than the possible block count should be returned - {0, []common.Hash{backend.genesis.Hash()}, []bool{true}, 1}, // The genesis block should be retrievable - {0, []common.Hash{rawdb.ReadCurrentHeader(tx).Hash()}, []bool{true}, 1}, // The chains head block should be retrievable - {0, []common.Hash{{}}, []bool{false}, 0}, // A non existent block should not be returned - - // Existing and non-existing blocks interleaved should not cause problems - {0, []common.Hash{ - {}, - block1.Hash(), - {}, - block10.Hash(), - {}, - block100.Hash(), - {}, - }, []bool{false, true, false, true, false, true, false}, 3}, - } - // Run each of the tests and verify the results against the chain - for i, tt := range tests { - // Collect the hashes to request, and the response to expectva - var ( - hashes []common.Hash - bodies []*eth.BlockBody - seen = make(map[int64]bool) - ) - for j := 0; j < tt.random; j++ { - for { - num := rand.Int63n(int64(rawdb.ReadCurrentHeader(tx).Number.Uint64())) - if !seen[num] { - seen[num] = true - - block, _ := rawdb.ReadBlockByNumber(tx, uint64(num)) - hashes = append(hashes, block.Hash()) - if len(bodies) < tt.expected { - bodies = append(bodies, ð.BlockBody{Transactions: block.Transactions(), Uncles: block.Uncles()}) - } - break - } - } - } - for j, hash := range tt.explicit { - hashes = append(hashes, hash) - if tt.available[j] && len(bodies) < tt.expected { - block, _ := rawdb.ReadBlockByHash(tx, hash) - bodies = append(bodies, ð.BlockBody{Transactions: block.Transactions(), Uncles: block.Uncles()}) - } - } - // Send the hash request and verify the response - if err := p2p.Send(peer.app, eth.GetBlockBodiesMsg, hashes); err != nil { - t.Fatal(err) - } - if err := p2p.ExpectMsg(peer.app, eth.BlockBodiesMsg, bodies); err != nil { - t.Errorf("test %d: bodies mismatch: %v", i, err) - } - } -} - -// Tests that the transaction receipts can be retrieved based on hashes. -func TestGetBlockReceipts65(t *testing.T) { testGetBlockReceipts(t, 65) } func TestGetBlockReceipts66(t *testing.T) { testGetBlockReceipts(t, 66) } func testGetBlockReceipts(t *testing.T, protocol uint) { diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index 15bd8bbcb29617730574c349db98c33ffd8abedb..83ee803ecbd84723f264b601d80db9b9292523a4 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -47,7 +47,6 @@ var DefaultFlags = []cli.Flag{ SyncLoopThrottleFlag, BadBlockFlag, utils.ListenPortFlag, - utils.ListenPort65Flag, utils.NATFlag, utils.NoDiscoverFlag, utils.DiscoveryV5Flag,