mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
eth/fetcher: fix data race in updateCustody
This commit is contained in:
parent
4bc885e809
commit
859cff7bf6
1 changed files with 17 additions and 7 deletions
|
|
@ -114,6 +114,7 @@ type BlobFetcher struct {
|
||||||
notify chan *blobTxAnnounce
|
notify chan *blobTxAnnounce
|
||||||
cleanup chan *payloadDelivery
|
cleanup chan *payloadDelivery
|
||||||
drop chan *txDrop
|
drop chan *txDrop
|
||||||
|
custodyCh chan types.CustodyBitmap
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
custody *types.CustodyBitmap
|
custody *types.CustodyBitmap
|
||||||
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue