diff --git a/src/main/scala/scorex/core/app/Version.scala b/src/main/scala/scorex/core/app/Version.scala index cb029805ad..5ca27569e6 100644 --- a/src/main/scala/scorex/core/app/Version.scala +++ b/src/main/scala/scorex/core/app/Version.scala @@ -46,7 +46,7 @@ object Version { val UtxoSnapsnotActivationVersion: Version = Version(5, 0, 12) - val NipopowActivationVersion: Version = Version(5, 0, 13) // todo: set proper version around release + val NipopowActivationVersion: Version = Version(5, 0, 13) } object ApplicationVersionSerializer extends ErgoSerializer[Version] { diff --git a/src/main/scala/scorex/core/network/PeerConnectionHandler.scala b/src/main/scala/scorex/core/network/PeerConnectionHandler.scala index ad3f850a9e..80cbbce51b 100644 --- a/src/main/scala/scorex/core/network/PeerConnectionHandler.scala +++ b/src/main/scala/scorex/core/network/PeerConnectionHandler.scala @@ -4,6 +4,7 @@ import akka.actor.{Actor, ActorRef, Cancellable, Props, SupervisorStrategy} import akka.io.Tcp import akka.io.Tcp._ import akka.util.{ByteString, CompactByteString} +import scorex.core.app.Version.Eip37ForkVersion import scorex.core.app.{ScorexContext, Version} import scorex.core.network.NetworkController.ReceivableMessages.{Handshaked, PenalizePeer} import scorex.core.network.PeerConnectionHandler.ReceivableMessages @@ -61,8 +62,8 @@ class PeerConnectionHandler(scorexSettings: ScorexSettings, override def postStop(): Unit = log.info(s"Peer handler to $connectionId destroyed") private def handshaking: Receive = { - handshakeTimeoutCancellableOpt = Some(context.system.scheduler.scheduleOnce(networkSettings.handshakeTimeout) - (self ! HandshakeTimeout)) + handshakeTimeoutCancellableOpt = + Some(context.system.scheduler.scheduleOnce(networkSettings.handshakeTimeout)(self ! HandshakeTimeout)) val hb = HandshakeSerializer.toBytes(createHandshakeMessage()) connection ! Tcp.Write(ByteString(hb)) log.info(s"Handshake sent to $connectionId") @@ -70,11 +71,7 @@ class PeerConnectionHandler(scorexSettings: ScorexSettings, receiveAndHandleHandshake { receivedHandshake => log.info(s"Got a Handshake from $connectionId") - val peerInfo = PeerInfo( - receivedHandshake.peerSpec, - System.currentTimeMillis(), - Some(direction) - ) + val peerInfo = PeerInfo(receivedHandshake.peerSpec, System.currentTimeMillis(), Some(direction)) val peer = ConnectedPeer(connectionDescription.connectionId, self, 0, Some(peerInfo)) selfPeer = Some(peer) @@ -85,17 +82,27 @@ class PeerConnectionHandler(scorexSettings: ScorexSettings, } orElse handshakeTimeout orElse closeCommands } + //ban this peer for the wrong handshake message + //peer will be added to the blacklist and the network controller will send CloseConnection + private def banPeer(): Unit = { + selfPeer.foreach(c => networkControllerRef ! PenalizePeer(c.connectionId.remoteAddress, PenaltyType.PermanentPenalty)) + } + private def receiveAndHandleHandshake(handler: Handshake => Unit): Receive = { case Received(data) => HandshakeSerializer.parseBytesTry(data.toArray) match { case Success(handshake) => - handler(handshake) + if (handshake.peerSpec.protocolVersion < Eip37ForkVersion) { + // peers not suporting EIP-37 hard-fork are stuck on another chain + log.info(s"Peer of version < 4.0.100 sent handshake $handshake") + banPeer() + } else { + handler(handshake) + } case Failure(t) => - log.info(s"Error during parsing a handshake: ${t.getMessage}") - //ban the peer for the wrong handshake message - //peer will be added to the blacklist and the network controller will send CloseConnection - selfPeer.foreach(c => networkControllerRef ! PenalizePeer(c.connectionId.remoteAddress, PenaltyType.PermanentPenalty)) + log.info(s"Error during parsing a handshake: ${t.getMessage}", t) + banPeer() } } @@ -234,7 +241,7 @@ class PeerConnectionHandler(scorexSettings: ScorexSettings, } } - private def createHandshakeMessage() = { + private def createHandshakeMessage(): Handshake = { Handshake( PeerSpec( networkSettings.agentName,