mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 21:19:24 +00:00
Connect broadcast
This commit is contained in:
@@ -48,6 +48,7 @@ pub(crate) struct TendermintImport<T: TendermintValidator> {
|
|||||||
validators: Arc<TendermintValidators<T>>,
|
validators: Arc<TendermintValidators<T>>,
|
||||||
|
|
||||||
number: Arc<RwLock<u64>>,
|
number: Arc<RwLock<u64>>,
|
||||||
|
gossip_queue: Arc<RwLock<Vec<SignedMessage<u16, T::Block, Signature>>>>,
|
||||||
importing_block: Arc<RwLock<Option<<T::Block as Block>::Hash>>>,
|
importing_block: Arc<RwLock<Option<<T::Block as Block>::Hash>>>,
|
||||||
pub(crate) machine: Arc<RwLock<Option<TendermintHandle<Self>>>>,
|
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 last_number = last_number.0 + 1;
|
||||||
let mut recv = gossip
|
let mut recv = gossip
|
||||||
.messages_for(TendermintGossip::<TendermintValidators<T>>::topic::<T::Block>(last_number));
|
.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() {
|
match recv.try_next() {
|
||||||
Ok(Some(msg)) => handle
|
Ok(Some(msg)) => handle
|
||||||
.messages
|
.messages
|
||||||
@@ -121,7 +135,7 @@ impl<T: TendermintValidator> TendermintAuthority<T> {
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Ok(None) => break,
|
Ok(None) => break 'outer,
|
||||||
// No messages available
|
// No messages available
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Check if we the block updated and should be listening on a different topic
|
// 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));
|
>(last_number));
|
||||||
}
|
}
|
||||||
yield_now().await;
|
yield_now().await;
|
||||||
|
break 'inner;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,6 +165,7 @@ impl<T: TendermintValidator> Clone for TendermintImport<T> {
|
|||||||
validators: self.validators.clone(),
|
validators: self.validators.clone(),
|
||||||
|
|
||||||
number: self.number.clone(),
|
number: self.number.clone(),
|
||||||
|
gossip_queue: self.gossip_queue.clone(),
|
||||||
importing_block: self.importing_block.clone(),
|
importing_block: self.importing_block.clone(),
|
||||||
machine: self.machine.clone(),
|
machine: self.machine.clone(),
|
||||||
|
|
||||||
@@ -175,6 +192,7 @@ impl<T: TendermintValidator> TendermintImport<T> {
|
|||||||
validators: Arc::new(TendermintValidators::new(client.clone())),
|
validators: Arc::new(TendermintValidators::new(client.clone())),
|
||||||
|
|
||||||
number: Arc::new(RwLock::new(0)),
|
number: Arc::new(RwLock::new(0)),
|
||||||
|
gossip_queue: Arc::new(RwLock::new(vec![])),
|
||||||
importing_block: Arc::new(RwLock::new(None)),
|
importing_block: Arc::new(RwLock::new(None)),
|
||||||
machine: 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>) {
|
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) {
|
async fn slash(&mut self, validator: u16) {
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
weights: weights.clone(),
|
weights: weights.clone(),
|
||||||
proposer,
|
proposer,
|
||||||
|
|
||||||
number: BlockNumber(last.0.0 + 1),
|
number: BlockNumber(last.0 .0 + 1),
|
||||||
canonical_start_time: last.1,
|
canonical_start_time: last.1,
|
||||||
// The end time of the last block is the start time for this one
|
// The end time of the last block is the start time for this one
|
||||||
// The Commit explicitly contains the end time, so loading the last commit will provide
|
// The Commit explicitly contains the end time, so loading the last commit will provide
|
||||||
|
|||||||
Reference in New Issue
Block a user