@@ -8,12 +8,14 @@ import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
88import io .iohk .ethereum .crypto .generateKeyPair
99import io .iohk .ethereum .db .storage .AppStateStorage
1010import io .iohk .ethereum .domain ._
11+ import io .iohk .ethereum .forkid .ForkId
1112import io .iohk .ethereum .network .EtcPeerManagerActor .{PeerInfo , RemoteStatus }
1213import io .iohk .ethereum .network .ForkResolver
1314import io .iohk .ethereum .network .PeerManagerActor .PeerConfiguration
1415import io .iohk .ethereum .network .handshaker .Handshaker .HandshakeComplete .{HandshakeFailure , HandshakeSuccess }
1516import io .iohk .ethereum .network .p2p .messages .Capability .Capabilities ._
1617import io .iohk .ethereum .network .p2p .messages .BaseETH6XMessages .Status .StatusEnc
18+ import io .iohk .ethereum .network .p2p .messages .ETH64
1719import io .iohk .ethereum .network .p2p .messages .ETH62 .GetBlockHeaders .GetBlockHeadersEnc
1820import io .iohk .ethereum .network .p2p .messages .ETH62 .{BlockHeaders , GetBlockHeaders }
1921import io .iohk .ethereum .network .p2p .messages .WireProtocol .Hello .HelloEnc
@@ -181,6 +183,40 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
181183 }
182184 }
183185
186+ it should " send status with fork id when peer supports ETH64" in new LocalPeerETH64Setup
187+ with RemotePeerETH64Setup {
188+
189+ val newChainWeight = ChainWeight .zero.increase(genesisBlock.header).increase(firstBlock.header)
190+
191+ blockchain.save(firstBlock, Nil , newChainWeight, saveAsBestBlock = true )
192+
193+ val newLocalStatusMsg =
194+ localStatusMsg
195+ .copy(
196+ bestHash = firstBlock.header.hash,
197+ totalDifficulty = newChainWeight.totalDifficulty,
198+ forkId = ForkId (0xfc64ec04L, Some (1150000 ))
199+ )
200+
201+ initHandshakerWithoutResolver.nextMessage.map(_.messageToSend) shouldBe Right (localHello : HelloEnc )
202+
203+ val handshakerAfterHelloOpt = initHandshakerWithoutResolver.applyMessage(remoteHello)
204+ assert(handshakerAfterHelloOpt.isDefined)
205+
206+ handshakerAfterHelloOpt.get.nextMessage.map(_.messageToSend.underlyingMsg) shouldBe Right (newLocalStatusMsg)
207+
208+ val handshakerAfterStatusOpt = handshakerAfterHelloOpt.get.applyMessage(remoteStatusMsg)
209+ assert(handshakerAfterStatusOpt.isDefined)
210+
211+ handshakerAfterStatusOpt.get.nextMessage match {
212+ case Left (HandshakeSuccess (peerInfo)) =>
213+ peerInfo.remoteStatus.protocolVersion shouldBe localStatus.protocolVersion
214+
215+ case other =>
216+ fail(s " Invalid handshaker state: $other" )
217+ }
218+ }
219+
184220 it should " fail if a timeout happened during hello exchange" in new TestSetup {
185221 val handshakerAfterTimeout = initHandshakerWithoutResolver.processTimeout
186222 handshakerAfterTimeout.nextMessage.map(_.messageToSend) shouldBe Left (
@@ -278,6 +314,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
278314 override val appStateStorage : AppStateStorage = TestSetup .this .storagesInstance.storages.appStateStorage
279315 override val capabilities : List [Capability ] = pv
280316 override val blockchainReader : BlockchainReader = TestSetup .this .blockchainReader
317+ override val blockchainConfig : BlockchainConfig = TestSetup .this .blockchainConfig
281318 }
282319
283320 val etcHandshakerConfigurationWithResolver = new MockEtcHandshakerConfiguration {
@@ -287,7 +324,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
287324 }
288325
289326 val initHandshakerWithoutResolver = EtcHandshaker (
290- new MockEtcHandshakerConfiguration (List (ProtocolVersions .ETC64 , ProtocolVersions .ETH63 ))
327+ new MockEtcHandshakerConfiguration (List (ProtocolVersions .ETC64 , ProtocolVersions .ETH63 , ProtocolVersions . ETH64 ))
291328 )
292329
293330 val initHandshakerWithResolver = EtcHandshaker (etcHandshakerConfigurationWithResolver)
@@ -300,7 +337,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
300337 val localHello = Hello (
301338 p2pVersion = EtcHelloExchangeState .P2pVersion ,
302339 clientId = Config .clientId,
303- capabilities = Seq (Etc64Capability , Eth63Capability ),
340+ capabilities = Seq (Etc64Capability , Eth63Capability , Eth64Capability ),
304341 listenPort = 0 , // Local node not listening
305342 nodeId = ByteString (nodeStatus.nodeId)
306343 )
@@ -320,6 +357,18 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
320357 val localStatus = RemoteStatus (localStatusMsg)
321358 }
322359
360+ trait LocalPeerETH64Setup extends LocalPeerSetup {
361+ val localStatusMsg = ETH64 .Status (
362+ protocolVersion = ProtocolVersions .ETH64 .version,
363+ networkId = Config .Network .peer.networkId,
364+ totalDifficulty = genesisBlock.header.difficulty,
365+ bestHash = genesisBlock.header.hash,
366+ genesisHash = genesisBlock.header.hash,
367+ forkId = ForkId (1L , None )
368+ )
369+ val localStatus = RemoteStatus (localStatusMsg)
370+ }
371+
323372 trait LocalPeerETC64Setup extends LocalPeerSetup {
324373 val localStatusMsg = ETC64 .Status (
325374 protocolVersion = ProtocolVersions .ETC64 .version,
@@ -378,4 +427,25 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
378427 genesisHash = genesisBlock.header.hash
379428 )
380429 }
430+
431+ trait RemotePeerETH64Setup extends RemotePeerSetup {
432+ val remoteHello = Hello (
433+ p2pVersion = EtcHelloExchangeState .P2pVersion ,
434+ clientId = " remote-peer" ,
435+ capabilities = Seq (Eth64Capability ),
436+ listenPort = remotePort,
437+ nodeId = ByteString (remoteNodeStatus.nodeId)
438+ )
439+
440+ val remoteStatusMsg = ETH64 .Status (
441+ protocolVersion = ProtocolVersions .ETH64 .version,
442+ networkId = Config .Network .peer.networkId,
443+ totalDifficulty = 0 ,
444+ bestHash = genesisBlock.header.hash,
445+ genesisHash = genesisBlock.header.hash,
446+ forkId = ForkId (2L , Some (3L ))
447+ )
448+
449+ val remoteStatus = RemoteStatus (remoteStatusMsg)
450+ }
381451}
0 commit comments