Skip to content

Conversation

@NicolasDorier
Copy link
Contributor

@NicolasDorier NicolasDorier commented Sep 5, 2016

if pindexPrev was null, we would get a problem at pindexPrev->GetMedianTimePast()

@dcousens
Copy link
Contributor

dcousens commented Sep 5, 2016

utACK 8a87470

Submitted a PR for your PR, see NicolasDorier#1

@luke-jr
Copy link
Member

luke-jr commented Sep 5, 2016

This means we're not enforcing it on the genesis block? Doesn't look like a practical problem today, but feels like a booby-trap. :/

@NicolasDorier
Copy link
Contributor Author

@NicolasDorier NicolasDorier changed the title Trivial: ContextualCheckBlockHeader should never have pindexPrev equals to NULL Trivial: Assert all the things! Sep 9, 2016
@NicolasDorier
Copy link
Contributor Author

Added one more assert which make review more easy. This one bit me quite a few time, as pIndex sometimes refers to the block being evaluated, and sometimes to the previous one.

@dcousens
Copy link
Contributor

dcousens commented Sep 9, 2016

utACK 34a37ba

@NicolasDorier
Copy link
Contributor Author

NicolasDorier commented Sep 9, 2016

mmh failure with last commit, investigating it. Interesting.

@NicolasDorier
Copy link
Contributor Author

NicolasDorier commented Sep 9, 2016

yuk, the problem was that pindex->phashBlock == NULL is used as a flag to know if it is called by CreateNewBlock...

@morcos
Copy link
Contributor

morcos commented Sep 12, 2016

I don't think we should tag PR's like this with "Trivial"
Perhaps I'm misremembering, but I thought "Trivial" was for things that only changed comments or strings that couldn't possibly change behavior. This PR takes at least a little bit of thinking about.

I don't have much of an opinion on the actual changes.

@sipa
Copy link
Member

sipa commented Sep 12, 2016 via email

src/pow.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

This case (Genesis block) is never actually necessary?

Copy link
Contributor

@dcousens dcousens Sep 13, 2016

Choose a reason for hiding this comment

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

GetNextWorkRequired is never called with pindexLast == NULL (as written, not as tested, aka, per the code base)

@NicolasDorier
Copy link
Contributor Author

NicolasDorier commented Sep 13, 2016

Actually I thought that we were in the "this so obviously does not change behaviour that it does not need review" condition, until I saw that phashBlock could be NULL...

If it is not obvious then maybe this PR is not worth the review time, I can remove some commits if needed to make it trivial again.

But on the other side, I added assert to make non trivial things more visible...

@dcousens
Copy link
Contributor

dcousens commented Sep 13, 2016

I think the PR is still worth it for the simple fact it adds more information/context to the code.
However, perhaps as discussed on IRC, it might be better to just remove the assertions and de-reference the pointers at the call sites by using a C++ reference.

@laanwj
Copy link
Member

laanwj commented Sep 13, 2016

If it is not obvious then maybe this PR is not worth the review time, I can remove some commits if needed to make it trivial again.

I think these changes are okay, let's just not call it trivial. As @morcos says the trivial denomination is for puls that don't change code, e.g. documentation typos, string typos, comment changes. Asserts generate code and can in principle create bad situations like DoS attacks if they're remote-triggerable so need to be carefully reviewed.
(which doesn't mean that changes to assertions aren't worth review time)

@NicolasDorier NicolasDorier changed the title Trivial: Assert all the things! Assert all the things! Sep 14, 2016
@maflcko
Copy link
Member

maflcko commented Sep 30, 2016

utACK dc64a16af92bf459dde32c32cea11b266db54f04

@maflcko
Copy link
Member

maflcko commented Dec 4, 2016

Needs rebase.

@NicolasDorier
Copy link
Contributor Author

rebased

Copy link
Contributor

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

utACK 61b84a0142cd736a2b819b771fc843703ab8ae65 (+/- comment on comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

(or, generally, by TestBlockValidity)

@NicolasDorier
Copy link
Contributor Author

addressed TheBlueMatt comment

@NicolasDorier
Copy link
Contributor Author

Anything missing ?

@NicolasDorier
Copy link
Contributor Author

not sure what to do with this PR. I think it increases readability... but it has been open since september. Do I keep open ?

@laanwj
Copy link
Member

laanwj commented Mar 14, 2017

Yeah let's merge it. Asserting out is better than crashing with a NULL pointer dereference.

@laanwj laanwj merged commit 4d51e9b into bitcoin:master Mar 14, 2017
laanwj added a commit that referenced this pull request Mar 14, 2017
4d51e9b Assert ConnectBlock block and pIndex are the same block (NicolasDorier)
972714c pow: GetNextWorkRequired never called with NULL pindexLast (Daniel Cousens)
cc44c8f ContextualCheckBlockHeader should never have pindexPrev to NULL (NicolasDorier)

Tree-SHA512: 7cc568bf9417267c335f21ec3d1505b26e56e5b3d5f4d3dbb555279489800aaa65a3bcd7bc376e274dd102912aec16ddbb18de2e2060b2667b41eb979cd9321e
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 26, 2019
4d51e9b Assert ConnectBlock block and pIndex are the same block (NicolasDorier)
972714c pow: GetNextWorkRequired never called with NULL pindexLast (Daniel Cousens)
cc44c8f ContextualCheckBlockHeader should never have pindexPrev to NULL (NicolasDorier)

Tree-SHA512: 7cc568bf9417267c335f21ec3d1505b26e56e5b3d5f4d3dbb555279489800aaa65a3bcd7bc376e274dd102912aec16ddbb18de2e2060b2667b41eb979cd9321e
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants