Skip to content

Commit e7bf478

Browse files
committed
fix: update tests + rebase issues
1 parent 0621b43 commit e7bf478

5 files changed

Lines changed: 44 additions & 61 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ missing_safety_doc = "allow"
8686
cargo_common_metadata = "allow"
8787
multiple_crate_versions = "allow"
8888
too_many_lines = "allow"
89+
cognitive_complexity = "allow"

crates/node/src/handlers/consensus/handler.rs

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ use types::{
1919
proto::ProtoDecode,
2020
};
2121

22-
#[derive(Clone)]
23-
struct RawBlockBytes(Vec<u8>);
24-
25-
impl types::proto::ProtoEncode for RawBlockBytes {
26-
fn encode(&self) -> Result<Vec<u8>, String> {
27-
Ok(self.0.clone())
28-
}
29-
}
30-
3122
#[async_trait::async_trait]
3223
impl<N: Network, W: Wallet> Handler<N, W> for ConsensusState {
3324
async fn handle(
@@ -124,17 +115,19 @@ impl<N: Network, W: Wallet> Handler<N, W> for ConsensusState {
124115
})?;
125116

126117
match broadcast {
127-
BroadcastMessage::Consensus(consensus_message) => match consensus_message {
128-
ConsensusMessage::LeaderAnnouncement(announcement) => {
129-
self.handle_leader_announcement(node, &announcement)?;
130-
}
131-
ConsensusMessage::NewRound(round) => {
132-
self.handle_new_round(node, peer, round)?;
133-
}
134-
ConsensusMessage::Vote(vote) => {
135-
self.handle_vote(node, peer, &vote).await;
118+
BroadcastMessage::Consensus(consensus_message) => {
119+
match consensus_message {
120+
ConsensusMessage::LeaderAnnouncement(announcement) => {
121+
self.handle_leader_announcement(node, &announcement)?;
122+
}
123+
ConsensusMessage::NewRound(round) => {
124+
self.handle_new_round(node, peer, round)?;
125+
}
126+
ConsensusMessage::Vote(vote) => {
127+
self.handle_vote(node, peer, &vote).await;
128+
}
136129
}
137-
},
130+
}
138131
BroadcastMessage::Block(raw_block) => {
139132
match Block::deserialize(&raw_block) {
140133
Ok(block) => {
@@ -161,41 +154,33 @@ impl<N: Network, W: Wallet> Handler<N, W> for ConsensusState {
161154
));
162155
};
163156

164-
// Validate block by comparing transactions rather than entire block
165-
// (timestamps and proposers will be different for each node)
166-
if local_block.body.transactions == block.body.transactions {
167-
info!("Block is valid. Sending prevote.");
168-
self.send_vote(node, &block, VoteType::Prevote)?;
169-
} else {
170-
info!(
171-
"Block is invalid. Not voting - transaction mismatch"
172-
);
173-
info!(
174-
"Local txs: {}, Received txs: {}",
175-
local_block.body.transactions.len(),
176-
block.body.transactions.len()
157+
// Validate block by comparing transactions rather than entire block
158+
// (timestamps and proposers will be different for each node)
159+
if local_block.body.transactions == block.body.transactions
160+
{
161+
info!("Block is valid. Sending prevote.");
162+
self.send_vote(node, &block, VoteType::Prevote)?;
163+
} else {
164+
info!(
165+
"Block is invalid. Not voting - transaction mismatch"
166+
);
167+
info!(
168+
"Local txs: {}, Received txs: {}",
169+
local_block.body.transactions.len(),
170+
block.body.transactions.len()
171+
);
172+
}
173+
}
174+
Err(e) => {
175+
tracing::warn!(
176+
"Failed to deserialize proposed block from {}: {}",
177+
peer,
178+
e
177179
);
178180
}
179181
}
180-
Err(e) => {
181-
tracing::warn!(
182-
"Failed to deserialize proposed block from {}: {}",
183-
peer,
184-
e
185-
);
186-
}
187-
}
188-
}
189-
190-
if message.topic == self.vote_topic.hash() {
191-
let vote_message: ConsensusMessage =
192-
ConsensusMessage::decode(&message.data).map_err(|e| {
193-
NodeError::Error(format!("Failed to decode vote message: {e}"))
194-
})?;
195-
196-
if let ConsensusMessage::Vote(vote) = vote_message {
197-
self.handle_vote(node, peer, &vote).await;
198182
}
183+
_ => {}
199184
}
200185
}
201186
}

crates/node/src/handlers/dkg/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use frost_secp256k1::{
44
Identifier,
55
keys::dkg::{round1, round2},
66
};
7-
use libp2p::{PeerId, gossipsub};
7+
use libp2p::PeerId;
88

99
pub mod handler;
1010
pub mod key_creation;
@@ -14,9 +14,6 @@ pub struct DkgState {
1414
pub dkg_listeners: HashSet<PeerId>,
1515
pub round1_listeners: HashSet<PeerId>,
1616

17-
pub start_dkg_topic: libp2p::gossipsub::IdentTopic,
18-
pub round1_topic: libp2p::gossipsub::IdentTopic,
19-
2017
pub round1_peer_packages: BTreeMap<Identifier, round1::Package>,
2118
pub round2_peer_packages: BTreeMap<Identifier, round2::Package>,
2219

@@ -36,8 +33,6 @@ impl DkgState {
3633
Self {
3734
dkg_listeners: HashSet::new(),
3835
round1_listeners: HashSet::new(),
39-
start_dkg_topic: gossipsub::IdentTopic::new("start-dkg"),
40-
round1_topic: gossipsub::IdentTopic::new("round1_topic"),
4136
round1_peer_packages: BTreeMap::new(),
4237
round2_peer_packages: BTreeMap::new(),
4338
r1_secret_package: None,

tests/src/consensus/block_consensus.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod block_consensus_tests {
99
};
1010
use tokio::sync::mpsc::unbounded_channel;
1111
use types::{
12+
broadcast::BroadcastMessage,
1213
consensus::{Vote, VoteType},
1314
intents::DepositIntent,
1415
network::network_protocol::Network,
@@ -287,11 +288,12 @@ mod block_consensus_tests {
287288
vote: Vote,
288289
) {
289290
let network = cluster.networks.get(&from_peer).unwrap();
290-
let topic = libp2p::gossipsub::IdentTopic::new("consensus");
291+
let topic = libp2p::gossipsub::IdentTopic::new("broadcast");
291292

292293
// Simulate vote broadcast using ConsensusMessage
293-
let consensus_msg = types::consensus::ConsensusMessage::Vote(vote);
294-
let _ = network.send_broadcast(topic, consensus_msg);
294+
let broadcast_msg =
295+
BroadcastMessage::Consensus(types::consensus::ConsensusMessage::Vote(vote));
296+
let _ = network.send_broadcast(topic, broadcast_msg);
295297
cluster.run_n_iterations(2).await;
296298
}
297299

tests/src/mocks/network.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ impl MockNodeCluster {
237237
for peer_id in peers.iter().filter(|peer_id| *peer_id != receipient_peer) {
238238
sender.queue(NetworkEvent::Subscribed {
239239
peer_id: *peer_id,
240-
topic: libp2p::gossipsub::IdentTopic::new("start-dkg").hash(),
240+
topic: libp2p::gossipsub::IdentTopic::new("broadcast").hash(),
241241
});
242242
sender.queue(NetworkEvent::Subscribed {
243243
peer_id: *peer_id,
244-
topic: libp2p::gossipsub::IdentTopic::new("round1_topic").hash(),
244+
topic: libp2p::gossipsub::IdentTopic::new("broadcast").hash(),
245245
});
246246
}
247247

0 commit comments

Comments
 (0)