Skip to content

Commit 6535282

Browse files
committed
Prevent tx send for confirmed txs, add disabled announce logging.
1 parent 6c56434 commit 6535282

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/protocols/protocol_block_out.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,15 @@ bool protocol_block_out::handle_reorganized(code ec, size_t fork_height,
461461
announce.elements().push_back(block->header());
462462

463463
if (!announce.elements().empty())
464+
{
464465
SEND2(announce, handle_send, _1, announce.command);
466+
467+
////const auto hash = announce.elements().front().hash();
468+
////LOG_DEBUG(LOG_NODE)
469+
//// << "Announced block header [" << encode_hash(hash)
470+
//// << "] to [" << authority() << "].";
471+
}
472+
465473
return true;
466474
}
467475
else
@@ -474,7 +482,15 @@ bool protocol_block_out::handle_reorganized(code ec, size_t fork_height,
474482
{ inventory::type_id::block, block->header().hash() });
475483

476484
if (!announce.inventories().empty())
485+
{
477486
SEND2(announce, handle_send, _1, announce.command);
487+
488+
////const auto hash = announce.inventories().front().hash();
489+
////LOG_DEBUG(LOG_NODE)
490+
//// << "Announced block inventory [" << encode_hash(hash)
491+
//// << "] to [" << authority() << "].";
492+
}
493+
478494
return true;
479495
}
480496
}

src/protocols/protocol_transaction_out.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace node {
3333

3434
using namespace bc::blockchain;
3535
using namespace bc::chain;
36+
using namespace bc::database;
3637
using namespace bc::message;
3738
using namespace bc::network;
3839
using namespace std::placeholders;
@@ -175,12 +176,16 @@ void protocol_transaction_out::send_next_data(inventory_ptr inventory)
175176

176177
// TODO: send block_transaction message as applicable.
177178
void protocol_transaction_out::send_transaction(const code& ec,
178-
transaction_ptr transaction, size_t, size_t, inventory_ptr inventory)
179+
transaction_ptr transaction, size_t, size_t position,
180+
inventory_ptr inventory)
179181
{
180182
if (stopped(ec))
181183
return;
182184

183-
if (ec == error::not_found)
185+
// Treat already confirmed transactions as not found.
186+
auto confirmed = !ec && position != transaction_database::unconfirmed;
187+
188+
if (ec == error::not_found || confirmed)
184189
{
185190
LOG_DEBUG(LOG_NODE)
186191
<< "Transaction requested by [" << authority() << "] not found.";
@@ -189,6 +194,8 @@ void protocol_transaction_out::send_transaction(const code& ec,
189194
BITCOIN_ASSERT(!inventory->inventories().empty());
190195
const not_found reply{ inventory->inventories().back() };
191196
SEND2(reply, handle_send, _1, reply.command);
197+
198+
// TODO: recursion hazard.
192199
handle_send_next(error::success, inventory);
193200
return;
194201
}
@@ -243,6 +250,10 @@ bool protocol_transaction_out::handle_notification(const code& ec,
243250
static const auto id = inventory::type_id::transaction;
244251
const inventory announce{ { id, message->hash() } };
245252
SEND2(announce, handle_send, _1, announce.command);
253+
254+
////LOG_DEBUG(LOG_NODE)
255+
//// << "Announced tx [" << encode_hash(message->hash()) << "] to ["
256+
//// << authority() << "].";
246257
return true;
247258
}
248259

0 commit comments

Comments
 (0)