-
Notifications
You must be signed in to change notification settings - Fork 787
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
Simplify the nano::ledger::successor function to make its implementation more obvious. #4484
Conversation
b897c69
to
24e4cfa
Compare
@@ -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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
… 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.
…f there is a successor block.
24e4cfa
to
5681836
Compare
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.