mining: Fix getmininginfo currentblockweight inaccuracy #17790

pull andrewtoth wants to merge 2 commits into bitcoin:master from andrewtoth:getmininginfo-weight changing 2 files +7 −4
  1. andrewtoth commented at 8:29 pm on December 22, 2019: 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.
  2. fanquake added the label Mining on Dec 22, 2019
  3. in src/miner.cpp:150 in 4f6c231d6d outdated
    146@@ -148,12 +147,14 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
    147     coinbaseTx.vout.resize(1);
    148     coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
    149     coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
    150-    coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
    151+    coinbaseTx.vin[0].scriptSig = CScript() << nHeight << CScriptNum(1);
    


    andrewtoth commented at 8:31 pm on December 22, 2019:
    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.
  4. andrewtoth renamed this:
    Fix getmininginfo currentblockweight inaccuracy
    mining: Fix getmininginfo currentblockweight inaccuracy
    on Dec 22, 2019
  5. DrahtBot commented at 11:13 pm on December 22, 2019: 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.

  6. Fix getmininginfo currentblockweight inaccuracy 248908cf10
  7. Fix getmininginfo currentblockweight test 1b177fef0f
  8. andrewtoth force-pushed on Dec 27, 2019
  9. luke-jr commented at 7:23 pm on January 3, 2020: member
    The client/miner decides the generated outputs, so it can’t be accurate…
  10. andrewtoth commented at 4:54 pm on January 5, 2020: contributor
    @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.
  11. andrewtoth closed this on Jan 5, 2020

  12. bitcoin locked this on Feb 15, 2022
  13. andrewtoth deleted the branch on Aug 17, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-21 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me