@@ -8,12 +8,14 @@ import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup
8
8
import io .iohk .ethereum .crypto .generateKeyPair
9
9
import io .iohk .ethereum .db .storage .AppStateStorage
10
10
import io .iohk .ethereum .domain ._
11
+ import io .iohk .ethereum .forkid .ForkId
11
12
import io .iohk .ethereum .network .EtcPeerManagerActor .{PeerInfo , RemoteStatus }
12
13
import io .iohk .ethereum .network .ForkResolver
13
14
import io .iohk .ethereum .network .PeerManagerActor .PeerConfiguration
14
15
import io .iohk .ethereum .network .handshaker .Handshaker .HandshakeComplete .{HandshakeFailure , HandshakeSuccess }
15
16
import io .iohk .ethereum .network .p2p .messages .Capability .Capabilities ._
16
17
import io .iohk .ethereum .network .p2p .messages .BaseETH6XMessages .Status .StatusEnc
18
+ import io .iohk .ethereum .network .p2p .messages .ETH64
17
19
import io .iohk .ethereum .network .p2p .messages .ETH62 .GetBlockHeaders .GetBlockHeadersEnc
18
20
import io .iohk .ethereum .network .p2p .messages .ETH62 .{BlockHeaders , GetBlockHeaders }
19
21
import io .iohk .ethereum .network .p2p .messages .WireProtocol .Hello .HelloEnc
@@ -181,6 +183,40 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
181
183
}
182
184
}
183
185
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
+
184
220
it should " fail if a timeout happened during hello exchange" in new TestSetup {
185
221
val handshakerAfterTimeout = initHandshakerWithoutResolver.processTimeout
186
222
handshakerAfterTimeout.nextMessage.map(_.messageToSend) shouldBe Left (
@@ -278,6 +314,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
278
314
override val appStateStorage : AppStateStorage = TestSetup .this .storagesInstance.storages.appStateStorage
279
315
override val capabilities : List [Capability ] = pv
280
316
override val blockchainReader : BlockchainReader = TestSetup .this .blockchainReader
317
+ override val blockchainConfig : BlockchainConfig = TestSetup .this .blockchainConfig
281
318
}
282
319
283
320
val etcHandshakerConfigurationWithResolver = new MockEtcHandshakerConfiguration {
@@ -287,7 +324,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
287
324
}
288
325
289
326
val initHandshakerWithoutResolver = EtcHandshaker (
290
- new MockEtcHandshakerConfiguration (List (ProtocolVersions .ETC64 , ProtocolVersions .ETH63 ))
327
+ new MockEtcHandshakerConfiguration (List (ProtocolVersions .ETC64 , ProtocolVersions .ETH63 , ProtocolVersions . ETH64 ))
291
328
)
292
329
293
330
val initHandshakerWithResolver = EtcHandshaker (etcHandshakerConfigurationWithResolver)
@@ -300,7 +337,7 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
300
337
val localHello = Hello (
301
338
p2pVersion = EtcHelloExchangeState .P2pVersion ,
302
339
clientId = Config .clientId,
303
- capabilities = Seq (Etc64Capability , Eth63Capability ),
340
+ capabilities = Seq (Etc64Capability , Eth63Capability , Eth64Capability ),
304
341
listenPort = 0 , // Local node not listening
305
342
nodeId = ByteString (nodeStatus.nodeId)
306
343
)
@@ -320,6 +357,18 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
320
357
val localStatus = RemoteStatus (localStatusMsg)
321
358
}
322
359
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
+
323
372
trait LocalPeerETC64Setup extends LocalPeerSetup {
324
373
val localStatusMsg = ETC64 .Status (
325
374
protocolVersion = ProtocolVersions .ETC64 .version,
@@ -378,4 +427,25 @@ class EtcHandshakerSpec extends AnyFlatSpec with Matchers {
378
427
genesisHash = genesisBlock.header.hash
379
428
)
380
429
}
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
+ }
381
451
}
0 commit comments