Bitcoin Core  24.1.0
P2P Digital Currency
feebumper.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2020 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_WALLET_FEEBUMPER_H
6 #define BITCOIN_WALLET_FEEBUMPER_H
7 
8 #include <consensus/consensus.h>
9 #include <script/interpreter.h>
10 #include <primitives/transaction.h>
11 
12 class uint256;
13 enum class FeeEstimateMode;
14 struct bilingual_str;
15 
16 namespace wallet {
17 class CCoinControl;
18 class CWallet;
19 class CWalletTx;
20 
21 namespace feebumper {
22 
23 enum class Result
24 {
25  OK,
30  MISC_ERROR,
31 };
32 
34 bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid);
35 
48  const uint256& txid,
49  const CCoinControl& coin_control,
50  std::vector<bilingual_str>& errors,
51  CAmount& old_fee,
52  CAmount& new_fee,
54  bool require_mine);
55 
60 
66  const uint256& txid,
67  CMutableTransaction&& mtx,
68  std::vector<bilingual_str>& errors,
69  uint256& bumped_txid);
70 
72 {
73 private:
74  int m_sigs_count{0};
75  int64_t m_sigs_weight{0};
76 
77 public:
78  void AddSigWeight(const size_t weight, const SigVersion sigversion)
79  {
80  switch (sigversion) {
81  case SigVersion::BASE:
84  break;
86  m_sigs_weight += weight;
87  m_sigs_count++;
88  break;
91  assert(false);
92  }
93  }
94 
95  int64_t GetWeightDiffToMax() const
96  {
97  // Note: the witness scaling factor is already accounted for because the count is multiplied by it.
98  return (/* max signature size=*/ 72 * m_sigs_count) - m_sigs_weight;
99  }
100 };
101 
103 {
104 private:
106 
107 public:
109 
110  bool CheckECDSASignature(const std::vector<unsigned char>& sig, const std::vector<unsigned char>& pubkey, const CScript& script, SigVersion sigversion) const override
111  {
112  if (m_checker.CheckECDSASignature(sig, pubkey, script, sigversion)) {
113  m_weights.AddSigWeight(sig.size(), sigversion);
114  return true;
115  }
116  return false;
117  }
118 };
119 
120 } // namespace feebumper
121 } // namespace wallet
122 
123 #endif // BITCOIN_WALLET_FEEBUMPER_H
virtual bool CheckECDSASignature(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
Definition: interpreter.h:246
const BaseSignatureChecker & m_checker
Definition: interpreter.h:310
Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, key path spending; see BIP 341...
static const int WITNESS_SCALE_FACTOR
Definition: consensus.h:21
assert(!tx.IsCoinBase())
Bilingual messages:
Definition: translation.h:18
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, script path spending, leaf version 0xc0; see...
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
Definition: feebumper.cpp:146
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
Definition: feebumper.cpp:299
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool CheckECDSASignature(const std::vector< unsigned char > &sig, const std::vector< unsigned char > &pubkey, const CScript &script, SigVersion sigversion) const override
Definition: feebumper.h:110
SignatureWeightChecker(SignatureWeights &weights, const BaseSignatureChecker &checker)
Definition: feebumper.h:108
int64_t GetWeightDiffToMax() const
Definition: feebumper.h:95
FeeEstimateMode
Definition: feerate.h:21
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:235
Definition: node.h:39
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
Definition: feebumper.cpp:294
256-bit opaque blob.
Definition: uint256.h:119
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:410
A mutable version of CTransaction.
Definition: transaction.h:372
void AddSigWeight(const size_t weight, const SigVersion sigversion)
Definition: feebumper.h:78
Result CreateRateBumpTransaction(CWallet &wallet, const uint256 &txid, const CCoinControl &coin_control, std::vector< bilingual_str > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx, bool require_mine)
Create bumpfee transaction based on feerate estimates.
Definition: feebumper.cpp:157
Coin Control Features.
Definition: coincontrol.h:29
SigVersion
Definition: interpreter.h:188