diff --git a/src/main/scala/io/iohk/ethereum/blockchain/sync/regular/BlockBroadcast.scala b/src/main/scala/io/iohk/ethereum/blockchain/sync/regular/BlockBroadcast.scala index 3467e56e0b..bcceb38c67 100644 --- a/src/main/scala/io/iohk/ethereum/blockchain/sync/regular/BlockBroadcast.scala +++ b/src/main/scala/io/iohk/ethereum/blockchain/sync/regular/BlockBroadcast.scala @@ -14,10 +14,10 @@ import io.iohk.ethereum.network.Peer import io.iohk.ethereum.network.PeerId import io.iohk.ethereum.network.p2p.MessageSerializable import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.ETC64 import io.iohk.ethereum.network.p2p.messages.ETH62 import io.iohk.ethereum.network.p2p.messages.ETH62.BlockHash -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily._ class BlockBroadcast(val etcPeerManager: ActorRef) { @@ -47,9 +47,10 @@ class BlockBroadcast(val etcPeerManager: ActorRef) { obtainRandomPeerSubset(peers.values.map(_.peer).toSet).foreach { peer => val remoteStatus = peers(peer.id).peerInfo.remoteStatus - val message: MessageSerializable = remoteStatus.protocolFamily match { - case ETH => blockToBroadcast.as63 - case ETC => blockToBroadcast.as64 + val message: MessageSerializable = remoteStatus.capability match { + case Capability.ETH63 => blockToBroadcast.as63 + case Capability.ETH64 => blockToBroadcast.as63 + case Capability.ETC64 => blockToBroadcast.asEtc64 } etcPeerManager ! EtcPeerManagerActor.SendMessage(message, peer.id) } @@ -80,6 +81,6 @@ object BlockBroadcast { */ case class BlockToBroadcast(block: Block, chainWeight: ChainWeight) { def as63: BaseETH6XMessages.NewBlock = BaseETH6XMessages.NewBlock(block, chainWeight.totalDifficulty) - def as64: ETC64.NewBlock = ETC64.NewBlock(block, chainWeight) + def asEtc64: ETC64.NewBlock = ETC64.NewBlock(block, chainWeight) } } diff --git a/src/main/scala/io/iohk/ethereum/forkid/ForkIdValidator.scala b/src/main/scala/io/iohk/ethereum/forkid/ForkIdValidator.scala index 5cd8b061f0..860a7a08ce 100644 --- a/src/main/scala/io/iohk/ethereum/forkid/ForkIdValidator.scala +++ b/src/main/scala/io/iohk/ethereum/forkid/ForkIdValidator.scala @@ -22,9 +22,12 @@ case object Connect extends ForkIdValidationResult case object ErrRemoteStale extends ForkIdValidationResult case object ErrLocalIncompatibleOrStale extends ForkIdValidationResult +import cats.effect._ + object ForkIdValidator { - implicit val unsafeLogger: SelfAwareStructuredLogger[Task] = Slf4jLogger.getLogger[Task] + implicit val taskLogger: SelfAwareStructuredLogger[Task] = Slf4jLogger.getLogger[Task] + implicit val syncIoLogger: SelfAwareStructuredLogger[SyncIO] = Slf4jLogger.getLogger[SyncIO] val maxUInt64: BigInt = (BigInt(0x7fffffffffffffffL) << 1) + 1 // scalastyle:ignore magic.number diff --git a/src/main/scala/io/iohk/ethereum/network/EtcPeerManagerActor.scala b/src/main/scala/io/iohk/ethereum/network/EtcPeerManagerActor.scala index dacbb9f327..445b3f4f8e 100644 --- a/src/main/scala/io/iohk/ethereum/network/EtcPeerManagerActor.scala +++ b/src/main/scala/io/iohk/ethereum/network/EtcPeerManagerActor.scala @@ -20,6 +20,7 @@ import io.iohk.ethereum.network.handshaker.Handshaker.HandshakeResult import io.iohk.ethereum.network.p2p.Message import io.iohk.ethereum.network.p2p.MessageSerializable import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.Codes import io.iohk.ethereum.network.p2p.messages.ETC64 import io.iohk.ethereum.network.p2p.messages.ETC64.NewBlock @@ -27,9 +28,6 @@ import io.iohk.ethereum.network.p2p.messages.ETH62.BlockHeaders import io.iohk.ethereum.network.p2p.messages.ETH62.GetBlockHeaders import io.iohk.ethereum.network.p2p.messages.ETH62.NewBlockHashes import io.iohk.ethereum.network.p2p.messages.ETH64 -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily.ETC -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily.ETH import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect import io.iohk.ethereum.utils.ByteStringUtils @@ -243,8 +241,7 @@ object EtcPeerManagerActor { * (they are different versions of Status msg) */ case class RemoteStatus( - protocolFamily: ProtocolFamily, - protocolVersion: Int, + capability: Capability, networkId: Int, chainWeight: ChainWeight, bestHash: ByteString, @@ -252,8 +249,7 @@ object EtcPeerManagerActor { ) { override def toString: String = s"RemoteStatus { " + - s"protocolFamily: $protocolFamily, " + - s"protocolVersion: $protocolVersion, " + + s"capability: $capability, " + s"networkId: $networkId, " + s"chainWeight: $chainWeight, " + s"bestHash: ${ByteStringUtils.hash2string(bestHash)}, " + @@ -264,8 +260,7 @@ object EtcPeerManagerActor { object RemoteStatus { def apply(status: ETH64.Status): RemoteStatus = RemoteStatus( - ETH, - status.protocolVersion, + Capability.ETH64, status.networkId, ChainWeight.totalDifficultyOnly(status.totalDifficulty), status.bestHash, @@ -274,8 +269,7 @@ object EtcPeerManagerActor { def apply(status: ETC64.Status): RemoteStatus = RemoteStatus( - ETC, - status.protocolVersion, + Capability.ETC64, status.networkId, status.chainWeight, status.bestHash, @@ -284,8 +278,7 @@ object EtcPeerManagerActor { def apply(status: BaseETH6XMessages.Status): RemoteStatus = RemoteStatus( - ETH, - status.protocolVersion, + Capability.ETH63, status.networkId, ChainWeight.totalDifficultyOnly(status.totalDifficulty), status.bestHash, diff --git a/src/main/scala/io/iohk/ethereum/network/handshaker/EtcHelloExchangeState.scala b/src/main/scala/io/iohk/ethereum/network/handshaker/EtcHelloExchangeState.scala index 55caf8b438..89409fb6f7 100644 --- a/src/main/scala/io/iohk/ethereum/network/handshaker/EtcHelloExchangeState.scala +++ b/src/main/scala/io/iohk/ethereum/network/handshaker/EtcHelloExchangeState.scala @@ -6,7 +6,6 @@ import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo import io.iohk.ethereum.network.handshaker.Handshaker.NextMessage import io.iohk.ethereum.network.p2p.Message import io.iohk.ethereum.network.p2p.messages.Capability -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect import io.iohk.ethereum.network.p2p.messages.WireProtocol.Hello import io.iohk.ethereum.utils.Config @@ -31,21 +30,21 @@ case class EtcHelloExchangeState(handshakerConfiguration: EtcHandshakerConfigura log.debug("Protocol handshake finished with peer ({})", hello) // FIXME in principle this should be already negotiated Capability.negotiate(hello.capabilities.toList, handshakerConfiguration.blockchainConfig.capabilities) match { - case Some(ProtocolVersions.ETC64) => + case Some(Capability.ETC64) => log.debug("Negotiated protocol version with client {} is etc/64", hello.clientId) EtcNodeStatus64ExchangeState(handshakerConfiguration) - case Some(ProtocolVersions.ETH63) => + case Some(Capability.ETH63) => log.debug("Negotiated protocol version with client {} is eth/63", hello.clientId) EthNodeStatus63ExchangeState(handshakerConfiguration) - case Some(ProtocolVersions.ETH64) => + case Some(Capability.ETH64) => log.debug("Negotiated protocol version with client {} is eth/64", hello.clientId) EthNodeStatus64ExchangeState(handshakerConfiguration) case _ => log.debug( s"Connected peer does not support {} / {} / {} protocol. Disconnecting.", - ProtocolVersions.ETH63, - ProtocolVersions.ETH64, - ProtocolVersions.ETC64 + Capability.ETH63, + Capability.ETH64, + Capability.ETC64 ) DisconnectedState(Disconnect.Reasons.IncompatibleP2pProtocolVersion) } diff --git a/src/main/scala/io/iohk/ethereum/network/handshaker/EtcNodeStatus64ExchangeState.scala b/src/main/scala/io/iohk/ethereum/network/handshaker/EtcNodeStatus64ExchangeState.scala index 3845bf8b7b..62fd272d8c 100644 --- a/src/main/scala/io/iohk/ethereum/network/handshaker/EtcNodeStatus64ExchangeState.scala +++ b/src/main/scala/io/iohk/ethereum/network/handshaker/EtcNodeStatus64ExchangeState.scala @@ -4,8 +4,8 @@ import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo import io.iohk.ethereum.network.EtcPeerManagerActor.RemoteStatus import io.iohk.ethereum.network.p2p.Message import io.iohk.ethereum.network.p2p.MessageSerializable +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.ETC64 -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions case class EtcNodeStatus64ExchangeState( handshakerConfiguration: EtcHandshakerConfiguration @@ -22,7 +22,7 @@ case class EtcNodeStatus64ExchangeState( val chainWeight = blockchain.getChainWeightByHash(bestBlockHeader.hash).get val status = ETC64.Status( - protocolVersion = ProtocolVersions.ETC64.version, + protocolVersion = Capability.ETC64.version, networkId = peerConfiguration.networkId, chainWeight = chainWeight, bestHash = bestBlockHeader.hash, diff --git a/src/main/scala/io/iohk/ethereum/network/handshaker/EthNodeStatus63ExchangeState.scala b/src/main/scala/io/iohk/ethereum/network/handshaker/EthNodeStatus63ExchangeState.scala index 8decf88785..fb277be1b3 100644 --- a/src/main/scala/io/iohk/ethereum/network/handshaker/EthNodeStatus63ExchangeState.scala +++ b/src/main/scala/io/iohk/ethereum/network/handshaker/EthNodeStatus63ExchangeState.scala @@ -5,7 +5,7 @@ import io.iohk.ethereum.network.EtcPeerManagerActor.RemoteStatus import io.iohk.ethereum.network.p2p.Message import io.iohk.ethereum.network.p2p.MessageSerializable import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability case class EthNodeStatus63ExchangeState( handshakerConfiguration: EtcHandshakerConfiguration @@ -23,7 +23,7 @@ case class EthNodeStatus63ExchangeState( val chainWeight = blockchain.getChainWeightByHash(bestBlockHeader.hash).get val status = BaseETH6XMessages.Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = peerConfiguration.networkId, totalDifficulty = chainWeight.totalDifficulty, bestHash = bestBlockHeader.hash, diff --git a/src/main/scala/io/iohk/ethereum/network/handshaker/EthNodeStatus64ExchangeState.scala b/src/main/scala/io/iohk/ethereum/network/handshaker/EthNodeStatus64ExchangeState.scala index a6344dd30c..89061588da 100644 --- a/src/main/scala/io/iohk/ethereum/network/handshaker/EthNodeStatus64ExchangeState.scala +++ b/src/main/scala/io/iohk/ethereum/network/handshaker/EthNodeStatus64ExchangeState.scala @@ -1,12 +1,17 @@ package io.iohk.ethereum.network.handshaker +import cats.effect._ + +import io.iohk.ethereum.forkid.Connect import io.iohk.ethereum.forkid.ForkId +import io.iohk.ethereum.forkid.ForkIdValidator import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo import io.iohk.ethereum.network.EtcPeerManagerActor.RemoteStatus import io.iohk.ethereum.network.p2p.Message import io.iohk.ethereum.network.p2p.MessageSerializable +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.ETH64 -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect case class EthNodeStatus64ExchangeState( handshakerConfiguration: EtcHandshakerConfiguration @@ -15,8 +20,18 @@ case class EthNodeStatus64ExchangeState( import handshakerConfiguration._ def applyResponseMessage: PartialFunction[Message, HandshakerState[PeerInfo]] = { case status: ETH64.Status => - // TODO: validate fork id of the remote peer - applyRemoteStatusMessage(RemoteStatus(status)) + import ForkIdValidator.syncIoLogger + (for { + validationResult <- + ForkIdValidator.validatePeer[SyncIO](blockchainReader.genesisHeader.hash, blockchainConfig)( + blockchainReader.getBestBlockNumber(), + status.forkId + ) + _ = log.info("Fork id validation result was: {}", validationResult) + } yield validationResult match { + case Connect => applyRemoteStatusMessage(RemoteStatus(status)) + case _ => DisconnectedState[PeerInfo](Disconnect.Reasons.UselessPeer) + }).unsafeRunSync() } override protected def createStatusMsg(): MessageSerializable = { @@ -25,7 +40,7 @@ case class EthNodeStatus64ExchangeState( val genesisHash = blockchainReader.genesisHeader.hash val status = ETH64.Status( - protocolVersion = ProtocolVersions.ETH64.version, + protocolVersion = Capability.ETH64.version, networkId = peerConfiguration.networkId, totalDifficulty = chainWeight.totalDifficulty, bestHash = bestBlockHeader.hash, diff --git a/src/main/scala/io/iohk/ethereum/network/p2p/MessageDecoders.scala b/src/main/scala/io/iohk/ethereum/network/p2p/MessageDecoders.scala index 7e06fcba80..c9a0519d0b 100644 --- a/src/main/scala/io/iohk/ethereum/network/p2p/MessageDecoders.scala +++ b/src/main/scala/io/iohk/ethereum/network/p2p/MessageDecoders.scala @@ -109,9 +109,9 @@ object ETH63MessageDecoder extends MessageDecoder { object EthereumMessageDecoder { def ethMessageDecoder(protocolVersion: Capability): MessageDecoder = protocolVersion match { - case Capability.Capabilities.Etc64Capability => ETC64MessageDecoder.orElse(NetworkMessageDecoder) - case Capability.Capabilities.Eth63Capability => ETH63MessageDecoder.orElse(NetworkMessageDecoder) - case Capability.Capabilities.Eth64Capability => ETH64MessageDecoder.orElse(NetworkMessageDecoder) - case _ => throw new RuntimeException(s"Unsupported Protocol Version $protocolVersion") + case Capability.ETC64 => ETC64MessageDecoder.orElse(NetworkMessageDecoder) + case Capability.ETH63 => ETH63MessageDecoder.orElse(NetworkMessageDecoder) + case Capability.ETH64 => ETH64MessageDecoder.orElse(NetworkMessageDecoder) + case _ => throw new RuntimeException(s"Unsupported Protocol Version $protocolVersion") } } diff --git a/src/main/scala/io/iohk/ethereum/network/p2p/messages/Capability.scala b/src/main/scala/io/iohk/ethereum/network/p2p/messages/Capability.scala index a9bcc8f8a0..40c1f16044 100644 --- a/src/main/scala/io/iohk/ethereum/network/p2p/messages/Capability.scala +++ b/src/main/scala/io/iohk/ethereum/network/p2p/messages/Capability.scala @@ -6,54 +6,61 @@ import io.iohk.ethereum.rlp.RLPImplicitConversions._ import io.iohk.ethereum.rlp.RLPImplicits._ import io.iohk.ethereum.rlp.RLPList import io.iohk.ethereum.rlp.RLPSerializable +import io.iohk.ethereum.rlp.RLPValue import io.iohk.ethereum.rlp.rawDecode -case class Capability(name: String, version: Byte) +sealed trait ProtocolFamily +object ProtocolFamily { + final case object ETH extends ProtocolFamily + final case object ETC extends ProtocolFamily + implicit class ProtocolFamilyEnc(val msg: ProtocolFamily) extends RLPSerializable { + override def toRLPEncodable: RLPEncodeable = msg match { + case ETH => RLPValue("eth".getBytes()) + case ETC => RLPValue("etc".getBytes()) + } + } +} + +sealed abstract class Capability(val name: ProtocolFamily, val version: Byte) object Capability { + case object ETH63 extends Capability(ProtocolFamily.ETH, 63) //scalastyle:ignore magic.number + case object ETH64 extends Capability(ProtocolFamily.ETH, 64) //scalastyle:ignore magic.number + case object ETC64 extends Capability(ProtocolFamily.ETC, 64) //scalastyle:ignore magic.number + + def parse(s: String): Option[Capability] = s match { + case "eth/63" => Some(ETH63) + case "eth/64" => Some(ETH64) + case "etc/64" => Some(ETC64) + case _ => None // TODO: log unknown capability? + } + + def parseUnsafe(s: String): Capability = + parse(s).getOrElse(throw new RuntimeException(s"Capability $s not supported by Mantis")) + def negotiate(c1: List[Capability], c2: List[Capability]): Option[Capability] = c1.intersect(c2) match { case Nil => None case l => Some(best(l)) } - private val pattern = "(.*)/(\\d*)".r - - def parseUnsafe(protocolVersion: String): Capability = - protocolVersion match { - case pattern(name, version) => - val c = Capability(name, version.toByte) - if (Capabilities.All.contains(c)) - c - else - throw new RuntimeException(s"Capability $protocolVersion not supported by Mantis") - case _ => throw new RuntimeException(s"Unable to parse capability $protocolVersion") - } - //TODO consider how this scoring should be handled with 'snap' and other extended protocols def best(capabilities: List[Capability]): Capability = capabilities.maxBy(_.version) implicit class CapabilityEnc(val msg: Capability) extends RLPSerializable { - override def toRLPEncodable: RLPEncodeable = RLPList(msg.name, msg.version) + override def toRLPEncodable: RLPEncodeable = RLPList(msg.name.toRLPEncodable, msg.version) } implicit class CapabilityDec(val bytes: Array[Byte]) extends AnyVal { - def toCapability: Capability = CapabilityRLPEncodableDec(rawDecode(bytes)).toCapability + def toCapability: Option[Capability] = CapabilityRLPEncodableDec(rawDecode(bytes)).toCapability } implicit class CapabilityRLPEncodableDec(val rLPEncodeable: RLPEncodeable) extends AnyVal { - def toCapability: Capability = rLPEncodeable match { - case RLPList(name, version) => Capability(name, version) + def toCapability: Option[Capability] = rLPEncodeable match { + case RLPList(name, version) => parse(s"${stringEncDec.decode(name)}/${byteEncDec.decode(version)}") case _ => throw new RLPException("Cannot decode Capability") } } - object Capabilities { - val Eth63Capability: Capability = ProtocolVersions.ETH63 - val Eth64Capability: Capability = ProtocolVersions.ETH64 - val Etc64Capability: Capability = ProtocolVersions.ETC64 - - val All: Seq[Capability] = Seq(ProtocolVersions.ETC64, ProtocolVersions.ETH63, ProtocolVersions.ETH64) - } } diff --git a/src/main/scala/io/iohk/ethereum/network/p2p/messages/WireProtocol.scala b/src/main/scala/io/iohk/ethereum/network/p2p/messages/WireProtocol.scala index 8673d4b0ea..87b9eb6838 100644 --- a/src/main/scala/io/iohk/ethereum/network/p2p/messages/WireProtocol.scala +++ b/src/main/scala/io/iohk/ethereum/network/p2p/messages/WireProtocol.scala @@ -34,7 +34,7 @@ object WireProtocol { def toHello: Hello = rawDecode(bytes) match { case RLPList(p2pVersion, clientId, (capabilities: RLPList), listenPort, nodeId, _*) => - Hello(p2pVersion, clientId, capabilities.items.map(_.toCapability), listenPort, nodeId) + Hello(p2pVersion, clientId, capabilities.items.map(_.toCapability).flatten, listenPort, nodeId) case _ => throw new RuntimeException("Cannot decode Hello") } } diff --git a/src/main/scala/io/iohk/ethereum/network/p2p/messages/package.scala b/src/main/scala/io/iohk/ethereum/network/p2p/messages/package.scala index 09473103a4..c6756b9e98 100644 --- a/src/main/scala/io/iohk/ethereum/network/p2p/messages/package.scala +++ b/src/main/scala/io/iohk/ethereum/network/p2p/messages/package.scala @@ -1,43 +1,23 @@ package io.iohk.ethereum.network.p2p -package messages { - sealed trait ProtocolFamily - object ProtocolFamily { - final case object ETH extends ProtocolFamily - final case object ETC extends ProtocolFamily - } -} - package object messages { - object ProtocolVersions { - val ETH61: Capability = Capability("eth", 61.toByte) - val ETH62: Capability = Capability("eth", 62.toByte) - val ETH63: Capability = Capability("eth", 63.toByte) - val ETH64: Capability = Capability("eth", 64.toByte) - val ETH65: Capability = Capability("eth", 65.toByte) - val ETH66: Capability = Capability("eth", 66.toByte) - val ETC64: Capability = Capability("etc", 64.toByte) - - val SNAP1: Capability = Capability("snap", 1.toByte) - - val SubProtocolOffset = 0x10 - } + val SubProtocolOffset = 0x10 object Codes { - val StatusCode: Int = ProtocolVersions.SubProtocolOffset + 0x00 - val NewBlockHashesCode: Int = ProtocolVersions.SubProtocolOffset + 0x01 - val SignedTransactionsCode: Int = ProtocolVersions.SubProtocolOffset + 0x02 - val GetBlockHeadersCode: Int = ProtocolVersions.SubProtocolOffset + 0x03 - val BlockHeadersCode: Int = ProtocolVersions.SubProtocolOffset + 0x04 - val GetBlockBodiesCode: Int = ProtocolVersions.SubProtocolOffset + 0x05 - val BlockBodiesCode: Int = ProtocolVersions.SubProtocolOffset + 0x06 - val NewBlockCode: Int = ProtocolVersions.SubProtocolOffset + 0x07 + val StatusCode: Int = SubProtocolOffset + 0x00 + val NewBlockHashesCode: Int = SubProtocolOffset + 0x01 + val SignedTransactionsCode: Int = SubProtocolOffset + 0x02 + val GetBlockHeadersCode: Int = SubProtocolOffset + 0x03 + val BlockHeadersCode: Int = SubProtocolOffset + 0x04 + val GetBlockBodiesCode: Int = SubProtocolOffset + 0x05 + val BlockBodiesCode: Int = SubProtocolOffset + 0x06 + val NewBlockCode: Int = SubProtocolOffset + 0x07 // This message is removed in ETH62 and this code is reused in ETH65 with different msg type - val BlockHashesFromNumberCode: Int = ProtocolVersions.SubProtocolOffset + 0x08 - val GetNodeDataCode: Int = ProtocolVersions.SubProtocolOffset + 0x0d - val NodeDataCode: Int = ProtocolVersions.SubProtocolOffset + 0x0e - val GetReceiptsCode: Int = ProtocolVersions.SubProtocolOffset + 0x0f - val ReceiptsCode: Int = ProtocolVersions.SubProtocolOffset + 0x10 + val BlockHashesFromNumberCode: Int = SubProtocolOffset + 0x08 + val GetNodeDataCode: Int = SubProtocolOffset + 0x0d + val NodeDataCode: Int = SubProtocolOffset + 0x0e + val GetReceiptsCode: Int = SubProtocolOffset + 0x0f + val ReceiptsCode: Int = SubProtocolOffset + 0x10 } } diff --git a/src/test/scala/io/iohk/ethereum/blockchain/sync/BlockBroadcastSpec.scala b/src/test/scala/io/iohk/ethereum/blockchain/sync/BlockBroadcastSpec.scala index 4d0dfc37db..3c14439152 100644 --- a/src/test/scala/io/iohk/ethereum/blockchain/sync/BlockBroadcastSpec.scala +++ b/src/test/scala/io/iohk/ethereum/blockchain/sync/BlockBroadcastSpec.scala @@ -24,11 +24,10 @@ import io.iohk.ethereum.network.EtcPeerManagerActor.RemoteStatus import io.iohk.ethereum.network.Peer import io.iohk.ethereum.network.PeerId import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.ETC64.NewBlock import io.iohk.ethereum.network.p2p.messages.ETH62 import io.iohk.ethereum.network.p2p.messages.ETH62.NewBlockHashes -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions class BlockBroadcastSpec extends TestKit(ActorSystem("BlockBroadcastSpec_System")) @@ -62,9 +61,7 @@ class BlockBroadcastSpec val blockHeader: BlockHeader = baseBlockHeader.copy(number = initialPeerInfo.maxBlockNumber - 3) val newBlockNewHashes = NewBlockHashes(Seq(ETH62.BlockHash(blockHeader.hash, blockHeader.number))) val peerInfo = initialPeerInfo - .copy(remoteStatus = - peerStatus.copy(protocolFamily = ProtocolFamily.ETH, protocolVersion = ProtocolVersions.ETH63.version) - ) + .copy(remoteStatus = peerStatus.copy(capability = Capability.ETH63)) .withChainWeight(ChainWeight.totalDifficultyOnly(initialPeerInfo.chainWeight.totalDifficulty)) val newBlock = BaseETH6XMessages.NewBlock(Block(blockHeader, BlockBody(Nil, Nil)), peerInfo.chainWeight.totalDifficulty + 2) @@ -179,8 +176,7 @@ class BlockBroadcastSpec val baseBlockHeader = Fixtures.Blocks.Block3125369.header val peerStatus: RemoteStatus = RemoteStatus( - protocolFamily = ProtocolFamily.ETC, - protocolVersion = ProtocolVersions.ETC64.version, + capability = Capability.ETC64, networkId = 1, chainWeight = ChainWeight(10, 10000), bestHash = Fixtures.Blocks.Block3125369.header.hash, diff --git a/src/test/scala/io/iohk/ethereum/blockchain/sync/PeersClientSpec.scala b/src/test/scala/io/iohk/ethereum/blockchain/sync/PeersClientSpec.scala index bdbabbac43..d145bb9d93 100644 --- a/src/test/scala/io/iohk/ethereum/blockchain/sync/PeersClientSpec.scala +++ b/src/test/scala/io/iohk/ethereum/blockchain/sync/PeersClientSpec.scala @@ -16,8 +16,7 @@ import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo import io.iohk.ethereum.network.EtcPeerManagerActor.RemoteStatus import io.iohk.ethereum.network.Peer import io.iohk.ethereum.network.PeerId -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability class PeersClientSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyChecks { "PeerClient" should "determined the best peer based on it latest checkpoint number and total difficulty" in { @@ -81,8 +80,7 @@ class PeersClientSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyC val peer3: Peer = Peer(PeerId("peer3"), new InetSocketAddress("127.0.0.1", 3), TestProbe().ref, false) private val peerStatus = RemoteStatus( - protocolFamily = ProtocolFamily.ETH, - protocolVersion = ProtocolVersions.ETH63.version, + capability = Capability.ETH63, networkId = 1, chainWeight = ChainWeight(0, 0), bestHash = ByteString.empty, diff --git a/src/test/scala/io/iohk/ethereum/blockchain/sync/PivotBlockSelectorSpec.scala b/src/test/scala/io/iohk/ethereum/blockchain/sync/PivotBlockSelectorSpec.scala index b9c925fcd9..daf465fd38 100644 --- a/src/test/scala/io/iohk/ethereum/blockchain/sync/PivotBlockSelectorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/blockchain/sync/PivotBlockSelectorSpec.scala @@ -36,10 +36,9 @@ import io.iohk.ethereum.network.PeerEventBusActor.Unsubscribe import io.iohk.ethereum.network.PeerId import io.iohk.ethereum.network.p2p.Message import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.NewBlock +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.Codes import io.iohk.ethereum.network.p2p.messages.ETH62._ -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions import io.iohk.ethereum.utils.Config.SyncConfig class PivotBlockSelectorSpec @@ -588,8 +587,7 @@ class PivotBlockSelectorSpec val peer1Status: RemoteStatus = RemoteStatus( - ProtocolFamily.ETC, - ProtocolVersions.ETC64.version, + Capability.ETC64, 1, ChainWeight.totalDifficultyOnly(20), ByteString("peer1_bestHash"), diff --git a/src/test/scala/io/iohk/ethereum/blockchain/sync/StateSyncSpec.scala b/src/test/scala/io/iohk/ethereum/blockchain/sync/StateSyncSpec.scala index c326347ae1..3a2bda5687 100644 --- a/src/test/scala/io/iohk/ethereum/blockchain/sync/StateSyncSpec.scala +++ b/src/test/scala/io/iohk/ethereum/blockchain/sync/StateSyncSpec.scala @@ -39,10 +39,9 @@ import io.iohk.ethereum.network.EtcPeerManagerActor._ import io.iohk.ethereum.network.Peer import io.iohk.ethereum.network.PeerEventBusActor.PeerEvent.MessageFromPeer import io.iohk.ethereum.network.PeerId +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.ETH63.GetNodeData.GetNodeDataEnc import io.iohk.ethereum.network.p2p.messages.ETH63.NodeData -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions import io.iohk.ethereum.utils.Config class StateSyncSpec @@ -132,8 +131,7 @@ class StateSyncSpec val syncInit: TestProbe = TestProbe() val peerStatus: RemoteStatus = RemoteStatus( - protocolFamily = ProtocolFamily.ETH, - protocolVersion = ProtocolVersions.ETH63.version, + capability = Capability.ETH63, networkId = 1, chainWeight = ChainWeight.totalDifficultyOnly(10000), bestHash = Fixtures.Blocks.Block3125369.header.hash, diff --git a/src/test/scala/io/iohk/ethereum/blockchain/sync/TestSyncPeers.scala b/src/test/scala/io/iohk/ethereum/blockchain/sync/TestSyncPeers.scala index 378ebd7408..2269d6dd5d 100644 --- a/src/test/scala/io/iohk/ethereum/blockchain/sync/TestSyncPeers.scala +++ b/src/test/scala/io/iohk/ethereum/blockchain/sync/TestSyncPeers.scala @@ -10,8 +10,7 @@ import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo import io.iohk.ethereum.network.EtcPeerManagerActor.RemoteStatus import io.iohk.ethereum.network.Peer import io.iohk.ethereum.network.PeerId -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability trait TestSyncPeers { self: TestSyncConfig => implicit def system: ActorSystem @@ -26,8 +25,7 @@ trait TestSyncPeers { self: TestSyncConfig => val peer1Status: RemoteStatus = RemoteStatus( - ProtocolFamily.ETC, - ProtocolVersions.ETC64.version, + Capability.ETC64, 1, ChainWeight.totalDifficultyOnly(20), ByteString("peer1_bestHash"), diff --git a/src/test/scala/io/iohk/ethereum/blockchain/sync/fast/FastSyncBranchResolverActorSpec.scala b/src/test/scala/io/iohk/ethereum/blockchain/sync/fast/FastSyncBranchResolverActorSpec.scala index 8c257a63f1..31947fd94c 100644 --- a/src/test/scala/io/iohk/ethereum/blockchain/sync/fast/FastSyncBranchResolverActorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/blockchain/sync/fast/FastSyncBranchResolverActorSpec.scala @@ -42,10 +42,9 @@ import io.iohk.ethereum.network.EtcPeerManagerActor._ import io.iohk.ethereum.network.Peer import io.iohk.ethereum.network.PeerEventBusActor.PeerEvent.MessageFromPeer import io.iohk.ethereum.network.PeerId +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.ETH62.BlockHeaders import io.iohk.ethereum.network.p2p.messages.ETH62.GetBlockHeaders -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions import io.iohk.ethereum.utils.Logger class FastSyncBranchResolverActorSpec @@ -262,11 +261,10 @@ class FastSyncBranchResolverActorSpec def peerId(number: Int): PeerId = PeerId(s"peer_$number") def getPeer(id: PeerId): Peer = Peer(id, new InetSocketAddress("127.0.0.1", 0), TestProbe(id.value).ref, incomingConnection = false) - def getPeerInfo(peer: Peer, protocolVersion: Int = ProtocolVersions.ETC64.version): PeerInfo = { + def getPeerInfo(peer: Peer): PeerInfo = { val status = RemoteStatus( - ProtocolFamily.ETC, - protocolVersion, + Capability.ETC64, 1, ChainWeight.totalDifficultyOnly(1), ByteString(s"${peer.id}_bestHash"), diff --git a/src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncFixtures.scala b/src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncFixtures.scala index c3ae629e08..75c57aab57 100644 --- a/src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncFixtures.scala +++ b/src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncFixtures.scala @@ -44,12 +44,11 @@ import io.iohk.ethereum.network.PeerEventBusActor.PeerEvent.MessageFromPeer import io.iohk.ethereum.network.PeerEventBusActor.Subscribe import io.iohk.ethereum.network.PeerId import io.iohk.ethereum.network.p2p.Message +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.ETC64.NewBlock import io.iohk.ethereum.network.p2p.messages.ETH62._ import io.iohk.ethereum.network.p2p.messages.ETH63.GetNodeData import io.iohk.ethereum.network.p2p.messages.ETH63.NodeData -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions import io.iohk.ethereum.security.SecureRandomBuilder import io.iohk.ethereum.utils.Config.SyncConfig @@ -125,13 +124,11 @@ trait RegularSyncFixtures { self: Matchers with AsyncMockFactory => def getPeerInfo( peer: Peer, - protocolFamily: ProtocolFamily = ProtocolFamily.ETC, - protocolVersion: Int = ProtocolVersions.ETC64.version + capability: Capability = Capability.ETC64 ): PeerInfo = { val status = RemoteStatus( - protocolFamily, - protocolVersion, + capability, 1, ChainWeight.totalDifficultyOnly(1), ByteString(s"${peer.id}_bestHash"), diff --git a/src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncSpec.scala b/src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncSpec.scala index bfba082ea7..e4b0cb4e84 100644 --- a/src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncSpec.scala +++ b/src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncSpec.scala @@ -54,13 +54,12 @@ import io.iohk.ethereum.network.PeerEventBusActor.PeerSelector import io.iohk.ethereum.network.PeerEventBusActor.Subscribe import io.iohk.ethereum.network.PeerEventBusActor.SubscriptionClassifier.MessageClassifier import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.Codes import io.iohk.ethereum.network.p2p.messages.ETC64.NewBlock import io.iohk.ethereum.network.p2p.messages.ETH62._ import io.iohk.ethereum.network.p2p.messages.ETH63.GetNodeData import io.iohk.ethereum.network.p2p.messages.ETH63.NodeData -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions import io.iohk.ethereum.utils.Config.SyncConfig class RegularSyncSpec @@ -711,7 +710,7 @@ class RegularSyncSpec val peerWithETH63: (Peer, PeerInfo) = { val id = peerId(handshakedPeers.size) val peer = getPeer(id) - val peerInfo = getPeerInfo(peer, ProtocolFamily.ETH, ProtocolVersions.ETH63.version) + val peerInfo = getPeerInfo(peer, Capability.ETH63) (peer, peerInfo) } diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/DebugServiceSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/DebugServiceSpec.scala index bd2b948f73..8daa4cf597 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/DebugServiceSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/DebugServiceSpec.scala @@ -26,8 +26,7 @@ import io.iohk.ethereum.network.PeerActor import io.iohk.ethereum.network.PeerId import io.iohk.ethereum.network.PeerManagerActor import io.iohk.ethereum.network.PeerManagerActor.Peers -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability class DebugServiceSpec extends TestKit(ActorSystem("ActorSystem_DebugServiceSpec")) @@ -77,8 +76,7 @@ class DebugServiceSpec val debugService = new DebugService(peerManager.ref, etcPeerManager.ref) val peerStatus: RemoteStatus = RemoteStatus( - protocolFamily = ProtocolFamily.ETH, - protocolVersion = ProtocolVersions.ETH63.version, + capability = Capability.ETH63, networkId = 1, chainWeight = ChainWeight.totalDifficultyOnly(10000), bestHash = Fixtures.Blocks.Block3125369.header.hash, diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/EthInfoServiceSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/EthInfoServiceSpec.scala index 54facb8242..91247bb957 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/EthInfoServiceSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/EthInfoServiceSpec.scala @@ -161,7 +161,7 @@ class EthServiceSpec val syncingController: TestProbe = TestProbe() - val currentProtocolVersion = 11 + val currentProtocolVersion = Capability.ETH63.version lazy val ethService = new EthInfoService( blockchain, @@ -171,7 +171,7 @@ class EthServiceSpec stxLedger, keyStore, syncingController.ref, - Capability("eth", currentProtocolVersion.toByte), + Capability.ETH63, Timeouts.shortTimeout ) diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerFixture.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerFixture.scala index 5a8dc563ae..98b3af6bf5 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerFixture.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerFixture.scala @@ -87,8 +87,6 @@ class JsonRpcControllerFixture(implicit system: ActorSystem) override val filterManagerQueryTimeout: FiniteDuration = Timeouts.normalTimeout } - val currentProtocolVersion = 63 - val appStateStorage: AppStateStorage = mock[AppStateStorage] val web3Service = new Web3Service val netService: NetService = mock[NetService] @@ -101,7 +99,7 @@ class JsonRpcControllerFixture(implicit system: ActorSystem) stxLedger, keyStore, syncingController.ref, - Capability("eth", currentProtocolVersion.toByte), + Capability.ETH63, Timeouts.shortTimeout ) diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerSpec.scala index 5e21bf513f..74fb44f0b6 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerSpec.scala @@ -31,8 +31,7 @@ import io.iohk.ethereum.jsonrpc.server.http.JsonRpcHttpServer import io.iohk.ethereum.jsonrpc.server.ipc.JsonRpcIpcServer import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo import io.iohk.ethereum.network.EtcPeerManagerActor.RemoteStatus -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability class JsonRpcControllerSpec extends TestKit(ActorSystem("JsonRpcControllerSpec_System")) @@ -122,8 +121,7 @@ class JsonRpcControllerSpec it should "debug_listPeersInfo" in new JsonRpcControllerFixture { val peerStatus = RemoteStatus( - protocolFamily = ProtocolFamily.ETH, - protocolVersion = ProtocolVersions.ETH63.version, + capability = Capability.ETH63, networkId = 1, chainWeight = ChainWeight.totalDifficultyOnly(10000), bestHash = Fixtures.Blocks.Block3125369.header.hash, diff --git a/src/test/scala/io/iohk/ethereum/network/EtcPeerManagerSpec.scala b/src/test/scala/io/iohk/ethereum/network/EtcPeerManagerSpec.scala index 64b9e162e8..ae0714a794 100644 --- a/src/test/scala/io/iohk/ethereum/network/EtcPeerManagerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/EtcPeerManagerSpec.scala @@ -29,11 +29,10 @@ import io.iohk.ethereum.network.PeerEventBusActor.PeerSelector import io.iohk.ethereum.network.PeerEventBusActor.Subscribe import io.iohk.ethereum.network.PeerEventBusActor.SubscriptionClassifier._ import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.NewBlock +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.Codes import io.iohk.ethereum.network.p2p.messages.ETC64 import io.iohk.ethereum.network.p2p.messages.ETH62._ -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect import io.iohk.ethereum.utils.Config @@ -302,8 +301,7 @@ class EtcPeerManagerSpec extends AnyFlatSpec with Matchers { val forkResolver = new ForkResolver.EtcForkResolver(blockchainConfig.daoForkConfig.get) val peerStatus: RemoteStatus = RemoteStatus( - protocolFamily = ProtocolFamily.ETH, - protocolVersion = ProtocolVersions.ETH63.version, + capability = Capability.ETH63, networkId = 1, chainWeight = ChainWeight.totalDifficultyOnly(10000), bestHash = Fixtures.Blocks.Block3125369.header.hash, @@ -319,7 +317,7 @@ class EtcPeerManagerSpec extends AnyFlatSpec with Matchers { ) val initialPeerInfoETC64: PeerInfo = PeerInfo( - remoteStatus = peerStatus.copy(protocolVersion = ProtocolVersions.ETC64.version), + remoteStatus = peerStatus.copy(capability = Capability.ETC64), chainWeight = peerStatus.chainWeight, forkAccepted = false, maxBlockNumber = Fixtures.Blocks.Block3125369.header.number, diff --git a/src/test/scala/io/iohk/ethereum/network/PeerActorHandshakingSpec.scala b/src/test/scala/io/iohk/ethereum/network/PeerActorHandshakingSpec.scala index 8b8ae074c3..63a74a28c7 100644 --- a/src/test/scala/io/iohk/ethereum/network/PeerActorHandshakingSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/PeerActorHandshakingSpec.scala @@ -28,8 +28,7 @@ import io.iohk.ethereum.network.handshaker.Handshaker.NextMessage import io.iohk.ethereum.network.handshaker._ import io.iohk.ethereum.network.p2p.Message import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.Status -import io.iohk.ethereum.network.p2p.messages.Capability.Capabilities._ -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect import io.iohk.ethereum.network.p2p.messages.WireProtocol.Hello import io.iohk.ethereum.network.p2p.messages.WireProtocol.Pong @@ -181,7 +180,7 @@ class PeerActorHandshakingSpec extends AnyFlatSpec with Matchers { object DefaultValues { val defaultStatusMsg: Status = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = 1, totalDifficulty = Fixtures.Blocks.Genesis.header.difficulty, bestHash = Fixtures.Blocks.Genesis.header.hash, @@ -204,7 +203,7 @@ class PeerActorHandshakingSpec extends AnyFlatSpec with Matchers { val defaultHello: Hello = Hello( p2pVersion = 0, clientId = "notused", - capabilities = Seq(Eth63Capability), + capabilities = Seq(Capability.ETH63), listenPort = 0, nodeId = ByteString.empty ) diff --git a/src/test/scala/io/iohk/ethereum/network/PeerEventBusActorSpec.scala b/src/test/scala/io/iohk/ethereum/network/PeerEventBusActorSpec.scala index 7b6048c8f7..5ab613aeec 100644 --- a/src/test/scala/io/iohk/ethereum/network/PeerEventBusActorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/PeerEventBusActorSpec.scala @@ -19,8 +19,7 @@ import io.iohk.ethereum.network.PeerEventBusActor.PeerEvent.PeerDisconnected import io.iohk.ethereum.network.PeerEventBusActor.PeerEvent.PeerHandshakeSuccessful import io.iohk.ethereum.network.PeerEventBusActor.PeerSelector import io.iohk.ethereum.network.PeerEventBusActor.SubscriptionClassifier._ -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.WireProtocol.Ping import io.iohk.ethereum.network.p2p.messages.WireProtocol.Pong @@ -251,8 +250,7 @@ class PeerEventBusActorSpec extends AnyFlatSpec with Matchers { val peerEventBusActor: ActorRef = system.actorOf(PeerEventBusActor.props) val peerStatus: RemoteStatus = RemoteStatus( - protocolFamily = ProtocolFamily.ETH, - protocolVersion = ProtocolVersions.ETH63.version, + capability = Capability.ETH63, networkId = 1, chainWeight = ChainWeight.totalDifficultyOnly(10000), bestHash = Fixtures.Blocks.Block3125369.header.hash, diff --git a/src/test/scala/io/iohk/ethereum/network/PeerManagerSpec.scala b/src/test/scala/io/iohk/ethereum/network/PeerManagerSpec.scala index 013199bdcb..7c264b851a 100644 --- a/src/test/scala/io/iohk/ethereum/network/PeerManagerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/PeerManagerSpec.scala @@ -53,8 +53,7 @@ import io.iohk.ethereum.network.discovery.DiscoveryConfig import io.iohk.ethereum.network.discovery.Node import io.iohk.ethereum.network.discovery.PeerDiscoveryManager import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.NewBlock -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect import io.iohk.ethereum.utils.Config @@ -632,8 +631,7 @@ class PeerManagerSpec val blacklist: CacheBasedBlacklist = CacheBasedBlacklist(cache) val peerStatus: RemoteStatus = RemoteStatus( - protocolFamily = ProtocolFamily.ETH, - protocolVersion = ProtocolVersions.ETH63.version, + capability = Capability.ETH63, networkId = 1, chainWeight = ChainWeight.totalDifficultyOnly(10000), bestHash = Fixtures.Blocks.Block3125369.header.hash, diff --git a/src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala b/src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala index dbc80daeb9..47a947ee5d 100644 --- a/src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/handshaker/EtcHandshakerSpec.scala @@ -22,13 +22,11 @@ import io.iohk.ethereum.network.handshaker.Handshaker.HandshakeComplete.Handshak import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.Status.StatusEnc import io.iohk.ethereum.network.p2p.messages.Capability -import io.iohk.ethereum.network.p2p.messages.Capability.Capabilities._ import io.iohk.ethereum.network.p2p.messages.ETC64 import io.iohk.ethereum.network.p2p.messages.ETH62.BlockHeaders import io.iohk.ethereum.network.p2p.messages.ETH62.GetBlockHeaders import io.iohk.ethereum.network.p2p.messages.ETH62.GetBlockHeaders.GetBlockHeadersEnc import io.iohk.ethereum.network.p2p.messages.ETH64 -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect import io.iohk.ethereum.network.p2p.messages.WireProtocol.Hello import io.iohk.ethereum.network.p2p.messages.WireProtocol.Hello.HelloEnc @@ -88,7 +86,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { assert(handshakerAfterStatusOpt.isDefined) handshakerAfterStatusOpt.get.nextMessage match { case Left(HandshakeSuccess(peerInfo)) => - peerInfo.remoteStatus.protocolVersion shouldBe localStatus.protocolVersion + peerInfo.remoteStatus.capability shouldBe localStatus.capability case other => fail(s"Invalid handshaker state: $other") @@ -119,7 +117,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { assert(handshakerAfterStatusOpt.isDefined) handshakerAfterStatusOpt.get.nextMessage match { case Left(HandshakeSuccess(peerInfo)) => - peerInfo.remoteStatus.protocolVersion shouldBe localStatus.protocolVersion + peerInfo.remoteStatus.capability shouldBe localStatus.capability case other => fail(s"Invalid handshaker state: $other") @@ -192,7 +190,8 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { } } - it should "send status with fork id when peer supports ETH64" in new LocalPeerETH64Setup with RemotePeerETH64Setup { + it should "connect correctly after validating fork id when peer supports ETH64" in new LocalPeerETH64Setup + with RemotePeerETH64Setup { val newChainWeight = ChainWeight.zero.increase(genesisBlock.header).increase(firstBlock.header) @@ -218,13 +217,52 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { handshakerAfterStatusOpt.get.nextMessage match { case Left(HandshakeSuccess(peerInfo)) => - peerInfo.remoteStatus.protocolVersion shouldBe localStatus.protocolVersion + peerInfo.remoteStatus.capability shouldBe localStatus.capability case other => fail(s"Invalid handshaker state: $other") } } + it should "disconnect from a useless peer after validating fork id when peer supports ETH64" in new LocalPeerETH64Setup + with RemotePeerETH64Setup { + + val newChainWeight = ChainWeight.zero.increase(genesisBlock.header).increase(firstBlock.header) + + blockchainWriter.save(firstBlock, Nil, newChainWeight, saveAsBestBlock = true) + + val newLocalStatusMsg = + localStatusMsg + .copy( + bestHash = firstBlock.header.hash, + totalDifficulty = newChainWeight.totalDifficulty, + forkId = ForkId(0xfc64ec04L, Some(1150000)) + ) + + initHandshakerWithoutResolver.nextMessage.map(_.messageToSend) shouldBe Right(localHello: HelloEnc) + + val newRemoteStatusMsg = + remoteStatusMsg + .copy( + forkId = ForkId(1, None) // ForkId that is incompatible with our chain + ) + + val handshakerAfterHelloOpt = initHandshakerWithoutResolver.applyMessage(remoteHello) + assert(handshakerAfterHelloOpt.isDefined) + + handshakerAfterHelloOpt.get.nextMessage.map(_.messageToSend.underlyingMsg) shouldBe Right(newLocalStatusMsg) + + val handshakerAfterStatusOpt = handshakerAfterHelloOpt.get.applyMessage(newRemoteStatusMsg) + assert(handshakerAfterStatusOpt.isDefined) + + handshakerAfterStatusOpt.get.nextMessage match { + case Left(HandshakeFailure(Disconnect.Reasons.UselessPeer)) => succeed + case other => + fail(s"Invalid handshaker state: $other") + } + + } + it should "fail if a timeout happened during hello exchange" in new TestSetup { val handshakerAfterTimeout = initHandshakerWithoutResolver.processTimeout handshakerAfterTimeout.nextMessage.map(_.messageToSend) shouldBe Left( @@ -274,9 +312,8 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { } it should "fail if the remote peer doesn't support ETH63/ETC64" in new RemotePeerETH63Setup { - val eth62Capability = ProtocolVersions.ETH62 val handshakerAfterHelloOpt = - initHandshakerWithResolver.applyMessage(remoteHello.copy(capabilities = Seq(eth62Capability))) + initHandshakerWithResolver.applyMessage(remoteHello.copy(capabilities = Nil)) assert(handshakerAfterHelloOpt.isDefined) handshakerAfterHelloOpt.get.nextMessage.leftSide shouldBe Left( HandshakeFailure(Disconnect.Reasons.IncompatibleP2pProtocolVersion) @@ -331,7 +368,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { } val initHandshakerWithoutResolver: EtcHandshaker = EtcHandshaker( - new MockEtcHandshakerConfiguration(List(ProtocolVersions.ETC64, ProtocolVersions.ETH63, ProtocolVersions.ETH64)) + new MockEtcHandshakerConfiguration(List(Capability.ETC64, Capability.ETH63, Capability.ETH64)) ) val initHandshakerWithResolver: EtcHandshaker = EtcHandshaker(etcHandshakerConfigurationWithResolver) @@ -344,7 +381,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { val localHello: Hello = Hello( p2pVersion = EtcHelloExchangeState.P2pVersion, clientId = Config.clientId, - capabilities = Seq(Etc64Capability, Eth63Capability, Eth64Capability), + capabilities = Seq(Capability.ETC64, Capability.ETH63, Capability.ETH64), listenPort = 0, //Local node not listening nodeId = ByteString(nodeStatus.nodeId) ) @@ -355,7 +392,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { trait LocalPeerETH63Setup extends LocalPeerSetup { val localStatusMsg: BaseETH6XMessages.Status = BaseETH6XMessages.Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = Config.Network.peer.networkId, totalDifficulty = genesisBlock.header.difficulty, bestHash = genesisBlock.header.hash, @@ -366,7 +403,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { trait LocalPeerETH64Setup extends LocalPeerSetup { val localStatusMsg: ETH64.Status = ETH64.Status( - protocolVersion = ProtocolVersions.ETH64.version, + protocolVersion = Capability.ETH64.version, networkId = Config.Network.peer.networkId, totalDifficulty = genesisBlock.header.difficulty, bestHash = genesisBlock.header.hash, @@ -378,7 +415,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { trait LocalPeerETC64Setup extends LocalPeerSetup { val localStatusMsg: ETC64.Status = ETC64.Status( - protocolVersion = ProtocolVersions.ETC64.version, + protocolVersion = Capability.ETC64.version, networkId = Config.Network.peer.networkId, chainWeight = ChainWeight.zero.increase(genesisBlock.header), bestHash = genesisBlock.header.hash, @@ -400,13 +437,13 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { val remoteHello: Hello = Hello( p2pVersion = EtcHelloExchangeState.P2pVersion, clientId = "remote-peer", - capabilities = Seq(Eth63Capability), + capabilities = Seq(Capability.ETH63), listenPort = remotePort, nodeId = ByteString(remoteNodeStatus.nodeId) ) val remoteStatusMsg: BaseETH6XMessages.Status = BaseETH6XMessages.Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = Config.Network.peer.networkId, totalDifficulty = 0, bestHash = genesisBlock.header.hash, @@ -420,14 +457,14 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { val remoteHello: Hello = Hello( p2pVersion = EtcHelloExchangeState.P2pVersion, clientId = "remote-peer", - capabilities = Seq(Etc64Capability, Eth63Capability), + capabilities = Seq(Capability.ETC64, Capability.ETH63), listenPort = remotePort, nodeId = ByteString(remoteNodeStatus.nodeId) ) val remoteStatusMsg: ETC64.Status = ETC64.Status( - protocolVersion = ProtocolVersions.ETC64.version, + protocolVersion = Capability.ETC64.version, networkId = Config.Network.peer.networkId, chainWeight = ChainWeight.zero, bestHash = genesisBlock.header.hash, @@ -439,18 +476,18 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers { val remoteHello: Hello = Hello( p2pVersion = EtcHelloExchangeState.P2pVersion, clientId = "remote-peer", - capabilities = Seq(Eth64Capability), + capabilities = Seq(Capability.ETH64), listenPort = remotePort, nodeId = ByteString(remoteNodeStatus.nodeId) ) val remoteStatusMsg: ETH64.Status = ETH64.Status( - protocolVersion = ProtocolVersions.ETH64.version, + protocolVersion = Capability.ETH64.version, networkId = Config.Network.peer.networkId, totalDifficulty = 0, bestHash = genesisBlock.header.hash, genesisHash = genesisBlock.header.hash, - forkId = ForkId(2L, Some(3L)) + forkId = ForkId(0xfc64ec04L, Some(1150000)) ) val remoteStatus: RemoteStatus = RemoteStatus(remoteStatusMsg) diff --git a/src/test/scala/io/iohk/ethereum/network/p2p/MessageCodecSpec.scala b/src/test/scala/io/iohk/ethereum/network/p2p/MessageCodecSpec.scala index 73fa3a3e4e..a143506c63 100644 --- a/src/test/scala/io/iohk/ethereum/network/p2p/MessageCodecSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/p2p/MessageCodecSpec.scala @@ -7,8 +7,7 @@ import org.scalatest.matchers.should.Matchers import io.iohk.ethereum.network.handshaker.EtcHelloExchangeState import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.Status -import io.iohk.ethereum.network.p2p.messages.Capability.Capabilities._ -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.WireProtocol.Hello import io.iohk.ethereum.network.rlpx.FrameCodec import io.iohk.ethereum.network.rlpx.MessageCodec @@ -85,7 +84,7 @@ class MessageCodecSpec extends AnyFlatSpec with Matchers { val helloV5: Hello = Hello( p2pVersion = EtcHelloExchangeState.P2pVersion, clientId = Config.clientId, - capabilities = Seq(Eth63Capability), + capabilities = Seq(Capability.ETH63), listenPort = 0, //Local node not listening nodeId = ByteString(1) ) @@ -93,7 +92,7 @@ class MessageCodecSpec extends AnyFlatSpec with Matchers { val helloV4: Hello = helloV5.copy(p2pVersion = 4) val status: Status = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = Config.Network.peer.networkId, totalDifficulty = 1, bestHash = ByteString(1), @@ -101,7 +100,7 @@ class MessageCodecSpec extends AnyFlatSpec with Matchers { ) val decoder: MessageDecoder = - NetworkMessageDecoder.orElse(EthereumMessageDecoder.ethMessageDecoder(Eth63Capability)) + NetworkMessageDecoder.orElse(EthereumMessageDecoder.ethMessageDecoder(Capability.ETH63)) val messageCodec = new MessageCodec(frameCodec, decoder, negotiatedLocalP2PVersion) val remoteMessageCodec = new MessageCodec(remoteFrameCodec, decoder, negotiatedRemoteP2PVersion) diff --git a/src/test/scala/io/iohk/ethereum/network/p2p/MessageDecodersSpec.scala b/src/test/scala/io/iohk/ethereum/network/p2p/MessageDecodersSpec.scala index 6975b31d34..2e306faaa2 100644 --- a/src/test/scala/io/iohk/ethereum/network/p2p/MessageDecodersSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/p2p/MessageDecodersSpec.scala @@ -11,7 +11,7 @@ import io.iohk.ethereum.ObjectGenerators import io.iohk.ethereum.domain.ChainWeight import io.iohk.ethereum.forkid.ForkId import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.SignedTransactions -import io.iohk.ethereum.network.p2p.messages.Capability.Capabilities._ +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages._ import io.iohk.ethereum.security.SecureRandomBuilder @@ -38,7 +38,7 @@ class MessageDecodersSpec extends AnyFlatSpec with Matchers with SecureRandomBui val hello = WireProtocol.Hello( p2pVersion = 4, clientId = "mantis", - capabilities = Seq(Eth63Capability), + capabilities = Seq(Capability.ETH63), listenPort = 3333, nodeId = ByteString( Hex.decode( @@ -57,23 +57,17 @@ class MessageDecodersSpec extends AnyFlatSpec with Matchers with SecureRandomBui val newBlockHashesETH62 = ETH62.NewBlockHashes(Seq(ETH62.BlockHash(exampleHash, 1), ETH62.BlockHash(exampleHash, 2))) - decode(ProtocolVersions.ETH63) + decode(Capability.ETH63) .fromBytes(Codes.NewBlockHashesCode, NewBlockHashesETH62bytes) shouldBe Right(newBlockHashesETH62) - decode(ProtocolVersions.ETC64) + decode(Capability.ETC64) .fromBytes(Codes.NewBlockHashesCode, NewBlockHashesETH62bytes) shouldBe Right(newBlockHashesETH62) - decode(ProtocolVersions.ETH64) + decode(Capability.ETH64) .fromBytes(Codes.NewBlockHashesCode, NewBlockHashesETH62bytes) shouldBe Right(newBlockHashesETH62) } - it should "not decode message from older version of protocol as newer version" in { - assertThrows[RuntimeException] { - decode(ProtocolVersions.ETH62).fromBytes(Codes.NewBlockHashesCode, NewBlockHashesETH61bytes) - } - } - it should "decode BlockHashesFromNumber message for all supported versions of protocol" in { val blockHashesFromNumber = ETH61.BlockHashesFromNumber(12, 40) - decode(ProtocolVersions.ETH63).fromBytes( + decode(Capability.ETH63).fromBytes( Codes.BlockHashesFromNumberCode, blockHashesFromNumberBytes ) shouldBe Right(blockHashesFromNumber) @@ -83,13 +77,13 @@ class MessageDecodersSpec extends AnyFlatSpec with Matchers with SecureRandomBui val getBlockHeaders = ETH62.GetBlockHeaders(Left(1), 1, 1, false) val getBlockHeadersBytes: Array[Byte] = getBlockHeaders.toBytes - decode(ProtocolVersions.ETH63).fromBytes(Codes.GetBlockHeadersCode, getBlockHeadersBytes) shouldBe Right( + decode(Capability.ETH63).fromBytes(Codes.GetBlockHeadersCode, getBlockHeadersBytes) shouldBe Right( getBlockHeaders ) - decode(ProtocolVersions.ETH64).fromBytes(Codes.GetBlockHeadersCode, getBlockHeadersBytes) shouldBe Right( + decode(Capability.ETH64).fromBytes(Codes.GetBlockHeadersCode, getBlockHeadersBytes) shouldBe Right( getBlockHeaders ) - decode(ProtocolVersions.ETC64).fromBytes(Codes.GetBlockHeadersCode, getBlockHeadersBytes) shouldBe Right( + decode(Capability.ETC64).fromBytes(Codes.GetBlockHeadersCode, getBlockHeadersBytes) shouldBe Right( getBlockHeaders ) } @@ -98,22 +92,22 @@ class MessageDecodersSpec extends AnyFlatSpec with Matchers with SecureRandomBui val blockHeaders = ETH62.BlockHeaders(ObjectGenerators.seqBlockHeaderGen.sample.get) val blockHeadersBytes: Array[Byte] = blockHeaders.toBytes - decode(ProtocolVersions.ETH63).fromBytes(Codes.BlockHeadersCode, blockHeadersBytes) shouldBe Right(blockHeaders) - decode(ProtocolVersions.ETH64).fromBytes(Codes.BlockHeadersCode, blockHeadersBytes) shouldBe Right(blockHeaders) - decode(ProtocolVersions.ETC64).fromBytes(Codes.BlockHeadersCode, blockHeadersBytes) shouldBe Right(blockHeaders) + decode(Capability.ETH63).fromBytes(Codes.BlockHeadersCode, blockHeadersBytes) shouldBe Right(blockHeaders) + decode(Capability.ETH64).fromBytes(Codes.BlockHeadersCode, blockHeadersBytes) shouldBe Right(blockHeaders) + decode(Capability.ETC64).fromBytes(Codes.BlockHeadersCode, blockHeadersBytes) shouldBe Right(blockHeaders) } it should "decode GetBlockBodies message for all supported versions of protocol" in { val getBlockBodies = ETH62.GetBlockBodies(Seq(exampleHash)) val getBlockBodiesBytes: Array[Byte] = getBlockBodies.toBytes - decode(ProtocolVersions.ETH63).fromBytes(Codes.GetBlockBodiesCode, getBlockBodiesBytes) shouldBe Right( + decode(Capability.ETH63).fromBytes(Codes.GetBlockBodiesCode, getBlockBodiesBytes) shouldBe Right( getBlockBodies ) - decode(ProtocolVersions.ETH64).fromBytes(Codes.GetBlockBodiesCode, getBlockBodiesBytes) shouldBe Right( + decode(Capability.ETH64).fromBytes(Codes.GetBlockBodiesCode, getBlockBodiesBytes) shouldBe Right( getBlockBodies ) - decode(ProtocolVersions.ETC64).fromBytes(Codes.GetBlockBodiesCode, getBlockBodiesBytes) shouldBe Right( + decode(Capability.ETC64).fromBytes(Codes.GetBlockBodiesCode, getBlockBodiesBytes) shouldBe Right( getBlockBodies ) } @@ -122,58 +116,58 @@ class MessageDecodersSpec extends AnyFlatSpec with Matchers with SecureRandomBui val blockBodies = ETH62.BlockBodies(Seq(Fixtures.Blocks.Block3125369.body, Fixtures.Blocks.DaoForkBlock.body)) val blockBodiesBytes: Array[Byte] = blockBodies.toBytes - decode(ProtocolVersions.ETH63).fromBytes(Codes.BlockBodiesCode, blockBodiesBytes) shouldBe Right(blockBodies) - decode(ProtocolVersions.ETH64).fromBytes(Codes.BlockBodiesCode, blockBodiesBytes) shouldBe Right(blockBodies) - decode(ProtocolVersions.ETC64).fromBytes(Codes.BlockBodiesCode, blockBodiesBytes) shouldBe Right(blockBodies) + decode(Capability.ETH63).fromBytes(Codes.BlockBodiesCode, blockBodiesBytes) shouldBe Right(blockBodies) + decode(Capability.ETH64).fromBytes(Codes.BlockBodiesCode, blockBodiesBytes) shouldBe Right(blockBodies) + decode(Capability.ETC64).fromBytes(Codes.BlockBodiesCode, blockBodiesBytes) shouldBe Right(blockBodies) } it should "decode GetNodeData message for all supported versions of protocol" in { val getNodeData = ETH63.GetNodeData(Seq(exampleHash)) val getNodeDataBytes: Array[Byte] = getNodeData.toBytes - decode(ProtocolVersions.ETH63).fromBytes(Codes.GetNodeDataCode, getNodeDataBytes) shouldBe Right(getNodeData) - decode(ProtocolVersions.ETH64).fromBytes(Codes.GetNodeDataCode, getNodeDataBytes) shouldBe Right(getNodeData) - decode(ProtocolVersions.ETC64).fromBytes(Codes.GetNodeDataCode, getNodeDataBytes) shouldBe Right(getNodeData) + decode(Capability.ETH63).fromBytes(Codes.GetNodeDataCode, getNodeDataBytes) shouldBe Right(getNodeData) + decode(Capability.ETH64).fromBytes(Codes.GetNodeDataCode, getNodeDataBytes) shouldBe Right(getNodeData) + decode(Capability.ETC64).fromBytes(Codes.GetNodeDataCode, getNodeDataBytes) shouldBe Right(getNodeData) } it should "decode NodeData message for all supported versions of protocol" in { val nodeData = ETH63.NodeData(Seq(exampleHash)) val nodeDataBytes: Array[Byte] = nodeData.toBytes - decode(ProtocolVersions.ETH63).fromBytes(Codes.NodeDataCode, nodeDataBytes) shouldBe Right(nodeData) - decode(ProtocolVersions.ETH64).fromBytes(Codes.NodeDataCode, nodeDataBytes) shouldBe Right(nodeData) - decode(ProtocolVersions.ETC64).fromBytes(Codes.NodeDataCode, nodeDataBytes) shouldBe Right(nodeData) + decode(Capability.ETH63).fromBytes(Codes.NodeDataCode, nodeDataBytes) shouldBe Right(nodeData) + decode(Capability.ETH64).fromBytes(Codes.NodeDataCode, nodeDataBytes) shouldBe Right(nodeData) + decode(Capability.ETC64).fromBytes(Codes.NodeDataCode, nodeDataBytes) shouldBe Right(nodeData) } it should "decode GetReceipts message for all supported versions of protocol" in { val getReceipts = ETH63.GetReceipts(Seq(exampleHash)) val getReceiptsBytes: Array[Byte] = getReceipts.toBytes - decode(ProtocolVersions.ETH63).fromBytes(Codes.GetReceiptsCode, getReceiptsBytes) shouldBe Right(getReceipts) - decode(ProtocolVersions.ETH64).fromBytes(Codes.GetReceiptsCode, getReceiptsBytes) shouldBe Right(getReceipts) - decode(ProtocolVersions.ETC64).fromBytes(Codes.GetReceiptsCode, getReceiptsBytes) shouldBe Right(getReceipts) + decode(Capability.ETH63).fromBytes(Codes.GetReceiptsCode, getReceiptsBytes) shouldBe Right(getReceipts) + decode(Capability.ETH64).fromBytes(Codes.GetReceiptsCode, getReceiptsBytes) shouldBe Right(getReceipts) + decode(Capability.ETC64).fromBytes(Codes.GetReceiptsCode, getReceiptsBytes) shouldBe Right(getReceipts) } it should "decode Receipts message for all supported versions of protocol" in { val receipts = ETH63.Receipts(ObjectGenerators.receiptsGen(3).sample.get) val receiptsBytes: Array[Byte] = receipts.toBytes - decode(ProtocolVersions.ETH63).fromBytes(Codes.ReceiptsCode, receiptsBytes) shouldBe Right(receipts) - decode(ProtocolVersions.ETH64).fromBytes(Codes.ReceiptsCode, receiptsBytes) shouldBe Right(receipts) - decode(ProtocolVersions.ETC64).fromBytes(Codes.ReceiptsCode, receiptsBytes) shouldBe Right(receipts) + decode(Capability.ETH63).fromBytes(Codes.ReceiptsCode, receiptsBytes) shouldBe Right(receipts) + decode(Capability.ETH64).fromBytes(Codes.ReceiptsCode, receiptsBytes) shouldBe Right(receipts) + decode(Capability.ETC64).fromBytes(Codes.ReceiptsCode, receiptsBytes) shouldBe Right(receipts) } it should "decode Status message for all supported versions of protocol" in { - val status63 = BaseETH6XMessages.Status(ProtocolVersions.ETH63.version, 1, BigInt(100), exampleHash, exampleHash) + val status63 = BaseETH6XMessages.Status(Capability.ETH63.version, 1, BigInt(100), exampleHash, exampleHash) val status63Bytes: Array[Byte] = status63.toBytes val statusEtc64 = - ETC64.Status(ProtocolVersions.ETH63.version, 1, ChainWeight(1, BigInt(100)), exampleHash, exampleHash) + ETC64.Status(Capability.ETH63.version, 1, ChainWeight(1, BigInt(100)), exampleHash, exampleHash) val statusEth64 = - ETH64.Status(ProtocolVersions.ETH64.version, 1, BigInt(100), exampleHash, exampleHash, ForkId(1L, None)) + ETH64.Status(Capability.ETH64.version, 1, BigInt(100), exampleHash, exampleHash, ForkId(1L, None)) - decode(ProtocolVersions.ETH63).fromBytes(Codes.StatusCode, status63Bytes) shouldBe Right(status63) - decode(ProtocolVersions.ETH64).fromBytes(Codes.StatusCode, statusEth64.toBytes) shouldBe Right(statusEth64) - decode(ProtocolVersions.ETC64).fromBytes(Codes.StatusCode, statusEtc64.toBytes) shouldBe Right(statusEtc64) + decode(Capability.ETH63).fromBytes(Codes.StatusCode, status63Bytes) shouldBe Right(status63) + decode(Capability.ETH64).fromBytes(Codes.StatusCode, statusEth64.toBytes) shouldBe Right(statusEth64) + decode(Capability.ETC64).fromBytes(Codes.StatusCode, statusEtc64.toBytes) shouldBe Right(statusEtc64) } it should "decode NewBlock message for all supported versions of protocol" in { @@ -181,32 +175,26 @@ class MessageDecodersSpec extends AnyFlatSpec with Matchers with SecureRandomBui val newBlock63Bytes: Array[Byte] = newBlock63.toBytes val newBlock64 = ObjectGenerators.newBlock64Gen(secureRandom, None).sample.get - decode(ProtocolVersions.ETH63).fromBytes(Codes.NewBlockCode, newBlock63Bytes) shouldBe Right(newBlock63) - decode(ProtocolVersions.ETH64).fromBytes(Codes.NewBlockCode, newBlock63Bytes) shouldBe Right(newBlock63) - decode(ProtocolVersions.ETC64).fromBytes(Codes.NewBlockCode, newBlock64.toBytes) shouldBe Right(newBlock64) + decode(Capability.ETH63).fromBytes(Codes.NewBlockCode, newBlock63Bytes) shouldBe Right(newBlock63) + decode(Capability.ETH64).fromBytes(Codes.NewBlockCode, newBlock63Bytes) shouldBe Right(newBlock63) + decode(Capability.ETC64).fromBytes(Codes.NewBlockCode, newBlock64.toBytes) shouldBe Right(newBlock64) } it should "decode SignedTransactions message for all supported versions of protocol" in { val signedTransactions = SignedTransactions(ObjectGenerators.signedTxSeqGen(3, secureRandom, None).sample.get) val signedTransactionsBytes: Array[Byte] = signedTransactions.toBytes - decode(ProtocolVersions.ETH63) + decode(Capability.ETH63) .fromBytes(Codes.SignedTransactionsCode, signedTransactionsBytes) shouldBe Right(signedTransactions) - decode(ProtocolVersions.ETH64) + decode(Capability.ETH64) .fromBytes(Codes.SignedTransactionsCode, signedTransactionsBytes) shouldBe Right(signedTransactions) - decode(ProtocolVersions.ETC64) + decode(Capability.ETC64) .fromBytes(Codes.SignedTransactionsCode, signedTransactionsBytes) shouldBe Right(signedTransactions) } it should "not decode message not existing in given protocol" in { - decode(ProtocolVersions.ETH63) + decode(Capability.ETH63) .fromBytes(Codes.SignedTransactionsCode, blockHashesFromNumberBytes) shouldBe a[Left[_, Message]] } - - it should "not decode message of not supported protocol" in { - assertThrows[RuntimeException] { - decode(ProtocolVersions.ETH61).fromBytes(Codes.NewBlockHashesCode, NewBlockHashesETH61bytes) - } - } } diff --git a/src/test/scala/io/iohk/ethereum/network/p2p/PeerActorSpec.scala b/src/test/scala/io/iohk/ethereum/network/p2p/PeerActorSpec.scala index 22614dc09d..136b4b68bd 100644 --- a/src/test/scala/io/iohk/ethereum/network/p2p/PeerActorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/p2p/PeerActorSpec.scala @@ -45,12 +45,9 @@ import io.iohk.ethereum.network.handshaker.EtcHandshakerConfiguration import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.Status import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.Status.StatusEnc import io.iohk.ethereum.network.p2p.messages.Capability -import io.iohk.ethereum.network.p2p.messages.Capability.Capabilities._ import io.iohk.ethereum.network.p2p.messages.ETC64 import io.iohk.ethereum.network.p2p.messages.ETH62.GetBlockHeaders.GetBlockHeadersEnc import io.iohk.ethereum.network.p2p.messages.ETH62._ -import io.iohk.ethereum.network.p2p.messages.ProtocolFamily -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect.DisconnectEnc import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect.Reasons import io.iohk.ethereum.network.p2p.messages.WireProtocol.Hello.HelloEnc @@ -102,7 +99,7 @@ class PeerActorSpec it should "try to reconnect on broken rlpx connection" in new NodeStatusSetup with HandshakerSetup { implicit override lazy val system = ActorSystem("PeerActorSpec_System") - override def protocol: Capability = ProtocolVersions.ETH63 + override def protocol: Capability = Capability.ETH63 val time = new VirtualTime @@ -153,12 +150,12 @@ class PeerActorSpec rlpxConnection.reply(RLPxConnectionHandler.ConnectionEstablished(remoteNodeId)) //Hello exchange - val remoteHello = Hello(4, "test-client", Seq(Eth63Capability), 9000, ByteString("unused")) + val remoteHello = Hello(4, "test-client", Seq(Capability.ETH63), 9000, ByteString("unused")) rlpxConnection.expectMsgPF() { case RLPxConnectionHandler.SendMessage(_: HelloEnc) => () } rlpxConnection.send(peer, RLPxConnectionHandler.MessageReceived(remoteHello)) val remoteStatus = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = peerConf.networkId, totalDifficulty = daoForkBlockChainTotalDifficulty + 100000, // remote is after the fork bestHash = ByteString("blockhash"), @@ -191,12 +188,12 @@ class PeerActorSpec rlpxConnection.reply(RLPxConnectionHandler.ConnectionEstablished(remoteNodeId)) //Hello exchange - val remoteHello = Hello(4, "test-client", Seq(Eth63Capability), 9000, ByteString("unused")) + val remoteHello = Hello(4, "test-client", Seq(Capability.ETH63), 9000, ByteString("unused")) rlpxConnection.expectMsgPF() { case RLPxConnectionHandler.SendMessage(_: HelloEnc) => () } rlpxConnection.send(peer, RLPxConnectionHandler.MessageReceived(remoteHello)) val remoteStatus = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = peerConf.networkId, totalDifficulty = daoForkBlockChainTotalDifficulty + 100000, // remote is after the fork bestHash = ByteString("blockhash"), @@ -211,7 +208,7 @@ class PeerActorSpec } it should "successfully connect to ETC peer with protocol 64" in new TestSetup { - override def protocol: Capability = ProtocolVersions.ETC64 + override def protocol: Capability = Capability.ETC64 val uri = new URI(s"enode://${Hex.toHexString(remoteNodeId.toArray[Byte])}@localhost:9000") val completeUri = new URI(s"enode://${Hex.toHexString(remoteNodeId.toArray[Byte])}@127.0.0.1:9000?discport=9000") peer ! PeerActor.ConnectTo(uri) @@ -221,12 +218,12 @@ class PeerActorSpec rlpxConnection.reply(RLPxConnectionHandler.ConnectionEstablished(remoteNodeId)) //Hello exchange - val remoteHello = Hello(4, "test-client", Seq(Etc64Capability, Eth63Capability), 9000, ByteString("unused")) + val remoteHello = Hello(4, "test-client", Seq(Capability.ETC64, Capability.ETH63), 9000, ByteString("unused")) rlpxConnection.expectMsgPF() { case RLPxConnectionHandler.SendMessage(_: HelloEnc) => () } rlpxConnection.send(peer, RLPxConnectionHandler.MessageReceived(remoteHello)) val remoteStatus = ETC64.Status( - protocolVersion = ProtocolVersions.ETC64.version, + protocolVersion = Capability.ETC64.version, networkId = peerConf.networkId, chainWeight = ChainWeight.totalDifficultyOnly(daoForkBlockChainTotalDifficulty + 100000), // remote is after the fork @@ -260,12 +257,12 @@ class PeerActorSpec rlpxConnection.reply(RLPxConnectionHandler.ConnectionEstablished(remoteNodeId)) //Hello exchange - val remoteHello = Hello(4, "test-client", Seq(Eth63Capability), 9000, ByteString("unused")) + val remoteHello = Hello(4, "test-client", Seq(Capability.ETH63), 9000, ByteString("unused")) rlpxConnection.expectMsgPF() { case RLPxConnectionHandler.SendMessage(_: HelloEnc) => () } rlpxConnection.send(peer, RLPxConnectionHandler.MessageReceived(remoteHello)) val remoteStatus = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = peerConf.networkId, totalDifficulty = daoForkBlockChainTotalDifficulty + 100000, // remote is after the fork bestHash = ByteString("blockhash"), @@ -294,7 +291,7 @@ class PeerActorSpec rlpxConnection.expectMsgClass(classOf[RLPxConnectionHandler.ConnectTo]) rlpxConnection.reply(RLPxConnectionHandler.ConnectionEstablished(remoteNodeId)) - val remoteHello = Hello(4, "test-client", Seq(Eth63Capability), 9000, ByteString("unused")) + val remoteHello = Hello(4, "test-client", Seq(Capability.ETH63), 9000, ByteString("unused")) rlpxConnection.expectMsgPF() { case RLPxConnectionHandler.SendMessage(_: HelloEnc) => () } rlpxConnection.send(peer, RLPxConnectionHandler.MessageReceived(remoteHello)) @@ -308,7 +305,7 @@ class PeerActorSpec .commit() val remoteStatus = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = peerConf.networkId, totalDifficulty = daoForkBlockChainTotalDifficulty + 100000, // remote is after the fork bestHash = ByteString("blockhash"), @@ -329,12 +326,12 @@ class PeerActorSpec rlpxConnection.expectMsgClass(classOf[RLPxConnectionHandler.ConnectTo]) rlpxConnection.reply(RLPxConnectionHandler.ConnectionEstablished(remoteNodeId)) - val remoteHello = Hello(4, "test-client", Seq(Eth63Capability), 9000, ByteString("unused")) + val remoteHello = Hello(4, "test-client", Seq(Capability.ETH63), 9000, ByteString("unused")) rlpxConnection.expectMsgPF() { case RLPxConnectionHandler.SendMessage(_: HelloEnc) => () } rlpxConnection.send(peer, RLPxConnectionHandler.MessageReceived(remoteHello)) val remoteStatus = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = peerConf.networkId, totalDifficulty = daoForkBlockChainTotalDifficulty + 100000, // remote is after the fork bestHash = ByteString("blockhash"), @@ -376,12 +373,12 @@ class PeerActorSpec rlpxConnection.expectMsgClass(classOf[RLPxConnectionHandler.ConnectTo]) rlpxConnection.reply(RLPxConnectionHandler.ConnectionEstablished(remoteNodeId)) - val remoteHello = Hello(4, "test-client", Seq(Eth63Capability), 9000, ByteString("unused")) + val remoteHello = Hello(4, "test-client", Seq(Capability.ETH63), 9000, ByteString("unused")) rlpxConnection.expectMsgPF() { case RLPxConnectionHandler.SendMessage(_: HelloEnc) => () } rlpxConnection.send(peer, RLPxConnectionHandler.MessageReceived(remoteHello)) val remoteStatus = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = peerConf.networkId, totalDifficulty = daoForkBlockChainTotalDifficulty + 100000, // remote is after the fork bestHash = ByteString("blockhash"), @@ -408,12 +405,12 @@ class PeerActorSpec rlpxConnection.expectMsgClass(classOf[RLPxConnectionHandler.ConnectTo]) rlpxConnection.reply(RLPxConnectionHandler.ConnectionEstablished(remoteNodeId)) - val remoteHello = Hello(4, "test-client", Seq(Eth63Capability), 9000, ByteString("unused")) + val remoteHello = Hello(4, "test-client", Seq(Capability.ETH63), 9000, ByteString("unused")) rlpxConnection.expectMsgPF() { case RLPxConnectionHandler.SendMessage(_: HelloEnc) => () } rlpxConnection.send(peer, RLPxConnectionHandler.MessageReceived(remoteHello)) val remoteStatus = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = peerConf.networkId, totalDifficulty = daoForkBlockChainTotalDifficulty + 100000, // remote is after the fork bestHash = ByteString("blockhash"), @@ -432,8 +429,7 @@ class PeerActorSpec it should "stay connected to pre fork peer" in new TestSetup { val remoteStatus = RemoteStatus( - protocolFamily = ProtocolFamily.ETH, - protocolVersion = ProtocolVersions.ETH63.version, + capability = Capability.ETH63, networkId = peerConf.networkId, chainWeight = ChainWeight.totalDifficultyOnly(daoForkBlockChainTotalDifficulty - 200000), // remote is before the fork @@ -471,12 +467,12 @@ class PeerActorSpec rlpxConnection.expectMsgClass(classOf[RLPxConnectionHandler.ConnectTo]) rlpxConnection.reply(RLPxConnectionHandler.ConnectionEstablished(remoteNodeId)) - val remoteHello = Hello(4, "test-client", Seq(Eth63Capability), 9000, ByteString("unused")) + val remoteHello = Hello(4, "test-client", Seq(Capability.ETH63), 9000, ByteString("unused")) rlpxConnection.expectMsgPF() { case RLPxConnectionHandler.SendMessage(_: HelloEnc) => () } rlpxConnection.send(peer, RLPxConnectionHandler.MessageReceived(remoteHello)) val remoteStatus = Status( - protocolVersion = ProtocolVersions.ETH63.version, + protocolVersion = Capability.ETH63.version, networkId = peerConf.networkId, totalDifficulty = daoForkBlockChainTotalDifficulty + 100000, // remote is after the fork bestHash = ByteString("blockhash"), @@ -596,7 +592,7 @@ class PeerActorSpec } trait TestSetup extends NodeStatusSetup with BlockUtils with HandshakerSetup { - override def protocol: Capability = ProtocolVersions.ETH63 + override def protocol: Capability = Capability.ETH63 val genesisHash = genesisBlock.hash diff --git a/src/test/scala/io/iohk/ethereum/network/p2p/messages/MessagesSerializationSpec.scala b/src/test/scala/io/iohk/ethereum/network/p2p/messages/MessagesSerializationSpec.scala index 4816668695..f576a0b09d 100644 --- a/src/test/scala/io/iohk/ethereum/network/p2p/messages/MessagesSerializationSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/p2p/messages/MessagesSerializationSpec.scala @@ -24,10 +24,10 @@ class MessagesSerializationSpec extends AnyWordSpec with ScalaCheckPropertyCheck "encoding and decoding Hello" should { "return same result" in { verify( - Hello(1, "teest", Seq(Capability("Sample", 1), Capability("Sample", 2)), 1, ByteString("Id")), + Hello(1, "teest", Seq(Capability.ETH63, Capability.ETH64), 1, ByteString("Id")), (m: Hello) => m.toBytes, Hello.code, - ProtocolVersions.ETH63 + Capability.ETH63 ) } } @@ -38,20 +38,20 @@ class MessagesSerializationSpec extends AnyWordSpec with ScalaCheckPropertyCheck Disconnect(Disconnect.Reasons.AlreadyConnected), (m: Disconnect) => m.toBytes, Disconnect.code, - ProtocolVersions.ETH63 + Capability.ETH63 ) } } "encoding and decoding Ping" should { "return same result" in { - verify(Ping(), (m: Ping) => m.toBytes, Ping.code, ProtocolVersions.ETH63) + verify(Ping(), (m: Ping) => m.toBytes, Ping.code, Capability.ETH63) } } "encoding and decoding Pong" should { "return same result" in { - verify(Pong(), (m: Pong) => m.toBytes, Pong.code, ProtocolVersions.ETH63) + verify(Pong(), (m: Pong) => m.toBytes, Pong.code, Capability.ETH63) } } } @@ -60,14 +60,14 @@ class MessagesSerializationSpec extends AnyWordSpec with ScalaCheckPropertyCheck "encoding and decoding SignedTransactions" should { "return same result" in { val msg = SignedTransactions(Fixtures.Blocks.Block3125369.body.transactionList) - verify(msg, (m: SignedTransactions) => m.toBytes, Codes.SignedTransactionsCode, ProtocolVersions.ETH63) + verify(msg, (m: SignedTransactions) => m.toBytes, Codes.SignedTransactionsCode, Capability.ETH63) } } "encoding and decoding NewBlock" should { "return same result for NewBlock v63" in { val msg = NewBlock(Fixtures.Blocks.Block3125369.block, 2323) - verify(msg, (m: NewBlock) => m.toBytes, Codes.NewBlockCode, ProtocolVersions.ETH63) + verify(msg, (m: NewBlock) => m.toBytes, Codes.NewBlockCode, Capability.ETH63) } } } @@ -76,35 +76,35 @@ class MessagesSerializationSpec extends AnyWordSpec with ScalaCheckPropertyCheck "encoding and decoding Status" should { "return same result for Status v64" in { val msg = ETC64.Status(1, 2, ChainWeight(2, 5), ByteString("HASH"), ByteString("HASH2")) - verify(msg, (m: ETC64.Status) => m.toBytes, Codes.StatusCode, ProtocolVersions.ETC64) + verify(msg, (m: ETC64.Status) => m.toBytes, Codes.StatusCode, Capability.ETC64) } } "encoding and decoding NewBlock" should { "return same result for NewBlock v64" in { val msg = ETC64.NewBlock(Fixtures.Blocks.Block3125369.block, ChainWeight(2323, 21)) - verify(msg, (m: ETC64.NewBlock) => m.toBytes, Codes.NewBlockCode, ProtocolVersions.ETC64) + verify(msg, (m: ETC64.NewBlock) => m.toBytes, Codes.NewBlockCode, Capability.ETC64) } } } "ETH63" when { - val version = ProtocolVersions.ETH63 + val version = Capability.ETH63 "encoding and decoding Status" should { "return same result for Status v63" in { val msg = Status(1, 2, 2, ByteString("HASH"), ByteString("HASH2")) - verify(msg, (m: Status) => m.toBytes, Codes.StatusCode, ProtocolVersions.ETH63) + verify(msg, (m: Status) => m.toBytes, Codes.StatusCode, Capability.ETH63) } } commonEthAssertions(version) } "ETH64" when { - val version = ProtocolVersions.ETH64 + val version = Capability.ETH64 "encoding and decoding Status" should { "return same result" in { val msg = ETH64.Status(1, 2, 3, ByteString("HASH"), ByteString("HASH2"), ForkId(1L, None)) - verify(msg, (m: ETH64.Status) => m.toBytes, Codes.StatusCode, ProtocolVersions.ETH64) + verify(msg, (m: ETH64.Status) => m.toBytes, Codes.StatusCode, Capability.ETH64) } } commonEthAssertions(version) diff --git a/src/test/scala/io/iohk/ethereum/network/p2p/messages/NodeDataSpec.scala b/src/test/scala/io/iohk/ethereum/network/p2p/messages/NodeDataSpec.scala index 6678352ca1..a56fd9c6bd 100644 --- a/src/test/scala/io/iohk/ethereum/network/p2p/messages/NodeDataSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/p2p/messages/NodeDataSpec.scala @@ -19,6 +19,7 @@ import io.iohk.ethereum.mpt.LeafNode import io.iohk.ethereum.mpt.MptNode import io.iohk.ethereum.mpt.NullNode import io.iohk.ethereum.network.p2p.EthereumMessageDecoder +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.ETH63.MptNodeEncoders._ import io.iohk.ethereum.network.p2p.messages.ETH63._ import io.iohk.ethereum.rlp.RLPImplicitConversions._ @@ -89,7 +90,7 @@ class NodeDataSpec extends AnyFlatSpec with Matchers { it should "be decoded properly" in { val result = EthereumMessageDecoder - .ethMessageDecoder(ProtocolVersions.ETH63) + .ethMessageDecoder(Capability.ETH63) .fromBytes(Codes.NodeDataCode, encode(encodedNodeData)) .getOrElse(fail("Should have decoded NodeData")) @@ -106,7 +107,7 @@ class NodeDataSpec extends AnyFlatSpec with Matchers { it should "be decoded previously encoded value" in { EthereumMessageDecoder - .ethMessageDecoder(ProtocolVersions.ETH63) + .ethMessageDecoder(Capability.ETH63) .fromBytes(Codes.NodeDataCode, nodeData.toBytes) shouldBe Right(nodeData) } diff --git a/src/test/scala/io/iohk/ethereum/network/p2p/messages/ReceiptsSpec.scala b/src/test/scala/io/iohk/ethereum/network/p2p/messages/ReceiptsSpec.scala index 3092e727e9..1eb844e63d 100644 --- a/src/test/scala/io/iohk/ethereum/network/p2p/messages/ReceiptsSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/p2p/messages/ReceiptsSpec.scala @@ -11,6 +11,7 @@ import io.iohk.ethereum.domain.Address import io.iohk.ethereum.domain.Receipt import io.iohk.ethereum.domain.TxLogEntry import io.iohk.ethereum.network.p2p.EthereumMessageDecoder +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.ETH63.Receipts import io.iohk.ethereum.rlp.RLPImplicitConversions._ import io.iohk.ethereum.rlp.RLPImplicits._ @@ -56,7 +57,7 @@ class ReceiptsSpec extends AnyFlatSpec with Matchers { it should "decode receipts" in { EthereumMessageDecoder - .ethMessageDecoder(ProtocolVersions.ETH63) + .ethMessageDecoder(Capability.ETH63) .fromBytes( Codes.ReceiptsCode, encode(encodedReceipts) @@ -65,7 +66,7 @@ class ReceiptsSpec extends AnyFlatSpec with Matchers { it should "decode encoded receipts" in { EthereumMessageDecoder - .ethMessageDecoder(ProtocolVersions.ETH63) + .ethMessageDecoder(Capability.ETH63) .fromBytes(Codes.ReceiptsCode, receipts.toBytes) shouldBe Right(receipts) } } diff --git a/src/test/scala/io/iohk/ethereum/network/rlpx/RLPxConnectionHandlerSpec.scala b/src/test/scala/io/iohk/ethereum/network/rlpx/RLPxConnectionHandlerSpec.scala index 29f5ad42c8..aa0511294b 100644 --- a/src/test/scala/io/iohk/ethereum/network/rlpx/RLPxConnectionHandlerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/rlpx/RLPxConnectionHandlerSpec.scala @@ -22,8 +22,7 @@ import io.iohk.ethereum.Timeouts import io.iohk.ethereum.WithActorSystemShutDown import io.iohk.ethereum.network.p2p.MessageDecoder import io.iohk.ethereum.network.p2p.MessageSerializable -import io.iohk.ethereum.network.p2p.messages.Capability.Capabilities -import io.iohk.ethereum.network.p2p.messages.ProtocolVersions +import io.iohk.ethereum.network.p2p.messages.Capability import io.iohk.ethereum.network.p2p.messages.WireProtocol.Hello import io.iohk.ethereum.network.p2p.messages.WireProtocol.Ping import io.iohk.ethereum.network.rlpx.RLPxConnectionHandler.HelloCodec @@ -192,7 +191,7 @@ class RLPxConnectionHandlerSpec override def fromBytes(`type`: Int, payload: Array[Byte]) = throw new Exception("Mock message decoder fails to decode all messages") } - val protocolVersion = ProtocolVersions.ETH63 + val protocolVersion = Capability.ETH63 val mockHandshaker: AuthHandshaker = mock[AuthHandshaker] val connection: TestProbe = TestProbe() val mockMessageCodec: MessageCodec = mock[MessageCodec] @@ -243,7 +242,7 @@ class RLPxConnectionHandlerSpec .returning((response, AuthHandshakeSuccess(mock[Secrets], ByteString()))) (mockHelloExtractor.readHello _) .expects(ByteString.empty) - .returning(Some((Hello(5, "", Capabilities.Eth63Capability :: Nil, 30303, ByteString("abc")), Seq.empty))) + .returning(Some((Hello(5, "", Capability.ETH63 :: Nil, 30303, ByteString("abc")), Seq.empty))) (mockMessageCodec.readMessages _) .expects(hello) .returning(Nil) //For processing of messages after handshaking finishes