diff --git a/cmd/devp2p/internal/ethtest/conn.go b/cmd/devp2p/internal/ethtest/conn.go index 246dfce906..567609da17 100644 --- a/cmd/devp2p/internal/ethtest/conn.go +++ b/cmd/devp2p/internal/ethtest/conn.go @@ -67,6 +67,7 @@ func (s *Suite) dialAs(key *ecdsa.PrivateKey) (*Conn, error) { } conn.caps = []p2p.Cap{ {Name: "eth", Version: 70}, + {Name: "eth", Version: 69}, } conn.ourHighestProtoVersion = 70 return &conn, nil @@ -339,10 +340,12 @@ loop: if have, want := msg.ForkID, chain.ForkID(); !reflect.DeepEqual(have, want) { return fmt.Errorf("wrong fork ID in status: have %v, want %v", have, want) } - if have, want := msg.ProtocolVersion, c.ourHighestProtoVersion; have != uint32(want) { - return fmt.Errorf("wrong protocol version: have %v, want %v", have, want) + for _, cap := range c.caps { + if cap.Name == "eth" && cap.Version == uint(msg.ProtocolVersion) { + break loop + } } - break loop + return fmt.Errorf("wrong protocol version: have %v, want %v", msg.ProtocolVersion, c.caps) case discMsg: var msg []p2p.DiscReason if rlp.DecodeBytes(data, &msg); len(msg) == 0 { diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index b658d89675..dda01e8d3b 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -426,6 +426,9 @@ func (s *Suite) TestGetReceipts(t *utesting.T) { // Find some blocks containing receipts. var hashes = make([]common.Hash, 0, 3) for i := range s.chain.Len() { + if uint64(i) == s.chain.txInfo.LargeReceiptBlock && conn.negotiatedProtoVersion < eth.ETH70 { + continue + } block := s.chain.GetBlock(i) if len(block.Transactions()) > 0 { hashes = append(hashes, block.Hash()) @@ -435,36 +438,63 @@ func (s *Suite) TestGetReceipts(t *utesting.T) { } } - // Create block bodies request. - req := ð.GetReceiptsPacket70{ - RequestId: 66, - GetReceiptsRequest: (eth.GetReceiptsRequest)(hashes), - FirstBlockReceiptIndex: 0, - } - if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil { - t.Fatalf("could not write to connection: %v", err) - } - // Wait for response. - resp := new(eth.ReceiptsPacket70) - if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil { - t.Fatalf("error reading block bodies msg: %v", err) - } - if got, want := resp.RequestId, req.RequestId; got != want { - t.Fatalf("unexpected request id in respond", got, want) - } - if len(resp.List) != len(req.GetReceiptsRequest) { - t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(resp.List)) + if conn.negotiatedProtoVersion < eth.ETH70 { + // Create block bodies request. + req := ð.GetReceiptsPacket69{ + RequestId: 66, + GetReceiptsRequest: (eth.GetReceiptsRequest)(hashes), + } + if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil { + t.Fatalf("could not write to connection: %v", err) + } + // Wait for response. + resp := new(eth.ReceiptsPacket[*eth.ReceiptList69]) + if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil { + t.Fatalf("error reading block receipts msg: %v", err) + } + if got, want := resp.RequestId, req.RequestId; got != want { + t.Fatalf("unexpected request id in respond", got, want) + } + if len(resp.List) != len(req.GetReceiptsRequest) { + t.Fatalf("wrong receipts in response: expected %d receipts, got %d", len(req.GetReceiptsRequest), len(resp.List)) + } + } else { + // Create block bodies request. + req := ð.GetReceiptsPacket70{ + RequestId: 66, + GetReceiptsRequest: (eth.GetReceiptsRequest)(hashes), + FirstBlockReceiptIndex: 0, + } + if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil { + t.Fatalf("could not write to connection: %v", err) + } + // Wait for response. + resp := new(eth.ReceiptsPacket70) + if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil { + t.Fatalf("error reading block receipts msg: %v", err) + } + if got, want := resp.RequestId, req.RequestId; got != want { + t.Fatalf("unexpected request id in respond", got, want) + } + if len(resp.List) != len(req.GetReceiptsRequest) { + t.Fatalf("wrong receipts in response: expected %d receipts, got %d", len(req.GetReceiptsRequest), len(resp.List)) + } } } func (s *Suite) TestGetLargeReceipts(t *utesting.T) { - t.Log(`This test sends GetReceipts requests to the node for large receipt (>10MiB) in the test chain.`) + t.Log(`This test sends GetReceipts requests to the node for large receipt (>10MiB) in the test chain. + This test is meaningful only if the client supports protocol version greater than or equal to ETH70.`) conn, err := s.dialAndPeer(nil) if err != nil { t.Fatalf("peering failed: %v", err) } defer conn.Close() + if conn.negotiatedProtoVersion < eth.ETH70 { + return + } + // Find block with large receipt. // Place the large receipt block hash in the middle of the query start := max(s.chain.txInfo.LargeReceiptBlock-2, 0) diff --git a/eth/protocols/eth/protocol.go b/eth/protocols/eth/protocol.go index 56ce169f2e..cab7f32b81 100644 --- a/eth/protocols/eth/protocol.go +++ b/eth/protocols/eth/protocol.go @@ -41,7 +41,7 @@ const ProtocolName = "eth" // ProtocolVersions are the supported versions of the `eth` protocol (first // is primary). -var ProtocolVersions = []uint{ETH69, ETH68, ETH70} +var ProtocolVersions = []uint{ETH70, ETH69, ETH68} // protocolLengths are the number of implemented message corresponding to // different protocol versions.