Skip to content
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

Aggregator single signatures buffer #1934

Merged
merged 43 commits into from
Sep 19, 2024

Conversation

Alenar
Copy link
Collaborator

@Alenar Alenar commented Sep 13, 2024

Content

This PR introduce a buffer mechanism in aggregator to make it able to store signatures that come from signers that are ahead of it, making easier to have signers that handle their signing rhythm themself are they won't need to rely on the aggregator certificate pending to issue single signatures.

When a aggregator receive a single signature it will now:

  1. Try to register it as before.
  2. If registration failed because an open message isn't open for the associated signed entity:
    a. Check the signature against its embedded signed message and the current stake distribution.
    b. If check fail check it using next epoch stake distribution (as the signer can already be at the next epoch when crossing epoch boundary).
    c. If any of the two previous succeed store the signature in a store, a new table in our main sqlite file, alongside it's associated signed entity discriminant.

When a aggregator create a new open message it will now:

  1. Check if for the new open message signed entity discriminant there's buffered signatures.
  2. Try to register immediately the buffered signatures.
  3. If a registration fails because of an invalid signature, skip it and continue to register the signatures (as there's an high chance that the failure is due to the signature being for another message with the same discriminant).
  4. Delete successfully registered buffered signatures from the buffer store.

Pre-submit checklist

  • Branch
    • Tests are provided (if possible)
    • Crates versions are updated (if relevant)
    • CHANGELOG file is updated (if relevant)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
  • PR
    • No clippy warnings in the CI
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested
  • Documentation
    • Update README file (if relevant)
    • Update documentation website (if relevant)
    • Add dev blog post (if relevant)

Comments

Issue(s)

Closes #1900

Copy link

github-actions bot commented Sep 13, 2024

Test Results

    4 files  ± 0     54 suites  +1   9m 39s ⏱️ -56s
1 290 tests +29  1 290 ✅ +29  0 💤 ±0  0 ❌ ±0 
1 501 runs  +29  1 501 ✅ +29  0 💤 ±0  0 ❌ ±0 

Results for commit 5b578c7. ± Comparison against base commit 62dbe88.

This pull request removes 16 and adds 45 tests. Note that renamed tests count towards both.
mithril-aggregator ‑ http_server::routes::signatures_routes::tests::test_register_signatures_post_ok
mithril-aggregator ‑ services::certifier::tests::should_clean_epoch_when_inform_epoch
mithril-aggregator ‑ services::certifier::tests::should_create_certificate_when_multi_signature_produced
mithril-aggregator ‑ services::certifier::tests::should_mark_open_message_expired_when_exists
mithril-aggregator ‑ services::certifier::tests::should_not_create_certificate_for_open_message_already_certified
mithril-aggregator ‑ services::certifier::tests::should_not_create_certificate_for_open_message_not_created
mithril-aggregator ‑ services::certifier::tests::should_not_create_certificate_when_no_multi_signature_produced
mithril-aggregator ‑ services::certifier::tests::should_not_mark_open_message_expired_when_does_not_expire
mithril-aggregator ‑ services::certifier::tests::should_not_mark_open_message_expired_when_has_not_expired_yet
mithril-aggregator ‑ services::certifier::tests::should_not_register_invalid_single_signature
…
mithril-aggregator ‑ database::query::buffered_single_signature::delete_buffered_single_signature::tests::test_delete_buffered_single_signature_records_by_discriminant_and_party_ids
mithril-aggregator ‑ database::query::buffered_single_signature::get_buffered_single_signature::tests::test_get_all
mithril-aggregator ‑ database::query::buffered_single_signature::get_buffered_single_signature::tests::test_get_buffered_single_signature_records_by_discriminant
mithril-aggregator ‑ database::query::buffered_single_signature::insert_or_replace_buffered_single_signature::tests::allow_to_insert_record_with_different_party_id_and_discriminant_but_different_signature
mithril-aggregator ‑ database::query::buffered_single_signature::insert_or_replace_buffered_single_signature::tests::insert_records_in_empty_db
mithril-aggregator ‑ database::query::buffered_single_signature::insert_or_replace_buffered_single_signature::tests::inserting_record_with_same_party_id_and_discriminant_replace_previous_record
mithril-aggregator ‑ database::query::buffered_single_signature::insert_or_replace_buffered_single_signature::tests::inserting_same_record_twice_should_replace_first_insert
mithril-aggregator ‑ database::record::buffered_single_signature_record::tests::building_fake_generate_different_protocol_single_signature
mithril-aggregator ‑ database::record::buffered_single_signature_record::tests::test_convert_single_signatures
mithril-aggregator ‑ database::repository::buffered_single_signature_repository::tests::remove_buffered_signatures
…

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@sfauvel sfauvel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -146,12 +147,45 @@ mod tests {
.unwrap();
}

#[tokio::test]
async fn test_register_signatures_post_ok_202() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's a good thing to speak about code 202 in test name when we don't see it in the test even if It seems normal that it is like this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's implicit since in the code and test we use enum variant with the explicit name of the http code.

Until now this is how we have named those tests has it has the benefit of clarity as long as you have some knowledge of the http code numbers. A requirement that can be though as reasonable since this whole part is an http api.

openapi.yaml Outdated Show resolved Hide resolved
mithril-aggregator/src/multi_signer.rs Outdated Show resolved Hide resolved
mithril-aggregator/src/services/certifier/interface.rs Outdated Show resolved Hide resolved
Comment on lines +396 to +422
// Todo: Refactor this code to avoid code duplication by making the signable_builder_service
// able to retrieve the next avk by itself.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should open an issue to plan that refactor

Copy link
Member

@jpraynaud jpraynaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good 👍

I'm a bit worried that signature entities without message will not be buffered.
I also left few comments and questions.

@Alenar Alenar force-pushed the ensemble/1900/aggregator_signatures_buffer branch 2 times, most recently from 335512b to b308cc1 Compare September 18, 2024 15:42
By computing the Signed Entity Type and the protocol message without
having to get the current open message.

Required to be able to buffer incoming single signatures as an
open message is not yet opened.
Since a certifier decorator will be added, this will avoid stacking too
much files or too much the certifier file.
- `interface`: contains the trait & error definition
- `certifier_service`: the implementation
…ssage

For the message type, the buffered signatures will be removed from the
buffer.
If check using the current one fails, as a signer may detect epoch
change before the aggregator and issue single signatures.
This allow caller to know if the signature was registered for immediate
use or buffered.
In order to remove the InMemory store.

Doing so required to be more precise with the tests signatures used. IE
most"register_signature" tests needs a single signature that have a
signed message but when reading them from the store the store doesn't
keep the signed message leading to problems with some assert_eq.
It will be used to know if a single signature can be buffered or not.
Instead of validating their `signed_message` as this will be handled by
another component beforehand.
For retrocompatibility with previously stored signatures (with open
messages in aggregator).
…ed_message is unauthenticated

As there's no value to send it to the certifier since it will reject it
anyway.
As we won't be able to always set this value (ie: with the upcoming p2p
registration).

In order to do so an refactor have to be done in `mithril-signer` so the
`RegisterSignatureMessage::signed_message` property can be set.
And the trait method from `message_string` to `to_message`.
* Simpify some code docs.
* Enhance `delete_buffered_single_signature` tests
* Make some naming more clear
@Alenar Alenar force-pushed the ensemble/1900/aggregator_signatures_buffer branch from b308cc1 to ad4d1db Compare September 19, 2024 08:56
Copy link
Member

@jpraynaud jpraynaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

I left minor comments below.

* Mithril-aggregator from `0.5.63` to `0.5.64`
* Mithril-signer from `0.2.183` to `0.2.184`
* Mithril-common from `0.4.51` to `0.4.52`
* OpenApi from `0.1.29` to `0.1.30`
@Alenar Alenar merged commit 27fdfa0 into main Sep 19, 2024
39 of 40 checks passed
@Alenar Alenar deleted the ensemble/1900/aggregator_signatures_buffer branch September 19, 2024 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aggregator buffers signatures for unknown open message
4 participants