GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
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
Implement MappedShuffle for tracking the permutation of an array
Implement static method for creating a randomized JSDescription
Randomize JoinSplits in z_sendmany
No find method? Apparently not. Sigh.
Not for json_spirit::Array, because it doesn't have begin() or end().
The comment at 2eeb6be#diff-63ec75bfb71c2d4e26f2a95d5168f5e5R504 is stale.
I can't follow that link to anywhere useful.
Line 504 (after the commit).
This can be inputs(info.vjsin); I think.
Not with boost::array AFAICT.
Huh, I thought I checked the docs.
template<typename U> array& operator=(const array<U, N>&);
That's from another array; info.vjsin is a std::vector<JSInput>.
OK, never mind then.
This can be arrInputMap(inputMap); instead of the loop, I think.
Not with json_spirit::Array AFAICT.
[Comment] Maybe some day we should add the standard iteration API to json_spirit::Array? I personally prefer shorter conventional idioms instead of repeated larger code blocks.
ut(ACK+cov) modulo the stale comment at 2eeb6be#diff-63ec75bfb71c2d4e26f2a95d5168f5e5R504 . Addressing other comments is optional. Note that I wrote the first two commits with @str4d, so another ACK is needed.
Refactor test code to better test JSDescription::Randomized()
Remove stale comment
@daira comments addressed.
ut(ACK+cov). Still needs another ACK.
This looks good to me, cannot review it extensively enough to ACK though.
) should be ] ?
No, the end of the range is exclusive.
Hmm, ok, maybe it's a C++ thing to use interval notation in documentation. I can't recall seeing this style for other languages.
function gen could return a value which is out of bounds for the iterator.
The definition of gen is that it returns a value in [0,n); I will add assertions that this is the case.
This should never return -1 right? Since we always have two output notes?
It should never return -1 because outputmap is always length 2 and contains 1. If we want to have a stronger assertion, I can add it.
[Comment] I would like an assertion here so that with minimal effort a new reader doesn't have to know those "remote invariants", eg: always length 2. (Does not block.)
We could raise std::logic_error instead of returning -1; that would avoid the risk of an out-of-bounds access if the -1 were used.
Ditto above, this should never be -1 right?
The len parameter can be removed. Both iterators should span the same distance, so you can compute the len value in the body of the function with something like size_t len = std::distance(first.begin(), first.end()). Could use an assert to ensure both iterators are of the same len,
size_t len = std::distance(first.begin(), first.end())
Or just last-first, which is what the equivalence code in std::shuffle uses. But that means we have to pass in both begin() and end() for both collections (which is why @daira and I opted at the time for len). If you prefer that style, I can change it.
I think this is clearer as it is.
I don't mind.
Assert that inputs and inputMap are the same length? And see comment below about not needing the ZC_NUM_JS_INPUTS parameter.
You can already locally see that they must be the same length, from the declarations, so I don't think that an assertion adds anything.
Why is this changing? Thanks.
Because otherwise g++ complains that params is defined twice.
First review pass complete and ran tests. Will review a second time after feedback on comments.
ACK code review.
Not-yet-ACK'd test coverage.
[comment] I'm curious why we don't use std::shuffle if we're reimplementing the same algorithm. If we std::shuffle a list of pairs of (i, x) where i is the original index, could we achieve the same result while reusing std? (I can't tell if that'd be nicer or worse for ergonomics, yet.)
@bitcartel originally used that approach, but the specification of std::shuffle and URNG are not strong enough to guarantee determinism (needed for first and firstMap to be permuted in the same way), use of a secure RNG, and a uniform distribution over permutations.
I think you mean @str4d ?
Add more assertions, throw if find_output params are invalid
Pending concerns addressed.
ACK (have not checked code coverage)
ACK aa36398. I'm happy with coverage, so @zkbot r+
📌 Commit aa36398 has been approved by daira
Auto merge of #1561 - str4d:778-randomise-note-order, r=daira
Randomize JoinSplit input and output orders
⌛️ Testing commit aa36398 with merge 0dfe612...
☀️ Test successful - zcash
@Zenitur What version of g++ are you using? What's your OS environment?
@bitcartel, Debian Linux 7.0 Wheezy, x86_64 arch
I have been copied binaries compiled with GCC 4.9.2 from another PC. Now I just tell you about an error in code
After applying #838 (comment) there is no compiling errors anymore