Skip to content

Commit d3f018f

Browse files
committed
eth: drop eth/65, the last non-reqid protocol version
1 parent 1b5582a commit d3f018f

15 files changed

+179
-609
lines changed

cmd/devp2p/internal/ethtest/suite_test.go

+1-1
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.AllEthTests() {
48+
for _, test := range suite.Eth66Tests() {
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

+2-2
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.ETH65 {
452-
return fmt.Errorf("%w: advertized %d < required %d", errTooOld, p.version, eth.ETH65)
451+
if p.version < eth.ETH66 {
452+
return fmt.Errorf("%w: advertized %d < required %d", errTooOld, p.version, eth.ETH66)
453453
}
454454
mode := d.getMode()
455455

eth/downloader/downloader_test.go

+2-93
Large diffs are not rendered by default.

eth/downloader/peer.go

+4-4
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.ETH65, eth.ETH66, idle, throughput)
416+
return ps.idlePeers(eth.ETH66, 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.ETH65, eth.ETH66, idle, throughput)
428+
return ps.idlePeers(eth.ETH66, 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.ETH65, eth.ETH66, idle, throughput)
440+
return ps.idlePeers(eth.ETH66, 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.ETH65, eth.ETH66, idle, throughput)
452+
return ps.idlePeers(eth.ETH66, eth.ETH66, idle, throughput)
453453
}
454454

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

eth/handler.go

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

119119
// channels for fetcher, syncer, txsyncLoop
120-
txsyncCh chan *txsync
121120
quitSync chan struct{}
122121

123122
chainSync *chainSyncer
@@ -140,7 +139,6 @@ func newHandler(config *handlerConfig) (*handler, error) {
140139
chain: config.Chain,
141140
peers: newPeerSet(),
142141
whitelist: config.Whitelist,
143-
txsyncCh: make(chan *txsync),
144142
quitSync: make(chan struct{}),
145143
}
146144
if config.Sync == downloader.FullSync {
@@ -408,9 +406,8 @@ func (h *handler) Start(maxPeers int) {
408406
go h.minedBroadcastLoop()
409407

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

416413
func (h *handler) Stop() {

eth/handler_eth_test.go

+21-17
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ 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) }
8483
func TestForkIDSplit66(t *testing.T) { testForkIDSplit(t, eth.ETH66) }
8584

8685
func testForkIDSplit(t *testing.T, protocol uint) {
@@ -236,7 +235,6 @@ func testForkIDSplit(t *testing.T, protocol uint) {
236235
}
237236

238237
// Tests that received transactions are added to the local pool.
239-
func TestRecvTransactions65(t *testing.T) { testRecvTransactions(t, eth.ETH65) }
240238
func TestRecvTransactions66(t *testing.T) { testRecvTransactions(t, eth.ETH66) }
241239

242240
func testRecvTransactions(t *testing.T, protocol uint) {
@@ -294,7 +292,6 @@ func testRecvTransactions(t *testing.T, protocol uint) {
294292
}
295293

296294
// This test checks that pending transactions are sent.
297-
func TestSendTransactions65(t *testing.T) { testSendTransactions(t, eth.ETH65) }
298295
func TestSendTransactions66(t *testing.T) { testSendTransactions(t, eth.ETH66) }
299296

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

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

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

381378
// Tests that transactions get propagated to all attached peers, either via direct
382379
// broadcasts or via announcements/retrievals.
383-
func TestTransactionPropagation65(t *testing.T) { testTransactionPropagation(t, eth.ETH65) }
384380
func TestTransactionPropagation66(t *testing.T) { testTransactionPropagation(t, eth.ETH66) }
385381

386382
func testTransactionPropagation(t *testing.T, protocol uint) {
@@ -521,8 +517,8 @@ func testCheckpointChallenge(t *testing.T, syncmode downloader.SyncMode, checkpo
521517
defer p2pLocal.Close()
522518
defer p2pRemote.Close()
523519

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)
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)
526522
defer local.Close()
527523
defer remote.Close()
528524

@@ -543,30 +539,39 @@ func testCheckpointChallenge(t *testing.T, syncmode downloader.SyncMode, checkpo
543539
if err := remote.Handshake(1, td, head.Hash(), genesis.Hash(), forkid.NewIDWithChain(handler.chain), forkid.NewFilter(handler.chain)); err != nil {
544540
t.Fatalf("failed to run protocol handshake")
545541
}
546-
547542
// Connect a new peer and check that we receive the checkpoint challenge.
548543
if checkpoint {
549-
if err := remote.ExpectRequestHeadersByNumber(response.Number.Uint64(), 1, 0, false); err != nil {
550-
t.Fatalf("challenge mismatch: %v", err)
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)
551557
}
552558
// Create a block to reply to the challenge if no timeout is simulated.
553559
if !timeout {
554560
if empty {
555-
if err := remote.SendBlockHeaders([]*types.Header{}); err != nil {
561+
if err := remote.ReplyBlockHeaders(request.RequestId, []*types.Header{}); err != nil {
556562
t.Fatalf("failed to answer challenge: %v", err)
557563
}
558564
} else if match {
559-
if err := remote.SendBlockHeaders([]*types.Header{response}); err != nil {
565+
if err := remote.ReplyBlockHeaders(request.RequestId, []*types.Header{response}); err != nil {
560566
t.Fatalf("failed to answer challenge: %v", err)
561567
}
562568
} else {
563-
if err := remote.SendBlockHeaders([]*types.Header{{Number: response.Number}}); err != nil {
569+
if err := remote.ReplyBlockHeaders(request.RequestId, []*types.Header{{Number: response.Number}}); err != nil {
564570
t.Fatalf("failed to answer challenge: %v", err)
565571
}
566572
}
567573
}
568574
}
569-
570575
// Wait until the test timeout passes to ensure proper cleanup
571576
time.Sleep(syncChallengeTimeout + 300*time.Millisecond)
572577

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

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)
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)
624629
defer sourcePeer.Close()
625630
defer sinkPeer.Close()
626631

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

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

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

eth/protocols/eth/handler.go

+15-32
Original file line numberDiff line numberDiff line change
@@ -171,39 +171,21 @@ 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-
191174
var eth66 = map[uint64]msgHandler{
192175
NewBlockHashesMsg: handleNewBlockhashes,
193176
NewBlockMsg: handleNewBlock,
194177
TransactionsMsg: handleTransactions,
195178
NewPooledTransactionHashesMsg: handleNewPooledTransactionHashes,
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,
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,
207189
}
208190

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

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

0 commit comments

Comments
 (0)