coordinator/tributary tests#783
Conversation
…, avoid overflow panic
This reverts commit 4a1cf91.
|
FYI, some of the above CI failures are because they're misconfigured. For anything With this PR,
I don't assume this PR is final, so no worries on the failures, I just wanted to clarify which lights are expected to be red and which lights should be green. If any CIs are being a problem, feel free to poke me :) For new crates, there's some basic definitions which have to be added for it to work as expected, and now, even for updates to/new dependencies, |
|
That's disgusting re: Defensive assertions are good. I have a note the processor really should be flush with them. I have yet to review the PR itself, these are just a pair of comments on the summary :) |
…cends from This reverts a myriad of `cargo update`s.
A `u32`, when incremented by one, is technically feasible to overflow. This PR changed it to return `None` for the next topic if it did overflow, but that'd technically stop creating topics for ongoing protocols. This transformed a panic (which would crash the entire `coordinator`) into a liveness failure for this specific Tributary due to inaccurately claiming there was no next topic (an unsound definition which would become a more localized liveness issue). This uses a `u64` to ensure this state is unreachable when started from zero, and incremented by one, unless so many years pass this is definitively irrelevant.
Only pushing some elements meant that this vector no longer corresponded to the list of validators. Since each element wasn't paired with a validator's ID, it became meaningless. The `assert` which triggered was the underlying fault, and it's been adjusted to only check the amount of non-zero elements is now less than or equal to `f`.
While it currently _can_ be collapsed to the function `required_participation`, the ability for per-topic thresholds is desired. The calculation is also updated to be infallible.
Moving to `SigningProtocolRound` would be nice if all such transactions fit that model. As shown, not all transactions do. Kludging them into `SigningProtocolRound` isn't preferred, and it appears to have been improperly done for `SigningProtocolRound` (causing a `clippy` lint which was allowed).
Some are made more flexible, removing the need for other approximate variants. Test helpers which encoded a non-syntactic semantic context via their name have been removed outright, especially as `substrate/primitives` shouldn't have helpers for Coordinator-specific definitions which may not be universal or applicable to the Substrate context. Similarly, these should likely be moved to `tests/helpers` where we have more flexibility. We want to publish `substrate/primitives` but I couldn't care less about the idea of publishing these test helpers and committing to them under our API in any way. While the `Cargo.toml` already has a comment on the `test-helpers` feature, their own crate entirely avoid any contamination here.
…s` type aliases I understand the intent. Unfortunately, these definitions were incorrect. For a FROST protocol over Ristretto, the preprocess will be 64 bytes and the share 32 bytes. This is used for the DKG confirmation, batches, where the former hard-coded such a definition. For batches, the process is routed via `VariantSignId` where the same processing occurs for transactions. Signing transactions on external networks has a preprocess, share, of length variable to the external network and its signing protocol. For Ethereum, it'd be a 66-byte preprocess and 32-byte share. For Bitcoin, it's a 64-byte preprocess and 32-byte share _per input_ (concatenated into a single byte blob). For Monero, it's a 160-byte preprocess and 32-byte share _per input_ (again so concatenated).
The tests in `coordinator/tributary/src/tests/scan_tributary.rs` demonstrated creating a tributary with one `NewSetInformation`, before reading from it with another, which should be obviously invalid? `NewSetInformation::genesis` has been added to make the genesis deterministic and binding to the `NewSetInformation`, allowing the `ScanTributaryTask` to check its initialized with values consistent to how the Tributary itself was initialized. This updates the cited tests accordingly.
One has an unclear story. Others have a pattern of checking a single message (less than the threshold) causes no events, but doesn't check all messages less than the threshold cause no events.
coordinator/tributary/src/tests/transaction.rs1) [bug] Identified in
impl ReadWrite for Transaction:Replaced the usage of:
for:
And added the tests
sequential_reads_from_shared_readerandborsh_from_reader_rejects_shared_reader_with_trailing_bytesto verify the behavior, as using the previous method would fail on the scenario of multiple transactions on reader.coordinator/tributary/src/tests/db.rs1) [feat] Added an assertion for the commented case:
Here:
Not entirely necessary just defensive.
2) [bug] Bad usage of ::get(): replaced by ::key()
Found a bug which, given the nature of the accumulate function using a Generic type D for the data, when an Accumulate entry is added for a Preprocess ([u8; 64]) type, later a type of Share ([u8; 32]) would panic with a "Not all bytes read" error trying to deserialize the DB entry for the preceding topic's type. This is fixed by not trying to
gettheAccumulatedentry with D as a type to deserialize, but rather getting its preceding topickeyand usingtxn.get()instead.From:
To:
3) [bug] attempt * BASE_REATTEMPT_DELAY overflow:
From:
To:
Before, a too high attempt * BASE_REATTEMPT_DELAY could overflow the u32::max, now convert each value to u64 first, before doing the operation which avoids the u32 overflow.
coordinator/tributary/src/tests/lib.rs1) [bug] panic on slash_report's added with a value of 0
By not filtering the 0 points reports,
slash_reportpanics when expected to be less or equal thanfThe fix is: