Skip to content

Commit 786f0a7

Browse files
author
Łukasz Gąsior
committed
Send proper config based on vm type
1 parent 9e8b4de commit 786f0a7

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

src/main/scala/io/iohk/ethereum/extvm/ExtVMInterface.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import akka.stream.{ActorMaterializer, OverflowStrategy}
77
import akka.stream.scaladsl.{Framing, Keep, Sink, SinkQueueWithCancel, Source, SourceQueueWithComplete, Tcp}
88
import akka.util.ByteString
99
import io.iohk.ethereum.ledger.{InMemoryWorldStateProxy, InMemoryWorldStateProxyStorage}
10-
import io.iohk.ethereum.utils.BlockchainConfig
10+
import io.iohk.ethereum.utils.{BlockchainConfig, VmConfig}
1111
import io.iohk.ethereum.vm._
1212

1313
import scala.annotation.tailrec
1414
import scala.util.{Failure, Success, Try}
1515

16-
class ExtVMInterface(host: String, port: Int, blockchainConfig: BlockchainConfig, testMode: Boolean)(implicit system: ActorSystem)
16+
class ExtVMInterface(externaVmConfig: VmConfig.ExternalConfig, blockchainConfig: BlockchainConfig, testMode: Boolean)(implicit system: ActorSystem)
1717
extends VM[InMemoryWorldStateProxy, InMemoryWorldStateProxyStorage]{
1818

1919
private implicit val materializer = ActorMaterializer()
@@ -29,7 +29,7 @@ class ExtVMInterface(host: String, port: Int, blockchainConfig: BlockchainConfig
2929
private def initConnection(): Unit = {
3030
close()
3131

32-
val connection = Tcp().outgoingConnection(host, port)
32+
val connection = Tcp().outgoingConnection(externaVmConfig.host, externaVmConfig.port)
3333

3434
val (connOut, connIn) = Source.queue[ByteString](QueueBufferSize, OverflowStrategy.dropTail)
3535
.via(connection)
@@ -41,7 +41,7 @@ class ExtVMInterface(host: String, port: Int, blockchainConfig: BlockchainConfig
4141
out = Some(connOut)
4242
in = Some(connIn)
4343

44-
val client = new VMClient(new MessageHandler(connIn, connOut), testMode)
44+
val client = new VMClient(externaVmConfig, new MessageHandler(connIn, connOut), testMode)
4545
client.sendHello(ApiVersionProvider.version, blockchainConfig)
4646
//TODO: await hello response, check version
4747

src/main/scala/io/iohk/ethereum/extvm/VMClient.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import io.iohk.ethereum.vm.{WorldStateProxy, _}
55
import Implicits._
66
import akka.util.ByteString
77
import io.iohk.ethereum.domain._
8-
import io.iohk.ethereum.utils.{BlockchainConfig, Logger}
8+
import io.iohk.ethereum.utils.{BlockchainConfig, Logger, VmConfig}
99

1010
import scala.annotation.tailrec
1111

@@ -14,13 +14,17 @@ import scala.annotation.tailrec
1414
* This is useful to override configuration for each test, rather than to recreate the VM.
1515
*/
1616
class VMClient(
17+
externalVmConfig: VmConfig.ExternalConfig,
1718
messageHandler: MessageHandler,
1819
testMode: Boolean)
1920
extends Logger {
2021

2122
def sendHello(version: String, blockchainConfig: BlockchainConfig): Unit = {
2223
val config = BlockchainConfigForEvm(blockchainConfig)
23-
val configMsg = msg.Hello.Config.EthereumConfig(buildEthereumConfigMsg(BlockchainConfigForEvm(blockchainConfig)))
24+
val configMsg = externalVmConfig.vmType match {
25+
case VmConfig.ExternalConfig.VmTypeIele => msg.Hello.Config.IeleConfig(buildIeleConfigMsg())
26+
case _ => msg.Hello.Config.EthereumConfig(buildEthereumConfigMsg(config))
27+
}
2428
val helloMsg = msg.Hello(version, configMsg)
2529
messageHandler.sendMessage(helloMsg)
2630
}
@@ -154,6 +158,9 @@ class VMClient(
154158
accountStartNonce = blockchainConfig.accountStartNonce
155159
)
156160

161+
private def buildIeleConfigMsg(): msg.IeleConfig =
162+
msg.IeleConfig()
163+
157164
private def buildBlockHeaderMsg(header: BlockHeader): msg.BlockHeader =
158165
msg.BlockHeader(
159166
beneficiary = header.beneficiary,

src/main/scala/io/iohk/ethereum/nodebuilder/VmSetup.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object VmSetup {
1919

2020
case (External, Some(extConf)) =>
2121
startExternalVm(extConf)
22-
new ExtVMInterface(extConf.host, extConf.port, blockchainConfig, testMode)
22+
new ExtVMInterface(extConf, blockchainConfig, testMode)
2323

2424
case _ =>
2525
throw new RuntimeException("Missing vm.external config for external VM")

src/main/scala/io/iohk/ethereum/utils/Config.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,22 @@ object VmConfig {
369369
case object External extends VmMode
370370
}
371371

372+
object ExternalConfig {
373+
val VmTypeIele = "iele"
374+
val VmTypeKevm = "kevm"
375+
val VmTypeMantis = "mantis"
376+
val VmTypeNone = "none"
377+
378+
val supportedVmTypes = Set(VmTypeIele, VmTypeKevm, VmTypeMantis, VmTypeNone)
379+
}
380+
372381
case class ExternalConfig(vmType: String, executablePath: Option[String], host: String, port: Int)
373382

374383
def apply(mpConfig: TypesafeConfig): VmConfig = {
375384
def parseExternalConfig(): ExternalConfig = {
385+
import ExternalConfig._
386+
376387
val extConf = mpConfig.getConfig("vm.external")
377-
val supportedVmTypes = Set("iele", "kevm", "mantis", "none")
378388
val vmType = extConf.getString("vm-type").toLowerCase
379389
require(supportedVmTypes.contains(vmType), "vm.external.vm-type must be one of: " + supportedVmTypes.mkString(", "))
380390

src/test/scala/io/iohk/ethereum/extvm/VMClientSpec.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import akka.util.ByteString
44
import com.trueaccord.scalapb.GeneratedMessageCompanion
55
import io.iohk.ethereum.domain.{Account, Address, UInt256}
66
import io.iohk.ethereum.extvm.msg.CallContext.Config
7-
import io.iohk.ethereum.utils.BlockchainConfig
7+
import io.iohk.ethereum.utils.{BlockchainConfig, VmConfig}
88
import io.iohk.ethereum.vm.utils.MockVmInput
99
import io.iohk.ethereum.vm._
1010
import org.scalamock.scalatest.MockFactory
@@ -188,7 +188,9 @@ class VMClientSpec extends FlatSpec with Matchers with MockFactory {
188188
val resultQueryMsg = msg.VMQuery(query = msg.VMQuery.Query.CallResult(callResultMsg))
189189

190190
val messageHandler = mock[MessageHandler]
191-
val vmClient = new VMClient(messageHandler, testMode = false)
191+
192+
val externalVmConfig = VmConfig.ExternalConfig("mantis", None, "127.0.0.1", 0)
193+
val vmClient = new VMClient(externalVmConfig, messageHandler, testMode = false)
192194
}
193195

194196
}

0 commit comments

Comments
 (0)