fix hive test errors

This commit is contained in:
healthykim 2026-04-13 22:47:53 +02:00
parent d2b36d4c0b
commit f7e46cc505
9 changed files with 61 additions and 51 deletions

View file

@ -66,9 +66,11 @@ func (s *Suite) dialAs(key *ecdsa.PrivateKey) (*Conn, error) {
return nil, err return nil, err
} }
conn.caps = []p2p.Cap{ conn.caps = []p2p.Cap{
{Name: "eth", Version: 72},
{Name: "eth", Version: 70},
{Name: "eth", Version: 69}, {Name: "eth", Version: 69},
} }
conn.ourHighestProtoVersion = 69 conn.ourHighestProtoVersion = 72
return &conn, nil return &conn, nil
} }
@ -167,11 +169,15 @@ func (c *Conn) ReadEth() (any, error) {
case eth.TransactionsMsg: case eth.TransactionsMsg:
msg = new(eth.TransactionsPacket) msg = new(eth.TransactionsPacket)
case eth.NewPooledTransactionHashesMsg: case eth.NewPooledTransactionHashesMsg:
msg = new(eth.NewPooledTransactionHashesPacket70) msg = new(eth.NewPooledTransactionHashesPacket72)
case eth.GetPooledTransactionsMsg: case eth.GetPooledTransactionsMsg:
msg = new(eth.GetPooledTransactionsPacket) msg = new(eth.GetPooledTransactionsPacket)
case eth.PooledTransactionsMsg: case eth.PooledTransactionsMsg:
msg = new(eth.PooledTransactionsPacket) msg = new(eth.PooledTransactionsPacket)
case eth.GetCellsMsg:
msg = new(eth.GetCellsRequest)
case eth.CellsMsg:
msg = new(eth.CellsResponse)
default: default:
panic(fmt.Sprintf("unhandled eth msg code %d", code)) panic(fmt.Sprintf("unhandled eth msg code %d", code))
} }

View file

@ -32,7 +32,7 @@ const (
// Unexported devp2p protocol lengths from p2p package. // Unexported devp2p protocol lengths from p2p package.
const ( const (
baseProtoLen = 16 baseProtoLen = 16
ethProtoLen = 18 ethProtoLen = 20
snapProtoLen = 8 snapProtoLen = 8
) )

View file

@ -865,7 +865,7 @@ the transactions using a GetPooledTransactions request.`)
} }
// Send announcement. // Send announcement.
ann := eth.NewPooledTransactionHashesPacket70{Types: txTypes, Sizes: sizes, Hashes: hashes} ann := eth.NewPooledTransactionHashesPacket72{Types: txTypes, Sizes: sizes, Hashes: hashes}
err = conn.Write(ethProto, eth.NewPooledTransactionHashesMsg, ann) err = conn.Write(ethProto, eth.NewPooledTransactionHashesMsg, ann)
if err != nil { if err != nil {
t.Fatalf("failed to write to connection: %v", err) t.Fatalf("failed to write to connection: %v", err)
@ -883,7 +883,7 @@ the transactions using a GetPooledTransactions request.`)
t.Fatalf("unexpected number of txs requested: wanted %d, got %d", len(hashes), len(msg.GetPooledTransactionsRequest)) t.Fatalf("unexpected number of txs requested: wanted %d, got %d", len(hashes), len(msg.GetPooledTransactionsRequest))
} }
return return
case *eth.NewPooledTransactionHashesPacket70: case *eth.NewPooledTransactionHashesPacket72:
continue continue
case *eth.TransactionsPacket: case *eth.TransactionsPacket:
continue continue
@ -902,11 +902,11 @@ func makeSidecar(data ...byte) *types.BlobTxSidecar {
for i := range blobs { for i := range blobs {
blobs[i][0] = data[i] blobs[i][0] = data[i]
c, _ := kzg4844.BlobToCommitment(&blobs[i]) c, _ := kzg4844.BlobToCommitment(&blobs[i])
p, _ := kzg4844.ComputeBlobProof(&blobs[i], c) cellProofs, _ := kzg4844.ComputeCellProofs(&blobs[i])
commitments = append(commitments, c) commitments = append(commitments, c)
proofs = append(proofs, p) proofs = append(proofs, cellProofs...)
} }
return types.NewBlobTxSidecar(types.BlobSidecarVersion0, blobs, commitments, proofs) return types.NewBlobTxSidecar(types.BlobSidecarVersion1, blobs, commitments, proofs)
} }
func (s *Suite) makeBlobTxs(count, blobs int, discriminator byte) (txs types.Transactions) { func (s *Suite) makeBlobTxs(count, blobs int, discriminator byte) (txs types.Transactions) {
@ -949,24 +949,26 @@ func (s *Suite) TestBlobViolations(t *utesting.T) {
t2 = s.makeBlobTxs(2, 3, 0x2) t2 = s.makeBlobTxs(2, 3, 0x2)
) )
for _, test := range []struct { for _, test := range []struct {
ann eth.NewPooledTransactionHashesPacket70 ann eth.NewPooledTransactionHashesPacket72
resp eth.PooledTransactionsResponse resp eth.PooledTransactionsResponse
}{ }{
// Invalid tx size. // Invalid tx size.
{ {
ann: eth.NewPooledTransactionHashesPacket70{ ann: eth.NewPooledTransactionHashesPacket72{
Types: []byte{types.BlobTxType, types.BlobTxType}, Types: []byte{types.BlobTxType, types.BlobTxType},
Sizes: []uint32{uint32(t1[0].Size()), uint32(t1[1].Size() + 10)}, Sizes: []uint32{uint32(t1[0].Size()), uint32(t1[1].Size() + 10)},
Hashes: []common.Hash{t1[0].Hash(), t1[1].Hash()}, Hashes: []common.Hash{t1[0].Hash(), t1[1].Hash()},
Mask: *types.CustodyBitmapAll,
}, },
resp: eth.PooledTransactionsResponse(t1), resp: eth.PooledTransactionsResponse(t1),
}, },
// Wrong tx type. // Wrong tx type.
{ {
ann: eth.NewPooledTransactionHashesPacket70{ ann: eth.NewPooledTransactionHashesPacket72{
Types: []byte{types.DynamicFeeTxType, types.BlobTxType}, Types: []byte{types.DynamicFeeTxType, types.BlobTxType},
Sizes: []uint32{uint32(t2[0].Size()), uint32(t2[1].Size())}, Sizes: []uint32{uint32(t2[0].Size()), uint32(t2[1].Size())},
Hashes: []common.Hash{t2[0].Hash(), t2[1].Hash()}, Hashes: []common.Hash{t2[0].Hash(), t2[1].Hash()},
Mask: *types.CustodyBitmapAll,
}, },
resp: eth.PooledTransactionsResponse(t2), resp: eth.PooledTransactionsResponse(t2),
}, },
@ -994,15 +996,21 @@ func (s *Suite) TestBlobViolations(t *utesting.T) {
if code, _, err := conn.Read(); err != nil { if code, _, err := conn.Read(); err != nil {
t.Fatalf("expected disconnect on blob violation, got err: %v", err) t.Fatalf("expected disconnect on blob violation, got err: %v", err)
} else if code != discMsg { } else if code != discMsg {
if code == protoOffset(ethProto)+eth.NewPooledTransactionHashesMsg { for {
// sometimes we'll get a blob transaction hashes announcement before the disconnect code, _, err := conn.Read()
// because blob transactions are scheduled to be fetched right away. if err != nil {
if code, _, err = conn.Read(); err != nil { t.Fatalf("expected disconnect on blob violation, got err: %v", err)
t.Fatalf("expected disconnect on blob violation, got err on second read: %v", err) }
if code == discMsg {
break
}
switch code {
case protoOffset(ethProto) + eth.NewPooledTransactionHashesMsg,
protoOffset(ethProto) + eth.GetCellsMsg:
continue
default:
t.Fatalf("expected disconnect on blob violation, got msg code: %d", code)
} }
}
if code != discMsg {
t.Fatalf("expected disconnect on blob violation, got msg code: %d", code)
} }
} }
conn.Close() conn.Close()
@ -1021,14 +1029,14 @@ func mangleSidecar(tx *types.Transaction) *types.Transaction {
func (s *Suite) TestBlobTxWithoutSidecar(t *utesting.T) { func (s *Suite) TestBlobTxWithoutSidecar(t *utesting.T) {
t.Log(`This test checks that a blob transaction first advertised/transmitted without blobs will result in the sending peer being disconnected, and the full transaction should be successfully retrieved from another peer.`) t.Log(`This test checks that a blob transaction first advertised/transmitted without blobs will result in the sending peer being disconnected, and the full transaction should be successfully retrieved from another peer.`)
tx := s.makeBlobTxs(1, 2, 42)[0] tx := s.makeBlobTxs(1, 2, 42)[0].WithoutBlob()
badTx := tx.WithoutBlobTxSidecar() badTx := tx.WithoutBlobTxSidecar()
s.testBadBlobTx(t, tx, badTx) s.testBadBlobTx(t, tx, badTx)
} }
func (s *Suite) TestBlobTxWithMismatchedSidecar(t *utesting.T) { func (s *Suite) TestBlobTxWithMismatchedSidecar(t *utesting.T) {
t.Log(`This test checks that a blob transaction first advertised/transmitted without blobs, whose commitment don't correspond to the blob_versioned_hashes in the transaction, will result in the sending peer being disconnected, and the full transaction should be successfully retrieved from another peer.`) t.Log(`This test checks that a blob transaction first advertised/transmitted without blobs, whose commitment don't correspond to the blob_versioned_hashes in the transaction, will result in the sending peer being disconnected, and the full transaction should be successfully retrieved from another peer.`)
tx := s.makeBlobTxs(1, 2, 43)[0] tx := s.makeBlobTxs(1, 2, 43)[0].WithoutBlob()
badTx := mangleSidecar(tx) badTx := mangleSidecar(tx)
s.testBadBlobTx(t, tx, badTx) s.testBadBlobTx(t, tx, badTx)
} }
@ -1092,10 +1100,11 @@ func (s *Suite) testBadBlobTx(t *utesting.T, tx *types.Transaction, badTx *types
return return
} }
ann := eth.NewPooledTransactionHashesPacket70{ ann := eth.NewPooledTransactionHashesPacket72{
Types: []byte{types.BlobTxType}, Types: []byte{types.BlobTxType},
Sizes: []uint32{uint32(badTx.Size())}, Sizes: []uint32{uint32(badTx.Size())},
Hashes: []common.Hash{badTx.Hash()}, Hashes: []common.Hash{badTx.Hash()},
Mask: *types.CustodyBitmapAll,
} }
if err := conn.Write(ethProto, eth.NewPooledTransactionHashesMsg, ann); err != nil { if err := conn.Write(ethProto, eth.NewPooledTransactionHashesMsg, ann); err != nil {
@ -1143,14 +1152,15 @@ func (s *Suite) testBadBlobTx(t *utesting.T, tx *types.Transaction, badTx *types
return return
} }
ann := eth.NewPooledTransactionHashesPacket70{ ann := eth.NewPooledTransactionHashesPacket72{
Types: []byte{types.BlobTxType}, Types: []byte{types.BlobTxType},
Sizes: []uint32{uint32(tx.Size())}, Sizes: []uint32{uint32(tx.Size())},
Hashes: []common.Hash{tx.Hash()}, Hashes: []common.Hash{tx.Hash()},
Mask: *types.CustodyBitmapAll,
} }
if err := conn.Write(ethProto, eth.NewPooledTransactionHashesMsg, ann); err != nil { if err := conn.Write(ethProto, eth.NewPooledTransactionHashesMsg, ann); err != nil {
errc <- fmt.Errorf("sending announcement failed: %v", err) errc <- fmt.Errorf("sending first announcement failed: %v", err)
return return
} }

View file

@ -74,7 +74,7 @@ func (s *Suite) sendTxs(t *utesting.T, txs []*types.Transaction) error {
for _, tx := range txs { for _, tx := range txs {
got[tx.Hash()] = true got[tx.Hash()] = true
} }
case *eth.NewPooledTransactionHashesPacket70: case *eth.NewPooledTransactionHashesPacket72:
for _, hash := range msg.Hashes { for _, hash := range msg.Hashes {
got[hash] = true got[hash] = true
} }
@ -160,7 +160,7 @@ func (s *Suite) sendInvalidTxs(t *utesting.T, txs []*types.Transaction) error {
return fmt.Errorf("received bad tx: %s", tx.Hash()) return fmt.Errorf("received bad tx: %s", tx.Hash())
} }
} }
case *eth.NewPooledTransactionHashesPacket70: case *eth.NewPooledTransactionHashesPacket72:
for _, hash := range msg.Hashes { for _, hash := range msg.Hashes {
if _, ok := invalids[hash]; ok { if _, ok := invalids[hash]; ok {
return fmt.Errorf("received bad tx: %s", hash) return fmt.Errorf("received bad tx: %s", hash)

View file

@ -59,7 +59,7 @@ func (h *ethHandler) AcceptTxs() bool {
func (h *ethHandler) Handle(peer *eth.Peer, packet eth.Packet) error { func (h *ethHandler) Handle(peer *eth.Peer, packet eth.Packet) error {
// Consume any broadcasts and announces, forwarding the rest to the downloader // Consume any broadcasts and announces, forwarding the rest to the downloader
switch packet := packet.(type) { switch packet := packet.(type) {
case *eth.NewPooledTransactionHashesPacket71: case *eth.NewPooledTransactionHashesPacket72:
hashes, err := h.txFetcher.Notify(peer.ID(), packet.Types, packet.Sizes, packet.Hashes) hashes, err := h.txFetcher.Notify(peer.ID(), packet.Types, packet.Sizes, packet.Hashes)
if err != nil { if err != nil {
return err return err
@ -69,7 +69,7 @@ func (h *ethHandler) Handle(peer *eth.Peer, packet eth.Packet) error {
} }
return nil return nil
case *eth.NewPooledTransactionHashesPacket70: case *eth.NewPooledTransactionHashesPacket71:
_, err := h.txFetcher.Notify(peer.ID(), packet.Types, packet.Sizes, packet.Hashes) _, err := h.txFetcher.Notify(peer.ID(), packet.Types, packet.Sizes, packet.Hashes)
return err return err
@ -113,17 +113,11 @@ func handleTransactions(peer *eth.Peer, list []*types.Transaction, directBroadca
// If we receive any blob transactions missing sidecars, or with // If we receive any blob transactions missing sidecars, or with
// sidecars that don't correspond to the versioned hashes reported // sidecars that don't correspond to the versioned hashes reported
// in the header, disconnect from the sending peer. // in the header, disconnect from the sending peer.
if peer.Version() >= eth.ETH72 { if tx.BlobTxSidecar() == nil {
if tx.BlobTxSidecar() != nil && len(tx.BlobTxSidecar().Blobs) != 0 { return errors.New("received sidecar-less blob transaction")
return fmt.Errorf("not allowed to respond with full-blob transaction under eth72") }
} if err := tx.BlobTxSidecar().ValidateBlobCommitmentHashes(tx.BlobHashes()); err != nil {
} else { return err
if tx.BlobTxSidecar() == nil {
return errors.New("received sidecar-less blob transaction")
}
if err := tx.BlobTxSidecar().ValidateBlobCommitmentHashes(tx.BlobHashes()); err != nil {
return err
}
} }
} }
} }

View file

@ -51,7 +51,7 @@ func (h *testEthHandler) PeerInfo(enode.ID) interface{} { panic("not used
func (h *testEthHandler) Handle(peer *eth.Peer, packet eth.Packet) error { func (h *testEthHandler) Handle(peer *eth.Peer, packet eth.Packet) error {
switch packet := packet.(type) { switch packet := packet.(type) {
case *eth.NewPooledTransactionHashesPacket70: case *eth.NewPooledTransactionHashesPacket71:
h.txAnnounces.Send(packet.Hashes) h.txAnnounces.Send(packet.Hashes)
return nil return nil

View file

@ -483,7 +483,7 @@ func handleNewPooledTransactionHashes(backend Backend, msg Decoder, peer *Peer)
if !backend.AcceptTxs() { if !backend.AcceptTxs() {
return nil return nil
} }
ann := new(NewPooledTransactionHashesPacket70) ann := new(NewPooledTransactionHashesPacket71)
if err := msg.Decode(ann); err != nil { if err := msg.Decode(ann); err != nil {
return err return err
} }
@ -503,7 +503,7 @@ func handleNewPooledTransactionHashes71(backend Backend, msg Decoder, peer *Peer
if !backend.AcceptTxs() { if !backend.AcceptTxs() {
return nil return nil
} }
ann := new(NewPooledTransactionHashesPacket71) ann := new(NewPooledTransactionHashesPacket72)
if err := msg.Decode(ann); err != nil { if err := msg.Decode(ann); err != nil {
return err return err
} }

View file

@ -173,9 +173,9 @@ func (p *Peer) sendPooledTransactionHashes(hashes []common.Hash, types []byte, s
// Mark all the transactions as known, but ensure we don't overflow our limits // Mark all the transactions as known, but ensure we don't overflow our limits
p.knownTxs.Add(hashes...) p.knownTxs.Add(hashes...)
if p.version >= ETH72 { if p.version >= ETH72 {
return p2p.Send(p.rw, NewPooledTransactionHashesMsg, NewPooledTransactionHashesPacket71{Types: types, Sizes: sizes, Hashes: hashes, Mask: cells}) return p2p.Send(p.rw, NewPooledTransactionHashesMsg, NewPooledTransactionHashesPacket72{Types: types, Sizes: sizes, Hashes: hashes, Mask: cells})
} }
return p2p.Send(p.rw, NewPooledTransactionHashesMsg, NewPooledTransactionHashesPacket70{Types: types, Sizes: sizes, Hashes: hashes}) return p2p.Send(p.rw, NewPooledTransactionHashesMsg, NewPooledTransactionHashesPacket71{Types: types, Sizes: sizes, Hashes: hashes})
} }
// AsyncSendPooledTransactionHashes queues a list of transactions hashes to eventually // AsyncSendPooledTransactionHashes queues a list of transactions hashes to eventually

View file

@ -234,16 +234,16 @@ type ReceiptsPacket struct {
// ReceiptsRLPResponse is used for receipts, when we already have it encoded // ReceiptsRLPResponse is used for receipts, when we already have it encoded
type ReceiptsRLPResponse []rlp.RawValue type ReceiptsRLPResponse []rlp.RawValue
// NewPooledTransactionHashesPacket70 represents a transaction announcement packet on eth/69. // NewPooledTransactionHashesPacket71 represents a transaction announcement packet on eth/69.
type NewPooledTransactionHashesPacket70 struct { type NewPooledTransactionHashesPacket71 struct {
Types []byte Types []byte
Sizes []uint32 Sizes []uint32
Hashes []common.Hash Hashes []common.Hash
} }
// NewPooledTransactionHashesPacket71 represents a transaction announcement packet on ETH/72 // NewPooledTransactionHashesPacket72 represents a transaction announcement packet on ETH/72
// with an additional custody bitmap field for cell-based blob data availability. // with an additional custody bitmap field for cell-based blob data availability.
type NewPooledTransactionHashesPacket71 struct { type NewPooledTransactionHashesPacket72 struct {
Types []byte Types []byte
Sizes []uint32 Sizes []uint32
Hashes []common.Hash Hashes []common.Hash
@ -329,12 +329,12 @@ func (*GetBlockBodiesRequest) Kind() byte { return GetBlockBodiesMsg }
func (*BlockBodiesResponse) Name() string { return "BlockBodies" } func (*BlockBodiesResponse) Name() string { return "BlockBodies" }
func (*BlockBodiesResponse) Kind() byte { return BlockBodiesMsg } func (*BlockBodiesResponse) Kind() byte { return BlockBodiesMsg }
func (*NewPooledTransactionHashesPacket70) Name() string { return "NewPooledTransactionHashes" }
func (*NewPooledTransactionHashesPacket70) Kind() byte { return NewPooledTransactionHashesMsg }
func (*NewPooledTransactionHashesPacket71) Name() string { return "NewPooledTransactionHashes" } func (*NewPooledTransactionHashesPacket71) Name() string { return "NewPooledTransactionHashes" }
func (*NewPooledTransactionHashesPacket71) Kind() byte { return NewPooledTransactionHashesMsg } func (*NewPooledTransactionHashesPacket71) Kind() byte { return NewPooledTransactionHashesMsg }
func (*NewPooledTransactionHashesPacket72) Name() string { return "NewPooledTransactionHashes" }
func (*NewPooledTransactionHashesPacket72) Kind() byte { return NewPooledTransactionHashesMsg }
func (*GetPooledTransactionsRequest) Name() string { return "GetPooledTransactions" } func (*GetPooledTransactionsRequest) Name() string { return "GetPooledTransactions" }
func (*GetPooledTransactionsRequest) Kind() byte { return GetPooledTransactionsMsg } func (*GetPooledTransactionsRequest) Kind() byte { return GetPooledTransactionsMsg }