2023-08-16 19:27:31 +02:00
|
|
|
// Copyright (c) 2017-2020 The Bitcoin Core developers
|
2019-01-09 07:16:50 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_NODE_TRANSACTION_H
|
|
|
|
#define BITCOIN_NODE_TRANSACTION_H
|
|
|
|
|
2019-02-22 17:09:44 +01:00
|
|
|
#include <attributes.h>
|
2020-04-23 00:38:35 +02:00
|
|
|
#include <policy/feerate.h>
|
2019-01-09 07:16:50 +01:00
|
|
|
#include <primitives/transaction.h>
|
2021-11-16 16:19:47 +01:00
|
|
|
#include <util/error.h>
|
2019-01-30 06:32:38 +01:00
|
|
|
|
Merge bitcoin/bitcoin#22528: refactor: move GetTransaction to node/transaction.cpp
f685a13bef0418663015ea6d8f448f075510c0ec doc: GetTransaction()/getrawtransaction follow-ups to #22383 (John Newbery)
abc57e1f0882a1a2bb20474648419979af6e383d refactor: move `GetTransaction(...)` to node/transaction.cpp (Sebastian Falbesoner)
Pull request description:
~This PR is based on #22383, which should be reviewed first~ (merged by now).
In [yesterday's PR review club session to PR 22383](https://bitcoincore.reviews/22383), the idea of moving the function `GetTransaction(...)` from src/validation.cpp to src/node/transaction.cpp came up. With this, the circular dependency "index/txindex -> validation -> index/txindex" is removed (see change in `lint-circular-dependencies.sh`). Thanks to jnewbery for suggesting and to sipa for providing historical background.
Relevant IRC log:
```
17:52 <jnewbery> Was anyone surprised that GetTransaction() is in validation.cpp? It seems to me that node/transaction.cpp would be a more appropriate place for it.
17:53 <raj_> jnewbery, +1
17:53 <stickies-v> agreed!
17:54 <glozow> jnewbery ya
17:54 <jnewbery> seems weird that validation would call into txindex. I wonder if we remove this function, then validation would no longer need to #include txindex
17:54 <sipa> GetTransaction predates node/transaction.cpp, and even the generic index framework itself :)
17:55 <sipa> (before 0.8, validation itself used the txindex)
17:55 <jnewbery> (and GetTransaction() seems like a natural sibling to BroadcastTransaction(), which is already in node/transaction.cpp)
17:55 <jnewbery> sipa: right, this is not meant as a criticism of course. Just wondering if we can organize things a bit more rationally now that we have better separation between things.
17:55 <sipa> jnewbery: sure, just providing background
17:56 <sipa> seems very reasonable to move it elsewhere now
```
The commit should be trivial to review with `--color-moved`.
ACKs for top commit:
jnewbery:
Code review ACK f685a13bef0418663015ea6d8f448f075510c0ec
rajarshimaitra:
tACK https://github.com/bitcoin/bitcoin/pull/22528/commits/f685a13bef0418663015ea6d8f448f075510c0ec
mjdietzx:
crACK f685a13bef0418663015ea6d8f448f075510c0ec
LarryRuane:
Code review, test ACK f685a13bef0418663015ea6d8f448f075510c0ec
Tree-SHA512: 0e844a6ecb1be04c638b55bc4478c2949549a4fcae01c984eee078de74d176fb19d508fc09360a62ad130677bfa7daf703b67870800e55942838d7313246248c
2021-07-28 18:19:38 +02:00
|
|
|
class CBlockIndex;
|
|
|
|
class CTxMemPool;
|
2022-04-05 11:09:41 +02:00
|
|
|
struct NodeContext;
|
Merge bitcoin/bitcoin#22528: refactor: move GetTransaction to node/transaction.cpp
f685a13bef0418663015ea6d8f448f075510c0ec doc: GetTransaction()/getrawtransaction follow-ups to #22383 (John Newbery)
abc57e1f0882a1a2bb20474648419979af6e383d refactor: move `GetTransaction(...)` to node/transaction.cpp (Sebastian Falbesoner)
Pull request description:
~This PR is based on #22383, which should be reviewed first~ (merged by now).
In [yesterday's PR review club session to PR 22383](https://bitcoincore.reviews/22383), the idea of moving the function `GetTransaction(...)` from src/validation.cpp to src/node/transaction.cpp came up. With this, the circular dependency "index/txindex -> validation -> index/txindex" is removed (see change in `lint-circular-dependencies.sh`). Thanks to jnewbery for suggesting and to sipa for providing historical background.
Relevant IRC log:
```
17:52 <jnewbery> Was anyone surprised that GetTransaction() is in validation.cpp? It seems to me that node/transaction.cpp would be a more appropriate place for it.
17:53 <raj_> jnewbery, +1
17:53 <stickies-v> agreed!
17:54 <glozow> jnewbery ya
17:54 <jnewbery> seems weird that validation would call into txindex. I wonder if we remove this function, then validation would no longer need to #include txindex
17:54 <sipa> GetTransaction predates node/transaction.cpp, and even the generic index framework itself :)
17:55 <sipa> (before 0.8, validation itself used the txindex)
17:55 <jnewbery> (and GetTransaction() seems like a natural sibling to BroadcastTransaction(), which is already in node/transaction.cpp)
17:55 <jnewbery> sipa: right, this is not meant as a criticism of course. Just wondering if we can organize things a bit more rationally now that we have better separation between things.
17:55 <sipa> jnewbery: sure, just providing background
17:56 <sipa> seems very reasonable to move it elsewhere now
```
The commit should be trivial to review with `--color-moved`.
ACKs for top commit:
jnewbery:
Code review ACK f685a13bef0418663015ea6d8f448f075510c0ec
rajarshimaitra:
tACK https://github.com/bitcoin/bitcoin/pull/22528/commits/f685a13bef0418663015ea6d8f448f075510c0ec
mjdietzx:
crACK f685a13bef0418663015ea6d8f448f075510c0ec
LarryRuane:
Code review, test ACK f685a13bef0418663015ea6d8f448f075510c0ec
Tree-SHA512: 0e844a6ecb1be04c638b55bc4478c2949549a4fcae01c984eee078de74d176fb19d508fc09360a62ad130677bfa7daf703b67870800e55942838d7313246248c
2021-07-28 18:19:38 +02:00
|
|
|
namespace Consensus {
|
|
|
|
struct Params;
|
|
|
|
}
|
2022-04-05 11:09:41 +02:00
|
|
|
|
2020-04-23 00:38:35 +02:00
|
|
|
/** Maximum fee rate for sendrawtransaction and testmempoolaccept RPC calls.
|
|
|
|
* Also used by the GUI when broadcasting a completed PSBT.
|
|
|
|
* By default, a transaction with a fee rate higher than this will be rejected
|
|
|
|
* by these RPCs and the GUI. This can be overridden with the maxfeerate argument.
|
|
|
|
*/
|
|
|
|
static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
|
|
|
|
|
2019-01-30 06:32:38 +01:00
|
|
|
/**
|
2021-12-12 18:06:50 +01:00
|
|
|
* Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
|
|
|
|
*
|
|
|
|
* Mempool submission can be synchronous (will await mempool entry notification
|
|
|
|
* over the CValidationInterface) or asynchronous (will submit and not wait for
|
|
|
|
* notification), depending on the value of wait_callback. wait_callback MUST
|
|
|
|
* NOT be set while cs_main, cs_mempool or cs_wallet are held to avoid
|
|
|
|
* deadlock.
|
2019-01-30 06:32:38 +01:00
|
|
|
*
|
2022-04-05 11:09:41 +02:00
|
|
|
* @param[in] node reference to node context
|
2019-01-30 06:32:38 +01:00
|
|
|
* @param[in] tx the transaction to broadcast
|
2020-01-20 20:35:12 +01:00
|
|
|
* @param[out] err_string reference to std::string to fill with error string if available
|
2021-12-12 18:06:50 +01:00
|
|
|
* @param[in] max_tx_fee reject txs with fees higher than this (if 0, accept any fee)
|
|
|
|
* @param[in] relay flag if both mempool insertion and p2p relay are requested
|
2020-01-20 20:35:12 +01:00
|
|
|
* @param[in] wait_callback wait until callbacks have been processed to avoid stale result due to a sequentially RPC.
|
2019-02-22 17:09:44 +01:00
|
|
|
* return error
|
2019-01-30 06:32:38 +01:00
|
|
|
*/
|
2022-04-05 11:09:41 +02:00
|
|
|
[[nodiscard]] TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, std::string& err_string, const CAmount& highfee, bool relay, bool wait_callback, bool bypass_limits = false);
|
2019-01-09 07:16:50 +01:00
|
|
|
|
Merge bitcoin/bitcoin#22528: refactor: move GetTransaction to node/transaction.cpp
f685a13bef0418663015ea6d8f448f075510c0ec doc: GetTransaction()/getrawtransaction follow-ups to #22383 (John Newbery)
abc57e1f0882a1a2bb20474648419979af6e383d refactor: move `GetTransaction(...)` to node/transaction.cpp (Sebastian Falbesoner)
Pull request description:
~This PR is based on #22383, which should be reviewed first~ (merged by now).
In [yesterday's PR review club session to PR 22383](https://bitcoincore.reviews/22383), the idea of moving the function `GetTransaction(...)` from src/validation.cpp to src/node/transaction.cpp came up. With this, the circular dependency "index/txindex -> validation -> index/txindex" is removed (see change in `lint-circular-dependencies.sh`). Thanks to jnewbery for suggesting and to sipa for providing historical background.
Relevant IRC log:
```
17:52 <jnewbery> Was anyone surprised that GetTransaction() is in validation.cpp? It seems to me that node/transaction.cpp would be a more appropriate place for it.
17:53 <raj_> jnewbery, +1
17:53 <stickies-v> agreed!
17:54 <glozow> jnewbery ya
17:54 <jnewbery> seems weird that validation would call into txindex. I wonder if we remove this function, then validation would no longer need to #include txindex
17:54 <sipa> GetTransaction predates node/transaction.cpp, and even the generic index framework itself :)
17:55 <sipa> (before 0.8, validation itself used the txindex)
17:55 <jnewbery> (and GetTransaction() seems like a natural sibling to BroadcastTransaction(), which is already in node/transaction.cpp)
17:55 <jnewbery> sipa: right, this is not meant as a criticism of course. Just wondering if we can organize things a bit more rationally now that we have better separation between things.
17:55 <sipa> jnewbery: sure, just providing background
17:56 <sipa> seems very reasonable to move it elsewhere now
```
The commit should be trivial to review with `--color-moved`.
ACKs for top commit:
jnewbery:
Code review ACK f685a13bef0418663015ea6d8f448f075510c0ec
rajarshimaitra:
tACK https://github.com/bitcoin/bitcoin/pull/22528/commits/f685a13bef0418663015ea6d8f448f075510c0ec
mjdietzx:
crACK f685a13bef0418663015ea6d8f448f075510c0ec
LarryRuane:
Code review, test ACK f685a13bef0418663015ea6d8f448f075510c0ec
Tree-SHA512: 0e844a6ecb1be04c638b55bc4478c2949549a4fcae01c984eee078de74d176fb19d508fc09360a62ad130677bfa7daf703b67870800e55942838d7313246248c
2021-07-28 18:19:38 +02:00
|
|
|
/**
|
|
|
|
* Return transaction with a given hash.
|
|
|
|
* If mempool is provided and block_index is not provided, check it first for the tx.
|
|
|
|
* If -txindex is available, check it next for the tx.
|
|
|
|
* Finally, if block_index is provided, check for tx by reading entire block from disk.
|
|
|
|
*
|
|
|
|
* @param[in] block_index The block to read from disk, or nullptr
|
|
|
|
* @param[in] mempool If provided, check mempool for tx
|
|
|
|
* @param[in] hash The txid
|
|
|
|
* @param[in] consensusParams The params
|
|
|
|
* @param[out] hashBlock The block hash, if the tx was found via -txindex or block_index
|
|
|
|
* @returns The tx if found, otherwise nullptr
|
|
|
|
*/
|
|
|
|
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
|
|
|
|
|
2019-01-09 07:16:50 +01:00
|
|
|
#endif // BITCOIN_NODE_TRANSACTION_H
|