Merge bitcoin/bitcoin#33962: refactor: replace manual promise with SyncWithValidationInterfaceQueue
e71c4df168refactor: replace manual promise with SyncWithValidationInterfaceQueue (ANtutov) Pull request description: `BroadcastTransaction()` now waits for validation callbacks using the built-in `validation_signals>SyncWithValidationInterfaceQueue()` instead of creating a local `std::promise` and scheduling a lambda. This removes an unnecessary allocation and uses the canonical API. ACKs for top commit: maflcko: review ACKe71c4df168🌃 rkrux: lgtm ACKe71c4df168sedited: ACKe71c4df168Tree-SHA512: 602994ba3c2ac91996068aee6eac7e788c3832d7ab949519a9420d2b59e2a67d2d4e67c3c9191ba60e9caa75f1524a95b0851fcd40b6732f6a9956a011b4a120
This commit is contained in:
1 file changed
+1
-7
@@ -15,8 +15,6 @@
|
|||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
#include <node/transaction.h>
|
#include <node/transaction.h>
|
||||||
|
|
||||||
#include <future>
|
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
static TransactionError HandleATMPError(const TxValidationState& state, std::string& err_string_out)
|
static TransactionError HandleATMPError(const TxValidationState& state, std::string& err_string_out)
|
||||||
{
|
{
|
||||||
@@ -45,7 +43,6 @@ TransactionError BroadcastTransaction(NodeContext& node,
|
|||||||
assert(node.mempool);
|
assert(node.mempool);
|
||||||
assert(node.peerman);
|
assert(node.peerman);
|
||||||
|
|
||||||
std::promise<void> promise;
|
|
||||||
Txid txid = tx->GetHash();
|
Txid txid = tx->GetHash();
|
||||||
Wtxid wtxid = tx->GetWitnessHash();
|
Wtxid wtxid = tx->GetWitnessHash();
|
||||||
bool callback_set = false;
|
bool callback_set = false;
|
||||||
@@ -118,9 +115,6 @@ TransactionError BroadcastTransaction(NodeContext& node,
|
|||||||
// with a transaction to/from their wallet, immediately call some
|
// with a transaction to/from their wallet, immediately call some
|
||||||
// wallet RPC, and get a stale result because callbacks have not
|
// wallet RPC, and get a stale result because callbacks have not
|
||||||
// yet been processed.
|
// yet been processed.
|
||||||
node.validation_signals->CallFunctionInValidationInterfaceQueue([&promise] {
|
|
||||||
promise.set_value();
|
|
||||||
});
|
|
||||||
callback_set = true;
|
callback_set = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +123,7 @@ TransactionError BroadcastTransaction(NodeContext& node,
|
|||||||
if (callback_set) {
|
if (callback_set) {
|
||||||
// Wait until Validation Interface clients have been notified of the
|
// Wait until Validation Interface clients have been notified of the
|
||||||
// transaction entering the mempool.
|
// transaction entering the mempool.
|
||||||
promise.get_future().wait();
|
node.validation_signals->SyncWithValidationInterfaceQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (broadcast_method) {
|
switch (broadcast_method) {
|
||||||
|
|||||||
Reference in new issue
Block a user