mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 00:39:26 +00:00
cmd/devp2p: test for non-existent block request (#31506)
Add tests for GetBlockHeaders that verify client does not disconnect when unlikely block numbers are requested, e.g. max uint64. --------- Co-authored-by: lightclient <lightclient@protonmail.com>
This commit is contained in:
parent
af9673b143
commit
ed93a5ac04
1 changed files with 43 additions and 0 deletions
|
|
@ -70,6 +70,7 @@ func (s *Suite) EthTests() []utesting.Test {
|
||||||
{Name: "Status", Fn: s.TestStatus},
|
{Name: "Status", Fn: s.TestStatus},
|
||||||
// get block headers
|
// get block headers
|
||||||
{Name: "GetBlockHeaders", Fn: s.TestGetBlockHeaders},
|
{Name: "GetBlockHeaders", Fn: s.TestGetBlockHeaders},
|
||||||
|
{Name: "GetNonexistentBlockHeaders", Fn: s.TestGetNonexistentBlockHeaders},
|
||||||
{Name: "SimultaneousRequests", Fn: s.TestSimultaneousRequests},
|
{Name: "SimultaneousRequests", Fn: s.TestSimultaneousRequests},
|
||||||
{Name: "SameRequestID", Fn: s.TestSameRequestID},
|
{Name: "SameRequestID", Fn: s.TestSameRequestID},
|
||||||
{Name: "ZeroRequestID", Fn: s.TestZeroRequestID},
|
{Name: "ZeroRequestID", Fn: s.TestZeroRequestID},
|
||||||
|
|
@ -158,6 +159,48 @@ func (s *Suite) TestGetBlockHeaders(t *utesting.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Suite) TestGetNonexistentBlockHeaders(t *utesting.T) {
|
||||||
|
t.Log(`This test sends GetBlockHeaders requests for nonexistent blocks (using max uint64 value)
|
||||||
|
to check if the node disconnects after receiving multiple invalid requests.`)
|
||||||
|
|
||||||
|
conn, err := s.dial()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("dial failed: %v", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
if err := conn.peer(s.chain, nil); err != nil {
|
||||||
|
t.Fatalf("peering failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create request with max uint64 value for a nonexistent block
|
||||||
|
badReq := ð.GetBlockHeadersPacket{
|
||||||
|
GetBlockHeadersRequest: ð.GetBlockHeadersRequest{
|
||||||
|
Origin: eth.HashOrNumber{Number: ^uint64(0)},
|
||||||
|
Amount: 1,
|
||||||
|
Skip: 0,
|
||||||
|
Reverse: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send request 10 times. Some clients are lient on the first few invalids.
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
badReq.RequestId = uint64(i)
|
||||||
|
if err := conn.Write(ethProto, eth.GetBlockHeadersMsg, badReq); err != nil {
|
||||||
|
if err == errDisc {
|
||||||
|
t.Fatalf("peer disconnected after %d requests", i+1)
|
||||||
|
}
|
||||||
|
t.Fatalf("write failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if peer disconnects at the end.
|
||||||
|
code, _, err := conn.Read()
|
||||||
|
if err == errDisc || code == discMsg {
|
||||||
|
t.Fatal("peer improperly disconnected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Suite) TestSimultaneousRequests(t *utesting.T) {
|
func (s *Suite) TestSimultaneousRequests(t *utesting.T) {
|
||||||
t.Log(`This test requests blocks headers from the node, performing two requests
|
t.Log(`This test requests blocks headers from the node, performing two requests
|
||||||
concurrently, with different request IDs.`)
|
concurrently, with different request IDs.`)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue