-
Notifications
You must be signed in to change notification settings - Fork 179
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
[Access] Fix slice iteration bug in TrieUpdate protobuf conversion #4593
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4593 +/- ##
==========================================
- Coverage 56.25% 54.53% -1.72%
==========================================
Files 653 915 +262
Lines 64699 85352 +20653
==========================================
+ Hits 36396 46550 +10154
- Misses 25362 35219 +9857
- Partials 2941 3583 +642
Flags with carried forward coverage won't be shown. Click here to find out more.
|
for i, path := range t.Paths { | ||
paths[i] = path[:] | ||
for i := range t.Paths { | ||
paths[i] = t.Paths[i][:] |
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.
The two methods seem similar, and later changes to t.Paths
seem to also impact paths
(because array element pointers are equal) : https://go.dev/play/p/HD8XhfcFJDa
Maybe I didn't get what the bug is in the first place.
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.
the original bug was that the slice (and thus pointer to the underlying array) were reused resulting in the grpc response including a bunch of copies of the last element.
I opted to not make a copy here since there are likely to be a large number of paths, and the underlying data structure should be immutable.
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.
By updating slices to arrays, the issue and solution could be reproduced. Thank you!
https://go.dev/play/p/VMUv-aWUf8O
There was a bug in the logic that converts
ledger.TrieUpdate
objects to their protobuf form. The iteration did not properly handle memory reuse by the for loop, resulting the the output containing copies of the last element only.This PR updates this logic to use the correct element, and improves tests to cover this case.
The previous tests only use a single path in the
TrieUpdate
, so this case was never exercised.