/Users/eugenesiegel/btc/bitcoin/src/interfaces/mining.h
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | // Copyright (c) 2024-present The Bitcoin Core developers | 
| 2 |  | // Distributed under the MIT software license, see the accompanying | 
| 3 |  | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | 
| 4 |  |  | 
| 5 |  | #ifndef BITCOIN_INTERFACES_MINING_H | 
| 6 |  | #define BITCOIN_INTERFACES_MINING_H | 
| 7 |  |  | 
| 8 |  | #include <consensus/amount.h> | 
| 9 |  | #include <interfaces/types.h> | 
| 10 |  | #include <node/types.h> | 
| 11 |  | #include <primitives/block.h> | 
| 12 |  | #include <primitives/transaction.h> | 
| 13 |  | #include <uint256.h> | 
| 14 |  | #include <util/time.h> | 
| 15 |  |  | 
| 16 |  | #include <cstdint> | 
| 17 |  | #include <memory> | 
| 18 |  | #include <optional> | 
| 19 |  | #include <vector> | 
| 20 |  |  | 
| 21 |  | namespace node { | 
| 22 |  | struct NodeContext; | 
| 23 |  | } // namespace node | 
| 24 |  |  | 
| 25 |  | class BlockValidationState; | 
| 26 |  | class CScript; | 
| 27 |  |  | 
| 28 |  | namespace interfaces { | 
| 29 |  |  | 
| 30 |  | //! Block template interface | 
| 31 |  | class BlockTemplate | 
| 32 |  | { | 
| 33 |  | public: | 
| 34 | 0 |     virtual ~BlockTemplate() = default; | 
| 35 |  |  | 
| 36 |  |     virtual CBlockHeader getBlockHeader() = 0; | 
| 37 |  |     // Block contains a dummy coinbase transaction that should not be used. | 
| 38 |  |     virtual CBlock getBlock() = 0; | 
| 39 |  |  | 
| 40 |  |     // Fees per transaction, not including coinbase transaction. | 
| 41 |  |     virtual std::vector<CAmount> getTxFees() = 0; | 
| 42 |  |     // Sigop cost per transaction, not including coinbase transaction. | 
| 43 |  |     virtual std::vector<int64_t> getTxSigops() = 0; | 
| 44 |  |  | 
| 45 |  |     virtual CTransactionRef getCoinbaseTx() = 0; | 
| 46 |  |     virtual std::vector<unsigned char> getCoinbaseCommitment() = 0; | 
| 47 |  |     virtual int getWitnessCommitmentIndex() = 0; | 
| 48 |  |  | 
| 49 |  |     /** | 
| 50 |  |      * Compute merkle path to the coinbase transaction | 
| 51 |  |      * | 
| 52 |  |      * @return merkle path ordered from the deepest | 
| 53 |  |      */ | 
| 54 |  |     virtual std::vector<uint256> getCoinbaseMerklePath() = 0; | 
| 55 |  |  | 
| 56 |  |     /** | 
| 57 |  |      * Construct and broadcast the block. | 
| 58 |  |      * | 
| 59 |  |      * @returns if the block was processed, independent of block validity | 
| 60 |  |      */ | 
| 61 |  |     virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) = 0; | 
| 62 |  |  | 
| 63 |  |     /** | 
| 64 |  |      * Waits for fees in the next block to rise, a new tip or the timeout. | 
| 65 |  |      * | 
| 66 |  |      * @param[in] options   Control the timeout (default forever) and by how much total fees | 
| 67 |  |      *                      for the next block should rise (default infinite). | 
| 68 |  |      * | 
| 69 |  |      * @returns a new BlockTemplate or nothing if the timeout occurs. | 
| 70 |  |      * | 
| 71 |  |      * On testnet this will additionally return a template with difficulty 1 if | 
| 72 |  |      * the tip is more than 20 minutes old. | 
| 73 |  |      */ | 
| 74 |  |     virtual std::unique_ptr<BlockTemplate> waitNext(const node::BlockWaitOptions options = {}) = 0; | 
| 75 |  | }; | 
| 76 |  |  | 
| 77 |  | //! Interface giving clients (RPC, Stratum v2 Template Provider in the future) | 
| 78 |  | //! ability to create block templates. | 
| 79 |  | class Mining | 
| 80 |  | { | 
| 81 |  | public: | 
| 82 | 0 |     virtual ~Mining() = default; | 
| 83 |  |  | 
| 84 |  |     //! If this chain is exclusively used for testing | 
| 85 |  |     virtual bool isTestChain() = 0; | 
| 86 |  |  | 
| 87 |  |     //! Returns whether IBD is still in progress. | 
| 88 |  |     virtual bool isInitialBlockDownload() = 0; | 
| 89 |  |  | 
| 90 |  |     //! Returns the hash and height for the tip of this chain | 
| 91 |  |     virtual std::optional<BlockRef> getTip() = 0; | 
| 92 |  |  | 
| 93 |  |     /** | 
| 94 |  |      * Waits for the connected tip to change. During node initialization, this will | 
| 95 |  |      * wait until the tip is connected (regardless of `timeout`). | 
| 96 |  |      * | 
| 97 |  |      * @param[in] current_tip block hash of the current chain tip. Function waits | 
| 98 |  |      *                        for the chain tip to differ from this. | 
| 99 |  |      * @param[in] timeout     how long to wait for a new tip (default is forever) | 
| 100 |  |      * | 
| 101 |  |      * @retval BlockRef hash and height of the current chain tip after this call. | 
| 102 |  |      * @retval std::nullopt if the node is shut down. | 
| 103 |  |      */ | 
| 104 |  |     virtual std::optional<BlockRef> waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0; | 
| 105 |  |  | 
| 106 |  |    /** | 
| 107 |  |      * Construct a new block template. | 
| 108 |  |      * | 
| 109 |  |      * During node initialization, this will wait until the tip is connected. | 
| 110 |  |      * | 
| 111 |  |      * @param[in] options options for creating the block | 
| 112 |  |      * @retval BlockTemplate a block template. | 
| 113 |  |      * @retval std::nullptr if the node is shut down. | 
| 114 |  |      */ | 
| 115 |  |     virtual std::unique_ptr<BlockTemplate> createNewBlock(const node::BlockCreateOptions& options = {}) = 0; | 
| 116 |  |  | 
| 117 |  |     /** | 
| 118 |  |      * Checks if a given block is valid. | 
| 119 |  |      * | 
| 120 |  |      * @param[in] block       the block to check | 
| 121 |  |      * @param[in] options     verification options: the proof-of-work check can be | 
| 122 |  |      *                        skipped in order to verify a template generated by | 
| 123 |  |      *                        external software. | 
| 124 |  |      * @param[out] reason     failure reason (BIP22) | 
| 125 |  |      * @param[out] debug      more detailed rejection reason | 
| 126 |  |      * @returns               whether the block is valid | 
| 127 |  |      * | 
| 128 |  |      * For signets the challenge verification is skipped when check_pow is false. | 
| 129 |  |      */ | 
| 130 |  |     virtual bool checkBlock(const CBlock& block, const node::BlockCheckOptions& options, std::string& reason, std::string& debug) = 0; | 
| 131 |  |  | 
| 132 |  |     //! Get internal node context. Useful for RPC and testing, | 
| 133 |  |     //! but not accessible across processes. | 
| 134 | 0 |     virtual node::NodeContext* context() { return nullptr; } | 
| 135 |  | }; | 
| 136 |  |  | 
| 137 |  | //! Return implementation of Mining interface. | 
| 138 |  | std::unique_ptr<Mining> MakeMining(node::NodeContext& node); | 
| 139 |  |  | 
| 140 |  | } // namespace interfaces | 
| 141 |  |  | 
| 142 |  | #endif // BITCOIN_INTERFACES_MINING_H |