mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 12:49:23 +00:00
Connect broadcast
This commit is contained in:
@@ -48,6 +48,7 @@ pub(crate) struct TendermintImport<T: TendermintValidator> {
|
||||
validators: Arc<TendermintValidators<T>>,
|
||||
|
||||
number: Arc<RwLock<u64>>,
|
||||
gossip_queue: Arc<RwLock<Vec<SignedMessage<u16, T::Block, Signature>>>>,
|
||||
importing_block: Arc<RwLock<Option<<T::Block as Block>::Hash>>>,
|
||||
pub(crate) machine: Arc<RwLock<Option<TendermintHandle<Self>>>>,
|
||||
|
||||
@@ -108,7 +109,20 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
|
||||
let mut last_number = last_number.0 + 1;
|
||||
let mut recv = gossip
|
||||
.messages_for(TendermintGossip::<TendermintValidators<T>>::topic::<T::Block>(last_number));
|
||||
loop {
|
||||
'outer: loop {
|
||||
// Send out any queued messages
|
||||
let mut queue = self.0.gossip_queue.write().unwrap().drain(..).collect::<Vec<_>>();
|
||||
for msg in queue.drain(..) {
|
||||
gossip.gossip_message(
|
||||
TendermintGossip::<TendermintValidators<T>>::topic::<T::Block>(msg.number().0),
|
||||
msg.encode(),
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
// Handle any received messages
|
||||
// Makes sure to handle all pending messages before acquiring the out-queue lock again
|
||||
'inner: loop {
|
||||
match recv.try_next() {
|
||||
Ok(Some(msg)) => handle
|
||||
.messages
|
||||
@@ -121,7 +135,7 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
|
||||
})
|
||||
.await
|
||||
.unwrap(),
|
||||
Ok(None) => break,
|
||||
Ok(None) => break 'outer,
|
||||
// No messages available
|
||||
Err(_) => {
|
||||
// Check if we the block updated and should be listening on a different topic
|
||||
@@ -135,6 +149,8 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
|
||||
>(last_number));
|
||||
}
|
||||
yield_now().await;
|
||||
break 'inner;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,6 +165,7 @@ impl<T: TendermintValidator> Clone for TendermintImport<T> {
|
||||
validators: self.validators.clone(),
|
||||
|
||||
number: self.number.clone(),
|
||||
gossip_queue: self.gossip_queue.clone(),
|
||||
importing_block: self.importing_block.clone(),
|
||||
machine: self.machine.clone(),
|
||||
|
||||
@@ -175,6 +192,7 @@ impl<T: TendermintValidator> TendermintImport<T> {
|
||||
validators: Arc::new(TendermintValidators::new(client.clone())),
|
||||
|
||||
number: Arc::new(RwLock::new(0)),
|
||||
gossip_queue: Arc::new(RwLock::new(vec![])),
|
||||
importing_block: Arc::new(RwLock::new(None)),
|
||||
machine: Arc::new(RwLock::new(None)),
|
||||
|
||||
@@ -359,7 +377,7 @@ impl<T: TendermintValidator> Network for TendermintImport<T> {
|
||||
}
|
||||
|
||||
async fn broadcast(&mut self, msg: SignedMessage<u16, Self::Block, Signature>) {
|
||||
// TODO
|
||||
self.gossip_queue.write().unwrap().push(msg);
|
||||
}
|
||||
|
||||
async fn slash(&mut self, validator: u16) {
|
||||
|
||||
Reference in New Issue
Block a user