Skip to content

Commit c368f72

Browse files
authored
Revert "eth: drop eth/65, the last non-reqid protocol version" (#23426)
1 parent 5566e5d commit c368f72

File tree

15 files changed

+609
-179
lines changed

15 files changed

+609
-179
lines changed

cmd/devp2p/internal/ethtest/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestEthSuite(t *testing.T) {
4545
if err != nil {
4646
t.Fatalf("could not create new test suite: %v", err)
4747
}
48-
for _, test := range suite.Eth66Tests() {
48+
for _, test := range suite.AllEthTests() {
4949
t.Run(test.Name, func(t *testing.T) {
5050
result := utesting.RunTAP([]utesting.Test{{Name: test.Name, Fn: test.Fn}}, os.Stdout)
5151
if result[0].Failed {

eth/downloader/downloader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I
448448
d.mux.Post(DoneEvent{latest})
449449
}
450450
}()
451-
if p.version < eth.ETH66 {
452-
return fmt.Errorf("%w: advertized %d < required %d", errTooOld, p.version, eth.ETH66)
451+
if p.version < eth.ETH65 {
452+
return fmt.Errorf("%w: advertized %d < required %d", errTooOld, p.version, eth.ETH65)
453453
}
454454
mode := d.getMode()
455455

eth/downloader/downloader_test.go

Lines changed: 93 additions & 2 deletions
Large diffs are not rendered by default.

eth/downloader/peer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func (ps *peerSet) HeaderIdlePeers() ([]*peerConnection, int) {
413413
throughput := func(p *peerConnection) int {
414414
return p.rates.Capacity(eth.BlockHeadersMsg, time.Second)
415415
}
416-
return ps.idlePeers(eth.ETH66, eth.ETH66, idle, throughput)
416+
return ps.idlePeers(eth.ETH65, eth.ETH66, idle, throughput)
417417
}
418418

419419
// BodyIdlePeers retrieves a flat list of all the currently body-idle peers within
@@ -425,7 +425,7 @@ func (ps *peerSet) BodyIdlePeers() ([]*peerConnection, int) {
425425
throughput := func(p *peerConnection) int {
426426
return p.rates.Capacity(eth.BlockBodiesMsg, time.Second)
427427
}
428-
return ps.idlePeers(eth.ETH66, eth.ETH66, idle, throughput)
428+
return ps.idlePeers(eth.ETH65, eth.ETH66, idle, throughput)
429429
}
430430

431431
// ReceiptIdlePeers retrieves a flat list of all the currently receipt-idle peers
@@ -437,7 +437,7 @@ func (ps *peerSet) ReceiptIdlePeers() ([]*peerConnection, int) {
437437
throughput := func(p *peerConnection) int {
438438
return p.rates.Capacity(eth.ReceiptsMsg, time.Second)
439439
}
440-
return ps.idlePeers(eth.ETH66, eth.ETH66, idle, throughput)
440+
return ps.idlePeers(eth.ETH65, eth.ETH66, idle, throughput)
441441
}
442442

443443
// NodeDataIdlePeers retrieves a flat list of all the currently node-data-idle
@@ -449,7 +449,7 @@ func (ps *peerSet) NodeDataIdlePeers() ([]*peerConnection, int) {
449449
throughput := func(p *peerConnection) int {
450450
return p.rates.Capacity(eth.NodeDataMsg, time.Second)
451451
}
452-
return ps.idlePeers(eth.ETH66, eth.ETH66, idle, throughput)
452+
return ps.idlePeers(eth.ETH65, eth.ETH66, idle, throughput)
453453
}
454454

455455
// idlePeers retrieves a flat list of all currently idle peers satisfying the

eth/handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type handler struct {
117117
whitelist map[uint64]common.Hash
118118

119119
// channels for fetcher, syncer, txsyncLoop
120+
txsyncCh chan *txsync
120121
quitSync chan struct{}
121122

122123
chainSync *chainSyncer
@@ -139,6 +140,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
139140
chain: config.Chain,
140141
peers: newPeerSet(),
141142
whitelist: config.Whitelist,
143+
txsyncCh: make(chan *txsync),
142144
quitSync: make(chan struct{}),
143145
}
144146
if config.Sync == downloader.FullSync {
@@ -406,8 +408,9 @@ func (h *handler) Start(maxPeers int) {
406408
go h.minedBroadcastLoop()
407409

408410
// start sync handlers
409-
h.wg.Add(1)
411+
h.wg.Add(2)
410412
go h.chainSync.loop()
413+
go h.txsyncLoop64() // TODO(karalabe): Legacy initial tx echange, drop with eth/64.
411414
}
412415

413416
func (h *handler) Stop() {

eth/handler_eth_test.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (h *testEthHandler) Handle(peer *eth.Peer, packet eth.Packet) error {
8080

8181
// Tests that peers are correctly accepted (or rejected) based on the advertised
8282
// fork IDs in the protocol handshake.
83+
func TestForkIDSplit65(t *testing.T) { testForkIDSplit(t, eth.ETH65) }
8384
func TestForkIDSplit66(t *testing.T) { testForkIDSplit(t, eth.ETH66) }
8485

8586
func testForkIDSplit(t *testing.T, protocol uint) {
@@ -235,6 +236,7 @@ func testForkIDSplit(t *testing.T, protocol uint) {
235236
}
236237

237238
// Tests that received transactions are added to the local pool.
239+
func TestRecvTransactions65(t *testing.T) { testRecvTransactions(t, eth.ETH65) }
238240
func TestRecvTransactions66(t *testing.T) { testRecvTransactions(t, eth.ETH66) }
239241

240242
func testRecvTransactions(t *testing.T, protocol uint) {
@@ -292,6 +294,7 @@ func testRecvTransactions(t *testing.T, protocol uint) {
292294
}
293295

294296
// This test checks that pending transactions are sent.
297+
func TestSendTransactions65(t *testing.T) { testSendTransactions(t, eth.ETH65) }
295298
func TestSendTransactions66(t *testing.T) { testSendTransactions(t, eth.ETH66) }
296299

297300
func testSendTransactions(t *testing.T, protocol uint) {
@@ -303,7 +306,7 @@ func testSendTransactions(t *testing.T, protocol uint) {
303306

304307
insert := make([]*types.Transaction, 100)
305308
for nonce := range insert {
306-
tx := types.NewTransaction(uint64(nonce), common.Address{}, big.NewInt(0), 100000, big.NewInt(0), make([]byte, 10240))
309+
tx := types.NewTransaction(uint64(nonce), common.Address{}, big.NewInt(0), 100000, big.NewInt(0), make([]byte, txsyncPackSize/10))
307310
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)
308311

309312
insert[nonce] = tx
@@ -377,6 +380,7 @@ func testSendTransactions(t *testing.T, protocol uint) {
377380

378381
// Tests that transactions get propagated to all attached peers, either via direct
379382
// broadcasts or via announcements/retrievals.
383+
func TestTransactionPropagation65(t *testing.T) { testTransactionPropagation(t, eth.ETH65) }
380384
func TestTransactionPropagation66(t *testing.T) { testTransactionPropagation(t, eth.ETH66) }
381385

382386
func testTransactionPropagation(t *testing.T, protocol uint) {
@@ -517,8 +521,8 @@ func testCheckpointChallenge(t *testing.T, syncmode downloader.SyncMode, checkpo
517521
defer p2pLocal.Close()
518522
defer p2pRemote.Close()
519523

520-
local := eth.NewPeer(eth.ETH66, p2p.NewPeerPipe(enode.ID{1}, "", nil, p2pLocal), p2pLocal, handler.txpool)
521-
remote := eth.NewPeer(eth.ETH66, p2p.NewPeerPipe(enode.ID{2}, "", nil, p2pRemote), p2pRemote, handler.txpool)
524+
local := eth.NewPeer(eth.ETH65, p2p.NewPeerPipe(enode.ID{1}, "", nil, p2pLocal), p2pLocal, handler.txpool)
525+
remote := eth.NewPeer(eth.ETH65, p2p.NewPeerPipe(enode.ID{2}, "", nil, p2pRemote), p2pRemote, handler.txpool)
522526
defer local.Close()
523527
defer remote.Close()
524528

@@ -539,39 +543,30 @@ func testCheckpointChallenge(t *testing.T, syncmode downloader.SyncMode, checkpo
539543
if err := remote.Handshake(1, td, head.Hash(), genesis.Hash(), forkid.NewIDWithChain(handler.chain), forkid.NewFilter(handler.chain)); err != nil {
540544
t.Fatalf("failed to run protocol handshake")
541545
}
546+
542547
// Connect a new peer and check that we receive the checkpoint challenge.
543548
if checkpoint {
544-
msg, err := p2pRemote.ReadMsg()
545-
if err != nil {
546-
t.Fatalf("failed to read checkpoint challenge: %v", err)
547-
}
548-
request := new(eth.GetBlockHeadersPacket66)
549-
if err := msg.Decode(request); err != nil {
550-
t.Fatalf("failed to decode checkpoint challenge: %v", err)
551-
}
552-
query := request.GetBlockHeadersPacket
553-
if query.Origin.Number != response.Number.Uint64() || query.Amount != 1 || query.Skip != 0 || query.Reverse {
554-
t.Fatalf("challenge mismatch: have [%d, %d, %d, %v] want [%d, %d, %d, %v]",
555-
query.Origin.Number, query.Amount, query.Skip, query.Reverse,
556-
response.Number.Uint64(), 1, 0, false)
549+
if err := remote.ExpectRequestHeadersByNumber(response.Number.Uint64(), 1, 0, false); err != nil {
550+
t.Fatalf("challenge mismatch: %v", err)
557551
}
558552
// Create a block to reply to the challenge if no timeout is simulated.
559553
if !timeout {
560554
if empty {
561-
if err := remote.ReplyBlockHeaders(request.RequestId, []*types.Header{}); err != nil {
555+
if err := remote.SendBlockHeaders([]*types.Header{}); err != nil {
562556
t.Fatalf("failed to answer challenge: %v", err)
563557
}
564558
} else if match {
565-
if err := remote.ReplyBlockHeaders(request.RequestId, []*types.Header{response}); err != nil {
559+
if err := remote.SendBlockHeaders([]*types.Header{response}); err != nil {
566560
t.Fatalf("failed to answer challenge: %v", err)
567561
}
568562
} else {
569-
if err := remote.ReplyBlockHeaders(request.RequestId, []*types.Header{{Number: response.Number}}); err != nil {
563+
if err := remote.SendBlockHeaders([]*types.Header{{Number: response.Number}}); err != nil {
570564
t.Fatalf("failed to answer challenge: %v", err)
571565
}
572566
}
573567
}
574568
}
569+
575570
// Wait until the test timeout passes to ensure proper cleanup
576571
time.Sleep(syncChallengeTimeout + 300*time.Millisecond)
577572

@@ -624,8 +619,8 @@ func testBroadcastBlock(t *testing.T, peers, bcasts int) {
624619
defer sourcePipe.Close()
625620
defer sinkPipe.Close()
626621

627-
sourcePeer := eth.NewPeer(eth.ETH66, p2p.NewPeerPipe(enode.ID{byte(i)}, "", nil, sourcePipe), sourcePipe, nil)
628-
sinkPeer := eth.NewPeer(eth.ETH66, p2p.NewPeerPipe(enode.ID{0}, "", nil, sinkPipe), sinkPipe, nil)
622+
sourcePeer := eth.NewPeer(eth.ETH65, p2p.NewPeerPipe(enode.ID{byte(i)}, "", nil, sourcePipe), sourcePipe, nil)
623+
sinkPeer := eth.NewPeer(eth.ETH65, p2p.NewPeerPipe(enode.ID{0}, "", nil, sinkPipe), sinkPipe, nil)
629624
defer sourcePeer.Close()
630625
defer sinkPeer.Close()
631626

@@ -676,6 +671,7 @@ func testBroadcastBlock(t *testing.T, peers, bcasts int) {
676671

677672
// Tests that a propagated malformed block (uncles or transactions don't match
678673
// with the hashes in the header) gets discarded and not broadcast forward.
674+
func TestBroadcastMalformedBlock65(t *testing.T) { testBroadcastMalformedBlock(t, eth.ETH65) }
679675
func TestBroadcastMalformedBlock66(t *testing.T) { testBroadcastMalformedBlock(t, eth.ETH66) }
680676

681677
func testBroadcastMalformedBlock(t *testing.T, protocol uint) {

eth/protocols/eth/handler.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,39 @@ type Decoder interface {
171171
Time() time.Time
172172
}
173173

174+
var eth65 = map[uint64]msgHandler{
175+
GetBlockHeadersMsg: handleGetBlockHeaders,
176+
BlockHeadersMsg: handleBlockHeaders,
177+
GetBlockBodiesMsg: handleGetBlockBodies,
178+
BlockBodiesMsg: handleBlockBodies,
179+
GetNodeDataMsg: handleGetNodeData,
180+
NodeDataMsg: handleNodeData,
181+
GetReceiptsMsg: handleGetReceipts,
182+
ReceiptsMsg: handleReceipts,
183+
NewBlockHashesMsg: handleNewBlockhashes,
184+
NewBlockMsg: handleNewBlock,
185+
TransactionsMsg: handleTransactions,
186+
NewPooledTransactionHashesMsg: handleNewPooledTransactionHashes,
187+
GetPooledTransactionsMsg: handleGetPooledTransactions,
188+
PooledTransactionsMsg: handlePooledTransactions,
189+
}
190+
174191
var eth66 = map[uint64]msgHandler{
175192
NewBlockHashesMsg: handleNewBlockhashes,
176193
NewBlockMsg: handleNewBlock,
177194
TransactionsMsg: handleTransactions,
178195
NewPooledTransactionHashesMsg: handleNewPooledTransactionHashes,
179-
GetBlockHeadersMsg: handleGetBlockHeaders66,
180-
BlockHeadersMsg: handleBlockHeaders66,
181-
GetBlockBodiesMsg: handleGetBlockBodies66,
182-
BlockBodiesMsg: handleBlockBodies66,
183-
GetNodeDataMsg: handleGetNodeData66,
184-
NodeDataMsg: handleNodeData66,
185-
GetReceiptsMsg: handleGetReceipts66,
186-
ReceiptsMsg: handleReceipts66,
187-
GetPooledTransactionsMsg: handleGetPooledTransactions66,
188-
PooledTransactionsMsg: handlePooledTransactions66,
196+
// eth66 messages with request-id
197+
GetBlockHeadersMsg: handleGetBlockHeaders66,
198+
BlockHeadersMsg: handleBlockHeaders66,
199+
GetBlockBodiesMsg: handleGetBlockBodies66,
200+
BlockBodiesMsg: handleBlockBodies66,
201+
GetNodeDataMsg: handleGetNodeData66,
202+
NodeDataMsg: handleNodeData66,
203+
GetReceiptsMsg: handleGetReceipts66,
204+
ReceiptsMsg: handleReceipts66,
205+
GetPooledTransactionsMsg: handleGetPooledTransactions66,
206+
PooledTransactionsMsg: handlePooledTransactions66,
189207
}
190208

191209
// handleMessage is invoked whenever an inbound message is received from a remote
@@ -201,11 +219,10 @@ func handleMessage(backend Backend, peer *Peer) error {
201219
}
202220
defer msg.Discard()
203221

204-
var handlers = eth66
205-
//if peer.Version() >= ETH67 { // Left in as a sample when new protocol is added
206-
// handlers = eth67
207-
//}
208-
222+
var handlers = eth65
223+
if peer.Version() >= ETH66 {
224+
handlers = eth66
225+
}
209226
// Track the amount of time it takes to serve the request and run the handler
210227
if metrics.Enabled {
211228
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)

0 commit comments

Comments
 (0)