-
Notifications
You must be signed in to change notification settings - Fork 38.8k
rpc: Add generateblock to mine a custom set of transactions #17693
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
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
ec5ce9f to
7d93244
Compare
7d93244 to
5ad549b
Compare
5ad549b to
a9bff39
Compare
|
|
|
@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 |
|
Fair enough. Concept NACK retracted. |
a9bff39 to
643d351
Compare
|
concept ACK, we need it to test our systems as well |
|
Concept ACK on having an RPC that can do this, but I'm not convinced about the approach (see comment elsewhere). |
|
I'll take another look this week. Maybe I need to see the approaches side
by side.
…On Mon, Mar 16, 2020, 8:40 PM andrewtoth ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/miner.cpp
<#17693 (comment)>:
> nFees = 0;
}
Optional<int64_t> BlockAssembler::m_last_block_num_txs{nullopt};
Optional<int64_t> BlockAssembler::m_last_block_weight{nullopt};
-std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
+std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, const std::vector<CTransactionRef>* preselected_txs)
I did initially b0745f8
<b0745f8>
but @instagibbs <https://github.com/instagibbs> suggested I take this
approach instead #17653 (comment)
<#17653 (comment)>.
Now I'm not sure which is better, duplicating a lot of code from
BlockAssembler or modifying it to support adding preselected txs.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#17693 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABMAFU44MHTZUALQHO6WUSTRH3BJVANCNFSM4JXP3YZQ>
.
|
|
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. |
643d351 to
718796a
Compare
|
@sipa updated with your suggestion. |
maflcko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
src/rpc/mining.cpp
Outdated
There was a problem hiding this comment.
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
718796a to
8becb08
Compare
4292064 to
7524b64
Compare
|
re-ACK 7524b64 📁 Show signature and timestampSignature: Timestamp of file with hash |
|
Does this need release notes? |
|
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. |
Adjusted the upstream bitcoin/bitcoin#17693 for auxpow.
…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
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
| if (pblock->nNonce == std::numeric_limits<uint32_t>::max()) { | ||
| continue; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))
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.
The existing block generation rpcs for regtest,
generatetoaddressandgeneratetodescriptor, 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: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.