mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-08-04 14:04:49 +02:00
Merge 28345 via fix_bytespersigop_checks-mini
This commit is contained in:
commit
7750cf2b3f
@ -20,6 +20,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class BanMan;
|
class BanMan;
|
||||||
@ -208,7 +209,7 @@ public:
|
|||||||
virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0;
|
virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0;
|
||||||
|
|
||||||
//! Broadcast transaction.
|
//! 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.
|
//! Get wallet loader.
|
||||||
virtual WalletLoader& walletLoader() = 0;
|
virtual WalletLoader& walletLoader() = 0;
|
||||||
|
@ -338,7 +338,7 @@ public:
|
|||||||
if (chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin)) return coin;
|
if (chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin)) return coin;
|
||||||
return {};
|
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);
|
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.
|
// BroadcastTransaction can be called by RPC or by the wallet.
|
||||||
// chainman, mempool and peerman are initialized before the RPC server and wallet are started
|
// chainman, mempool and peerman are initialized before the RPC server and wallet are started
|
||||||
@ -68,16 +68,25 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||||||
wtxid = mempool_tx->GetWitnessHash();
|
wtxid = mempool_tx->GetWitnessHash();
|
||||||
} else {
|
} else {
|
||||||
// Transaction is not already in the mempool.
|
// 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
|
// First, call ATMP with test_accept and check the fee. If ATMP
|
||||||
// fails here, return error immediately.
|
// fails here, return error immediately.
|
||||||
const MempoolAcceptResult result = node.chainman->ProcessTransaction(tx, /*test_accept=*/ true);
|
const MempoolAcceptResult result = node.chainman->ProcessTransaction(tx, /*test_accept=*/ true);
|
||||||
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
||||||
return HandleATMPError(result.m_state, err_string);
|
return HandleATMPError(result.m_state, err_string);
|
||||||
} else if (result.m_base_fees.value() > max_tx_fee) {
|
} 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;
|
return TransactionError::MAX_FEE_EXCEEDED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Try to submit the transaction to the mempool.
|
// Try to submit the transaction to the mempool.
|
||||||
const MempoolAcceptResult result = node.chainman->ProcessTransaction(tx, /*test_accept=*/ false);
|
const MempoolAcceptResult result = node.chainman->ProcessTransaction(tx, /*test_accept=*/ false);
|
||||||
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <util/error.h>
|
#include <util/error.h>
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
class CTxMemPool;
|
class CTxMemPool;
|
||||||
namespace Consensus {
|
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.
|
* @param[in] wait_callback wait until callbacks have been processed to avoid stale result due to a sequentially RPC.
|
||||||
* return error
|
* 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.
|
* Return transaction with a given hash.
|
||||||
|
@ -116,7 +116,7 @@ void PSBTOperationsDialog::broadcastTransaction()
|
|||||||
CTransactionRef tx = MakeTransactionRef(mtx);
|
CTransactionRef tx = MakeTransactionRef(mtx);
|
||||||
std::string err_string;
|
std::string err_string;
|
||||||
TransactionError error =
|
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) {
|
if (error == TransactionError::OK) {
|
||||||
showStatus(tr("Transaction broadcast successfully! Transaction ID: %1")
|
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))};
|
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;
|
std::string err_string;
|
||||||
AssertLockNotHeld(cs_main);
|
AssertLockNotHeld(cs_main);
|
||||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
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) {
|
if (TransactionError::OK != err) {
|
||||||
throw JSONRPCTransactionError(err, err_string);
|
throw JSONRPCTransactionError(err, err_string);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user