mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-03 07:52:33 +02:00
Merge 28345 via fix_bytespersigop_checks-mini
This commit is contained in:
commit
7750cf2b3f
@ -20,6 +20,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
class BanMan;
|
||||
@ -208,7 +209,7 @@ public:
|
||||
virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0;
|
||||
|
||||
//! Broadcast transaction.
|
||||
virtual TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) = 0;
|
||||
virtual TransactionError broadcastTransaction(CTransactionRef tx, const std::variant<CAmount, CFeeRate>& max_tx_fee, std::string& err_string) = 0;
|
||||
|
||||
//! Get wallet loader.
|
||||
virtual WalletLoader& walletLoader() = 0;
|
||||
|
@ -338,7 +338,7 @@ public:
|
||||
if (chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin)) return coin;
|
||||
return {};
|
||||
}
|
||||
TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) override
|
||||
TransactionError broadcastTransaction(CTransactionRef tx, const std::variant<CAmount, CFeeRate>& max_tx_fee, std::string& err_string) override
|
||||
{
|
||||
return BroadcastTransaction(*m_context, std::move(tx), err_string, max_tx_fee, /*relay=*/ true, /*wait_callback=*/ false);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ static TransactionError HandleATMPError(const TxValidationState& state, std::str
|
||||
}
|
||||
}
|
||||
|
||||
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
|
||||
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const std::variant<CAmount, CFeeRate>& max_tx_fee, bool relay, bool wait_callback)
|
||||
{
|
||||
// BroadcastTransaction can be called by RPC or by the wallet.
|
||||
// chainman, mempool and peerman are initialized before the RPC server and wallet are started
|
||||
@ -68,14 +68,23 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
||||
wtxid = mempool_tx->GetWitnessHash();
|
||||
} else {
|
||||
// Transaction is not already in the mempool.
|
||||
if (max_tx_fee > 0) {
|
||||
const bool max_tx_fee_set{(std::holds_alternative<CAmount>(max_tx_fee) ? std::get<CAmount>(max_tx_fee) : std::get<CFeeRate>(max_tx_fee).GetFeePerK()) > 0};
|
||||
if (max_tx_fee_set) {
|
||||
// First, call ATMP with test_accept and check the fee. If ATMP
|
||||
// fails here, return error immediately.
|
||||
const MempoolAcceptResult result = node.chainman->ProcessTransaction(tx, /*test_accept=*/ true);
|
||||
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
||||
return HandleATMPError(result.m_state, err_string);
|
||||
} else if (result.m_base_fees.value() > max_tx_fee) {
|
||||
return TransactionError::MAX_FEE_EXCEEDED;
|
||||
} else {
|
||||
CAmount max_tx_fee_abs;
|
||||
if (std::holds_alternative<CFeeRate>(max_tx_fee)) {
|
||||
max_tx_fee_abs = std::get<CFeeRate>(max_tx_fee).GetFee(*Assert(result.m_vsize));
|
||||
} else {
|
||||
max_tx_fee_abs = std::get<CAmount>(max_tx_fee);
|
||||
}
|
||||
if (result.m_base_fees.value() > max_tx_fee_abs) {
|
||||
return TransactionError::MAX_FEE_EXCEEDED;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Try to submit the transaction to the mempool.
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <primitives/transaction.h>
|
||||
#include <util/error.h>
|
||||
|
||||
#include <variant>
|
||||
|
||||
class CBlockIndex;
|
||||
class CTxMemPool;
|
||||
namespace Consensus {
|
||||
@ -43,7 +45,7 @@ static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
|
||||
* @param[in] wait_callback wait until callbacks have been processed to avoid stale result due to a sequentially RPC.
|
||||
* return error
|
||||
*/
|
||||
[[nodiscard]] TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback);
|
||||
[[nodiscard]] TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, std::string& err_string, const std::variant<CAmount, CFeeRate>& max_tx_fee, bool relay, bool wait_callback);
|
||||
|
||||
/**
|
||||
* Return transaction with a given hash.
|
||||
|
@ -116,7 +116,7 @@ void PSBTOperationsDialog::broadcastTransaction()
|
||||
CTransactionRef tx = MakeTransactionRef(mtx);
|
||||
std::string err_string;
|
||||
TransactionError error =
|
||||
m_client_model->node().broadcastTransaction(tx, DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK(), err_string);
|
||||
m_client_model->node().broadcastTransaction(tx, DEFAULT_MAX_RAW_TX_FEE_RATE, err_string);
|
||||
|
||||
if (error == TransactionError::OK) {
|
||||
showStatus(tr("Transaction broadcast successfully! Transaction ID: %1")
|
||||
|
@ -83,13 +83,10 @@ static RPCHelpMan sendrawtransaction()
|
||||
|
||||
const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>(1))};
|
||||
|
||||
int64_t virtual_size = GetVirtualTransactionSize(*tx);
|
||||
CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
|
||||
|
||||
std::string err_string;
|
||||
AssertLockNotHeld(cs_main);
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
const TransactionError err = BroadcastTransaction(node, tx, err_string, max_raw_tx_fee, /*relay=*/true, /*wait_callback=*/true);
|
||||
const TransactionError err = BroadcastTransaction(node, tx, err_string, max_raw_tx_fee_rate, /*relay=*/true, /*wait_callback=*/true);
|
||||
if (TransactionError::OK != err) {
|
||||
throw JSONRPCTransactionError(err, err_string);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user