Skip to content

Create faster genesis root population method and get rid of Root.transfer_accounts_with #17659

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

Open
wants to merge 3 commits into
base: compatible
Choose a base branch
from

Conversation

cjjdespres
Copy link
Member

Explain your changes:

Instead of having a populate_root method to populate an existing, empty root ledger from genesis, the genesis ledger now has a create_root method. This method assumes the responsibility for creating the root ledger itself. The resulting API is more convenient to use elsewhere in the code base. This design also allows the create_root method to checkpoint the genesis ledger directly when the genesis ledger is backed by a database, which is much faster than an account transfer.

The transfer_accounts_with method has been removed - it is unclear if it is necessary.

Explain how you tested your changes:

The nightly tests should cover this change. I also added some temporary log lines to measure the time taken to populate a snarked root from genesis, to compare against the measurements I did in #17570. I got this result when I synced a daemon to mainnet with an empty config directory:

2025-08-21 20:01:35 UTC [Info] Starting genesis reset
2025-08-21 20:01:35 UTC [Info] Done genesis reset

So, this should resolve that issue as well.

Checklist:

  • Dependency versions are unchanged
  • Modified the current draft of release notes with details on what is completed or incomplete within this project
  • Document code purpose, how to use it
  • Tests were added for the new behavior
  • All tests pass (CI will check this if you didn't)
  • Serialized types are in stable-versioned modules
  • Does this close issues? List them

Instead of having a populate_root method to populate an existing, empty
root ledger from genesis, the genesis ledger now has a create_root
method. This method assumes the responsibility for creating the root
ledger itself. The create_root method can thus checkpoint the genesis
ledger directly when the genesis ledger is backed by a database.
@cjjdespres cjjdespres requested a review from a team as a code owner August 21, 2025 21:01
@cjjdespres
Copy link
Member Author

!ci-nightly-me

Ledger.Root.transfer_accounts_with
~stable:Ledger_transfer_stable.transfer_accounts
let transfer_snarked_root ~src ~dest =
Ledger_transfer_any.transfer_accounts
Copy link
Member Author

Choose a reason for hiding this comment

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

I kept the use of Ledger_transfer_any.transfer_accounts in this method. It's used exactly once, when populating the root snarked ledger from a recovered potential snarked ledger.

This could be removed too, if reading all the accounts in the database and regenerating the database structure is not important for this recovery mechanism.

Copy link
Member

Choose a reason for hiding this comment

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

We trust filesystem, right? So I'd suggest removing this as well.

@cjjdespres
Copy link
Member Author

!ci-build-me

@glyh
Copy link
Member

glyh commented Aug 21, 2025

CI is broken it seems

@glyh
Copy link
Member

glyh commented Aug 22, 2025

!ci-build-me

@@ -1029,7 +1029,8 @@ module For_tests = struct
~directory:(Filename.temp_file "snarked_ledger" "")
~ledger_depth
in
Persistent_root.reset_to_genesis_exn persistent_root ~precomputed_values ;
Async.Thread_safe.block_on_async_exn (fun () ->
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use this function in non-top level. Async.Thread_safe.block_on_async_exn is only supposed to be called once per OS process.

Copy link
Member

Choose a reason for hiding this comment

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

I'd propagate this _ Deferred.t all the way to top level.

@@ -77,11 +77,6 @@ struct
let as_unmasked t =
match t with Stable_db db -> Any_ledger.cast (module Stable_db) db

let transfer_accounts_with ~stable ~src ~dest =
Copy link
Member

Choose a reason for hiding this comment

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

Now this is no longer needed, can we go with my old solution using existential type for backing root with converting ledger? This seems to be place you pointed out that won't work with existential wrapped converting ledgers.

Context: #17645 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

I'll prepare 2 PR just in case.

Ledger.Root.transfer_accounts_with
~stable:Ledger_transfer_stable.transfer_accounts
let transfer_snarked_root ~src ~dest =
Ledger_transfer_any.transfer_accounts
Copy link
Member

Choose a reason for hiding this comment

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

We trust filesystem, right? So I'd suggest removing this as well.

(Mina_block.Validated.state_hash transition) ;
ignore
@@ populate_root (Persistent_root.Instance.snarked_ledger instance) ) ;
Async.Thread_safe.block_on_async_exn (fun () ->
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove these 2 Async.Thread_safe.block_on_async_exn as well?

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.

We appear to re-hash the genesis ledger when resetting the snarked root
2 participants