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

Block Number beacon in cardano transaction #1727

Merged
merged 31 commits into from
Jun 5, 2024

Conversation

Alenar
Copy link
Collaborator

@Alenar Alenar commented Jun 4, 2024

Content

This PR changes the beacon used for the CardanoTransactions signed entity type:

  • before: a CardanoDbBeacon (aka: network, epoch, immutable file number)
  • now: Epoch and block number tuple.

This changes decouples the production of cardano transactions signatures and proofs from the immutable file number and the cardano node database structure. Allowing us to go closer to the tip of the chain since, with a adapted block streamer, we won't have to wait for a immutable to be complete update our stored transactions.

In depth

  • Add a new parameter to the aggregator to configure the pacing at which the chain should be parsed: cardano_transactions_signing_config.
  • Update related type:
    • CardanoTransactionsSnapshot artifact: replace beacon with block_number (note: the epoch can still be fetched if it's wrapped by a SignedEntity<T> and is added to the related messages).
    • In ProtocolMessage and CardanoTransactionsProofsMessage: rename latest_immutable_file_number to latest_block_number.
  • Update services:
    • BlockScanner trait: use a Option<ChainPoint> for its lower bound and a BlockNumber for the upper bound. Previously it used a ImmutableFileNumber for both.
    • CardanoBlockScanner: ignore the bounds given as parameter and compute them itself (lower bound from db and upper bound take all completed immutables) since it still works using immutables files and there's no way go get the immutable file that contains a given block from the chain.
    • Updated the signable builder for cardano transactions, and the TransactionsImporter and BlockRangeRootRetriever traits, to use a BlockNumber instead of a ImmutableFileNumber.
  • Cleanup all certificate and signed entities based on CardanoTransactions from Aggregator database since their beacons changed.
  • Explorer: Updated to support the new beacon + use dynamic display for certificate signed_entity instead of relying on the deprecated beacon property.

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

This would have been considered a network breaking change on a stable signed entity type.

Issue(s)

Closes #1697

Alenar and others added 25 commits June 4, 2024 12:04
Adapt only code where other types don't need to be modified as well.
Making this change also result in updating `TransactionsImporter` and
`BlockRangeRootRetriever` traits methods to use a chain point.

Only `mithril-persistence` is adapted to this changes in this commit.
…ockNumber`

Plus add it to the openapi as it was missing.
Before it was using an ImmutableFileNumber for both bounds
As we can't retrieve the immutable file number associated to a block
number if it's not stored in the database (which will be typically the
case of the upper bound).
Ignoring the lower bound given has parameter.

We ignore it since it's a block number and not a immutable file number
and retrieving the later using the former is difficult since there's no
available function to do that in the cardano api.
…onRepository

As it will be needed from now on to compute the lower bound passed to
the BlockScanner.
With this change the lower bound of the scanner is now based on block
number instead of immutable file number.
* Give the LowerBoundFinder needed by the block scanner
* Remove the transaction 'store' build since it's already provided by the
  transaction 'repository' build
…hainPoint

Note: not compiling, we still need to update the
`CardanoTransactionsSnapshot`.
Leaving only one required to compute the immutable block scanner lower
bound.
Instead of `Epoch,ChainPoint`.

This is because we use this value as the upper bound of the blocks to
import and can't known easily the associated block hash and slot number
needed to constitute a ChainPoint (and we only need them for the lower
bound to allow Pallas to known the starting point).
This force to make the same change to the `TransactionImporter`,
`TransactionRetriever`,`BlockScanner` and the
`CardanoTransactionSnapshot`.

When a lower bound was required this is when we use a
`ChainPoint`(instead of a block number as before). To do this we added a
new condition to the `GetCardanoTransactionQuery` that get the
transactions with the highest block number in db (all transaction with a
same block number also share their slot number and block hash).

Co-authored-by: Sébastien Fauvel <[email protected]>
Co-authored-by: Damien Lachaume <[email protected]>
Since the importer doesn't know anymore about immutable file numbers and
the current block scanner role is precisely to fetch them for its
`ImmutableBlockStreamer`.

Co-authored-by: Sébastien Fauvel <[email protected]>
Co-authored-by: Damien Lachaume <[email protected]>
To compute the block number to be signed based on the chain tip.

Co-authored-by: Sébastien Fauvel <[email protected]>
Co-authored-by: Damien Lachaume <[email protected]>
And pass them where needed to deduce a signed entity type from a time
point.

Also define a default configuration with:
* `security_parameter`: 3000
* `step`: 90

End to end use more lax paramters (security param: 20, step: 15) since
it's far faster and the last transactions we see included have a block
number not that high (arround ~450).
…ransaction

Co-authored-by: Sébastien Fauvel <[email protected]>
Co-authored-by: Damien Lachaume <[email protected]>
Copy link

github-actions bot commented Jun 4, 2024

Test Results

    3 files  ±0     43 suites  ±0   8m 34s ⏱️ ±0s
1 012 tests +9  1 012 ✅ +9  0 💤 ±0  0 ❌ ±0 
1 110 runs  +9  1 110 ✅ +9  0 💤 ±0  0 ❌ ±0 

Results for commit 70a8a61. ± Comparison against base commit 3b542fd.

This pull request removes 7 and adds 16 tests. Note that renamed tests count towards both.
mithril-aggregator ‑ http_server::routes::proof_routes::tests::build_response_message_return_immutable_file_number_from_artifact_beacon
mithril-aggregator ‑ services::cardano_transactions_importer::tests::change_parsed_lower_bound_when_rescan_limit_is_set
mithril-common ‑ cardano_block_scanner::block_scanner::tests::test_parse_from_lower_bound_until_upper_bound
mithril-common ‑ cardano_block_scanner::block_scanner::tests::test_parse_up_to_given_beacon
mithril-persistence ‑ database::repository::cardano_transaction_repository::tests::get_transactions_up_to_return_empty_list_when_no_record_found_with_provided_immutable_file_number
mithril-persistence ‑ database::repository::cardano_transaction_repository::tests::repository_get_up_to_beacon_transactions
mithril-signer ‑ cardano_transactions_importer::tests::change_parsed_lower_bound_when_rescan_limit_is_set
mithril-aggregator ‑ configuration::test::can_build_config_with_ctx_signing_config_from_default_configuration
mithril-aggregator ‑ http_server::routes::proof_routes::tests::build_response_message_return_latest_block_number_from_artifact_beacon
mithril-common ‑ cardano_block_scanner::block_scanner::tests::change_parsed_lower_bound_when_rescan_limit_is_set
mithril-common ‑ cardano_block_scanner::block_scanner::tests::test_scan_ignore_given_lower_bound_instead_find_it_using_an_external_service
mithril-common ‑ cardano_block_scanner::block_scanner::tests::test_scan_with_lower_bound_ignore_upper_bound
mithril-common ‑ cardano_block_scanner::block_scanner::tests::test_scan_without_lower_bound_ignore_upper_bound
mithril-common ‑ entities::signed_entity_type::tests::computing_block_number_to_be_signed
mithril-common ‑ entities::signed_entity_type::tests::computing_block_number_to_be_signed_round_step_to_a_block_range_start
mithril-common ‑ entities::signed_entity_type::tests::serialize_beacon_to_json
mithril-common ‑ entities::signed_entity_type::tests::verify_signed_entity_type_properties_are_included_in_computed_hash
…

♻️ This comment has been updated with latest results.

By running its `import.sh` script on a 'run only' end to end.

Co-authored-by: Sébastien Fauvel <[email protected]>
Co-authored-by: Damien Lachaume <[email protected]>
Co-authored-by: Sébastien Fauvel <[email protected]>
Co-authored-by: Damien Lachaume <[email protected]>
@Alenar Alenar force-pushed the ensemble/1697/chain_point_beacon_in_cardano_transaction branch from 96d8bcf to fc41440 Compare June 4, 2024 15:52
mithril-client/src/type_alias.rs Outdated Show resolved Hide resolved
mithril-common/src/entities/signed_entity_type.rs Outdated Show resolved Hide resolved
openapi.yaml Outdated Show resolved Hide resolved
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.

Good job! LGTM 🚀

I left few comments and typo fixes below.

mithril-aggregator/src/configuration.rs Outdated Show resolved Hide resolved
mithril-aggregator/src/configuration.rs Outdated Show resolved Hide resolved
async fn parse_and_store_transactions_not_imported_yet(
&self,
from: Option<ImmutableFileNumber>,
until: ImmutableFileNumber,
from: Option<ChainPoint>,
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need the full ChainPoint here?

Suggested change
from: Option<ChainPoint>,
from: Option<BlockNumber>,

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 need the full chain point for the BlockStreamer called by this method.

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 may use a BlockNumber but doing so we need to transfer the responsibility to obtain a chain point from a block number to the streamer.

This would be cumbersome since:

  • The lower bound is acquired by the importer (that part of its current role), to do so it do a database round-trip.
  • We would need to define a trait that take a block number as parameter and return a chain point ... implemented by doing another database round-trip (so two needed instead of one as now).

Another possibility would be to remove altogether the lower bound computation from the importer and transfer it to the scanner.

Copy link
Member

@jpraynaud jpraynaud Jun 5, 2024

Choose a reason for hiding this comment

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

Indeed this shoudl probably be the responsibility of the scanner.
This can be done in a separate PR 👍

mithril-aggregator/src/services/signed_entity.rs Outdated Show resolved Hide resolved
mithril-common/src/entities/signed_entity_type.rs Outdated Show resolved Hide resolved
mithril-common/src/entities/signed_entity_type.rs Outdated Show resolved Hide resolved
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.

Looks good

- Aggregator `cardano_transactions_signing_config.step` from 90 to 120.
- Adjusts/fix multiples comments
- Add missing types in `mithril-client` re-exported common types.

Co-authored-by: Sébastien Fauvel <[email protected]>
Co-authored-by: Damien Lachaume <[email protected]>
@Alenar Alenar temporarily deployed to testing-preview June 5, 2024 10:03 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet June 5, 2024 10:03 — with GitHub Actions Inactive
Add a test that check the `get_transaction_highest_chain_point` of
the `CardanoTransactionRepository` handle correcly the common case of
multiple transaction with the same chain point.

Clarify cardano transactions artificat builder tests.

Co-authored-by: Sébastien Fauvel <[email protected]>
Co-authored-by: Damien Lachaume <[email protected]>
@Alenar Alenar force-pushed the ensemble/1697/chain_point_beacon_in_cardano_transaction branch from 3866581 to 026f3d6 Compare June 5, 2024 10:14
@Alenar Alenar temporarily deployed to testing-preview June 5, 2024 10:20 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet June 5, 2024 10:20 — with GitHub Actions Inactive
nodes:
* Mithril-aggregator from `0.5.14` to `0.5.15`
* Mithril-client from `0.8.1` to `0.8.2`
* Mithril-client-cli from `0.9.0` to `0.9.1`
* Mithril-client-wasm from `0.3.1` to `0.3.2`
* Mithril-common from `0.4.11` to `0.4.12`
* Mithril-signer from `0.2.139` to `0.2.140`

websites:
* Mithril-explorer from `0.7.0` to `0.7.1`

internal:
* Mithril-persistence from `0.2.1` to `0.2.2`

test-lab
* Mithril-aggregator-fake from `0.3.1` to `0.3.2`
* Mithril-end-to-end from `0.4.13` to `0.4.14`
@Alenar Alenar force-pushed the ensemble/1697/chain_point_beacon_in_cardano_transaction branch from de1d279 to 70a8a61 Compare June 5, 2024 12:57
@Alenar Alenar temporarily deployed to testing-preview June 5, 2024 13:05 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet June 5, 2024 13:05 — with GitHub Actions Inactive
@Alenar Alenar merged commit c6f32d0 into main Jun 5, 2024
41 checks passed
@Alenar Alenar deleted the ensemble/1697/chain_point_beacon_in_cardano_transaction branch June 5, 2024 13:17
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.

Sign Cardano transactions with ChainPoint based beacon
4 participants