From 9100431ebb6f9b5532a9422ce2857a51e73eb903 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Thu, 28 Nov 2024 16:53:08 -0300 Subject: [PATCH 01/33] tests: receipts tests draft --- cmd/devp2p/internal/ethtest/suite.go | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 5cb9fa0297d9..c563d66ca9c7 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -72,6 +72,8 @@ func (s *Suite) EthTests() []utesting.Test { {Name: "ZeroRequestID", Fn: s.TestZeroRequestID}, // get block bodies {Name: "GetBlockBodies", Fn: s.TestGetBlockBodies}, + // get block receipts + {Name: "GetBlockReceipts", Fn: s.TestGetBlockReceipts}, // // malicious handshakes + status {Name: "MaliciousHandshake", Fn: s.TestMaliciousHandshake}, {Name: "MaliciousStatus", Fn: s.TestMaliciousStatus}, @@ -338,6 +340,42 @@ and expects a response.`) func (s *Suite) TestGetBlockBodies(t *utesting.T) { t.Log(`This test sends GetBlockBodies requests to the node for known blocks in the test chain.`) + 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 block receipts request. + req := ð.GetReceiptsPacket{ + RequestId: 100, + GetReceiptsRequest: eth.GetReceiptsRequest{ + s.chain.blocks[30].Hash(), + s.chain.blocks[44].Hash(), + }, + } + 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.GetReceiptsPacket) + if err := conn.ReadMsg(ethProto, eth.GetReceiptsMsg, &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) + } + receipts := resp.GetReceiptsRequest + if len(receipts) != len(req.GetReceiptsRequest) { + t.Fatalf("wrong receipts in response: expected %d receipts, got %d", len(req.GetReceiptsRequest), len(receipts)) + } +} + +func (s *Suite) TestGetBlockReceipts(t *utesting.T) { + t.Log(`This test sends block receipts requests to the node for known blocks in the test chain.`) + conn, err := s.dial() if err != nil { t.Fatalf("dial failed: %v", err) From 171d9eb21b0304a06c3414cbf51d93cf882544fd Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Thu, 28 Nov 2024 17:19:27 -0300 Subject: [PATCH 02/33] debug: add some logs --- cmd/devp2p/internal/ethtest/suite.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index c563d66ca9c7..cd1489e992d8 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -345,10 +345,12 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) { t.Fatalf("dial failed: %v", err) } defer conn.Close() + t.Log("BEFORE CONN PEER") if err := conn.peer(s.chain, nil); err != nil { t.Fatalf("peering failed: %v", err) } // Create block receipts request. + t.Log("BEFORE INSTANTIATING REQUEST") req := ð.GetReceiptsPacket{ RequestId: 100, GetReceiptsRequest: eth.GetReceiptsRequest{ @@ -356,14 +358,17 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) { s.chain.blocks[44].Hash(), }, } + t.Log("BEFORE WRITING TO CONN") if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil { t.Fatalf("could not write to connection: %v", err) } // Wait for response. + t.Log("BEFORE WAITING RESPONSE") resp := new(eth.GetReceiptsPacket) if err := conn.ReadMsg(ethProto, eth.GetReceiptsMsg, &resp); err != nil { t.Fatalf("error reading block bodies msg: %v", err) } + t.Log("BEFORE CHECKING") if got, want := resp.RequestId, req.RequestId; got != want { t.Fatalf("unexpected request id in respond", got, want) } From 34b51cd1aa885cbd9421a3011993b2e4dfa25680 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Thu, 28 Nov 2024 17:36:54 -0300 Subject: [PATCH 03/33] debug: more logs --- cmd/devp2p/internal/ethtest/suite.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index cd1489e992d8..7ddeb77c0b44 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -345,7 +345,6 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) { t.Fatalf("dial failed: %v", err) } defer conn.Close() - t.Log("BEFORE CONN PEER") if err := conn.peer(s.chain, nil); err != nil { t.Fatalf("peering failed: %v", err) } @@ -386,10 +385,12 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { t.Fatalf("dial failed: %v", err) } defer conn.Close() + t.Log("BEFORE CONN PEER") if err := conn.peer(s.chain, nil); err != nil { t.Fatalf("peering failed: %v", err) } // Create block bodies request. + t.Log("BEFORE BUILDING REQUEST") req := ð.GetBlockBodiesPacket{ RequestId: 55, GetBlockBodiesRequest: eth.GetBlockBodiesRequest{ @@ -397,14 +398,18 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { s.chain.blocks[75].Hash(), }, } + + t.Log("BEFORE BUILDING REQUEST") if err := conn.Write(ethProto, eth.GetBlockBodiesMsg, req); err != nil { t.Fatalf("could not write to connection: %v", err) } // Wait for response. + t.Log("BEFORE BUILDING REQUEST") resp := new(eth.BlockBodiesPacket) if err := conn.ReadMsg(ethProto, eth.BlockBodiesMsg, &resp); err != nil { t.Fatalf("error reading block bodies msg: %v", err) } + t.Log("BEFORE EXPECTING RESPONSE") if got, want := resp.RequestId, req.RequestId; got != want { t.Fatalf("unexpected request id in respond", got, want) } From 32494402b4dd04d5c0f8d2635b49af2fd0887d14 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Thu, 28 Nov 2024 17:37:10 -0300 Subject: [PATCH 04/33] chore: remove wrong logs --- cmd/devp2p/internal/ethtest/suite.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 7ddeb77c0b44..ec071441ef79 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -349,7 +349,6 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) { t.Fatalf("peering failed: %v", err) } // Create block receipts request. - t.Log("BEFORE INSTANTIATING REQUEST") req := ð.GetReceiptsPacket{ RequestId: 100, GetReceiptsRequest: eth.GetReceiptsRequest{ @@ -357,17 +356,14 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) { s.chain.blocks[44].Hash(), }, } - t.Log("BEFORE WRITING TO CONN") if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil { t.Fatalf("could not write to connection: %v", err) } // Wait for response. - t.Log("BEFORE WAITING RESPONSE") resp := new(eth.GetReceiptsPacket) if err := conn.ReadMsg(ethProto, eth.GetReceiptsMsg, &resp); err != nil { t.Fatalf("error reading block bodies msg: %v", err) } - t.Log("BEFORE CHECKING") if got, want := resp.RequestId, req.RequestId; got != want { t.Fatalf("unexpected request id in respond", got, want) } From a5f7681e73689ce6cc5b4326187ebbc73918ae3d Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 13:33:49 -0300 Subject: [PATCH 05/33] test: try to log response --- cmd/devp2p/internal/ethtest/suite.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index ec071441ef79..c4c40ef57f26 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -18,6 +18,7 @@ package ethtest import ( "crypto/rand" + "fmt" "math/big" "reflect" @@ -410,6 +411,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { t.Fatalf("unexpected request id in respond", got, want) } bodies := resp.BlockBodiesResponse + t.Log(fmt.Sprintf("%v", bodies)) if len(bodies) != len(req.GetBlockBodiesRequest) { t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetBlockBodiesRequest), len(bodies)) } From cdef31029be78e3f0255c47268c9171e67f8c8e4 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 13:42:41 -0300 Subject: [PATCH 06/33] test: try to log response --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index c4c40ef57f26..0bc15e22683e 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -411,7 +411,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { t.Fatalf("unexpected request id in respond", got, want) } bodies := resp.BlockBodiesResponse - t.Log(fmt.Sprintf("%v", bodies)) + t.Log(fmt.Sprintf("%+v", bodies)) if len(bodies) != len(req.GetBlockBodiesRequest) { t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetBlockBodiesRequest), len(bodies)) } From 61bb8221712c4a3b8d5a59311b63cd1628e8edba Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 13:55:36 -0300 Subject: [PATCH 07/33] tests: fix message types --- cmd/devp2p/internal/ethtest/suite.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 0bc15e22683e..66f06b0b56e2 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -388,22 +388,22 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { } // Create block bodies request. t.Log("BEFORE BUILDING REQUEST") - req := ð.GetBlockBodiesPacket{ + req := ð.GetReceiptsPacket{ RequestId: 55, - GetBlockBodiesRequest: eth.GetBlockBodiesRequest{ + GetReceiptsRequest: eth.GetReceiptsRequest{ s.chain.blocks[54].Hash(), s.chain.blocks[75].Hash(), }, } t.Log("BEFORE BUILDING REQUEST") - if err := conn.Write(ethProto, eth.GetBlockBodiesMsg, req); err != nil { + if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil { t.Fatalf("could not write to connection: %v", err) } // Wait for response. t.Log("BEFORE BUILDING REQUEST") resp := new(eth.BlockBodiesPacket) - if err := conn.ReadMsg(ethProto, eth.BlockBodiesMsg, &resp); err != nil { + if err := conn.ReadMsg(ethProto, eth.GetReceiptsMsg, &resp); err != nil { t.Fatalf("error reading block bodies msg: %v", err) } t.Log("BEFORE EXPECTING RESPONSE") @@ -412,8 +412,8 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { } bodies := resp.BlockBodiesResponse t.Log(fmt.Sprintf("%+v", bodies)) - if len(bodies) != len(req.GetBlockBodiesRequest) { - t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetBlockBodiesRequest), len(bodies)) + if len(bodies) != len(req.GetReceiptsRequest) { + t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(bodies)) } } From b33d36111a393592ea296bc903bb0979407df965 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 14:05:21 -0300 Subject: [PATCH 08/33] tests: use proper packets --- cmd/devp2p/internal/ethtest/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 66f06b0b56e2..229bdd99f85b 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -402,7 +402,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { } // Wait for response. t.Log("BEFORE BUILDING REQUEST") - resp := new(eth.BlockBodiesPacket) + resp := new(eth.GetReceiptsPacket) if err := conn.ReadMsg(ethProto, eth.GetReceiptsMsg, &resp); err != nil { t.Fatalf("error reading block bodies msg: %v", err) } @@ -410,7 +410,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { if got, want := resp.RequestId, req.RequestId; got != want { t.Fatalf("unexpected request id in respond", got, want) } - bodies := resp.BlockBodiesResponse + bodies := resp.GetReceiptsRequest t.Log(fmt.Sprintf("%+v", bodies)) if len(bodies) != len(req.GetReceiptsRequest) { t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(bodies)) From 27cf7d6802c2624db699f87d7756677b48918492 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 15:38:54 -0300 Subject: [PATCH 09/33] tests: temporarily disable timeout --- cmd/devp2p/internal/ethtest/conn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/conn.go b/cmd/devp2p/internal/ethtest/conn.go index 757b137aa12d..f25177768830 100644 --- a/cmd/devp2p/internal/ethtest/conn.go +++ b/cmd/devp2p/internal/ethtest/conn.go @@ -107,7 +107,7 @@ func (c *Conn) Read() (uint64, []byte, error) { // ReadMsg attempts to read a devp2p message with a specific code. func (c *Conn) ReadMsg(proto Proto, code uint64, msg any) error { - c.SetReadDeadline(time.Now().Add(timeout)) + // c.SetReadDeadline(time.Now().Add(timeout)) for { got, data, err := c.Read() if err != nil { From e268331b4724005c6c269fc73bceb326aad654cc Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 16:02:26 -0300 Subject: [PATCH 10/33] tests: log response --- cmd/devp2p/internal/ethtest/suite.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 229bdd99f85b..dae5550ddf5a 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -404,6 +404,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { t.Log("BEFORE BUILDING REQUEST") resp := new(eth.GetReceiptsPacket) if err := conn.ReadMsg(ethProto, eth.GetReceiptsMsg, &resp); err != nil { + t.Log(fmt.Sprintf("%+v", *resp)) t.Fatalf("error reading block bodies msg: %v", err) } t.Log("BEFORE EXPECTING RESPONSE") From 5ea6d7712ecb5bd7691d27dede2e3cdc7ca1385a Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 16:13:07 -0300 Subject: [PATCH 11/33] tests: expect correct receipts packet --- cmd/devp2p/internal/ethtest/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index dae5550ddf5a..06b25263e0f6 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -402,8 +402,8 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { } // Wait for response. t.Log("BEFORE BUILDING REQUEST") - resp := new(eth.GetReceiptsPacket) - if err := conn.ReadMsg(ethProto, eth.GetReceiptsMsg, &resp); err != nil { + resp := new(eth.ReceiptsPacket) + if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil { t.Log(fmt.Sprintf("%+v", *resp)) t.Fatalf("error reading block bodies msg: %v", err) } From 0720d5c547efaf5a122bba9f4075952ec811fb85 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 16:16:18 -0300 Subject: [PATCH 12/33] tests: fix build --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 06b25263e0f6..2e3b6de721cf 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -411,7 +411,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { if got, want := resp.RequestId, req.RequestId; got != want { t.Fatalf("unexpected request id in respond", got, want) } - bodies := resp.GetReceiptsRequest + bodies := resp.ReceiptsResponse t.Log(fmt.Sprintf("%+v", bodies)) if len(bodies) != len(req.GetReceiptsRequest) { t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(bodies)) From a5ffaa4aae3bd9f54a035bbac720c10c40f5122b Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 16:45:30 -0300 Subject: [PATCH 13/33] tests: try with only one block --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 2e3b6de721cf..799b16e6eb6a 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -392,7 +392,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ s.chain.blocks[54].Hash(), - s.chain.blocks[75].Hash(), + // s.chain.blocks[75].Hash(), }, } From d8ca4162aaa4d7b5af6518f6cdf3588593ecdcb3 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 17:09:49 -0300 Subject: [PATCH 14/33] tests: restore multiple blocks --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 799b16e6eb6a..2e3b6de721cf 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -392,7 +392,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ s.chain.blocks[54].Hash(), - // s.chain.blocks[75].Hash(), + s.chain.blocks[75].Hash(), }, } From 0eba6fb460f53155bd6a2aa9eb8789df6ea247e3 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 29 Nov 2024 17:46:04 -0300 Subject: [PATCH 15/33] tests: single block --- cmd/devp2p/internal/ethtest/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 2e3b6de721cf..7049972cddfb 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -391,7 +391,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { req := ð.GetReceiptsPacket{ RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ - s.chain.blocks[54].Hash(), + // s.chain.blocks[54].Hash(), s.chain.blocks[75].Hash(), }, } @@ -405,7 +405,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { resp := new(eth.ReceiptsPacket) if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil { t.Log(fmt.Sprintf("%+v", *resp)) - t.Fatalf("error reading block bodies msg: %v", err) + t.Fatalf("error reading receipts msg: %v", err) } t.Log("BEFORE EXPECTING RESPONSE") if got, want := resp.RequestId, req.RequestId; got != want { From 3a5aa716b344adba0f9c6e8bff5b2680554f57d7 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Mon, 2 Dec 2024 15:05:31 -0300 Subject: [PATCH 16/33] tests: print received --- cmd/devp2p/internal/ethtest/suite.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 7049972cddfb..4e63369a9fcc 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -391,7 +391,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { req := ð.GetReceiptsPacket{ RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ - // s.chain.blocks[54].Hash(), + s.chain.blocks[54].Hash(), s.chain.blocks[75].Hash(), }, } @@ -412,7 +412,9 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { t.Fatalf("unexpected request id in respond", got, want) } bodies := resp.ReceiptsResponse - t.Log(fmt.Sprintf("%+v", bodies)) + for _, body := range bodies { + t.Log(fmt.Sprintf("%+v", body)) + } if len(bodies) != len(req.GetReceiptsRequest) { t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(bodies)) } From 03dd421cdff4f72c59c28f739105cf699ab2fdfc Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Mon, 2 Dec 2024 15:17:50 -0300 Subject: [PATCH 17/33] tests: test print --- cmd/devp2p/internal/ethtest/suite.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 4e63369a9fcc..f97ccebe6ee9 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -413,7 +413,9 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { } bodies := resp.ReceiptsResponse for _, body := range bodies { - t.Log(fmt.Sprintf("%+v", body)) + for _, a := range body { + t.Log(fmt.Sprintf("%+v", a)) + } } if len(bodies) != len(req.GetReceiptsRequest) { t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(bodies)) From 089919bd30b48fd087dd1bae19354300e7be6b68 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Mon, 2 Dec 2024 15:26:15 -0300 Subject: [PATCH 18/33] tests: decode bytes --- cmd/devp2p/internal/ethtest/suite.go | 5 ----- rlp/decode.go | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index f97ccebe6ee9..6377efa57f76 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -412,11 +412,6 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { t.Fatalf("unexpected request id in respond", got, want) } bodies := resp.ReceiptsResponse - for _, body := range bodies { - for _, a := range body { - t.Log(fmt.Sprintf("%+v", a)) - } - } if len(bodies) != len(req.GetReceiptsRequest) { t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(bodies)) } diff --git a/rlp/decode.go b/rlp/decode.go index 0fbca243ee0d..9c8d04b5d1d1 100644 --- a/rlp/decode.go +++ b/rlp/decode.go @@ -90,6 +90,7 @@ func Decode(r io.Reader, val interface{}) error { // DecodeBytes parses RLP data from b into val. Please see package-level documentation for // the decoding rules. The input must contain exactly one value and no trailing data. func DecodeBytes(b []byte, val interface{}) error { + fmt.Printf("DECODED BYTES: %v\n", b) r := (*sliceReader)(&b) stream := streamPool.Get().(*Stream) From ec6972c98ef114ef8192b628d9c7bd0269b19fa7 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Mon, 2 Dec 2024 16:43:36 -0300 Subject: [PATCH 19/33] test: comment block --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 6377efa57f76..37159ac365b4 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -391,7 +391,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { req := ð.GetReceiptsPacket{ RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ - s.chain.blocks[54].Hash(), + // s.chain.blocks[54].Hash(), s.chain.blocks[75].Hash(), }, } From ebc79f36cc4c6a60081b7eb1324677a420af79b1 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Mon, 2 Dec 2024 17:00:58 -0300 Subject: [PATCH 20/33] test: print decoded receipt --- cmd/devp2p/internal/ethtest/suite.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 37159ac365b4..c82f87be3b0a 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -411,8 +411,13 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { if got, want := resp.RequestId, req.RequestId; got != want { t.Fatalf("unexpected request id in respond", got, want) } - bodies := resp.ReceiptsResponse - if len(bodies) != len(req.GetReceiptsRequest) { + receipts := resp.ReceiptsResponse + for _, receipt := range receipts { + for _, r := range receipt { + fmt.Printf("DECODED RECEIPT: %v\n", r) + } + } + if len(receipts) != len(req.GetReceiptsRequest) { t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(bodies)) } } From e7983e6bc022138c52892a79bdcd7485cc3cb7ab Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Mon, 2 Dec 2024 17:07:01 -0300 Subject: [PATCH 21/33] tests: fix build --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index c82f87be3b0a..de7bda937ffe 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -418,7 +418,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { } } if len(receipts) != len(req.GetReceiptsRequest) { - t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(bodies)) + t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(receipts)) } } From 430a06544abfb0d92a478d4732483c59a995d8bc Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Tue, 3 Dec 2024 13:13:59 -0300 Subject: [PATCH 22/33] test: try with legacy receipt --- cmd/devp2p/internal/ethtest/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index de7bda937ffe..703f5d4226a2 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -391,8 +391,8 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { req := ð.GetReceiptsPacket{ RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ - // s.chain.blocks[54].Hash(), - s.chain.blocks[75].Hash(), + s.chain.blocks[54].Hash(), + // s.chain.blocks[75].Hash(), }, } From 637219c0a9bbe2440140e9976cd15bfac8dac7e3 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Tue, 3 Dec 2024 13:36:37 -0300 Subject: [PATCH 23/33] test: restore with non-legacy tx --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 703f5d4226a2..ee35b130f2e8 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -392,7 +392,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ s.chain.blocks[54].Hash(), - // s.chain.blocks[75].Hash(), + s.chain.blocks[75].Hash(), }, } From 860b7ff10fa69f5194cfe66061d89a0a42b1e025 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Tue, 3 Dec 2024 13:56:15 -0300 Subject: [PATCH 24/33] test: only legacy tx --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index ee35b130f2e8..703f5d4226a2 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -392,7 +392,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ s.chain.blocks[54].Hash(), - s.chain.blocks[75].Hash(), + // s.chain.blocks[75].Hash(), }, } From e8dbcc3a82f7a447e92675ea0a889315e51d3cb2 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Tue, 3 Dec 2024 14:20:08 -0300 Subject: [PATCH 25/33] test: test with more tx types --- cmd/devp2p/internal/ethtest/suite.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 703f5d4226a2..399e42282c05 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -391,7 +391,8 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { req := ð.GetReceiptsPacket{ RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ - s.chain.blocks[54].Hash(), + s.chain.blocks[275].Hash(), + s.chain.blocks[276].Hash(), // s.chain.blocks[75].Hash(), }, } From 2d8fa2ea6df14f6c4ca4029ad4f153a034056d2f Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Tue, 3 Dec 2024 15:47:22 -0300 Subject: [PATCH 26/33] test: readd block 75 --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 399e42282c05..ffd349c3381c 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -393,7 +393,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { GetReceiptsRequest: eth.GetReceiptsRequest{ s.chain.blocks[275].Hash(), s.chain.blocks[276].Hash(), - // s.chain.blocks[75].Hash(), + s.chain.blocks[75].Hash(), }, } From 85a2d1188c45a05fbb0f7d0b9ea0f80325333d83 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Wed, 4 Dec 2024 12:56:23 -0300 Subject: [PATCH 27/33] test: only block 75 --- cmd/devp2p/internal/ethtest/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index ffd349c3381c..bdfc4328a7c4 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -391,8 +391,8 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { req := ð.GetReceiptsPacket{ RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ - s.chain.blocks[275].Hash(), - s.chain.blocks[276].Hash(), + // s.chain.blocks[275].Hash(), + // s.chain.blocks[276].Hash(), s.chain.blocks[75].Hash(), }, } From d6ae02166eb1ede4bed887eb9f94d5cf4a6ab583 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Thu, 5 Dec 2024 14:21:21 -0300 Subject: [PATCH 28/33] test: multiple blocks --- cmd/devp2p/internal/ethtest/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index bdfc4328a7c4..ffd349c3381c 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -391,8 +391,8 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { req := ð.GetReceiptsPacket{ RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ - // s.chain.blocks[275].Hash(), - // s.chain.blocks[276].Hash(), + s.chain.blocks[275].Hash(), + s.chain.blocks[276].Hash(), s.chain.blocks[75].Hash(), }, } From c757b92a76385156ac081df71899eed5ef2aed34 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 6 Dec 2024 13:59:01 -0300 Subject: [PATCH 29/33] test: remove logs, add comment --- cmd/devp2p/internal/ethtest/suite.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index ffd349c3381c..209d49ec0d9c 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -374,6 +374,8 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) { } } +// Test the get block receipts p2p message works +// as expected, heavily based on the test for Block Bodies. func (s *Suite) TestGetBlockReceipts(t *utesting.T) { t.Log(`This test sends block receipts requests to the node for known blocks in the test chain.`) @@ -382,12 +384,10 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { t.Fatalf("dial failed: %v", err) } defer conn.Close() - t.Log("BEFORE CONN PEER") if err := conn.peer(s.chain, nil); err != nil { t.Fatalf("peering failed: %v", err) } // Create block bodies request. - t.Log("BEFORE BUILDING REQUEST") req := ð.GetReceiptsPacket{ RequestId: 55, GetReceiptsRequest: eth.GetReceiptsRequest{ @@ -397,27 +397,19 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { }, } - t.Log("BEFORE BUILDING REQUEST") if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil { t.Fatalf("could not write to connection: %v", err) } // Wait for response. - t.Log("BEFORE BUILDING REQUEST") resp := new(eth.ReceiptsPacket) if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil { t.Log(fmt.Sprintf("%+v", *resp)) t.Fatalf("error reading receipts msg: %v", err) } - t.Log("BEFORE EXPECTING RESPONSE") if got, want := resp.RequestId, req.RequestId; got != want { t.Fatalf("unexpected request id in respond", got, want) } receipts := resp.ReceiptsResponse - for _, receipt := range receipts { - for _, r := range receipt { - fmt.Printf("DECODED RECEIPT: %v\n", r) - } - } if len(receipts) != len(req.GetReceiptsRequest) { t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(receipts)) } From 4c67008147f2d87f0b115c23b29afe828fc0a83b Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 6 Dec 2024 14:01:10 -0300 Subject: [PATCH 30/33] chore: remove debugging --- cmd/devp2p/internal/ethtest/conn.go | 2 +- rlp/decode.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/conn.go b/cmd/devp2p/internal/ethtest/conn.go index f25177768830..757b137aa12d 100644 --- a/cmd/devp2p/internal/ethtest/conn.go +++ b/cmd/devp2p/internal/ethtest/conn.go @@ -107,7 +107,7 @@ func (c *Conn) Read() (uint64, []byte, error) { // ReadMsg attempts to read a devp2p message with a specific code. func (c *Conn) ReadMsg(proto Proto, code uint64, msg any) error { - // c.SetReadDeadline(time.Now().Add(timeout)) + c.SetReadDeadline(time.Now().Add(timeout)) for { got, data, err := c.Read() if err != nil { diff --git a/rlp/decode.go b/rlp/decode.go index 9c8d04b5d1d1..0fbca243ee0d 100644 --- a/rlp/decode.go +++ b/rlp/decode.go @@ -90,7 +90,6 @@ func Decode(r io.Reader, val interface{}) error { // DecodeBytes parses RLP data from b into val. Please see package-level documentation for // the decoding rules. The input must contain exactly one value and no trailing data. func DecodeBytes(b []byte, val interface{}) error { - fmt.Printf("DECODED BYTES: %v\n", b) r := (*sliceReader)(&b) stream := streamPool.Get().(*Stream) From 28bfbe9acfe592de37b1aa42dc0f868d3f468562 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 6 Dec 2024 14:02:30 -0300 Subject: [PATCH 31/33] chore: remove debugging --- cmd/devp2p/internal/ethtest/suite.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 209d49ec0d9c..0b26df472cfb 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -18,7 +18,6 @@ package ethtest import ( "crypto/rand" - "fmt" "math/big" "reflect" @@ -403,7 +402,6 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { // Wait for response. resp := new(eth.ReceiptsPacket) if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil { - t.Log(fmt.Sprintf("%+v", *resp)) t.Fatalf("error reading receipts msg: %v", err) } if got, want := resp.RequestId, req.RequestId; got != want { From 9372722d5f02b9de21cd928fbaee676d323daae8 Mon Sep 17 00:00:00 2001 From: fkrause98 Date: Fri, 6 Dec 2024 14:08:20 -0300 Subject: [PATCH 32/33] chore: restore block bodies p2p test --- cmd/devp2p/internal/ethtest/suite.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 0b26df472cfb..13cb37057e06 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -348,28 +348,28 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) { if err := conn.peer(s.chain, nil); err != nil { t.Fatalf("peering failed: %v", err) } - // Create block receipts request. - req := ð.GetReceiptsPacket{ - RequestId: 100, - GetReceiptsRequest: eth.GetReceiptsRequest{ - s.chain.blocks[30].Hash(), - s.chain.blocks[44].Hash(), + // Create block bodies request. + req := ð.GetBlockBodiesPacket{ + RequestId: 55, + GetBlockBodiesRequest: eth.GetBlockBodiesRequest{ + s.chain.blocks[54].Hash(), + s.chain.blocks[75].Hash(), }, } - if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil { + if err := conn.Write(ethProto, eth.GetBlockBodiesMsg, req); err != nil { t.Fatalf("could not write to connection: %v", err) } // Wait for response. - resp := new(eth.GetReceiptsPacket) - if err := conn.ReadMsg(ethProto, eth.GetReceiptsMsg, &resp); err != nil { + resp := new(eth.BlockBodiesPacket) + if err := conn.ReadMsg(ethProto, eth.BlockBodiesMsg, &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) } - receipts := resp.GetReceiptsRequest - if len(receipts) != len(req.GetReceiptsRequest) { - t.Fatalf("wrong receipts in response: expected %d receipts, got %d", len(req.GetReceiptsRequest), len(receipts)) + bodies := resp.BlockBodiesResponse + if len(bodies) != len(req.GetBlockBodiesRequest) { + t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetBlockBodiesRequest), len(bodies)) } } From 65c2da4df25edc9520225db33bcd3e0de0cc1167 Mon Sep 17 00:00:00 2001 From: Francisco Krause Arnim <56402156+fkrause98@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:19:25 -0300 Subject: [PATCH 33/33] Update cmd/devp2p/internal/ethtest/suite.go Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com> --- cmd/devp2p/internal/ethtest/suite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 13cb37057e06..5b6719661c39 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -409,7 +409,7 @@ func (s *Suite) TestGetBlockReceipts(t *utesting.T) { } receipts := resp.ReceiptsResponse if len(receipts) != len(req.GetReceiptsRequest) { - t.Fatalf("wrong bodies in response: expected %d bodies, got %d", len(req.GetReceiptsRequest), len(receipts)) + t.Fatalf("wrong receipts in response: expected %d receipts, got %d", len(req.GetReceiptsRequest), len(receipts)) } }