@@ -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]
3223impl < 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 }
0 commit comments