Skip to content
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

light: fix txpool causes panic on reorgOnNewHead #54

Merged
merged 6 commits into from
Mar 13, 2020

Conversation

meowsbits
Copy link
Contributor

Fixes #53

panic: runtime error: invalid memory address or nil pointer dereference
Mar 04 12:22:51 sf-etclabs sh[26575]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x1c0 pc=0xc5937c]
Mar 04 12:22:51 sf-etclabs sh[26575]: goroutine 57 [running]:
Mar 04 12:22:51 sf-etclabs sh[26575]: github.com/ethereum/go-ethereum/light.(*TxPool).reorgOnNewHead(0xc00038cc60, 0x11a2960, 0xc0204bd920, 0xc0209ec480,
0xc0204bd920, 0xc02096eb00, 0x8)
Mar 04 12:22:51 sf-etclabs sh[26575]:         /root/go/src/github.com/ethereum/go-ethereum/light/txpool.go:230 +0x23c
Mar 04 12:22:51 sf-etclabs sh[26575]: github.com/ethereum/go-ethereum/light.(*TxPool).setNewHead(0xc00038cc60, 0xc0209ec480)
Mar 04 12:22:51 sf-etclabs sh[26575]:         /root/go/src/github.com/ethereum/go-ethereum/light/txpool.go:311 +0x13a
Mar 04 12:22:51 sf-etclabs sh[26575]: github.com/ethereum/go-ethereum/light.(*TxPool).eventLoop(0xc00038cc60)
Mar 04 12:22:51 sf-etclabs sh[26575]:         /root/go/src/github.com/ethereum/go-ethereum/light/txpool.go:292 +0x53
Mar 04 12:22:51 sf-etclabs sh[26575]: created by github.com/ethereum/go-ethereum/light.NewTxPool
Mar 04 12:22:51 sf-etclabs sh[26575]:         /root/go/src/github.com/ethereum/go-ethereum/light/txpool.go:109 +0x3eb

Signed-off-by: meows b5c6@protonmail.com

panic: runtime error: invalid memory address or nil pointer dereference
Mar 04 12:22:51 sf-etclabs sh[26575]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x1c0 pc=0xc5937c]
Mar 04 12:22:51 sf-etclabs sh[26575]: goroutine 57 [running]:
Mar 04 12:22:51 sf-etclabs sh[26575]: github.com/ethereum/go-ethereum/light.(*TxPool).reorgOnNewHead(0xc00038cc60, 0x11a2960, 0xc0204bd920, 0xc0209ec480,
0xc0204bd920, 0xc02096eb00, 0x8)
Mar 04 12:22:51 sf-etclabs sh[26575]:         /root/go/src/github.com/ethereum/go-ethereum/light/txpool.go:230 +0x23c
Mar 04 12:22:51 sf-etclabs sh[26575]: github.com/ethereum/go-ethereum/light.(*TxPool).setNewHead(0xc00038cc60, 0xc0209ec480)
Mar 04 12:22:51 sf-etclabs sh[26575]:         /root/go/src/github.com/ethereum/go-ethereum/light/txpool.go:311 +0x13a
Mar 04 12:22:51 sf-etclabs sh[26575]: github.com/ethereum/go-ethereum/light.(*TxPool).eventLoop(0xc00038cc60)
Mar 04 12:22:51 sf-etclabs sh[26575]:         /root/go/src/github.com/ethereum/go-ethereum/light/txpool.go:292 +0x53
Mar 04 12:22:51 sf-etclabs sh[26575]: created by github.com/ethereum/go-ethereum/light.NewTxPool
Mar 04 12:22:51 sf-etclabs sh[26575]:         /root/go/src/github.com/ethereum/go-ethereum/light/txpool.go:109 +0x3eb

Signed-off-by: meows <b5c6@protonmail.com>
@meowsbits
Copy link
Contributor Author

@tzdybal If and when LGTY, we can merge it and then I'll also make the corresponding PR at ethereum/go-ethereum.

@meowsbits
Copy link
Contributor Author

beep @tzdybal

Copy link
Contributor

@tzdybal tzdybal left a comment

Choose a reason for hiding this comment

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

Is it possible to easily reproduce the issue in the test?

light/txpool.go Outdated
for _, hash := range oldHashes {
pool.rollbackTxs(hash, txc)

if newHeader == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This statement doesn't make much sense, especially in here.
Above, we assign newHeader to newh, and operate on newh. If newHeader was indeed nil, this would fail (except degenerated case when both newh/newHeader and oldHeader are nil).

If it actually can happen, or we want to be extra defensive, move the check above line 229.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was assuming oldh was nil...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PTAL at changes thru 687e626.

Have added some test cases and simplified the checks.

The check for newHeader nilness should happen earlier,
somewhere up the Chain Insertion line.

Signed-off-by: meows <b5c6@protonmail.com>
In real life, I think the ValidateHeaderChain
check is sufficient, but tests use the InsertChain method
without the Validate_ method prior, so that's why
I think both these checks are needed.

Signed-off-by: meows <b5c6@protonmail.com>
Adds a few edge-cases tests in TestTxPool which test:
- non-nil txpool header-hash (by provenance) returns a nil value from chaindb
  This could be from a bad chaindb or an otherwise fucked pool head hash.

  + The otherwise fucked case is also tested.
- pool attempts to set head to a nil value

Signed-off-by: meows <b5c6@protonmail.com>
Signed-off-by: meows <b5c6@protonmail.com>
Signed-off-by: meows <b5c6@protonmail.com>
@meowsbits meowsbits requested a review from tzdybal March 12, 2020 17:36
@meowsbits meowsbits merged commit 7662eae into master Mar 13, 2020
@meowsbits meowsbits deleted the fix/light-txpool-reorg branch March 13, 2020 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic at les txpool reorg
2 participants