mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-17 01:17:36 +00:00
Use an inner task to spawn Tributarys to minimize latency
This commit is contained in:
parent
1d9e2efc33
commit
15edea1389
1 changed files with 12 additions and 10 deletions
|
@ -58,7 +58,7 @@ pub struct ActiveTributary<D: Db, P: P2p> {
|
||||||
pub tributary: Arc<Tributary<D, Transaction, P>>,
|
pub tributary: Arc<Tributary<D, Transaction, P>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a tributary into the specified HashMap
|
// Creates a new tributary and sends it to all listeners.
|
||||||
async fn add_tributary<D: Db, Pro: Processors, P: P2p>(
|
async fn add_tributary<D: Db, Pro: Processors, P: P2p>(
|
||||||
db: D,
|
db: D,
|
||||||
key: Zeroizing<<Ristretto as Ciphersuite>::F>,
|
key: Zeroizing<<Ristretto as Ciphersuite>::F>,
|
||||||
|
@ -1050,15 +1050,17 @@ pub async fn run<D: Db, Pro: Processors, P: P2p>(
|
||||||
async move {
|
async move {
|
||||||
loop {
|
loop {
|
||||||
let spec = new_tributary_spec_recv.recv().await.unwrap();
|
let spec = new_tributary_spec_recv.recv().await.unwrap();
|
||||||
add_tributary(
|
// Uses an inner task as Tributary::new may take several seconds
|
||||||
raw_db.clone(),
|
tokio::spawn({
|
||||||
key.clone(),
|
let raw_db = raw_db.clone();
|
||||||
&processors,
|
let key = key.clone();
|
||||||
p2p.clone(),
|
let processors = processors.clone();
|
||||||
&new_tributary,
|
let p2p = p2p.clone();
|
||||||
spec.clone(),
|
let new_tributary = new_tributary.clone();
|
||||||
)
|
async move {
|
||||||
.await;
|
add_tributary(raw_db, key, &processors, p2p, &new_tributary, spec).await;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue