-
Notifications
You must be signed in to change notification settings - Fork 36.4k
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
refactor: Improve GetWitnessCommitmentIndex #19640
Conversation
b4d3f99
to
3a25f18
Compare
3a25f18
to
f4d5c7c
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
for (size_t o = block.vtx[0]->vout.size(); o > 0;) { | ||
const CTxOut& vout = block.vtx[0]->vout[--o]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This 1-based to 0-based array indexing conversion within the body seems rather odd, why not simply 0-base it right from the start:
for (int o = block.vtx[0]->vout.size()-1; o >= 0; o--) {
const TxOut& vout = block.vtx[0]->vout[o];
Drawback is that the loop counter type has to be changed from size_t
(unsigned) to int
signed, but I don't see why that would be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, need to change to signed. I'm fine with both TBH. Let's see what others say.
Concept NACK. I say this in every PR of this type: I don't think it makes sense to change consensus code unless we have some good reason to do so. See also my recent comment here. |
@sdaftuar it's fine. Just curious if it was intended to pick last element. |
@sipa ☝️ can you explain? |
The bip says that the last element has to be picked |
GetWitnessCommitmentIndex
finds the last output index of coinbase transaction. Currently iterates all outputs. This change reverses iteration and so it only iterates all outputs at worst case.