fix: 🚑 non checking genesis block in consensus

refactor: ♻️ clippy
This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-06-06 01:35:00 +03:00
parent a3b1675bc3
commit 4acd687685
4 changed files with 22 additions and 21 deletions

View file

@ -64,12 +64,12 @@ async fn receive_blockchain(
};
Some((ws_stream_receiver, blockchain))
} else {
return None;
None
}
}
Err(_) => return None,
Err(_) => None,
},
None => return None,
None => None,
}
}
@ -89,12 +89,12 @@ async fn receive_block(
};
Some((ws_stream_receiver, block))
} else {
return None;
None
}
}
Err(_) => return None,
Err(_) => None,
},
None => return None,
None => None,
}
}

View file

@ -11,15 +11,16 @@ pub async fn accept_agreement(
limbo_block: Arc<Mutex<Block>>,
) {
let mut received_blocks = vec![];
let empty_string = String::new();
loop {
for channel in consensus_data_channels.lock().await.iter_mut() {
match channel.block_receiver.try_recv() {
Ok(block) => {
if block.previous_hash == limbo_block.lock().await.previous_hash {
received_blocks.push(block);
}
if let Ok(block) = channel.block_receiver.try_recv() {
let limbo_block = limbo_block.lock().await;
if (limbo_block.previous_hash != empty_string)
&& (block.previous_hash == limbo_block.previous_hash)
{
received_blocks.push(block);
}
Err(_) => {}
}
}
@ -49,7 +50,9 @@ pub async fn accept_agreement(
*limbo_block.lock().await =
blockchain_thread_safe.lock().await.genesis_block.clone()
}
Err(_) => {}
Err(_) => {
todo!()
}
}
}
None => todo!(),

View file

@ -40,7 +40,7 @@ impl Ord for BlockReceiver {
impl PartialOrd for BlockReceiver {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.uuid.partial_cmp(&other.uuid)
Some(self.cmp(other))
}
}

View file

@ -54,7 +54,7 @@ pub async fn start_network(
uuid: Uuid::new_v4(),
};
let uuid = block_receiver.uuid.clone();
let uuid = block_receiver.uuid;
consensus_data_channels.lock().await.push(block_receiver);
@ -74,7 +74,6 @@ pub async fn start_network(
consensus_data_channels.remove(block_receiver_index);
};
drop(consensus_data_channels);
return ;
}
_ = sync_server(ws_stream_receiver, consensus_data_channel_sender) => {
@ -84,7 +83,6 @@ pub async fn start_network(
consensus_data_channels.remove(block_receiver_index);
};
drop(consensus_data_channels);
return ;
}
}
});
@ -102,7 +100,7 @@ async fn sync_server(
Some((ws_stream_receiver, block)) => (ws_stream_receiver, block),
None => return,
};
if let Err(_) = consensus_data_channel_sender.send(block) {
if consensus_data_channel_sender.send(block).is_err() {
return;
}
}
@ -121,12 +119,12 @@ async fn receive_block(
};
Some((ws_stream_receiver, block))
} else {
return None;
None
}
}
Err(_) => return None,
Err(_) => None,
},
None => return None,
None => None,
}
}