Skip to content

Conversation

@andrewtoth
Copy link
Contributor

@andrewtoth andrewtoth commented Dec 7, 2019

The existing block generation rpcs for regtest, generatetoaddress and generatetodescriptor, mine everything in the mempool up to the block weight limit. This makes it difficult to test a system for several scenarios where a different set of transactions are mined. For example:

  • Testing the common scenario where a transaction is replaced in the mempool but the replaced transaction is mined instead.
  • Testing for a double-spent transaction where a transaction that conflicts with the mempool is mined.
  • Testing for non-standard transactions that are mined.
  • Testing the scenario where several blocks are mined without a specific transaction in the mempool being included in a block.

This PR introduces a new rpc, generateblock, that takes an array of raw transactions and txids and mines only those and the coinbase. Any txids must be in the mempool, but the raw txs can be anything conforming to consensus rules. The coinbase can be specified as either an address or descriptor.

This reopens #17653 since it was closed by mistake.

Thanks to instagibbs for code suggestions that I used here.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 7, 2019

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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

Concept NACK, just make the block and submit it in the test suite...

@andrewtoth
Copy link
Contributor Author

@luke-jr What if there is no "test suite"? Usually when testing a system that talks to bitcoind with regtest I use cli to send from bitcoind wallet and generatetoaddress to mine blocks. With this setup it is very difficult to simulate double spend without having a second bitcoind and doing an extensive workaround. This seems to have a decent amount of interest, since this PR had a thumbs up and the original PR #17653 had two concept ACKs. Also, #16523 was created for this same purpose.

@luke-jr
Copy link
Member

luke-jr commented Jan 5, 2020

Fair enough. Concept NACK retracted.

@instagibbs
Copy link
Member

concept ACK, we need it to test our systems as well

@sipa
Copy link
Member

sipa commented Mar 17, 2020

Concept ACK on having an RPC that can do this, but I'm not convinced about the approach (see comment elsewhere).

@instagibbs
Copy link
Member

instagibbs commented Mar 17, 2020 via email

@sipa
Copy link
Member

sipa commented Mar 17, 2020

Ok, I see. But the first iteration of the code was duplicating everything, including the grinding. I'm suggesting not duplicating the grinding, but by just constructing a BlockTemplate directly, instead of overloading BlockAssembler to do that.

@andrewtoth
Copy link
Contributor Author

@sipa updated with your suggestion.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

ACK

Copy link
Member

Choose a reason for hiding this comment

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

comment for followup only: Allow a bypass of validity check for building block tests via RPC

@maflcko
Copy link
Member

maflcko commented Mar 27, 2020

re-ACK 7524b64 📁

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

re-ACK 7524b6479cb20471d827aec5500925c86c62ce1c 📁
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUioEAv/XByMTYwhQ58oELwHk0VDhpY7mgGWvhdkpepTAj3h6ubQIfmiDS4wFaqL
TGidhK5MYhc9ZZKYm6r2ZFCD6YQafvpn1K/ok0tfLgFbiAFRo3EJ4H8Nz0+M6M2F
J1ULhbnBypjPM+5guoh+Vo56EV4TBhYVeY76Y8i5qLEdiGjOBxlsAEoMY77T7jWg
QmSflP9mTIXGS2xbVQkzjPiKA7H8G0NCgZX5Zbi6COZ73J3nSCxURWGhyoS+03j0
R0RaEeDlfBtCFnSZHSk4DNuuCk8V+si8sqyCdsfCW5sVf/zHqDQn6PvlDN85DaQS
h2ybD8hf4IJWtk41CDVzhDQuTFD3dspPzNDX8FNbNttBRt/CAC1+UPTUaVsThBET
DKz0uCoO3DXwoKa0Akdz4bTf/GFlpRh8+BWC3A/lg1D3Hpc9RLcQKQbn6v434hWJ
Q6u6xgmBNmWtikLnfAOUSVm2mHwTxrQrSlLp6WD8kliM74oUAo0n6uQCpDNyvp39
4y2c1Gcd
=aDC3
-----END PGP SIGNATURE-----

Timestamp of file with hash df2de0a97ae347b1985267b6969efcbe2e76c6b0a484832ef46013bf7f784ade -

@andrewtoth
Copy link
Contributor Author

Does this need release notes?

@maflcko
Copy link
Member

maflcko commented Mar 27, 2020

A one-line release note in the "tests" section should be sufficient. This can be done after merge, since it is not clear if this makes it into 0.20 or 0.21

It only affects test, so it might make it into 0.20, but I wanted to wait for other reviewers first.

@maflcko maflcko merged commit 51e2ce4 into bitcoin:master Apr 10, 2020
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Apr 13, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 13, 2020
…ransactions

7524b64 Add tests for generateblock (Andrew Toth)
dcc8332 Add generateblock rpc (Andrew Toth)

Pull request description:

  The existing block generation rpcs for regtest, `generatetoaddress` and `generatetodescriptor`, mine everything in the mempool up to the block weight limit. This makes it difficult to test a system for several scenarios where a different set of transactions are mined. For example:
  - Testing the common scenario where a transaction is replaced in the mempool but the replaced transaction is mined instead.
  - Testing for a double-spent transaction where a transaction that conflicts with the mempool is mined.
  - Testing for non-standard transactions that are mined.
  - Testing the scenario where several blocks are mined without a specific transaction in the mempool being included in a block.

  This PR introduces a new rpc, `generateblock`, that takes an array of raw transactions and txids and mines only those and the coinbase. Any txids must be in the mempool, but the raw txs can be anything conforming to consensus rules. The coinbase can be specified as either an address or descriptor.

  This reopens bitcoin#17653 since it was closed by mistake.

  Thanks to instagibbs for code suggestions that I used here.

ACKs for top commit:
  MarcoFalke:
    re-ACK 7524b64 📁

Tree-SHA512: 857106007465b5b9b8a84b6d07c17cbf8378a33a72d32ff79abea1d5ab4babb4d53a11ddbb14595aa1fac9dfa1391e3a11403d742f69951beea2f683e8a01cd4
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 1, 2020
Summary:
```
The existing block generation rpcs for regtest, generatetoaddress and
generatetodescriptor, mine everything in the mempool up to the block
weight limit. This makes it difficult to test a system for several
scenarios where a different set of transactions are mined. For example:

    Testing the common scenario where a transaction is replaced in the
mempool but the replaced transaction is mined instead.
    Testing for a double-spent transaction where a transaction that
conflicts with the mempool is mined.
    Testing for non-standard transactions that are mined.
    Testing the scenario where several blocks are mined without a
specific transaction in the mempool being included in a block.

This PR introduces a new rpc, generateblock, that takes an array of raw
transactions and txids and mines only those and the coinbase. Any txids
must be in the mempool, but the raw txs can be anything conforming to
consensus rules. The coinbase can be specified as either an address or
descriptor.
```

Backport of core [[bitcoin/bitcoin#17693 | PR17693]].

The code has been adapted to remove the Segwit parts. For now the RPC
interface is kept identical to core, but it would be interesting to not
enforce CTOR in the call and sort the txs in the RPC code instead to
make it easier to mix raw txs and txids.

Test Plan:
  ninja check-functional

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D8553
Comment on lines -132 to -133
if (pblock->nNonce == std::numeric_limits<uint32_t>::max()) {
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

This change means that the extra_nonce logic is now unused. Previously if the nNonce field rolled, we'd go around the loop again and call IncrementExtraNonce(). Now we'll just return true.

I've proposed removing that logic entirely in #21533.

Copy link
Contributor

Choose a reason for hiding this comment

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

Never mind, I misunderstood the new interface for GenerateBlock():

  • returns false: generation of block failed
  • returns true with valid block_hash out-param: generation of block succeeded
  • returns true with invalid (nullified) block_hash out-param: generation of block didn't succeed, maximum nNonce reached

(thanks to @theStack for pointing this out: #21533 (review))

PhotoshiNakamoto added a commit to PhotonicBitcoin/pBTC-core that referenced this pull request Dec 11, 2021
Bitcoin Core PR: bitcoin/bitcoin#17693

Pull request description:

  The existing block generation rpcs for regtest, `generatetoaddress` and `generatetodescriptor`, mine everything in the mempool up to the block weight limit. This makes it difficult to test a system for several scenarios where a different set of transactions are mined. For example:
  - Testing the common scenario where a transaction is replaced in the mempool but the replaced transaction is mined instead.
  - Testing for a double-spent transaction where a transaction that conflicts with the mempool is mined.
  - Testing for non-standard transactions that are mined.
  - Testing the scenario where several blocks are mined without a specific transaction in the mempool being included in a block.

  This PR introduces a new rpc, `generateblock`, that takes an array of raw transactions and txids and mines only those and the coinbase. Any txids must be in the mempool, but the raw txs can be anything conforming to consensus rules. The coinbase can be specified as either an address or descriptor.

  This reopens bitcoin/bitcoin#17653 since it was closed by mistake.

  Thanks to instagibbs for code suggestions that I used here.
kwvg added a commit to kwvg/dash that referenced this pull request Apr 5, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Apr 19, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
@andrewtoth andrewtoth deleted the generateblock branch August 17, 2023 20:40
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.

8 participants