Skip to content

Commit c4b01d8

Browse files
authored
eth/fetcher: always expect transaction metadata in announcement (#30288)
This pull request drops the legacy transaction retrieval support from before eth68, adding the restrictions that transaction metadata must be provided along with the transaction announment.
1 parent 2f2e5b0 commit c4b01d8

File tree

2 files changed

+542
-452
lines changed

2 files changed

+542
-452
lines changed

eth/fetcher/tx_fetcher.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ var errTerminated = errors.New("terminated")
114114
type txAnnounce struct {
115115
origin string // Identifier of the peer originating the notification
116116
hashes []common.Hash // Batch of transaction hashes being announced
117-
metas []*txMetadata // Batch of metadatas associated with the hashes (nil before eth/68)
117+
metas []*txMetadata // Batch of metadata associated with the hashes
118118
}
119119

120120
// txMetadata is a set of extra data transmitted along the announcement for better
@@ -137,7 +137,7 @@ type txRequest struct {
137137
type txDelivery struct {
138138
origin string // Identifier of the peer originating the notification
139139
hashes []common.Hash // Batch of transaction hashes having been delivered
140-
metas []txMetadata // Batch of metadatas associated with the delivered hashes
140+
metas []txMetadata // Batch of metadata associated with the delivered hashes
141141
direct bool // Whether this is a direct reply or a broadcast
142142
}
143143

@@ -260,11 +260,11 @@ func (f *TxFetcher) Notify(peer string, types []byte, sizes []uint32, hashes []c
260260
underpriced++
261261
default:
262262
unknownHashes = append(unknownHashes, hash)
263-
if types == nil {
264-
unknownMetas = append(unknownMetas, nil)
265-
} else {
266-
unknownMetas = append(unknownMetas, &txMetadata{kind: types[i], size: sizes[i]})
267-
}
263+
264+
// Transaction metadata has been available since eth68, and all
265+
// legacy eth protocols (prior to eth68) have been deprecated.
266+
// Therefore, metadata is always expected in the announcement.
267+
unknownMetas = append(unknownMetas, &txMetadata{kind: types[i], size: sizes[i]})
268268
}
269269
}
270270
txAnnounceKnownMeter.Mark(duplicate)
@@ -892,13 +892,8 @@ func (f *TxFetcher) scheduleFetches(timer *mclock.Timer, timeout chan struct{},
892892
if len(hashes) >= maxTxRetrievals {
893893
return false // break in the for-each
894894
}
895-
if meta != nil { // Only set eth/68 and upwards
896-
bytes += uint64(meta.size)
897-
if bytes >= maxTxRetrievalSize {
898-
return false
899-
}
900-
}
901-
return true // scheduled, try to add more
895+
bytes += uint64(meta.size)
896+
return bytes < maxTxRetrievalSize
902897
})
903898
// If any hashes were allocated, request them from the peer
904899
if len(hashes) > 0 {

0 commit comments

Comments
 (0)