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

les: fix light fetcher database race #16103

Merged
merged 2 commits into from
Feb 19, 2018
Merged

Conversation

zsfelfoldi
Copy link
Contributor

This PR fixes #16101 by avoiding a potential chain db data race that can cause checkAnnouncedHeaders being called with a nil header. There is also another check for missing parent of validated header (with an error log message) which in theory should not happen but still it would be nice to know about if it happens anyway in some weird corner case.

@holiman
Copy link
Contributor

holiman commented Feb 16, 2018

On mobile, so maybe I missed something, but it looks wrong. You check if header is nil... And then use header.Number in the error message. That'll blow up.

les/fetcher.go Outdated
@@ -562,6 +562,10 @@ func (f *lightFetcher) checkAnnouncedHeaders(fp *fetcherPeerInfo, headers []*typ
// we ran out of recently delivered headers but have not reached a node known by this peer yet, continue matching
td = f.chain.GetTd(header.ParentHash, header.Number.Uint64()-1)
header = f.chain.GetHeader(header.ParentHash, header.Number.Uint64()-1)
if header == nil || td == nil {
log.Error("Missing parent of validated header", "hash", header.ParentHash, "number", header.Number.Uint64()-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will cause error if header is indeed 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.

Right, this one was a really stupid mistake.

les/fetcher.go Outdated
@@ -46,7 +46,7 @@ type lightFetcher struct {
peers map[*peer]*fetcherPeerInfo
lastUpdateStats *updateStatsEntry

lock sync.Mutex // qwerqwerqwe
lock sync.Mutex
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you replace qwerqwerqwe with some documentation about specifically what asset this lock protects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM

@karalabe karalabe added this to the 1.8.1 milestone Feb 19, 2018
@karalabe karalabe merged commit 1bdde62 into ethereum:master Feb 19, 2018
Copy link

@bryanicer bryanicer left a comment

Choose a reason for hiding this comment

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

good

prestonvanloon pushed a commit to prestonvanloon/go-ethereum that referenced this pull request Apr 2, 2018
* les: fix light fetcher database race

* les: lightFetcher comments
mariameda pushed a commit to NiluPlatform/go-nilu that referenced this pull request Aug 23, 2018
* les: fix light fetcher database race

* les: lightFetcher comments
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.

panic: runtime error: invalid memory address or nil pointer dereference
4 participants