@@ -26,6 +26,7 @@ pub struct ConsensusInterfaceImpl {
2626}
2727
2828impl ConsensusInterfaceImpl {
29+ #[ must_use]
2930 pub fn new ( ) -> ( Self , messenger:: Sender < ConsensusMessage , ConsensusResponse > ) {
3031 let ( tx, rx) = messenger:: channel ( 100 , Some ( 100 ) ) ;
3132 (
@@ -55,11 +56,11 @@ impl ConsensusInterfaceImpl {
5556 self . chain_interface_tx = Some ( tx) ;
5657 }
5758
58- pub fn set_peer_id ( & mut self , peer_id : PeerId ) {
59+ pub const fn set_peer_id ( & mut self , peer_id : PeerId ) {
5960 self . peer_id = Some ( peer_id) ;
6061 }
6162
62- pub fn set_max_validators ( & mut self , max_validators : usize ) {
63+ pub const fn set_max_validators ( & mut self , max_validators : usize ) {
6364 self . max_validators = Some ( max_validators) ;
6465 }
6566
@@ -165,14 +166,20 @@ impl ConsensusInterfaceImpl {
165166 self . state. current_round
166167 ) ;
167168
168- // Get the proposed block from chain interface
169- let proposer_bytes = self . peer_id . map ( |p| p. to_bytes ( ) ) . unwrap_or_default ( ) ;
169+ // Get the proposed block from chain ilibp2p::PeerId::to_bytes
170+ let proposer_bytes = self
171+ . peer_id
172+ . map ( libp2p:: PeerId :: to_bytes)
173+ . unwrap_or_default ( ) ;
170174 let block = self . get_proposed_block ( proposer_bytes) . await ?;
171175
172176 // Serialize and broadcast the block proposal
173177 let raw_block = block. serialize ( ) ?;
174178 let proposal_message = ConsensusNetMessage :: BlockProposal {
175- proposer : self . peer_id . map ( |p| p. to_bytes ( ) ) . unwrap_or_default ( ) ,
179+ proposer : self
180+ . peer_id
181+ . map ( libp2p:: PeerId :: to_bytes)
182+ . unwrap_or_default ( ) ,
176183 raw_block,
177184 } ;
178185
@@ -207,13 +214,13 @@ impl ConsensusInterfaceImpl {
207214 let proposer_bytes = self
208215 . state
209216 . proposer
210- . map ( |p| p . to_bytes ( ) )
217+ . map ( libp2p :: PeerId :: to_bytes)
211218 . unwrap_or_default ( ) ;
212219 let local_block = self . get_proposed_block ( proposer_bytes) . await ?;
213220
214221 if local_block == block {
215222 info ! ( "Block is valid. Sending prevote." ) ;
216- self . send_vote ( & block, VoteType :: Prevote ) ?;
223+ self . send_vote ( & block, & VoteType :: Prevote ) ?;
217224 } else {
218225 info ! ( "Block is invalid. Not voting - transaction mismatch" ) ;
219226 info ! (
@@ -227,7 +234,7 @@ impl ConsensusInterfaceImpl {
227234 Ok ( ( ) )
228235 }
229236
230- fn send_vote ( & self , block : & Block , vote_type : VoteType ) -> Result < ( ) , NodeError > {
237+ fn send_vote ( & self , block : & Block , vote_type : & VoteType ) -> Result < ( ) , NodeError > {
231238 let block_bytes = block. serialize ( ) ?;
232239 let mut hasher = Sha256 :: new ( ) ;
233240 hasher. update ( & block_bytes) ;
@@ -237,7 +244,10 @@ impl ConsensusInterfaceImpl {
237244 round : self . state . current_round ,
238245 height : self . state . current_height ,
239246 block_hash : block_hash. clone ( ) ,
240- voter : self . peer_id . map ( |p| p. to_bytes ( ) ) . unwrap_or_default ( ) ,
247+ voter : self
248+ . peer_id
249+ . map ( libp2p:: PeerId :: to_bytes)
250+ . unwrap_or_default ( ) ,
241251 vote_type : vote_type. clone ( ) ,
242252 } ;
243253
@@ -278,7 +288,10 @@ impl ConsensusInterfaceImpl {
278288 round : self . state . current_round ,
279289 height : self . state . current_height ,
280290 block_hash : vote. block_hash . clone ( ) ,
281- voter : self . peer_id . map ( |p| p. to_bytes ( ) ) . unwrap_or_default ( ) ,
291+ voter : self
292+ . peer_id
293+ . map ( libp2p:: PeerId :: to_bytes)
294+ . unwrap_or_default ( ) ,
282295 vote_type : VoteType :: Precommit ,
283296 } ;
284297
@@ -314,7 +327,10 @@ impl ConsensusInterfaceImpl {
314327
315328 self . state . block_finalized = true ;
316329
317- let proposer_bytes = self . peer_id . map ( |p| p. to_bytes ( ) ) . unwrap_or_default ( ) ;
330+ let proposer_bytes = self
331+ . peer_id
332+ . map ( libp2p:: PeerId :: to_bytes)
333+ . unwrap_or_default ( ) ;
318334 match self . get_proposed_block ( proposer_bytes) . await {
319335 Ok ( block) => match self . finalize_block ( block. clone ( ) ) . await {
320336 Ok ( ( ) ) => {
0 commit comments