Skip to content

Commit d5727f2

Browse files
Dmitry Voronovdmitry-workerjonringer
authored andcommitted
[ETCM-129] Scala 2.13 (#875)
* [ETCM-129] - Migrate to 2.13 Co-authored-by: dmitry-worker <[email protected]> Co-authored-by: Jonathan Ringer <[email protected]> Guided by: Piotr Paradzinski <[email protected]> Reviewed by: Enrique Rodríguez <[email protected]> Dependencies upgrade guide: Akosh Farkash <[email protected]>
1 parent b0be742 commit d5727f2

File tree

136 files changed

+786
-9390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+786
-9390
lines changed

.buildkite/pipeline.nix

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,7 @@ in
1414
nixExpr = commonAttrs // {
1515
label = "ensure Nix expressions are up-to-date";
1616
command = ''
17-
echo "Checking if Nix expressions are up-to-date..."
18-
19-
nix-shell --run 'sbtix-gen-all2'
20-
21-
set +e
22-
git diff --exit-code > nix-expr.patch
23-
if [ "$?" -eq "1" ]; then
24-
set -e
25-
echo "Nix expressions not up-to-date."
26-
echo "Download and apply the patch available in the artifact paths of this step:"
27-
echo " patch -p1 < nix-expr.patch"
28-
echo "Aborting."
29-
exit 1
30-
else
31-
set -e
32-
echo "Nix expressions up-to-date!"
33-
exit 0
34-
fi
17+
./update-nix.sh --check
3518
'';
3619
retry.automatic = false;
3720
artifactPaths = [
@@ -70,8 +53,8 @@ in
7053
'';
7154
artifactPaths = [
7255
"bytes/target/test-reports/**/*"
73-
"bytes/target/scala-2.12/scoverage-report/**/*"
74-
"bytes/target/scala-2.12/coverage-report/**/*"
56+
"bytes/target/scala-2.13/scoverage-report/**/*"
57+
"bytes/target/scala-2.13/coverage-report/**/*"
7558
];
7659
};
7760

@@ -83,8 +66,8 @@ in
8366
'';
8467
artifactPaths = [
8568
"crypto/target/test-reports/**/*"
86-
"crypto/target/scala-2.12/scoverage-report/**/*"
87-
"crypto/target/scala-2.12/coverage-report/**/*"
69+
"crypto/target/scala-2.13/scoverage-report/**/*"
70+
"crypto/target/scala-2.13/coverage-report/**/*"
8871
];
8972
};
9073

@@ -96,8 +79,8 @@ in
9679
'';
9780
artifactPaths = [
9881
"rlp/target/test-reports/**/*"
99-
"rlp/target/scala-2.12/scoverage-report/**/*"
100-
"rlp/target/scala-2.12/coverage-report/**/*"
82+
"rlp/target/scala-2.13/scoverage-report/**/*"
83+
"rlp/target/scala-2.13/coverage-report/**/*"
10184
];
10285
};
10386

@@ -109,8 +92,8 @@ in
10992
'';
11093
artifactPaths = [
11194
"target/test-reports/**/*"
112-
"target/scala-2.12/scoverage-report/**/*"
113-
"target/scala-2.12/coverage-report/**/*"
95+
"target/scala-2.13/scoverage-report/**/*"
96+
"target/scala-2.13/coverage-report/**/*"
11497
];
11598
};
11699

@@ -122,8 +105,8 @@ in
122105
'';
123106
artifactPaths = [
124107
"target/test-reports/**/*"
125-
"target/scala-2.12/scoverage-report/**/*"
126-
"target/scala-2.12/coverage-report/**/*"
108+
"target/scala-2.13/scoverage-report/**/*"
109+
"target/scala-2.13/coverage-report/**/*"
127110
];
128111
};
129112

.buildkite/shell.nix

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ let
1717
1818
exec ${pkgs.protobuf}/bin/protoc "$@"
1919
'';
20-
21-
sbtix = pkgs.callPackage sources.Sbtix { };
22-
2320
in
2421

2522
with pkgs;
26-
23+
2724
mkShell {
28-
29-
buildInputs = [ sbt solc jdk8 protoc-wrapper sbtix ];
25+
nativeBuildInputs = [ sbt solc jdk8 protoc-wrapper ];
3026
# SBT = "sbt -v -mem 2048 -J-Xmx4g -Dsbt.ivy.home=/cache/ivy2 -Dsbt.boot.directory=/cache/sbt -Dmaven.repo.local=/cache/maven -Dnix=true";
3127
SBT = "sbt -v -mem 2048 -J-Xmx4g -Dnix=true";
32-
SBTIX_GEN = "true";
3328
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ metals.sbt
2222

2323
# Nix
2424
result
25+
.nix/

README.md

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,40 +116,20 @@ In the root of the project:
116116
nix-build
117117
```
118118

119-
##### Regenerate lock files
119+
##### Update sbt+nix dependencies
120120

121-
```
122-
nix-shell
123-
sbtix-gen-all2
124-
```
125-
126-
OR
127-
128-
If the "ensure Nix expressions are up-to-date" step of your CI
129-
build has failed, check the artifacts of that step. There should be a
130-
patch provided, which you can apply locally with:
121+
When updating project dependencies, the nix fixed-output-derivation
122+
will need to be updated so that it includes the new dependency state.
131123

124+
To do so, please run:
132125
```
133-
patch -p1 < downloaded.patch
126+
./update-nix.sh
127+
git add ./nix/pkgs/mantis.nix
128+
git commit -m "Update nix-sbt sha"
134129
```
135130

136-
This patch will update the lock files for you.
137-
138-
###### Why so many lock files?
139-
140-
- `repo.nix` : generated by the `sbtix-gen` command and includes only the build dependencies for the project.
141-
- `project/repo.nix` : generated by the `sbtix-gen-all` command and includes only the plugin dependencies. Also generates `repo.nix`.
142-
- `project/project/repo.nix` : generated by the `sbtix-gen-all2` command and includes only the plugin dependencies. Also generates `repo.nix` and `project/repo.nix`.
143-
144-
##### error: unsupported argument 'submodules' to 'fetchGit'
145-
146-
You get this error when you aren't using a new-enough version of Nix (fetchGit support for submodules is recent).
147-
148-
To fix this, update the version of Nix you are using, or in a pinch:
149-
150-
- Remove the "submodules = true;" argument from fetchGit (in `./nix/pkgs/mantis/default.nix`).
151-
- `git submodule update --recursive --init`
152-
- `nix-build`
131+
*NOTE:* This should only be necessary when updating dependencies
132+
(For example, edits to build.sbt or project/plugins.sbt will likely need to be regenerated)
153133

154134
### Monitoring
155135

build.sbt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
1616
name := projectName,
1717
organization := "io.iohk",
1818
version := "3.2.1",
19-
scalaVersion := "2.12.12",
19+
scalaVersion := "2.13.4",
2020
// Scalanet snapshots are published to Sonatype after each build.
2121
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
2222
testOptions in Test += Tests
@@ -26,10 +26,6 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
2626
"-deprecation",
2727
"-feature",
2828
"-Xfatal-warnings",
29-
"-Xlint:unsound-match",
30-
"-Ywarn-inaccessible",
31-
"-Ywarn-unused-import",
32-
"-Ypartial-unification",
3329
"-encoding",
3430
"utf-8"
3531
),
@@ -211,7 +207,9 @@ lazy val node = {
211207
if (!nixBuild)
212208
node
213209
else
210+
//node.settings(PB.protocExecutable := file("protoc"))
214211
node.settings(PB.runProtoc in Compile := (args => Process("protoc", args) !))
212+
215213
}
216214

217215
coverageExcludedPackages := "io\\.iohk\\.ethereum\\.extvm\\.msg.*"

bytes/src/main/scala/io/iohk/ethereum/utils/ByteStringUtils.scala

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,68 @@ package io.iohk.ethereum.utils
22

33
import akka.util.ByteString
44

5+
import scala.collection.mutable
6+
import scala.math.Ordering.Implicits._
7+
58
object ByteStringUtils {
69
def hash2string(hash: ByteString): String =
710
Hex.toHexString(hash.toArray[Byte])
811

912
// unsafe
1013
def string2hash(hash: String): ByteString =
1114
ByteString(Hex.decode(hash))
15+
16+
17+
implicit class Padding(val bs: ByteString) extends AnyVal {
18+
def padToByteString(length: Int, b: Byte): ByteString = {
19+
if (length <= bs.length) bs else {
20+
val len = Math.max(bs.length, length)
21+
val result = new Array[Byte](len)
22+
bs.copyToArray(result, 0)
23+
var i = bs.length
24+
while (i < len) {
25+
result.update(i, b)
26+
i += 1
27+
}
28+
ByteString.fromArray(result)
29+
}
30+
}
31+
}
32+
33+
34+
sealed trait ByteStringElement {
35+
def len: Int
36+
def asByteArray: Array[Byte]
37+
}
38+
39+
implicit class ByteStringSelfElement(val bs: ByteString) extends ByteStringElement {
40+
def len: Int = bs.length
41+
def asByteArray: Array[Byte] = bs.toArray
42+
}
43+
44+
implicit class ByteStringArrayElement(val ar: Array[Byte]) extends ByteStringElement {
45+
def len: Int = ar.length
46+
def asByteArray: Array[Byte] = ar
47+
}
48+
49+
implicit class ByteStringByteElement(val b: Byte) extends ByteStringElement {
50+
def len: Int = 1
51+
def asByteArray: Array[Byte] = Array(b)
52+
}
53+
54+
implicit val byteStringOrdering: Ordering[ByteString] = {
55+
Ordering.by[ByteString, Seq[Byte]](_.toSeq)
56+
}
57+
58+
def concatByteStrings(head: ByteStringElement, tail: ByteStringElement*): ByteString = {
59+
val it = Iterator.single(head) ++ tail.iterator
60+
concatByteStrings(it)
61+
}
62+
63+
def concatByteStrings(elements: Iterator[ByteStringElement]): ByteString = {
64+
val builder = new mutable.ArrayBuilder.ofByte
65+
elements.foreach(el => builder.addAll(el.asByteArray))
66+
ByteString(builder.result())
67+
}
68+
1269
}

bytes/src/main/scala/io/iohk/ethereum/utils/ByteUtils.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ object ByteUtils {
9797

9898
def padLeft(bytes: ByteString, length: Int, byte: Byte = 0): ByteString = {
9999
val l = math.max(0, length - bytes.length)
100-
val fill = Seq.fill[Byte](l)(byte)
101-
fill ++: bytes
100+
val fill = Array.fill[Byte](l)(byte)
101+
ByteString.apply(fill) ++ bytes
102102
}
103103

104104
def compactPickledBytesToArray(buffer: ByteBuffer): Array[Byte] = {
@@ -141,7 +141,7 @@ object ByteUtils {
141141
* @param bigEndian - param specifying which int representation should be used.
142142
* @return Unit
143143
*/
144-
def intsToBytesMut(arr: Array[Int], b: Array[Byte], bigEndian: Boolean) {
144+
def intsToBytesMut(arr: Array[Int], b: Array[Byte], bigEndian: Boolean): Unit = {
145145
if (!bigEndian) {
146146
var off = 0
147147
var i = 0
@@ -187,7 +187,7 @@ object ByteUtils {
187187
* @param bigEndian - param specifying which int representation should be used.
188188
* @return Unit
189189
*/
190-
def bytesToIntsMut(b: Array[Byte], arr: Array[Int], bigEndian: Boolean) {
190+
def bytesToIntsMut(b: Array[Byte], arr: Array[Int], bigEndian: Boolean): Unit = {
191191
if (!bigEndian) {
192192
var off = 0
193193
var i = 0

bytes/src/main/scala/io/iohk/ethereum/utils/Hex.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ object Hex {
55
bytes.map("%02x".format(_)).mkString
66

77
def decode(hex: String): Array[Byte] =
8-
hex.replaceAll("[^0-9A-Fa-f]", "").sliding(2, 2).toArray.map(Integer.parseInt(_, 16).toByte)
8+
hex.toSeq.sliding(2, 2).toArray.map(s=> Integer.parseInt(s.unwrap, 16).toByte)
99
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package io.iohk.ethereum.utils
2+
3+
import akka.util.ByteString
4+
import org.scalatest.wordspec.AnyWordSpec
5+
import org.scalatest.matchers.should.Matchers
6+
import ByteStringUtils._
7+
import scala.collection.immutable.ArraySeq
8+
import scala.util.{Try, Success, Failure}
9+
10+
class ByteStringUtilsTest extends AnyWordSpec with Matchers {
11+
12+
"ByteStringUtilsTest" should {
13+
14+
"succeed parsing a valid hash string" in {
15+
val validHashString = "00FF00FF"
16+
val parsed = Try(string2hash(validHashString))
17+
val expected = ByteString(Array[Byte](0, -1, 0, -1))
18+
parsed shouldEqual Success(expected)
19+
}
20+
21+
"fail parsing a valid hash string" in {
22+
val invalidHashString = "XXYYZZXX"
23+
val parsed = Try(string2hash(invalidHashString))
24+
parsed shouldBe a[Failure[_]]
25+
}
26+
27+
"concatByteStrings for simple bytestrings" in {
28+
val bs1 = string2hash("0000")
29+
val bs2 = string2hash("FFFF")
30+
val summarized: ByteString = bs1 ++ bs2
31+
32+
val concatenated: ByteString = ByteStringUtils.concatByteStrings(bs1, bs2)
33+
summarized shouldEqual concatenated
34+
}
35+
36+
"concatByteStrings for various argument types" in {
37+
val bs1 = string2hash("0000")
38+
val bs2 = string2hash("FFFF")
39+
val bs3: Byte = 2
40+
val bs4 = Array[Byte](3, 3)
41+
val bs5 = Array[Byte](4, 4)
42+
val summarized: ByteString = bs1 ++ bs2
43+
val concatenated: ByteString = ByteStringUtils.concatByteStrings(bs1, bs2, bs3, bs4, bs5)
44+
concatenated shouldEqual string2hash("0000FFFF0203030404")
45+
}
46+
47+
"apply padding the same way seqOps does" in {
48+
val bsu = string2hash("0000FFFF")
49+
val seq = ArraySeq.unsafeWrapArray(bsu.toArray)
50+
bsu.padToByteString(3, 0) shouldEqual bsu // result is ByteString
51+
bsu.padTo(3,0) shouldEqual seq // result is Seq
52+
53+
val longSeq = ArraySeq[Byte](0, 0, -1, -1, 1 ,1)
54+
val longBsu = string2hash("0000FFFF0101")
55+
bsu.padToByteString(6, 1) shouldEqual longBsu
56+
bsu.padTo(6, 1) shouldEqual longSeq
57+
}
58+
59+
}
60+
}
61+

crypto/src/main/scala/io/iohk/ethereum/crypto/ECDSASignature.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ object ECDSASignature {
6464
case Some(id) if v == negativePointSign => (id * 2 + newNegativePointSign).toByte
6565
case Some(id) if v == positivePointSign => (id * 2 + newPositivePointSign).toByte
6666
case None => v
67+
case _ => throw new IllegalStateException(s"Unexpected pointSign. ChainId: ${chainId}, v: ${v}")
6768
}
6869

6970
ECDSASignature(r, s, pointSign)
@@ -176,6 +177,7 @@ case class ECDSASignature(r: BigInt, s: BigInt, v: Byte) {
176177
def bigInt2Bytes(b: BigInt) =
177178
ByteUtils.padLeft(ByteString(b.toByteArray).takeRight(RLength), RLength, 0)
178179

179-
bigInt2Bytes(r) ++ bigInt2Bytes(s) :+ v
180+
181+
bigInt2Bytes(r) ++ bigInt2Bytes(s) ++ ByteString(v)
180182
}
181183
}

crypto/src/main/scala/io/iohk/ethereum/crypto/MGF1BytesGeneratorExt.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.bouncycastle.crypto.Digest
1111
class MGF1BytesGeneratorExt(digest: Digest) {
1212
val digestSize: Int = digest.getDigestSize
1313

14-
private def itoOSP(i: Int, sp: Array[Byte]) {
14+
private def itoOSP(i: Int, sp: Array[Byte]): Unit = {
1515
sp(0) = (i >>> 24).toByte
1616
sp(1) = (i >>> 16).toByte
1717
sp(2) = (i >>> 8).toByte

0 commit comments

Comments
 (0)