Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Simplify the nano::ledger::successor function to make its implementation more obvious. #4484

Merged
merged 4 commits into from
Mar 15, 2024

Conversation

clemahieu
Copy link
Contributor

@clemahieu clemahieu commented Mar 12, 2024

These changes simplifies the way block successors are accessed.

Usages of store::block::successor are changed to ledger::successor.
ledger::successor returns a std::optionalnano::block_hash instead of a std::shared_ptrnano::block which allows users to determine if they want to load the block.
A convenience overload of ledger::successor is added which takes a block_hash and expands it to a qualified_root.

@@ -51,7 +51,8 @@ class ledger final
nano::uint128_t account_balance (store::transaction const &, nano::account const &, bool = false);
nano::uint128_t account_receivable (store::transaction const &, nano::account const &, bool = false);
nano::uint128_t weight (nano::account const &);
std::shared_ptr<nano::block> successor (store::transaction const &, nano::qualified_root const &);
std::optional<nano::block_hash> successor (store::transaction const &, nano::qualified_root const &) const noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on whether qualified root represents a block ( root and previous fields are non zero) or an account ( root is set account and previous is zero) this returns either the next block in chain or account. Is this accurate? How exactly the situation looks like with epoch or epoch-open blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's an ambiguity there that appeared when epoch blocks were created. Roots are only used for block PoW and vote_req hinting. The successor function gives precedence to the block hash rather than the account number. The net result is that vote_req root hints don't work for epoch-open blocks.

pwojcikdev
pwojcikdev previously approved these changes Mar 14, 2024
… so callsites don't necessarily need to load the block.
Adds ledger::successor convenience functions taking nano::block_hash and expands them to nano::qualified_root so both block successor and account open blocks are searched.
@clemahieu clemahieu merged commit 2d08704 into nanocurrency:develop Mar 15, 2024
17 of 27 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants