Skip to content

refactor: Remove need to pass chainparams to BlockManager methods - #27570

Merged
fanquake merged 3 commits into
bitcoin:masterfrom
maflcko:2305-blockman-chain-params-
May 5, 2023
Merged

fanquake merged 3 commits into
bitcoin:masterfrom
maflcko:2305-blockman-chain-params-

Conversation

@maflcko

@maflcko maflcko commented May 4, 2023

Copy link
Copy Markdown
Member

Seems confusing to pass chainparams to each method individually, when the params can't change anyway for the whole lifetime of the block manager, and also must be equal to the ones used by the chainstate manager.

Fix this issue by removing them from the methods and instead storing a reference once in a member field.

@DrahtBot

DrahtBot commented May 4, 2023 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK dergoegge, TheCharlatan

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27576 (kernel: Remove args, chainparams, chainparamsbase from kernel library by TheCharlatan)
  • #27491 (refactor: Move chain constants to the util library by TheCharlatan)
  • #27125 (refactor, kernel: Decouple ArgsManager from blockstorage by TheCharlatan)
  • #27006 (reduce cs_main scope, guard block index 'nFile' under a local mutex by furszy)
  • #15606 (assumeutxo by jamesob)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko maflcko changed the title refactor: Remove need to pass chainparams from BlockManager methods refactor: Remove need to pass chainparams to BlockManager methods May 4, 2023

@dergoegge dergoegge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Concept ACK

Should we do the same for Consensus::Params?

@maflcko

maflcko commented May 4, 2023

Copy link
Copy Markdown
Member Author

Should we do the same for Consensus::Params?

Yes, this is what this pull is doing.

@DrahtBot DrahtBot removed the CI failed label May 4, 2023

@dergoegge dergoegge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this is what this pull is doing.

Sorry, I was confused because Consensus::Params are stil being passed to ReadBlockFromDisk.

Comment thread src/node/blockstorage.h Resolved
Sosyetekadir

This comment was marked as spam.

@bitcoin bitcoin deleted a comment from Sosyetekadir May 4, 2023
MarcoFalke added 3 commits May 4, 2023 19:26
and use it in blockstorage.cpp
pindex can not be nullptr, so document that, and clear it up in the next
commit.
Also, replace pointer with reference while touching the signature.
@maflcko
maflcko force-pushed the 2305-blockman-chain-params- branch from fa1e7fb to fa5d7c3 Compare May 4, 2023 17:29
@dergoegge

Copy link
Copy Markdown
Member

What about these three:

bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::Params& consensusParams);
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, const CMessageHeader::MessageStartChars& message_start);

@maflcko

maflcko commented May 4, 2023

Copy link
Copy Markdown
Member Author

They are not members of the class BlockManager, so fixing them is non-trivial and should happen in a follow-up.

@dergoegge

Copy link
Copy Markdown
Member

They are not members of the class BlockManager, so fixing them is non-trivial and should happen in a follow-up.

Ugh for some reason I thought #27125 was already merged🤦

@dergoegge dergoegge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code review ACK fa5d7c3

@fanquake
fanquake requested a review from sedited May 5, 2023 10:31

@sedited sedited left a comment

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.

ACK fa5d7c3

Thank you for following up so quickly!

{
const auto params {CreateChainParams(ArgsManager{}, CBaseChainParams::MAIN)};
BlockManager blockman{{}};
node::BlockManager::Options blockman_opts{

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.

Nit: Can be const (here and elsewhere) and skip the node:: namespacing, since it is imported above. If this is merged before #27125 I will follow-up there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I left it mutable to make it less code-churn to run ApplyArgsManOptions in the future, which you called in 27125 at some point, but no longer in the current state.

I'll remove node:: in the next push or maybe a follow-up.

@fanquake

fanquake commented May 5, 2023

Copy link
Copy Markdown
Member

cc @jamesob, this is going to conflict with #15606.

@jamesob

jamesob commented May 5, 2023

Copy link
Copy Markdown
Contributor

Is this some kind of dependency for libbitcoinkernel or for something other than general tidy-up impulses? If so, feel free to merge - assumeutxo is fresh in my brain and handling the rebase won't be so painful as a result.

Otherwise, wouldn't mind this getting shelved for later. But really no big deal either way. I'd say if you're going to merge do it soon so that I can manage the rebase with fresh context.

@fanquake

fanquake commented May 5, 2023

Copy link
Copy Markdown
Member

Is this some kind of dependency for libbitcoinkernel or for something other than general tidy-up impulses?

It spawned out of here: #27125 (comment). If you're happy to rebase over then I'm just going to go-ahead and merge this now. @TheCharlatan can then address any of his own comments as part of #27125 (which is also going to conflict with 15606, so probably worth having a look there as well.)

@fanquake
fanquake merged commit ccd4db7 into bitcoin:master May 5, 2023
@maflcko
maflcko deleted the 2305-blockman-chain-params- branch May 6, 2023 07:25
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 19, 2024
Summary:
and use it in blockstorage.cpp

PR rationale:

> Seems confusing to pass chainparams to each method individually, when the params can't change anyway for the whole lifetime of the block manager, and also must be equal to the ones used by the chainstate manager.
>
> Fix this issue by removing them from the methods and instead storing a reference once in a member field.

This is a partial backport of [[bitcoin/bitcoin#27570 | core#27570]]
bitcoin/bitcoin@facdb8b
(partial) bitcoin/bitcoin@fa5d7c3

Depends on D16010

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D16015
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 19, 2024
Summary:
pindex can not be nullptr, so document that.

This concludes backport of [[bitcoin/bitcoin#27570 | core#27570]]
bitcoin/bitcoin@fa3f74a
(partial) bitcoin/bitcoin@fa5d7c3

Depends on D16015

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D16016
@bitcoin bitcoin locked and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants