Skip to content

Commit 86c4815

Browse files
authored
Merge pull request #1026 from josibake/relay-broadcast-transactions
relay broadcast transactions to peers
2 parents 31b10ba + 921c7f3 commit 86c4815

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

include/bitcoin/node/protocols/protocol_transaction_out_106.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,17 @@ class BCN_API protocol_transaction_out_106
5454
/// Process tx announcement.
5555
virtual bool do_announce(transaction_t link) NOEXCEPT;
5656

57+
virtual bool handle_broadcast_transaction(const code& ec,
58+
const network::messages::peer::transaction::cptr& message,
59+
uint64_t sender) NOEXCEPT;
60+
5761
virtual bool handle_receive_get_data(const code& ec,
5862
const network::messages::peer::get_data::cptr& message) NOEXCEPT;
5963
virtual void send_transaction(const code& ec, size_t index,
6064
const network::messages::peer::get_data::cptr& message) NOEXCEPT;
6165

66+
virtual bool announce(const system::hash_digest& hash) NOEXCEPT;
67+
6268
private:
6369
// These are thread safe.
6470
const bool node_witness_;

src/protocols/protocol_transaction_out_106.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void protocol_transaction_out_106::start() NOEXCEPT
4545

4646
// Events subscription is asynchronous, events may be missed.
4747
subscribe_chase(BIND(handle_chase, _1, _2, _3));
48+
SUBSCRIBE_BROADCAST(transaction, handle_broadcast_transaction, _1, _2, _3);
4849
SUBSCRIBE_CHANNEL(get_data, handle_receive_get_data, _1, _2);
4950
protocol_peer::start();
5051
}
@@ -54,6 +55,7 @@ void protocol_transaction_out_106::stopping(const code& ec) NOEXCEPT
5455
// Unsubscriber race is ok.
5556
BC_ASSERT(stranded());
5657
unsubscribe_chase();
58+
UNSUBSCRIBE_BROADCAST();
5759
protocol_peer::stopping(ec);
5860
}
5961

@@ -98,8 +100,30 @@ bool protocol_transaction_out_106::do_announce(transaction_t link) NOEXCEPT
98100
if (stopped())
99101
return false;
100102

101-
// Don't announce to peer that announced to us.
102-
const auto hash = query.get_tx_key(link);
103+
return announce(query.get_tx_key(link));
104+
}
105+
106+
bool protocol_transaction_out_106::handle_broadcast_transaction(const code& ec,
107+
const transaction::cptr& message, uint64_t sender) NOEXCEPT
108+
{
109+
BC_ASSERT(stranded());
110+
111+
if (stopped(ec))
112+
return false;
113+
114+
if (sender == identifier())
115+
return true;
116+
117+
if (!message || !message->transaction_ptr)
118+
return true;
119+
120+
return announce(message->transaction_ptr->hash(false));
121+
}
122+
123+
bool protocol_transaction_out_106::announce(const hash_digest& hash) NOEXCEPT
124+
{
125+
BC_ASSERT(stranded());
126+
103127
if (was_announced(hash))
104128
return true;
105129

0 commit comments

Comments
 (0)