@@ -355,10 +355,18 @@ async def read_msg(self) -> Tuple[protocol.Command, protocol._DecodedMsgType]:
355
355
# too much time is being spent on this again, we need to consider running this in a
356
356
# ProcessPoolExecutor(). Need to make sure we don't use all CPUs in the machine for that,
357
357
# though, otherwise asyncio's event loop can't run and we can't keep up with other peers.
358
- decoded_msg = cast (Dict [str , Any ], cmd .decode (msg ))
359
- self .logger .trace ("Successfully decoded %s msg: %s" , cmd , decoded_msg )
360
- self .received_msgs [cmd ] += 1
361
- return cmd , decoded_msg
358
+ try :
359
+ decoded_msg = cast (Dict [str , Any ], cmd .decode (msg ))
360
+ except MalformedMessage as err :
361
+ self .logger .debug (
362
+ "Malformed message from peer %s: CMD:%s Error: %r" ,
363
+ self , type (cmd ).__name__ , err ,
364
+ )
365
+ raise
366
+ else :
367
+ self .logger .trace ("Successfully decoded %s msg: %s" , cmd , decoded_msg )
368
+ self .received_msgs [cmd ] += 1
369
+ return cmd , decoded_msg
362
370
363
371
def handle_p2p_msg (self , cmd : protocol .Command , msg : protocol ._DecodedMsgType ) -> None :
364
372
"""Handle the base protocol (P2P) messages."""
@@ -837,8 +845,8 @@ async def start_peer(self, peer: BasePeer) -> None:
837
845
# check, we do it here because we want to perform it for incoming peer connections as
838
846
# well.
839
847
msgs = await self .ensure_same_side_on_dao_fork (peer )
840
- except DAOForkCheckFailure as e :
841
- self .logger .debug ("DAO fork check with %s failed: %s" , peer , e )
848
+ except DAOForkCheckFailure as err :
849
+ self .logger .debug ("DAO fork check with %s failed: %s" , peer , err )
842
850
await peer .disconnect (DisconnectReason .useless_peer )
843
851
return
844
852
asyncio .ensure_future (peer .run (finished_callback = self ._peer_finished ))
@@ -962,9 +970,15 @@ async def ensure_same_side_on_dao_fork(
962
970
else :
963
971
msgs .append ((cmd , msg ))
964
972
continue
965
- except (TimeoutError , PeerConnectionLost ) as e :
973
+ except (TimeoutError , PeerConnectionLost ) as err :
974
+ raise DAOForkCheckFailure (
975
+ "Timed out waiting for DAO fork header from {}: {}" .format (peer , err ))
976
+ except MalformedMessage as err :
966
977
raise DAOForkCheckFailure (
967
- "Timed out waiting for DAO fork header from {}: {}" .format (peer , e ))
978
+ "Malformed message while doing DAO fork check with {0}: {1}" .format (
979
+ peer , err ,
980
+ )
981
+ ) from err
968
982
969
983
try :
970
984
request .validate_headers (headers )
0 commit comments