-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
504 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
//! Transaction Pool | ||
//! | ||
//! Will handle initiating the tx-pool, providing the preprocessor required for the dandelion pool. | ||
|
||
mod dandelion; | ||
mod incoming_tx; | ||
mod manager; | ||
mod txs_being_handled; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use bytes::Bytes; | ||
use cuprate_dandelion_tower::{DandelionConfig, DandelionRouter}; | ||
use cuprate_p2p::NetworkInterface; | ||
use cuprate_p2p_core::ClearNet; | ||
use cuprate_wire::NetworkAddress; | ||
|
||
mod diffuse_service; | ||
mod stem_service; | ||
mod tx_store; | ||
|
||
struct DandelionTx(Bytes); | ||
|
||
type TxId = [u8; 32]; | ||
|
||
pub fn start_dandelion_router( | ||
clear_net: NetworkInterface<ClearNet>, | ||
) -> DandelionRouter< | ||
stem_service::OutboundPeerStream, | ||
diffuse_service::DiffuseService, | ||
NetworkAddress, | ||
stem_service::StemPeerService<ClearNet>, | ||
DandelionTx, | ||
> { | ||
DandelionRouter::new( | ||
diffuse_service::DiffuseService { | ||
clear_net_broadcast_service: clear_net.broadcast_svc(), | ||
}, | ||
stem_service::OutboundPeerStream { | ||
clear_net: clear_net.clone(), | ||
}, | ||
DandelionConfig { | ||
time_between_hop: Default::default(), | ||
epoch_duration: Default::default(), | ||
fluff_probability: 0.0, | ||
graph: Default::default(), | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::task::{Context, Poll}; | ||
use tower::Service; | ||
|
||
use crate::txpool::dandelion::DandelionTx; | ||
use cuprate_dandelion_tower::traits::DiffuseRequest; | ||
use cuprate_p2p::{BroadcastRequest, BroadcastSvc, NetworkInterface}; | ||
use cuprate_p2p_core::ClearNet; | ||
|
||
pub struct DiffuseService { | ||
pub clear_net_broadcast_service: BroadcastSvc<ClearNet>, | ||
} | ||
|
||
impl Service<DiffuseRequest<DandelionTx>> for DiffuseService { | ||
type Response = BroadcastSvc::Response; | ||
type Error = tower::BoxError; | ||
type Future = BroadcastSvc::Future; | ||
|
||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.clear_net_broadcast_service | ||
.poll_ready(cx) | ||
.map_err(Into::into) | ||
} | ||
|
||
fn call(&mut self, req: DiffuseRequest<DandelionTx>) -> Self::Future { | ||
self.clear_net_broadcast_service | ||
.call(BroadcastRequest::Transaction { | ||
tx_bytes: req.0 .0, | ||
direction: None, | ||
received_from: None, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use super::DandelionTx; | ||
use bytes::Bytes; | ||
use cuprate_dandelion_tower::traits::StemRequest; | ||
use cuprate_dandelion_tower::OutboundPeer; | ||
use cuprate_p2p::NetworkInterface; | ||
use cuprate_p2p_core::client::Client; | ||
use cuprate_p2p_core::{ClearNet, NetworkZone, PeerRequest, ProtocolRequest}; | ||
use cuprate_wire::protocol::NewTransactions; | ||
use cuprate_wire::NetworkAddress; | ||
use futures::Stream; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
use tower::Service; | ||
|
||
pub struct OutboundPeerStream { | ||
pub clear_net: NetworkInterface<ClearNet>, | ||
} | ||
|
||
impl Stream for OutboundPeerStream { | ||
type Item = Result<OutboundPeer<NetworkAddress, StemPeerService<ClearNet>>, tower::BoxError>; | ||
|
||
fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>> { | ||
Poll::Ready(Some(Ok(self | ||
.clear_net | ||
.client_pool() | ||
.outbound_client() | ||
.map_or(OutboundPeer::Exhausted, |client| { | ||
OutboundPeer::Peer(client.info.id.into(), StemPeerService(client)) | ||
})))) | ||
} | ||
} | ||
|
||
pub struct StemPeerService<N>(Client<N>); | ||
|
||
impl<N: NetworkZone> Service<StemRequest<DandelionTx>> for StemPeerService<N> { | ||
type Response = (); | ||
type Error = tower::BoxError; | ||
type Future = Client::Future; | ||
|
||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.0.poll_ready(cx) | ||
} | ||
|
||
fn call(&mut self, req: StemRequest<DandelionTx>) -> Self::Future { | ||
self.0 | ||
.call(PeerRequest::Protocol(ProtocolRequest::NewTransactions( | ||
NewTransactions { | ||
txs: vec![req.0 .0], | ||
dandelionpp_fluff: false, | ||
padding: Bytes::new(), | ||
}, | ||
))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::txpool::dandelion::{DandelionTx, TxId}; | ||
use bytes::Bytes; | ||
use cuprate_dandelion_tower::traits::{TxStoreRequest, TxStoreResponse}; | ||
use cuprate_database::RuntimeError; | ||
use cuprate_txpool::service::interface::{TxpoolReadRequest, TxpoolReadResponse}; | ||
use cuprate_txpool::service::{TxpoolReadHandle, TxpoolWriteHandle}; | ||
use futures::future::BoxFuture; | ||
use futures::{FutureExt, StreamExt, TryFutureExt}; | ||
use std::task::{Context, Poll}; | ||
use tower::util::Oneshot; | ||
use tower::{Service, ServiceExt}; | ||
|
||
pub struct TxStoreService { | ||
txpool_read_handle: TxpoolReadHandle, | ||
txpool_write_handle: TxpoolWriteHandle, | ||
} | ||
|
||
impl Service<TxStoreRequest<TxId>> for TxStoreService { | ||
type Response = TxStoreResponse<DandelionTx>; | ||
type Error = tower::BoxError; | ||
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>; | ||
|
||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
Poll::Ready(Ok(())) | ||
} | ||
|
||
fn call(&mut self, req: TxStoreRequest<TxId>) -> Self::Future { | ||
match req { | ||
TxStoreRequest::Get(tx_id) => self | ||
.txpool_read_handle | ||
.clone() | ||
.oneshot(TxpoolReadRequest::TxBlob(tx_id)) | ||
.map(|res| match res { | ||
Ok(TxpoolReadResponse::TxBlob(blob)) => Ok(TxStoreResponse::Transaction(Some( | ||
(DandelionTx(Bytes::from(blob)), todo!()), | ||
))), | ||
Err(RuntimeError::KeyNotFound) => Ok(TxStoreResponse::Transaction(None)), | ||
Err(e) => Err(e.into()), | ||
Ok(_) => unreachable!(), | ||
}) | ||
.boxed(), | ||
TxStoreRequest::Promote(tx_id) => { | ||
todo!() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.