eth/fetcher: fix data race in updateCustody

This commit is contained in:
healthykim 2026-05-27 23:43:42 +02:00
parent 4bc885e809
commit 859cff7bf6

View file

@ -111,11 +111,12 @@ type BlobFetcherFunctions struct {
// - Transactions to be fetched are moved to "fetching" // - Transactions to be fetched are moved to "fetching"
// if a payload/cell announcement is received during fetch, the peer is recorded as an alternate source. // if a payload/cell announcement is received during fetch, the peer is recorded as an alternate source.
type BlobFetcher struct { type BlobFetcher struct {
notify chan *blobTxAnnounce notify chan *blobTxAnnounce
cleanup chan *payloadDelivery cleanup chan *payloadDelivery
drop chan *txDrop drop chan *txDrop
quit chan struct{} custodyCh chan types.CustodyBitmap
custody *types.CustodyBitmap quit chan struct{}
custody *types.CustodyBitmap
txSeq uint64 // To make transactions fetched in arrival order txSeq uint64 // To make transactions fetched in arrival order
@ -160,6 +161,7 @@ func NewBlobFetcher(fn BlobFetcherFunctions, custody *types.CustodyBitmap, rand
notify: make(chan *blobTxAnnounce), notify: make(chan *blobTxAnnounce),
cleanup: make(chan *payloadDelivery), cleanup: make(chan *payloadDelivery),
drop: make(chan *txDrop), drop: make(chan *txDrop),
custodyCh: make(chan types.CustodyBitmap),
quit: make(chan struct{}), quit: make(chan struct{}),
full: make(map[common.Hash]struct{}), full: make(map[common.Hash]struct{}),
partial: make(map[common.Hash]struct{}), partial: make(map[common.Hash]struct{}),
@ -221,9 +223,14 @@ func (f *BlobFetcher) Drop(peer string) error {
} }
} }
// UpdateCustody hands a new custody bitmap to the fetcher loop. The actual
// swap happens inside the loop so f.custody is never read and written
// concurrently.
func (f *BlobFetcher) UpdateCustody(cells types.CustodyBitmap) { func (f *BlobFetcher) UpdateCustody(cells types.CustodyBitmap) {
// todo use lock or process inside of loop select {
f.custody = &cells case f.custodyCh <- cells:
case <-f.quit:
}
} }
func (f *BlobFetcher) Start() { func (f *BlobFetcher) Start() {
@ -632,6 +639,9 @@ func (f *BlobFetcher) loop() {
f.rescheduleTimeout(timeoutTimer, timeoutTrigger) f.rescheduleTimeout(timeoutTimer, timeoutTrigger)
} }
case cells := <-f.custodyCh:
f.custody = &cells
case <-f.quit: case <-f.quit:
return return
} }