Skip to content

core/txpool/legacypool: fix data race of txlookup access #31641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2025

Conversation

mirokuratczyk
Copy link
Contributor

The race detector flagged this in some automated tests I run against the simulated backend.

LegacyPool.Clear is only called by the simulated beacon chain so i'm not sure if this applies to anything other than the simulated backend. But other methods, like LegacyPool.SetGasTip, access pool.all while holding the pool lock, which could create a data race with LegacyPool.Add.

==================
WARNING: DATA RACE
Read at 0x00c004f8bf18 by goroutine 38690:
  github.com/ethereum/go-ethereum/core/txpool/legacypool.(*LegacyPool).Add()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/core/txpool/legacypool/legacypool.go:932 +0x12c
  github.com/ethereum/go-ethereum/core/txpool.(*TxPool).Add()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/core/txpool/txpool.go:428 +0x426
  github.com/ethereum/go-ethereum/eth.(*EthAPIBackend).SendTx()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/eth/api_backend.go:284 +0x144
  github.com/ethereum/go-ethereum/internal/ethapi.SubmitTransaction()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/internal/ethapi/api.go:1459 +0x1d0
  github.com/ethereum/go-ethereum/internal/ethapi.(*TransactionAPI).SendRawTransaction()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/internal/ethapi/api.go:1540 +0x115
  runtime.call128()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.2.linux-amd64/src/runtime/asm_amd64.s:778 +0x57
  reflect.Value.Call()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.2.linux-amd64/src/reflect/value.go:368 +0xb5
  github.com/ethereum/go-ethereum/rpc.(*callback).call()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/service.go:205 +0x488
  github.com/ethereum/go-ethereum/rpc.(*handler).runMethod()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:568 +0xab
  github.com/ethereum/go-ethereum/rpc.(*handler).handleCall()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:515 +0x369
  github.com/ethereum/go-ethereum/rpc.(*handler).handleCallMsg()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:473 +0x4a4
  github.com/ethereum/go-ethereum/rpc.(*handler).handleNonBatchCall()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:299 +0x311
  github.com/ethereum/go-ethereum/rpc.(*handler).handleMsg.func1.1()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:272 +0x44
  github.com/ethereum/go-ethereum/rpc.(*handler).startCallProc.func1()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:390 +0x19c

Previous write at 0x00c004f8bf18 by goroutine 38137:
  github.com/ethereum/go-ethereum/core/txpool/legacypool.(*LegacyPool).Clear()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/core/txpool/legacypool/legacypool.go:1888 +0x35a
  github.com/ethereum/go-ethereum/core/txpool.(*TxPool).Clear()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/core/txpool/txpool.go:572 +0x1af
  github.com/ethereum/go-ethereum/eth/catalyst.(*SimulatedBeacon).Rollback()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/eth/catalyst/simulated_beacon.go:315 +0xed5
  github.com/ethereum/go-ethereum/ethclient/simulated.(*Backend).Rollback()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/ethclient/simulated/backend.go:164 +0xe0b
  <calling code>

Goroutine 38690 (running) created at:
  github.com/ethereum/go-ethereum/rpc.(*handler).startCallProc()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:386 +0xe4
  github.com/ethereum/go-ethereum/rpc.(*handler).handleMsg.func1()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:271 +0xd5
  github.com/ethereum/go-ethereum/rpc.(*handler).handleResponses()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:442 +0x72b
  github.com/ethereum/go-ethereum/rpc.(*handler).handleMsg()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/handler.go:270 +0xb3
  github.com/ethereum/go-ethereum/rpc.(*Client).dispatch()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/client.go:651 +0x66e
  github.com/ethereum/go-ethereum/rpc.initClient.gowrap1()
      /home/runner/work/exchange/exchange/vendor/github.com/ethereum/go-ethereum/rpc/client.go:270 +0x4f

Goroutine 38137 (running) created at:
  <calling code>
  testing.tRunner()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.2.linux-amd64/src/testing/testing.go:1792 +0x225
  testing.(*T).Run.gowrap1()
      /home/runner/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.2.linux-amd64/src/testing/testing.go:1851 +0x44
==================

rjl493456442
rjl493456442 previously approved these changes Apr 17, 2025
Copy link
Member

@rjl493456442 rjl493456442 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rjl493456442 rjl493456442 changed the title core/txpool/legacypool: fix data race in Add core/txpool/legacypool: fix data race of txlookup access Apr 17, 2025
@rjl493456442 rjl493456442 added this to the 1.15.9 milestone Apr 17, 2025
@rjl493456442 rjl493456442 merged commit 8797497 into ethereum:master Apr 17, 2025
3 of 4 checks passed
@mirokuratczyk mirokuratczyk deleted the simulated_backend_fix branch April 17, 2025 13:01
sivaratrisrinivas pushed a commit to sivaratrisrinivas/go-ethereum that referenced this pull request Apr 21, 2025
0g-wh pushed a commit to 0glabs/0g-geth that referenced this pull request Apr 22, 2025
0g-wh pushed a commit to 0g-wh/0g-geth that referenced this pull request May 8, 2025
Rampex1 pushed a commit to streamingfast/go-ethereum that referenced this pull request May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants