Skip to content

Commit e48f0ee

Browse files
authored
Merge pull request #284 from evoskuil/master
Prevent tx send for confirmed txs, add disabled announce logging.
2 parents 6c56434 + 853f319 commit e48f0ee

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

data/bn.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ protocol_minimum = 31402
2929
services = 1
3030
# The magic number for message headers, defaults to 3652501241 (use 118034699 for testnet).
3131
identifier = 3652501241
32+
# Validate the checksum of network messages, defaults to false.
33+
validate_checksum = false
3234
# The port for incoming connections, defaults to 8333 (use 18333 for testnet).
3335
inbound_port = 8333
3436
# The target number of incoming network connections, defaults to 8.

src/parser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ options_metadata parser::load_settings()
192192
value<uint64_t>(&configured.network.services),
193193
"The services exposed by network connections, defaults to 1 (full node)."
194194
)
195+
(
196+
"network.validate_checksum",
197+
value<bool>(&configured.network.validate_checksum),
198+
"Validate the checksum of network messages, defaults to false."
199+
)
195200
(
196201
"network.identifier",
197202
value<uint32_t>(&configured.network.identifier),

src/protocols/protocol_block_in.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ bool protocol_block_in::handle_receive_headers(const code& ec,
211211
message->to_inventory(response->inventories(), inventory::type_id::block);
212212

213213
// Remove hashes of blocks that we already have.
214-
// BUGBUG: this removes blocks that are not in the main chain.
215214
chain_.filter_blocks(response, BIND2(send_get_data, _1, response));
216215
return true;
217216
}
@@ -227,7 +226,6 @@ bool protocol_block_in::handle_receive_inventory(const code& ec,
227226
message->reduce(response->inventories(), inventory::type_id::block);
228227

229228
// Remove hashes of blocks that we already have.
230-
// BUGBUG: this removes blocks that are not in the main chain.
231229
chain_.filter_blocks(response, BIND2(send_get_data, _1, response));
232230
return true;
233231
}

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)