Transaction broadcast (#209)
* Add transaction broadcast to all known peers once they have been accepted by our own transaction pool. * Some debug log Fixes #200
This commit is contained in:
@@ -139,6 +139,13 @@ impl Peer {
|
||||
self.proto.send_block(b)
|
||||
}
|
||||
|
||||
/// Sends the provided transaction to the remote peer. The request may be
|
||||
/// dropped if the remote peer is known to already have the transaction.
|
||||
pub fn send_transaction(&self, tx: &core::Transaction) -> Result<(), Error> {
|
||||
// TODO do not send if the peer sent us the tx in the first place
|
||||
self.proto.send_transaction(tx)
|
||||
}
|
||||
|
||||
pub fn send_header_request(&self, locator: Vec<Hash>) -> Result<(), Error> {
|
||||
self.proto.send_header_request(locator)
|
||||
}
|
||||
|
||||
@@ -270,6 +270,20 @@ impl Server {
|
||||
}
|
||||
}
|
||||
|
||||
/// Broadcasts the provided transaction to all our peers. A peer
|
||||
/// implementation may drop the broadcast request if it knows the
|
||||
/// remote peer already has the transaction.
|
||||
pub fn broadcast_transaction(&self, tx: &core::Transaction) {
|
||||
let peers = self.peers.write().unwrap();
|
||||
for p in peers.deref() {
|
||||
if p.is_connected() {
|
||||
if let Err(e) = p.send_transaction(tx) {
|
||||
debug!(LOGGER, "Error sending block to peer: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Number of peers we're currently connected to.
|
||||
pub fn peer_count(&self) -> u32 {
|
||||
self.peers.read().unwrap().len() as u32
|
||||
|
||||
Reference in New Issue
Block a user