Skip to content

Commit 0007235

Browse files
authored
Merge pull request #2045 from CortexFoundation/dev
txpool data race fix
2 parents a598710 + 5e15ebc commit 0007235

File tree

19 files changed

+688
-111
lines changed

19 files changed

+688
-111
lines changed

core/txpool/txpool.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import (
3838
)
3939

4040
const (
41-
// chainHeadChanSize is the size of channel listening to ChainHeadEvent.
42-
chainHeadChanSize = 10
4341
// txSlotSize is used to calculate how many data slots a single transaction
4442
// takes up based on its size. The slots are used as DoS protection, ensuring
4543
// that validating a new transaction remains a constant operation (in reality
@@ -298,7 +296,7 @@ func NewTxPool(config Config, chainconfig *params.ChainConfig, chain blockChain)
298296
queue: make(map[common.Address]*list),
299297
beats: make(map[common.Address]time.Time),
300298
all: newLookup(),
301-
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
299+
chainHeadCh: make(chan core.ChainHeadEvent),
302300
reqResetCh: make(chan *txpoolResetRequest),
303301
reqPromoteCh: make(chan *accountSet),
304302
queueTxEventCh: make(chan *types.Transaction),
@@ -333,16 +331,18 @@ func NewTxPool(config Config, chainconfig *params.ChainConfig, chain blockChain)
333331

334332
// Subscribe events from blockchain and start the main event loop.
335333
pool.chainHeadSub = pool.chain.SubscribeChainHeadEvent(pool.chainHeadCh)
334+
335+
head := chain.CurrentBlock()
336336
pool.wg.Add(1)
337-
go pool.loop()
337+
go pool.loop(head)
338338

339339
return pool
340340
}
341341

342342
// loop is the transaction pool's main event loop, waiting for and reacting to
343343
// outside blockchain events as well as for various reporting and transaction
344344
// eviction events.
345-
func (pool *TxPool) loop() {
345+
func (pool *TxPool) loop(head *types.Block) {
346346
defer pool.wg.Done()
347347

348348
var (
@@ -351,16 +351,13 @@ func (pool *TxPool) loop() {
351351
report = time.NewTicker(statsReportInterval)
352352
evict = time.NewTicker(evictionInterval)
353353
journal = time.NewTicker(pool.config.Rejournal)
354-
// Track the previous head headers for transaction reorgs
355-
head = pool.chain.CurrentBlock()
356354
)
357355
defer report.Stop()
358356
defer evict.Stop()
359357
defer journal.Stop()
360358

361359
// Notify tests that the init phase is done
362360
close(pool.initDoneCh)
363-
364361
for {
365362
select {
366363
// Handle ChainHeadEvent

go.mod

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.2
77
github.com/CortexFoundation/inference v1.0.2-0.20230307032835-9197d586a4e8
88
github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
9-
github.com/CortexFoundation/torrentfs v1.0.65-0.20240526145549-b060534fcf19
9+
github.com/CortexFoundation/torrentfs v1.0.65-0.20240528085256-81c24aed642e
1010
github.com/VictoriaMetrics/fastcache v1.12.2
1111
github.com/arsham/figurine v1.3.0
1212
github.com/aws/aws-sdk-go-v2 v1.27.0
@@ -146,7 +146,7 @@ require (
146146
github.com/elliotchance/orderedmap v1.6.0 // indirect
147147
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
148148
github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect
149-
github.com/getsentry/sentry-go v0.27.0 // indirect
149+
github.com/getsentry/sentry-go v0.28.0 // indirect
150150
github.com/go-llsqlite/adapter v0.1.0 // indirect
151151
github.com/go-llsqlite/crawshaw v0.5.2 // indirect
152152
github.com/go-logr/logr v1.4.2 // indirect
@@ -162,7 +162,7 @@ require (
162162
github.com/google/btree v1.1.2 // indirect
163163
github.com/google/flatbuffers v24.3.25+incompatible // indirect
164164
github.com/google/go-querystring v1.1.0 // indirect
165-
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af // indirect
165+
github.com/google/pprof v0.0.0-20240528025155-186aa0362fba // indirect
166166
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
167167
github.com/hashicorp/go-retryablehttp v0.7.6 // indirect
168168
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
@@ -187,7 +187,6 @@ require (
187187
github.com/naoina/go-stringutil v0.1.0 // indirect
188188
github.com/ncruces/go-strftime v0.1.9 // indirect
189189
github.com/nutsdb/nutsdb v1.0.4 // indirect
190-
github.com/nxadm/tail v1.4.11 // indirect
191190
github.com/oapi-codegen/runtime v1.1.1 // indirect
192191
github.com/otiai10/copy v1.14.0 // indirect
193192
github.com/pion/datachannel v1.5.6 // indirect
@@ -227,7 +226,7 @@ require (
227226
github.com/tklauser/numcpus v0.8.0 // indirect
228227
github.com/ucwong/filecache v1.0.6-0.20230405163841-810d53ced4bd // indirect
229228
github.com/ucwong/go-ttlmap v1.0.2-0.20221020173635-331e7ddde2bb // indirect
230-
github.com/ucwong/golang-kv v1.0.24-0.20240516111454-2b75a20c4c6b // indirect
229+
github.com/ucwong/golang-kv v1.0.24-0.20240526160259-ef630c06892e // indirect
231230
github.com/ucwong/shard v1.0.1-0.20240327124306-59a521744cae // indirect
232231
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
233232
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect

go.sum

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66/go.mod h1:
7070
github.com/CortexFoundation/torrentfs v1.0.13-0.20200623060705-ce027f43f2f8/go.mod h1:Ma+tGhPPvz4CEZHaqEJQMOEGOfHeQBiAoNd1zyc/w3Q=
7171
github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.mod h1:qnb3YlIJmuetVBtC6Lsejr0Xru+1DNmDCdTqnwy7lhk=
7272
github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
73-
github.com/CortexFoundation/torrentfs v1.0.65-0.20240526145549-b060534fcf19 h1:7nL8TOib65ROf/wqKxGzi4wKK/+lJfCb3fDCEi0rsw0=
74-
github.com/CortexFoundation/torrentfs v1.0.65-0.20240526145549-b060534fcf19/go.mod h1:RxxIF+0W4mi15V/bU9w26SqW0hHH9MzO7MqwkjPJF2w=
73+
github.com/CortexFoundation/torrentfs v1.0.65-0.20240528085256-81c24aed642e h1:XPgiOuI/BQmEYOhDfrEl7e0vksbkBe0meT6YZAd0y3w=
74+
github.com/CortexFoundation/torrentfs v1.0.65-0.20240528085256-81c24aed642e/go.mod h1:RTrewKfZZUqUIudGRYm7SydFQOnAQlmyQ2rggGH0CmA=
7575
github.com/CortexFoundation/wormhole v0.0.2-0.20240503144741-71d4d22383f0 h1:pePXS+/6usgcC1G2Ma3pX7fJwoRcgLPyu5SLawrTszc=
7676
github.com/CortexFoundation/wormhole v0.0.2-0.20240503144741-71d4d22383f0/go.mod h1:ipzmPabDgzYKUbXkGVe2gTkBEp+MsDx6pXGiuYzmP6s=
7777
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
@@ -484,16 +484,15 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
484484
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
485485
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
486486
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
487-
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
488487
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
489488
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
490489
github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 h1:IZqZOB2fydHte3kUgxrzK5E1fW7RQGeDwE8F/ZZnUYc=
491490
github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61/go.mod h1:Q0X6pkwTILDlzrGEckF6HKjXe48EgsY/l7K7vhY4MW8=
492491
github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
493492
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays=
494493
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
495-
github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps=
496-
github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
494+
github.com/getsentry/sentry-go v0.28.0 h1:7Rqx9M3ythTKy2J6uZLHmc8Sz9OGgIlseuO1iBX/s0M=
495+
github.com/getsentry/sentry-go v0.28.0/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg=
497496
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
498497
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
499498
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
@@ -622,8 +621,8 @@ github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OI
622621
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
623622
github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
624623
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
625-
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af h1:kmjWCqn2qkEml422C2Rrd27c3VGxi6a/6HNq8QmHRKM=
626-
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
624+
github.com/google/pprof v0.0.0-20240528025155-186aa0362fba h1:ql1qNgCyOB7iAEk8JTNM+zJrgIbnyCKX/wdlyPufP5g=
625+
github.com/google/pprof v0.0.0-20240528025155-186aa0362fba/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
627626
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
628627
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
629628
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -1250,8 +1249,8 @@ github.com/ucwong/filecache v1.0.6-0.20230405163841-810d53ced4bd h1:gBtlvLAsgLk+
12501249
github.com/ucwong/filecache v1.0.6-0.20230405163841-810d53ced4bd/go.mod h1:ddwX+NCjMZPdpzcGh1fcEbNTUTCtKgt2hC2rqvmLKgA=
12511250
github.com/ucwong/go-ttlmap v1.0.2-0.20221020173635-331e7ddde2bb h1:dVZH3AH9f7zB3VBmsjn25B7lfcAyMP4QxdFYTrfj7tg=
12521251
github.com/ucwong/go-ttlmap v1.0.2-0.20221020173635-331e7ddde2bb/go.mod h1:3yswsBsVuwsOjDvFfC5Na9XSEf4HC7mj3W3g6jvSY/s=
1253-
github.com/ucwong/golang-kv v1.0.24-0.20240516111454-2b75a20c4c6b h1:Npb+Ze6vYiegpPaeoBXcnqI+30BSgKAmcJUUeaJpbTs=
1254-
github.com/ucwong/golang-kv v1.0.24-0.20240516111454-2b75a20c4c6b/go.mod h1:imM8dDztRcIIowC8LX4yZktfXedsQd5vx12rvjLd5yA=
1252+
github.com/ucwong/golang-kv v1.0.24-0.20240526160259-ef630c06892e h1:/ZzdhL9NeC4ZQqSWNCVthxs/sh2L6mfOHWsT/Uaniyw=
1253+
github.com/ucwong/golang-kv v1.0.24-0.20240526160259-ef630c06892e/go.mod h1:UlksTP3dk+1JhhKwssAsgYxZJKxRdqHM3jzh6ZjQyzE=
12551254
github.com/ucwong/golang-set v1.8.1-0.20200419153428-d7b0b1ac2d43/go.mod h1:xu0FaiQFGbBcFZj2o7udZ5rbA8jRTsv47hkPoG5qQNM=
12561255
github.com/ucwong/goleveldb v1.0.3-0.20200508074755-578cba616f37/go.mod h1:dgJUTtDxq/ne6/JzZhHzF24OL/uqILz9IWk8HmT4V2g=
12571256
github.com/ucwong/goleveldb v1.0.3-0.20200618184106-f1c6bc3a428b/go.mod h1:7Sq6w7AfEZuB/a6mrlvHCSXCSkqojCMMrM3Ei12QAT0=
@@ -1564,7 +1563,6 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc
15641563
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15651564
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15661565
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1567-
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15681566
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15691567
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15701568
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

vendor/github.com/CortexFoundation/torrentfs/backend/caffe/t.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/CortexFoundation/torrentfs/backend/handler.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/README.md

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/check_in.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/dsn.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/integrations.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)