-
Notifications
You must be signed in to change notification settings - Fork 60
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: Use slices instead of maps #188
Conversation
return fmt.Errorf("block proof mismatch") | ||
} | ||
// preallocating polNodes helps with garbage collection | ||
polNodes := make([]polNode, len(trees)*3) |
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.
preallocating the polNodes before populating the pollard was the most significant improvement to gc pressure.
my assumption is that this helps because the polNodes are next to each other in memory so it's easier for the gc to do its job.
// the positions that are computed/not included in the proof. (also includes the targets) | ||
computedPositions := make([]uint64, 0, len(targets)*int(forestRows)) | ||
for row := uint8(0); row < forestRows; row++ { | ||
computedPositions = append(computedPositions, targets...) |
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 could be moved outside the loop right?
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.
oh nvm targets are mutated.
EDIT: No wait so all the targets are already allocated in the first go. All the ones afterwards just are duplicates.
Also seems like the computed positions are only used for pre-allocating in verifyBatchProof
in batchproof.go
so this could be moved outside the loop I think. Would also help in further lessening the gc pressure.
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.
I don't think it can. I think my naming here (targets
, nextTargets
) is a bit off so that might be why it seems wrong. On every iteration targets
holds the positions of the nodes on that row that are known, for row=0 it's the actual targets contained in the proof, on the rows above it's the the positions that can be computed. The nextTargets
variable is used to store the positions on the next row that can be computed and at the end of each iteration targets is assigned to nextTargets.
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.
Also seems like the computed positions are only used for pre-allocating in verifyBatchProof in batchproof.go so this could be moved outside the loop I think. Would also help in further lessening the gc pressure.
the computed positions are also needed in #185, but yeah in verifyBatchProof
they are unnecessary
// and has led to a number of bugs. It *is* special in a way, in that | ||
// the bottom row is the only thing you actually prove and add/delete, | ||
// but it'd be nice if it could all be treated uniformly. | ||
if len(bp.Proof) < 2 || len(targets) < 2 { |
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.
What would be a case where this clause is true?
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.
i added a comment there, let me know if that explains it.
rootMatches++ | ||
} | ||
} | ||
if len(rootCandidates) != rootMatches { |
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.
Since all roots should match in order for the batchProof to be valid, wouldn't it be better to return false in the block at line 232 if any root
doesn't match a rootCandidate
?
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.
rootCandidates
only holds a subset of the roots, so it could happen that a root does not match a candidate but by making sure that all candidates were matched to some root it still works out.
also added a comment there.
96cf573
to
06336b8
Compare
Is there any code that would cause backwards incompatibility with master? Right now, It's fine when I point the csn to my local bridgenode based off of this PR but crashes with this message when I point it at the current default server.
|
That's a great test. The roots should be exactly the same for every block. I think it errors because on master right now the 0-tree root is being send. utreexo/accumulator/forestproofs.go Lines 195 to 201 in 7f5d091
Edit: Actually the 0-tree roots are still being send. This is something else. |
was part of my experiments in #180.
Refactor
ProveBatch
,verifyBatchProof
andIngestBatchProof
to use slices.Preallocation of slices also helps with GC pressure.
also includes the
ProofPositions
function which is also part of #185, kinda stupid but otherwise this doesn't build.