[Fix] Use array for handshake commit hashes #4006
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to address the test failures seen in [this run](https://app.circleci.com/pipelines/github/ProvableHQ/snarkOS/2998/workflows/68fb3599-4c04-49b3-810f-2f35b013ff61/jobs/58981.
I believe this error occurs because in the current implementation any string that starts with a
?is considered invalid/unknown, whereas with this change there is exactly one sequence that corresponds to unknown.So it might encode
"?\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", but decoding it will returnunknown.Changes
The PR changes the SHA to always be encoded as a 40-byte array. There was code that converted it from a string, without checking the length, which was error-prone.
Additionally, it relied on a hardcoded
"unknown"string, which is now replaced by a constantUNKNOWN_SHA.An alternative fix would have been to change the protest to not generate a string containing
?, but, in the long-term, it is safer to also ensure we always send exactly 40 bytes.Reproducibility
I was able to reproduce this on
stagingby runningPROPTEST_SEED=e472a2f4ccb7abe5a6f77dc67ab294386b82e205ea3a889c7707fa15328545c3 cargo test --package snarkos-node-bft-events helpers::codec::tests::event_roundtripwhich generates the error below: