@@ -153,43 +153,45 @@ func NewDatastore(ctx context.Context, opts DatastoreOptions) Database {
153153}
154154
155155// WriteBlock writes the block and the block event to datastore.
156- func (d * Datastore ) WriteBlock (ctx context.Context , peer * enode.Node , block * types.Block , td * big.Int , tfs time.Time ) {
156+ func (d * Datastore ) WriteBlock (ctx context.Context , tracker GoroutineTracker , peer * enode.Node , block * types.Block , td * big.Int , tfs time.Time ) {
157157 if d .client == nil {
158158 return
159159 }
160160
161161 if d .ShouldWriteBlockEvents () {
162- d . jobs <- struct {}{}
163- go func () {
162+ tracker . TrackGoroutine ( func () {
163+ d . jobs <- struct {}{}
164164 d .writeEvent (peer , BlockEventsKind , block .Hash (), BlocksKind , tfs )
165165 <- d .jobs
166- }( )
166+ })
167167 }
168168
169169 if d .ShouldWriteBlocks () {
170- d . jobs <- struct {}{}
171- go func () {
170+ tracker . TrackGoroutine ( func () {
171+ d . jobs <- struct {}{}
172172 d .writeBlock (ctx , block , td , tfs )
173173 <- d .jobs
174- }( )
174+ })
175175 }
176176}
177177
178178// WriteBlockHeaders will write the block headers to datastore. It will not
179179// write block events because headers will only be sent to the sensor when
180180// requested. The block events will be written when the hash is received
181181// instead.
182- func (d * Datastore ) WriteBlockHeaders (ctx context.Context , headers []* types.Header , tfs time.Time ) {
182+ func (d * Datastore ) WriteBlockHeaders (ctx context.Context , tracker GoroutineTracker , headers []* types.Header , tfs time.Time ) {
183183 if d .client == nil || ! d .ShouldWriteBlocks () {
184184 return
185185 }
186186
187187 for _ , h := range headers {
188- d .jobs <- struct {}{}
189- go func (header * types.Header ) {
190- d .writeBlockHeader (ctx , header , tfs )
191- <- d .jobs
192- }(h )
188+ tracker .TrackGoroutine (func (header * types.Header ) func () {
189+ return func () {
190+ d .jobs <- struct {}{}
191+ d .writeBlockHeader (ctx , header , tfs )
192+ <- d .jobs
193+ }
194+ }(h ))
193195 }
194196}
195197
@@ -198,43 +200,43 @@ func (d *Datastore) WriteBlockHeaders(ctx context.Context, headers []*types.Head
198200// requested. The block events will be written when the hash is received
199201// instead. It will write the uncles and transactions to datastore if they
200202// don't already exist.
201- func (d * Datastore ) WriteBlockBody (ctx context.Context , body * eth.BlockBody , hash common.Hash , tfs time.Time ) {
203+ func (d * Datastore ) WriteBlockBody (ctx context.Context , tracker GoroutineTracker , body * eth.BlockBody , hash common.Hash , tfs time.Time ) {
202204 if d .client == nil || ! d .ShouldWriteBlocks () {
203205 return
204206 }
205207
206- d . jobs <- struct {}{}
207- go func () {
208+ tracker . TrackGoroutine ( func () {
209+ d . jobs <- struct {}{}
208210 d .writeBlockBody (ctx , body , hash , tfs )
209211 <- d .jobs
210- }( )
212+ })
211213}
212214
213215// WriteBlockHashes will write the block events to datastore.
214- func (d * Datastore ) WriteBlockHashes (ctx context.Context , peer * enode.Node , hashes []common.Hash , tfs time.Time ) {
216+ func (d * Datastore ) WriteBlockHashes (ctx context.Context , tracker GoroutineTracker , peer * enode.Node , hashes []common.Hash , tfs time.Time ) {
215217 if d .client == nil || ! d .ShouldWriteBlockEvents () || len (hashes ) == 0 {
216218 return
217219 }
218220
219- d . jobs <- struct {}{}
220- go func () {
221+ tracker . TrackGoroutine ( func () {
222+ d . jobs <- struct {}{}
221223 d .writeEvents (ctx , peer , BlockEventsKind , hashes , BlocksKind , tfs )
222224 <- d .jobs
223- }( )
225+ })
224226}
225227
226228// WriteTransactions will write the transactions and transaction events to datastore.
227- func (d * Datastore ) WriteTransactions (ctx context.Context , peer * enode.Node , txs []* types.Transaction , tfs time.Time ) {
229+ func (d * Datastore ) WriteTransactions (ctx context.Context , tracker GoroutineTracker , peer * enode.Node , txs []* types.Transaction , tfs time.Time ) {
228230 if d .client == nil {
229231 return
230232 }
231233
232234 if d .ShouldWriteTransactions () {
233- d . jobs <- struct {}{}
234- go func () {
235+ tracker . TrackGoroutine ( func () {
236+ d . jobs <- struct {}{}
235237 d .writeTransactions (ctx , txs , tfs )
236238 <- d .jobs
237- }( )
239+ })
238240 }
239241
240242 if d .ShouldWriteTransactionEvents () {
@@ -243,11 +245,11 @@ func (d *Datastore) WriteTransactions(ctx context.Context, peer *enode.Node, txs
243245 hashes = append (hashes , tx .Hash ())
244246 }
245247
246- d . jobs <- struct {}{}
247- go func () {
248+ tracker . TrackGoroutine ( func () {
249+ d . jobs <- struct {}{}
248250 d .writeEvents (ctx , peer , TransactionEventsKind , hashes , TransactionsKind , tfs )
249251 <- d .jobs
250- }( )
252+ })
251253 }
252254}
253255
0 commit comments