ethtest conn.go¶
| Source (upstream v1.17.3) | Current | |
|---|---|---|
| File | cmd/devp2p/internal/ethtest/conn.go |
conn.go |
| Symbol | (entire file) |
(entire file) |
| Ref | v1.17.3 |
etc/v1.17.3-full-node |
ETH/68 test client: StatusPacket68 with TD+Head fields, version 68 capability. Upstream switched to ETH/69 (StatusPacket69 with LatestBlock/LatestBlockHash).
Diff — vs upstream v1.17.3 (modified in-place)¶
--- a/cmd/devp2p/internal/ethtest/conn.go
+++ b/cmd/devp2p/internal/ethtest/conn.go
@@ -66,10 +66,9 @@
return nil, err
}
conn.caps = []p2p.Cap{
- {Name: "eth", Version: 70},
- {Name: "eth", Version: 69},
+ {Name: "eth", Version: 68},
}
- conn.ourHighestProtoVersion = 70
+ conn.ourHighestProtoVersion = 68
return &conn, nil
}
@@ -156,7 +155,7 @@
var msg any
switch int(code) {
case eth.StatusMsg:
- msg = new(eth.StatusPacket)
+ msg = new(eth.StatusPacket68)
case eth.GetBlockHeadersMsg:
msg = new(eth.GetBlockHeadersPacket)
case eth.BlockHeadersMsg:
@@ -165,6 +164,10 @@
msg = new(eth.GetBlockBodiesPacket)
case eth.BlockBodiesMsg:
msg = new(eth.BlockBodiesPacket)
+ case eth.NewBlockMsg:
+ msg = new(eth.NewBlockPacket)
+ case eth.NewBlockHashesMsg:
+ msg = new(eth.NewBlockHashesPacket)
case eth.TransactionsMsg:
msg = new(eth.TransactionsPacket)
case eth.NewPooledTransactionHashesMsg:
@@ -226,7 +229,7 @@
}
// dialAndPeer creates a peer connection and runs the handshake.
-func (s *Suite) dialAndPeer(status *eth.StatusPacket) (*Conn, error) {
+func (s *Suite) dialAndPeer(status *eth.StatusPacket68) (*Conn, error) {
c, err := s.dial()
if err != nil {
return nil, err
@@ -239,7 +242,7 @@
// peer performs both the protocol handshake and the status message
// exchange with the node in order to peer with it.
-func (c *Conn) peer(chain *Chain, status *eth.StatusPacket) error {
+func (c *Conn) peer(chain *Chain, status *eth.StatusPacket68) error {
if err := c.handshake(); err != nil {
return fmt.Errorf("handshake failed: %v", err)
}
@@ -312,7 +315,7 @@
}
// statusExchange performs a `Status` message exchange with the given node.
-func (c *Conn) statusExchange(chain *Chain, status *eth.StatusPacket) error {
+func (c *Conn) statusExchange(chain *Chain, status *eth.StatusPacket68) error {
loop:
for {
code, data, err := c.Read()
@@ -321,18 +324,17 @@
}
switch code {
case eth.StatusMsg + protoOffset(ethProto):
- msg := new(eth.StatusPacket)
+ msg := new(eth.StatusPacket68)
if err := rlp.DecodeBytes(data, &msg); err != nil {
return fmt.Errorf("error decoding status packet: %w", err)
}
- if have, want := msg.LatestBlock, chain.blocks[chain.Len()-1].NumberU64(); have != want {
- return fmt.Errorf("wrong head block in status, want: %d, have %d",
- want, have)
- }
- if have, want := msg.LatestBlockHash, chain.blocks[chain.Len()-1].Hash(); have != want {
+ if have, want := msg.Head, chain.blocks[chain.Len()-1].Hash(); have != want {
return fmt.Errorf("wrong head block in status, want: %#x (block %d) have %#x",
want, chain.blocks[chain.Len()-1].NumberU64(), have)
}
+ if have, want := msg.TD.Cmp(chain.TD()), 0; have != want {
+ return fmt.Errorf("wrong TD in status: have %v want %v", have, want)
+ }
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)
}
@@ -362,14 +364,13 @@
}
if status == nil {
// default status message
- status = ð.StatusPacket{
+ status = ð.StatusPacket68{
ProtocolVersion: uint32(c.negotiatedProtoVersion),
NetworkID: chain.config.ChainID.Uint64(),
+ TD: chain.TD(),
+ Head: chain.blocks[chain.Len()-1].Hash(),
Genesis: chain.blocks[0].Hash(),
ForkID: chain.ForkID(),
- EarliestBlock: 0,
- LatestBlock: chain.blocks[chain.Len()-1].NumberU64(),
- LatestBlockHash: chain.blocks[chain.Len()-1].Hash(),
}
}
if err := c.Write(ethProto, eth.StatusMsg, status); err != nil {
core-geth validation — +28 -10
| | | |---|---| | File | [`conn.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/cmd/devp2p/internal/ethtest/conn.go) | | Symbol | `` | | Ref | `v1.12.20` |--- a/core-geth/cmd/devp2p/internal/ethtest/conn.go
+++ b/etc/cmd/devp2p/internal/ethtest/conn.go
@@ -66,7 +66,6 @@
return nil, err
}
conn.caps = []p2p.Cap{
- {Name: "eth", Version: 67},
{Name: "eth", Version: 68},
}
conn.ourHighestProtoVersion = 68
@@ -130,11 +129,16 @@
return err
}
+var errDisc error = errors.New("disconnect")
+
// ReadEth reads an Eth sub-protocol wire message.
func (c *Conn) ReadEth() (any, error) {
c.SetReadDeadline(time.Now().Add(timeout))
for {
code, data, _, err := c.Conn.Read()
+ if code == discMsg {
+ return nil, errDisc
+ }
if err != nil {
return nil, err
}
@@ -151,7 +155,7 @@
var msg any
switch int(code) {
case eth.StatusMsg:
- msg = new(eth.StatusPacket)
+ msg = new(eth.StatusPacket68)
case eth.GetBlockHeadersMsg:
msg = new(eth.GetBlockHeadersPacket)
case eth.BlockHeadersMsg:
@@ -224,9 +228,21 @@
}
}
+// dialAndPeer creates a peer connection and runs the handshake.
+func (s *Suite) dialAndPeer(status *eth.StatusPacket68) (*Conn, error) {
+ c, err := s.dial()
+ if err != nil {
+ return nil, err
+ }
+ if err = c.peer(s.chain, status); err != nil {
+ c.Close()
+ }
+ return c, err
+}
+
// peer performs both the protocol handshake and the status message
// exchange with the node in order to peer with it.
-func (c *Conn) peer(chain *Chain, status *eth.StatusPacket) error {
+func (c *Conn) peer(chain *Chain, status *eth.StatusPacket68) error {
if err := c.handshake(); err != nil {
return fmt.Errorf("handshake failed: %v", err)
}
@@ -299,7 +315,7 @@
}
// statusExchange performs a `Status` message exchange with the given node.
-func (c *Conn) statusExchange(chain *Chain, status *eth.StatusPacket) error {
+func (c *Conn) statusExchange(chain *Chain, status *eth.StatusPacket68) error {
loop:
for {
code, data, err := c.Read()
@@ -308,7 +324,7 @@
}
switch code {
case eth.StatusMsg + protoOffset(ethProto):
- msg := new(eth.StatusPacket)
+ msg := new(eth.StatusPacket68)
if err := rlp.DecodeBytes(data, &msg); err != nil {
return fmt.Errorf("error decoding status packet: %w", err)
}
@@ -322,10 +338,12 @@
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
+ }
+ }
+ 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 {
@@ -346,9 +364,9 @@
}
if status == nil {
// default status message
- status = ð.StatusPacket{
+ status = ð.StatusPacket68{
ProtocolVersion: uint32(c.negotiatedProtoVersion),
- NetworkID: chain.config.GetChainID().Uint64(),
+ NetworkID: chain.config.ChainID.Uint64(),
TD: chain.TD(),
Head: chain.blocks[chain.Len()-1].Hash(),
Genesis: chain.blocks[0].Hash(),