Skip to content
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

mining: Fix getmininginfo currentblockweight inaccuracy #17790

Closed
wants to merge 2 commits into from

Conversation

andrewtoth
Copy link
Contributor

getmininginfo's currentblockweight field is not accurate. getblock on the latest mined block shows a different weight. This corrects that behaviour by storing the actual serialized weight instead of an estimate.

@@ -148,12 +147,14 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
coinbaseTx.vout.resize(1);
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << CScriptNum(1);
Copy link
Contributor Author

@andrewtoth andrewtoth Dec 22, 2019

Choose a reason for hiding this comment

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

The extraNonce is incremented before any block is generated, which adds 4 to the block weight. This adds an extraNonce of 1 here so that the following GetBlockWeight calculation is accurate and not 4 less.

@andrewtoth andrewtoth changed the title Fix getmininginfo currentblockweight inaccuracy mining: Fix getmininginfo currentblockweight inaccuracy Dec 22, 2019
@DrahtBot
Copy link
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #17693 (rpc: Add generateblock to mine a custom set of transactions by andrewtoth)

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.

@luke-jr
Copy link
Member

luke-jr commented Jan 3, 2020

The client/miner decides the generated outputs, so it can't be accurate...

@andrewtoth
Copy link
Contributor Author

@luke-jr I see, thanks. Perhaps this should be documented in the help text then, that this field is only an estimate? At least with this patch it would be accurate for blocks created with generatetoaddress. I doubt that's worth it though, so closing.

@andrewtoth andrewtoth closed this Jan 5, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
@andrewtoth andrewtoth deleted the getmininginfo-weight branch August 17, 2023 20:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants