Skip to content

Commit 856507c

Browse files
committed
ETCM-165: Move RLP into its own sbt sub-project.
1 parent 7031c7f commit 856507c

File tree

10 files changed

+165
-113
lines changed

10 files changed

+165
-113
lines changed

build.sbt

Lines changed: 136 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -9,70 +9,126 @@ val nixBuild = sys.props.isDefinedAt("nix")
99
// Enable dev mode: disable certain flags, etc.
1010
val mantisDev = sys.props.get("mantisDev").contains("true") || sys.env.get("MANTIS_DEV").contains("true")
1111

12-
val commonSettings = Seq(
13-
name := "mantis",
12+
def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
13+
name := s"mantis-${projectName}",
1414
version := "3.1.0",
1515
scalaVersion := "2.12.12",
1616
// Scalanet snapshots are published to Sonatype after each build.
1717
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
1818
testOptions in Test += Tests
19-
.Argument(TestFrameworks.ScalaTest, "-l", "EthashMinerSpec") // miner tests disabled by default
20-
)
19+
.Argument(TestFrameworks.ScalaTest, "-l", "EthashMinerSpec"), // miner tests disabled by default,
20+
21+
scalacOptions := Seq(
22+
"-unchecked",
23+
"-deprecation",
24+
"-feature",
25+
"-Xfatal-warnings",
26+
"-Xlint:unsound-match",
27+
"-Ywarn-inaccessible",
28+
"-Ywarn-unused-import",
29+
"-Ypartial-unification",
30+
"-encoding",
31+
"utf-8"
32+
),
33+
34+
scalacOptions in (Compile, console) ~= (_.filterNot(
35+
Set(
36+
"-Ywarn-unused-import",
37+
"-Xfatal-warnings"
38+
)
39+
)),
40+
41+
scalacOptions ~= (options => if (mantisDev) options.filterNot(_ == "-Xfatal-warnings") else options),
2142

22-
val malletDeps = Seq(
23-
Dependencies.scopt
24-
).flatten ++ Seq(
25-
Dependencies.jline,
26-
Dependencies.jna
43+
Test / parallelExecution := true,
44+
45+
testOptions in Test += Tests.Argument("-oDG"),
46+
47+
(scalastyleConfig in Test) := file("scalastyle-test-config.xml")
2748
)
2849

29-
val dep = {
30-
Seq(
31-
Dependencies.akka,
32-
Dependencies.akkaHttp,
33-
Dependencies.json4s,
34-
Dependencies.circe,
35-
Dependencies.boopickle,
36-
Dependencies.rocksDb,
37-
Dependencies.enumeratum,
38-
Dependencies.testing,
39-
Dependencies.cats,
40-
Dependencies.monix,
41-
Dependencies.network,
42-
Dependencies.twitterUtilCollection,
43-
Dependencies.crypto,
44-
Dependencies.scopt,
45-
Dependencies.logging,
46-
Dependencies.apacheCommons,
47-
Dependencies.micrometer,
48-
Dependencies.prometheus,
49-
Dependencies.cli,
50-
Dependencies.dependencies
51-
).flatten ++ malletDeps
50+
lazy val rlp = {
51+
// Adding an "it" config because in `Dependencies.scala` some are declared with `% "it,test"`
52+
// which would fail if the project didn't have configuration to add to.
53+
val Integration = config("it") extend Test
54+
55+
val rlp = project
56+
.in(file("rlp"))
57+
.configs(Integration)
58+
.settings(commonSettings("rlp"))
59+
.settings(
60+
libraryDependencies ++=
61+
Dependencies.akkaUtil ++
62+
Dependencies.shapeless ++
63+
Dependencies.testing
64+
)
65+
66+
rlp
5267
}
5368

54-
val Integration = config("it") extend Test
69+
lazy val node = {
5570

56-
val Benchmark = config("benchmark") extend Test
71+
val Integration = config("it") extend Test
5772

58-
val Evm = config("evm") extend Test
73+
val Benchmark = config("benchmark") extend Test
5974

60-
val Ets = config("ets") extend Test
75+
val Evm = config("evm") extend Test
6176

62-
val Snappy = config("snappy") extend Test
77+
val Ets = config("ets") extend Test
6378

64-
val Rpc = config("rpcTest") extend Test
79+
val Snappy = config("snappy") extend Test
6580

66-
val root = {
67-
val root = project
81+
val Rpc = config("rpcTest") extend Test
82+
83+
val malletDeps = Seq(
84+
Dependencies.scopt
85+
).flatten ++ Seq(
86+
Dependencies.jline,
87+
Dependencies.jna
88+
)
89+
90+
val dep = {
91+
Seq(
92+
Dependencies.akka,
93+
Dependencies.akkaHttp,
94+
Dependencies.json4s,
95+
Dependencies.circe,
96+
Dependencies.boopickle,
97+
Dependencies.rocksDb,
98+
Dependencies.enumeratum,
99+
Dependencies.testing,
100+
Dependencies.cats,
101+
Dependencies.monix,
102+
Dependencies.network,
103+
Dependencies.twitterUtilCollection,
104+
Dependencies.crypto,
105+
Dependencies.scopt,
106+
Dependencies.logging,
107+
Dependencies.apacheCommons,
108+
Dependencies.micrometer,
109+
Dependencies.prometheus,
110+
Dependencies.cli,
111+
Dependencies.dependencies
112+
).flatten ++ malletDeps
113+
}
114+
115+
scalastyleSources in Test ++= { (unmanagedSourceDirectories in Integration).value }
116+
117+
(test in Evm) := (test in Evm).dependsOn(solidityCompile).value
118+
(sourceDirectory in Evm) := baseDirectory.value / "src" / "evmTest"
119+
120+
val sep = java.io.File.separator
121+
122+
val node = project
68123
.in(file("."))
69124
.configs(Integration, Benchmark, Evm, Ets, Snappy, Rpc)
70125
.enablePlugins(BuildInfoPlugin)
126+
.dependsOn(rlp)
71127
.settings(
72128
buildInfoKeys := Seq[BuildInfoKey](name, version, git.gitHeadCommit),
73129
buildInfoPackage := "io.iohk.ethereum.utils"
74130
)
75-
.settings(commonSettings: _*)
131+
.settings(commonSettings("node"): _*)
76132
.settings(
77133
libraryDependencies ++= dep
78134
)
@@ -88,80 +144,50 @@ val root = {
88144
.settings(inConfig(Ets)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
89145
.settings(inConfig(Snappy)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
90146
.settings(inConfig(Rpc)(Defaults.testSettings :+ (Test / parallelExecution := false)): _*)
147+
.settings(
148+
// protobuf compilation
149+
// Into a subdirectory of src_managed to avoid it deleting other generated files; see https://github.com/sbt/sbt-buildinfo/issues/149
150+
PB.targets in Compile := Seq(
151+
scalapb.gen() -> (sourceManaged in Compile).value / "protobuf"
152+
),
153+
154+
// have the protobuf API version file as a resource
155+
unmanagedResourceDirectories in Compile += baseDirectory.value / "src" / "main" / "protobuf",
156+
157+
// Packaging
158+
mainClass in Compile := Some("io.iohk.ethereum.App"),
159+
executableScriptName := name.value,
160+
discoveredMainClasses in Compile := Seq(),
161+
// Requires the 'ant-javafx.jar' that comes with Oracle JDK
162+
// Enables creating an executable with the configuration files, has to be run on the OS corresponding to the desired version
163+
ThisBuild / jdkPackagerType := "image",
164+
165+
mappings in Universal += (resourceDirectory in Compile).value / "logback.xml" -> "conf/logback.xml",
166+
mappings in Universal += (resourceDirectory in Compile).value / "application.conf" -> "conf/base.conf",
167+
mappings in Universal ++= directory((resourceDirectory in Compile).value / "chains").map { case (f, name) =>
168+
f -> s"conf/$name"
169+
},
170+
171+
jdkPackagerJVMArgs := Seq(
172+
"-Dconfig.file=." + sep + "conf" + sep + "app.conf",
173+
"-Dlogback.configurationFile=." + sep + "conf" + sep + "logback.xml",
174+
"-Xss10M"
175+
)
176+
)
91177

92178
if (!nixBuild)
93-
root
179+
node
94180
else
95-
root.settings(PB.runProtoc in Compile := (args => Process("protoc", args) !))
181+
node.settings(PB.runProtoc in Compile := (args => Process("protoc", args) !))
96182
}
97183

98-
scalacOptions := Seq(
99-
"-unchecked",
100-
"-deprecation",
101-
"-feature",
102-
"-Xfatal-warnings",
103-
"-Xlint:unsound-match",
104-
"-Ywarn-inaccessible",
105-
"-Ywarn-unused-import",
106-
"-Ypartial-unification",
107-
"-encoding",
108-
"utf-8"
109-
)
110-
111-
scalacOptions in (Compile, console) ~= (_.filterNot(
112-
Set(
113-
"-Ywarn-unused-import",
114-
"-Xfatal-warnings"
115-
)
116-
))
117-
118-
scalacOptions ~= (options => if (mantisDev) options.filterNot(_ == "-Xfatal-warnings") else options)
119-
120-
Test / parallelExecution := true
121-
122-
testOptions in Test += Tests.Argument("-oDG")
123-
124-
// protobuf compilation
125-
// Into a subdirectory of src_managed to avoid it deleting other generated files; see https://github.com/sbt/sbt-buildinfo/issues/149
126-
PB.targets in Compile := Seq(
127-
scalapb.gen() -> (sourceManaged in Compile).value / "protobuf"
128-
)
129-
130-
// have the protobuf API version file as a resource
131-
unmanagedResourceDirectories in Compile += baseDirectory.value / "src" / "main" / "protobuf"
132-
133-
(test in Evm) := (test in Evm).dependsOn(solidityCompile).value
134-
(sourceDirectory in Evm) := baseDirectory.value / "src" / "evmTest"
135-
136-
(scalastyleConfig in Test) := baseDirectory.value / "scalastyle-test-config.xml"
137-
scalastyleSources in Test ++= { (unmanagedSourceDirectories in Integration).value }
138-
139-
// Packaging
140-
mainClass in Compile := Some("io.iohk.ethereum.App")
141-
Universal / executableScriptName := name.value
142-
discoveredMainClasses in Compile := Seq()
143-
// Requires the 'ant-javafx.jar' that comes with Oracle JDK
144-
// Enables creating an executable with the configuration files, has to be run on the OS corresponding to the desired version
145-
ThisBuild / jdkPackagerType := "image"
146-
147-
Universal / mappings += (resourceDirectory in Compile).value / "logback.xml" -> "conf/logback.xml"
148-
Universal / mappings += (resourceDirectory in Compile).value / "application.conf" -> "conf/base.conf"
149-
Universal / mappings ++= directory((resourceDirectory in Compile).value / "chains").map { case (f, name) =>
150-
f -> s"conf/$name"
151-
}
152-
153-
val sep = java.io.File.separator
154-
jdkPackagerJVMArgs := Seq(
155-
"-Dconfig.file=." + sep + "conf" + sep + "app.conf",
156-
"-Dlogback.configurationFile=." + sep + "conf" + sep + "logback.xml",
157-
"-Xss10M"
158-
)
159-
160184
coverageExcludedPackages := "io\\.iohk\\.ethereum\\.extvm\\.msg.*"
161185

162186
addCommandAlias(
163187
"compile-all",
164-
""";compile
188+
""";rlp/compile
189+
|;rlp/test:compile
190+
|;compile
165191
|;test:compile
166192
|;evm:compile
167193
|;it:compile
@@ -176,9 +202,13 @@ addCommandAlias(
176202
addCommandAlias(
177203
"pp",
178204
""";compile-all
205+
|;rlp/scalafmtAll
206+
|;rlp/scalastyle
207+
|;rlp/test:scalastyle
179208
|;scalafmtAll
180209
|;scalastyle
181210
|;test:scalastyle
211+
|;rlp/test
182212
|;testQuick
183213
|;it:test
184214
|""".stripMargin

project/Dependencies.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import sbt._
22

33
object Dependencies {
44

5+
val akkaUtil: Seq[ModuleID] = {
6+
val akkaVersion = "2.6.9"
7+
8+
Seq(
9+
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
10+
)
11+
}
12+
513
val akka: Seq[ModuleID] = {
614
val akkaVersion = "2.6.9"
715

@@ -133,4 +141,8 @@ object Dependencies {
133141
provider % "micrometer-registry-prometheus" % version
134142
)
135143
}
144+
145+
val shapeless: Seq[ModuleID] = Seq(
146+
"com.chuusai" %% "shapeless" % "2.3.3"
147+
)
136148
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.iohk.ethereum.rlp
2+
3+
protected[rlp] object Hex {
4+
def toHexString(bytes: Array[Byte]): String =
5+
bytes.map("%02x".format(_)).mkString
6+
7+
def decode(hex: String): Array[Byte] =
8+
hex.replaceAll("[^0-9A-Fa-f]", "").sliding(2, 2).toArray.map(Integer.parseInt(_, 16).toByte)
9+
}

src/main/scala/io/iohk/ethereum/rlp/RLP.scala renamed to rlp/src/main/scala/io/iohk/ethereum/rlp/RLP.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ private[rlp] object RLP {
135135
else Array[Byte](singleByte)
136136
}
137137

138+
private[rlp] def bigIntToUnsignedByteArray(i: BigInt): Array[Byte] = {
139+
val asByteArray = i.toByteArray
140+
if (asByteArray.head == 0) asByteArray.tail
141+
else asByteArray
142+
}
143+
138144
/**
139145
* This function converts a short value to a big endian byte array of minimal length
140146
*

src/main/scala/io/iohk/ethereum/rlp/RLPImplicits.scala renamed to rlp/src/main/scala/io/iohk/ethereum/rlp/RLPImplicits.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package io.iohk.ethereum.rlp
22

33
import akka.util.ByteString
44
import io.iohk.ethereum.rlp.RLP._
5-
import io.iohk.ethereum.utils.BigIntExtensionMethods.BigIntAsUnsigned
65
import RLPCodec.Ops
76

87
object RLPImplicits {
@@ -51,7 +50,7 @@ object RLPImplicits {
5150
implicit val bigIntEncDec = new RLPEncoder[BigInt] with RLPDecoder[BigInt] {
5251

5352
override def encode(obj: BigInt): RLPValue = RLPValue(
54-
if (obj.equals(BigInt(0))) byteToByteArray(0: Byte) else obj.toUnsignedByteArray
53+
if (obj.equals(BigInt(0))) byteToByteArray(0: Byte) else bigIntToUnsignedByteArray(obj)
5554
)
5655

5756
override def decode(rlp: RLPEncodeable): BigInt = rlp match {

src/main/scala/io/iohk/ethereum/rlp/package.scala renamed to rlp/src/main/scala/io/iohk/ethereum/rlp/package.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.iohk.ethereum
22

33
import akka.util.ByteString
4-
import org.bouncycastle.util.encoders.Hex
54
import scala.reflect.ClassTag
65
import scala.util.control.NonFatal
76

src/test/scala/io/iohk/ethereum/rlp/RLPSuite.scala renamed to rlp/src/test/scala/io/iohk/ethereum/rlp/RLPSuite.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ package io.iohk.ethereum.rlp
33
import akka.util.ByteString
44
import io.iohk.ethereum.rlp.RLPImplicitConversions._
55
import io.iohk.ethereum.rlp.RLPImplicits._
6-
import io.iohk.ethereum.utils.Logger
76
import org.scalacheck.{Arbitrary, Gen}
8-
import org.bouncycastle.util.encoders.Hex
97
import org.scalatestplus.scalacheck.{ScalaCheckDrivenPropertyChecks, ScalaCheckPropertyChecks}
108
import scala.language.implicitConversions
119
import scala.util.Try
1210
import org.scalatest.funsuite.AnyFunSuite
1311

14-
class RLPSuite extends AnyFunSuite with ScalaCheckPropertyChecks with ScalaCheckDrivenPropertyChecks with Logger {
12+
class RLPSuite extends AnyFunSuite with ScalaCheckPropertyChecks with ScalaCheckDrivenPropertyChecks {
1513

1614
test("nextElementIndex of empty data") {
1715
val maybeIndex = Try { nextElementIndex(Array.emptyByteArray, 0) }

src/benchmark/scala/io/iohk/ethereum/rlp/RLPSpeedSuite.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import io.iohk.ethereum.domain._
77
import io.iohk.ethereum.network.p2p.messages.CommonMessages.SignedTransactions._
88
import io.iohk.ethereum.utils.Logger
99
import org.scalacheck.Gen
10-
import org.bouncycastle.util.encoders.Hex
1110
import org.scalatest.funsuite.AnyFunSuite
1211
import org.scalatestplus.scalacheck.{ScalaCheckDrivenPropertyChecks, ScalaCheckPropertyChecks}
1312

0 commit comments

Comments
 (0)