Skip to content

Commit 335fe1d

Browse files
authored
Merge pull request #17 from 2140-dev/8-29-txrate
Track inventory annoucements of transactions
2 parents 079c38f + 829d703 commit 335fe1d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ pub enum TimedMessage {
181181
CFilters,
182182
/// Bitcoin blocks
183183
Block,
184-
/// Potential peers on the network
184+
/// Potential peers on the network, either `addr` or `addrv2`.
185185
Addr,
186+
/// Transaction announcements by `Tx`, `WTx`, or `WitnessTransaction`.
187+
TransactionAnnouncement,
186188
}
187189

188190
#[derive(Debug, Clone)]
@@ -196,6 +198,7 @@ impl TimedMessages {
196198
TimedMessage::CFilters,
197199
TimedMessage::Block,
198200
TimedMessage::Addr,
201+
TimedMessage::TransactionAnnouncement,
199202
] {
200203
map.insert(key, MessageRate::new());
201204
}

src/net.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use bitcoin::{
1616
};
1717
use p2p::{
1818
message::{NetworkMessage, RawNetworkMessage, V1MessageHeader},
19+
message_blockdata::Inventory,
1920
Magic, NetworkExt,
2021
};
2122

@@ -336,6 +337,26 @@ impl ConnectionReader {
336337
}
337338
}
338339
}
340+
NetworkMessage::Inv(payload) => {
341+
let payload = &payload.0;
342+
let now = Instant::now();
343+
if let Ok(mut lock) = self.timed_messages.lock() {
344+
for inv in payload {
345+
match inv {
346+
Inventory::WTx(_) => {
347+
lock.add_single(TimedMessage::TransactionAnnouncement, now);
348+
}
349+
Inventory::Transaction(_) => {
350+
lock.add_single(TimedMessage::TransactionAnnouncement, now);
351+
}
352+
Inventory::WitnessTransaction(_) => {
353+
lock.add_single(TimedMessage::TransactionAnnouncement, now);
354+
}
355+
_ => (),
356+
}
357+
}
358+
}
359+
}
339360
_ => (),
340361
}
341362
}

0 commit comments

Comments
 (0)