Skip to content

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

Merged
clemahieu merged 4 commits intonanocurrency:developfrom
clemahieu:ledger_successor_simplify
Mar 15, 2024
Merged

Simplify the nano::ledger::successor function to make its implementation more obvious.#4484
clemahieu merged 4 commits intonanocurrency:developfrom
clemahieu:ledger_successor_simplify

Conversation

@clemahieu
Copy link
Copy Markdown
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.

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
Copy Markdown
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
Copy Markdown
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 force-pushed the ledger_successor_simplify branch from 24e4cfa to 5681836 Compare March 15, 2024 09:53
@clemahieu clemahieu merged commit 2d08704 into nanocurrency:develop Mar 15, 2024
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.

2 participants