mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-21 14:22:38 +02:00
Merge #16452: refactor: use RelayTransaction in BroadcastTransaction utility
9bc8b28c1d26c28edf4bbc890be97c0ad7a73cb9 refactor : use RelayTransaction in BroadcastTransaction utility (Antoine Riard) Pull request description: Implementing suggestion in https://github.com/bitcoin/bitcoin/pull/15713#discussion_r306571420. Seems a reason of these node utilities is to glue with already there functions, so we should reuse them. ACKs for top commit: MarcoFalke: ACK 9bc8b28c1d26c28edf4bbc890be97c0ad7a73cb9 promag: ACK 9bc8b28c1d26c28edf4bbc890be97c0ad7a73cb9, verified there are no more `PushInventory(CInv(MSG_TX, ...`, nice refactor, 👍 @amitiuttarwar. jnewbery: ACK 9bc8b28c1d26c28edf4bbc890be97c0ad7a73cb9 jonatack: ACK 9bc8b28c1d26c28edf4bbc890be97c0ad7a73cb9, second @jnewbery's suggestions, my guess is they could be added without risking delaying this PR. Tree-SHA512: 841c65d5f0d9ead5380814bb2260d7ebf03f2a9bfa58a1025785d353bdb42f9122cc257993e6a7bd2bd3f2c74db19c5978cc14be0d83258124ca22e33d6d0164
This commit is contained in:
commit
7821821a23
@ -9,6 +9,7 @@
|
|||||||
#include <interfaces/handler.h>
|
#include <interfaces/handler.h>
|
||||||
#include <interfaces/wallet.h>
|
#include <interfaces/wallet.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
|
#include <net_processing.h>
|
||||||
#include <node/coin.h>
|
#include <node/coin.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
@ -292,8 +293,7 @@ public:
|
|||||||
}
|
}
|
||||||
void relayTransaction(const uint256& txid) override
|
void relayTransaction(const uint256& txid) override
|
||||||
{
|
{
|
||||||
CInv inv(MSG_TX, txid);
|
RelayTransaction(txid, *g_connman);
|
||||||
g_connman->ForEachNode([&inv](CNode* node) { node->PushInventory(inv); });
|
|
||||||
}
|
}
|
||||||
void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) override
|
void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) override
|
||||||
{
|
{
|
||||||
|
@ -1305,10 +1305,10 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RelayTransaction(const CTransaction& tx, CConnman* connman)
|
void RelayTransaction(const uint256& txid, const CConnman& connman)
|
||||||
{
|
{
|
||||||
CInv inv(MSG_TX, tx.GetHash());
|
CInv inv(MSG_TX, txid);
|
||||||
connman->ForEachNode([&inv](CNode* pnode)
|
connman.ForEachNode([&inv](CNode* pnode)
|
||||||
{
|
{
|
||||||
pnode->PushInventory(inv);
|
pnode->PushInventory(inv);
|
||||||
});
|
});
|
||||||
@ -1811,7 +1811,7 @@ void static ProcessOrphanTx(CConnman* connman, std::set<uint256>& orphan_work_se
|
|||||||
if (setMisbehaving.count(fromPeer)) continue;
|
if (setMisbehaving.count(fromPeer)) continue;
|
||||||
if (AcceptToMemoryPool(mempool, orphan_state, porphanTx, &fMissingInputs2, &removed_txn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
|
if (AcceptToMemoryPool(mempool, orphan_state, porphanTx, &fMissingInputs2, &removed_txn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
|
||||||
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
||||||
RelayTransaction(orphanTx, connman);
|
RelayTransaction(orphanHash, *connman);
|
||||||
for (unsigned int i = 0; i < orphanTx.vout.size(); i++) {
|
for (unsigned int i = 0; i < orphanTx.vout.size(); i++) {
|
||||||
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(orphanHash, i));
|
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(orphanHash, i));
|
||||||
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
|
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
|
||||||
@ -2498,7 +2498,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
|||||||
if (!AlreadyHave(inv) &&
|
if (!AlreadyHave(inv) &&
|
||||||
AcceptToMemoryPool(mempool, state, ptx, &fMissingInputs, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
|
AcceptToMemoryPool(mempool, state, ptx, &fMissingInputs, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
|
||||||
mempool.check(pcoinsTip.get());
|
mempool.check(pcoinsTip.get());
|
||||||
RelayTransaction(tx, connman);
|
RelayTransaction(tx.GetHash(), *connman);
|
||||||
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
||||||
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(inv.hash, i));
|
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(inv.hash, i));
|
||||||
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
|
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
|
||||||
@ -2577,7 +2577,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
|||||||
LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s)\n", tx.GetHash().ToString(), pfrom->GetId(), FormatStateMessage(state));
|
LogPrintf("Not relaying invalid transaction %s from whitelisted peer=%d (%s)\n", tx.GetHash().ToString(), pfrom->GetId(), FormatStateMessage(state));
|
||||||
} else {
|
} else {
|
||||||
LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->GetId());
|
LogPrintf("Force relaying tx %s from whitelisted peer=%d\n", tx.GetHash().ToString(), pfrom->GetId());
|
||||||
RelayTransaction(tx, connman);
|
RelayTransaction(tx.GetHash(), *connman);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,4 +90,7 @@ struct CNodeStateStats {
|
|||||||
/** Get statistics from node state */
|
/** Get statistics from node state */
|
||||||
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
|
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
|
||||||
|
|
||||||
|
/** Relay transaction to every node */
|
||||||
|
void RelayTransaction(const uint256&, const CConnman& connman);
|
||||||
|
|
||||||
#endif // BITCOIN_NET_PROCESSING_H
|
#endif // BITCOIN_NET_PROCESSING_H
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
|
#include <net_processing.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <util/validation.h>
|
#include <util/validation.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
@ -69,10 +70,7 @@ TransactionError BroadcastTransaction(const CTransactionRef tx, uint256& hashTx,
|
|||||||
return TransactionError::P2P_DISABLED;
|
return TransactionError::P2P_DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
CInv inv(MSG_TX, hashTx);
|
RelayTransaction(hashTx, *g_connman);
|
||||||
g_connman->ForEachNode([&inv](CNode* pnode) {
|
|
||||||
pnode->PushInventory(inv);
|
|
||||||
});
|
|
||||||
|
|
||||||
return TransactionError::OK;
|
return TransactionError::OK;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user