You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
consensus: Better document ComputeMerkleRoot & add test for return value #28457
At least twice we've had attempts to refactor ComputeMerkleRoot (#22046 & #22046). While the value of any sort of refactor is dubious, it may also come with subtle, unintended side-effects, see review comment here:
The added break only saves time if we receive a mutated block with repeated transactions. So this change isn't relevant unless a peer send us a block they mutated on purpose, in which case they get disconnected for that. So it really shouldn't change anything in a non-adversarial scenario.
If we break early and don't compute the full merkle root anymore, the return value of BlockMerkleRoot() changes. As a result, code calling BlockMerkleRoot()
If we break early and don't compute the full merkle root anymore
I'm not sure that review is correct. The break only exits the loop that sets the mutation localvar to save on needless further iterations. There shouldn't be a change in behavior.
My understanding is that no code change is needed here, only documentation that detecting a mutation only sets the output flag, not the returned root (plus an explicit regression test for that invariant), see #35161.
Activity
jonatack commentedon Sep 12, 2023
I'm not sure that review is correct. The break only exits the loop that sets the
mutationlocalvar to save on needless further iterations. There shouldn't be a change in behavior.mzumsande commentedon Sep 12, 2023
@jonatack is right, I misread the code, and the PR doesn't change behavior. Might still be good to better document this code though.
fanquake commentedon Sep 12, 2023
Yea. I don't think we are going to make the suggested change in either case.
l0rinc commentedon Apr 26, 2026
My understanding is that no code change is needed here, only documentation that detecting a mutation only sets the output flag, not the returned root (plus an explicit regression test for that invariant), see #35161.
fanquake commentedon May 22, 2026
Any discussion can continue in #35161.
Merge #35161: consensus: document merkle mutation root invariant