Skip to content

[ETCM-129] Scala 2.13 #875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
dade78e
[ETCM-266]-replaced-rate-limiter-built-on-twitter
Dec 23, 2020
a9caf47
Formatting applied
Dec 24, 2020
06b8b33
Fixed test to advance time programmaticaly
Dec 29, 2020
a2a4a26
Transit to guava cache
Dec 29, 2020
93b0aa0
Initial commit
Dec 18, 2020
2fd002a
[ETCM-129] - starting point of migration
Dec 29, 2020
e3d1594
Next step to 2.13
Dec 31, 2020
80e6ff5
Completed and tested 2.13 migration
Jan 1, 2021
e9089fe
Scalafmt fixes
Jan 1, 2021
0a27104
Updated nix expressions
Jan 1, 2021
cfb875f
Fixed imports in integration test
Jan 2, 2021
deea98c
First review fixes
Jan 4, 2021
426fd6e
Updated nix expressions
Jan 5, 2021
23bdbec
Merge branch 'develop' into feature/ETCM-129-scala-point-13
Jan 5, 2021
ae3348a
Nix files regenerated
Jan 7, 2021
2dce3cd
updated buildkite config
Jan 7, 2021
eb45270
Try another sbtix
Jan 7, 2021
7117dbe
Trying to downgrade sbt
Jan 7, 2021
484b690
Fixed deprecation warning
Jan 7, 2021
42cf732
Another deprecated warning
Jan 7, 2021
cc226ff
Updated more tests
Jan 7, 2021
d0a0f95
Merge branch 'develop' into feature/ETCM-129-scala-point-13
Jan 7, 2021
25ee0c1
More tests fixed
Jan 7, 2021
00cdbff
Add protoc options
jonringer Jan 8, 2021
1d01ff2
Use sbt-protoc==0.99
jonringer Jan 8, 2021
33973cf
Add sbt-derivation source
jonringer Jan 8, 2021
b30da41
Remove sbtix files
jonringer Jan 9, 2021
d2db8ec
WIP
jonringer Jan 9, 2021
695ffa4
Update nixpkgs, cleanup nix files
jonringer Jan 9, 2021
485a2c4
Use sbt-protoc 0.99.34, fix build
jonringer Jan 9, 2021
e574330
Remove more sbtix files
jonringer Jan 9, 2021
ce1d4d2
Remove sbtix references from buildkite
jonringer Jan 9, 2021
63db00c
Fix wrapper
jonringer Jan 9, 2021
465f1c6
Add update script
jonringer Jan 9, 2021
d9fd0f5
Update readme
jonringer Jan 9, 2021
7a1531a
Update buildkite nix smoke test
jonringer Jan 9, 2021
554d6db
Use newer version of nix for buildkite
jonringer Jan 9, 2021
de3145b
Use nixUnstable instead
jonringer Jan 9, 2021
218c05c
Use nixUnstable within update-nix.sh
jonringer Jan 9, 2021
fd113cd
Don't rely on PATH
jonringer Jan 9, 2021
e8d33c7
Use nix-cli 1.0 for hash calculation
jonringer Jan 9, 2021
bec2be4
Elaborate update instructions
jonringer Jan 9, 2021
29b6c7b
Merge pull request #882 from input-output-hk/feature/ETCM-129-scala-p…
Jan 11, 2021
ec36746
Merge branch 'develop' into feature/ETCM-129-scala-point-13
Jan 11, 2021
0f57d0e
Use only jdk8 when building nix
jonringer Jan 11, 2021
aae9ff5
Merge pull request #885 from input-output-hk/use-jdk8-nix
Jan 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions .buildkite/pipeline.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,7 @@ in
nixExpr = commonAttrs // {
label = "ensure Nix expressions are up-to-date";
command = ''
echo "Checking if Nix expressions are up-to-date..."
nix-shell --run 'sbtix-gen-all2'
set +e
git diff --exit-code > nix-expr.patch
if [ "$?" -eq "1" ]; then
set -e
echo "Nix expressions not up-to-date."
echo "Download and apply the patch available in the artifact paths of this step:"
echo " patch -p1 < nix-expr.patch"
echo "Aborting."
exit 1
else
set -e
echo "Nix expressions up-to-date!"
exit 0
fi
./update-nix.sh --check
'';
retry.automatic = false;
artifactPaths = [
Expand Down Expand Up @@ -70,8 +53,8 @@ in
'';
artifactPaths = [
"bytes/target/test-reports/**/*"
"bytes/target/scala-2.12/scoverage-report/**/*"
"bytes/target/scala-2.12/coverage-report/**/*"
"bytes/target/scala-2.13/scoverage-report/**/*"
"bytes/target/scala-2.13/coverage-report/**/*"
];
};

Expand All @@ -83,8 +66,8 @@ in
'';
artifactPaths = [
"crypto/target/test-reports/**/*"
"crypto/target/scala-2.12/scoverage-report/**/*"
"crypto/target/scala-2.12/coverage-report/**/*"
"crypto/target/scala-2.13/scoverage-report/**/*"
"crypto/target/scala-2.13/coverage-report/**/*"
];
};

Expand All @@ -96,8 +79,8 @@ in
'';
artifactPaths = [
"rlp/target/test-reports/**/*"
"rlp/target/scala-2.12/scoverage-report/**/*"
"rlp/target/scala-2.12/coverage-report/**/*"
"rlp/target/scala-2.13/scoverage-report/**/*"
"rlp/target/scala-2.13/coverage-report/**/*"
];
};

Expand All @@ -109,8 +92,8 @@ in
'';
artifactPaths = [
"target/test-reports/**/*"
"target/scala-2.12/scoverage-report/**/*"
"target/scala-2.12/coverage-report/**/*"
"target/scala-2.13/scoverage-report/**/*"
"target/scala-2.13/coverage-report/**/*"
];
};

Expand All @@ -122,8 +105,8 @@ in
'';
artifactPaths = [
"target/test-reports/**/*"
"target/scala-2.12/scoverage-report/**/*"
"target/scala-2.12/coverage-report/**/*"
"target/scala-2.13/scoverage-report/**/*"
"target/scala-2.13/coverage-report/**/*"
];
};

Expand Down
9 changes: 2 additions & 7 deletions .buildkite/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@ let
exec ${pkgs.protobuf}/bin/protoc "$@"
'';

sbtix = pkgs.callPackage sources.Sbtix { };

in

with pkgs;

mkShell {

buildInputs = [ sbt solc jdk8 protoc-wrapper sbtix ];
nativeBuildInputs = [ sbt solc jdk8 protoc-wrapper ];
# SBT = "sbt -v -mem 2048 -J-Xmx4g -Dsbt.ivy.home=/cache/ivy2 -Dsbt.boot.directory=/cache/sbt -Dmaven.repo.local=/cache/maven -Dnix=true";
SBT = "sbt -v -mem 2048 -J-Xmx4g -Dnix=true";
SBTIX_GEN = "true";
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ metals.sbt

# Nix
result
.nix/
38 changes: 9 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,40 +116,20 @@ In the root of the project:
nix-build
```

##### Regenerate lock files
##### Update sbt+nix dependencies

```
nix-shell
sbtix-gen-all2
```

OR

If the "ensure Nix expressions are up-to-date" step of your CI
build has failed, check the artifacts of that step. There should be a
patch provided, which you can apply locally with:
When updating project dependencies, the nix fixed-output-derivation
will need to be updated so that it includes the new dependency state.

To do so, please run:
```
patch -p1 < downloaded.patch
./update-nix.sh
git add ./nix/pkgs/mantis.nix
git commit -m "Update nix-sbt sha"
```

This patch will update the lock files for you.

###### Why so many lock files?

- `repo.nix` : generated by the `sbtix-gen` command and includes only the build dependencies for the project.
- `project/repo.nix` : generated by the `sbtix-gen-all` command and includes only the plugin dependencies. Also generates `repo.nix`.
- `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`.

##### error: unsupported argument 'submodules' to 'fetchGit'

You get this error when you aren't using a new-enough version of Nix (fetchGit support for submodules is recent).

To fix this, update the version of Nix you are using, or in a pinch:

- Remove the "submodules = true;" argument from fetchGit (in `./nix/pkgs/mantis/default.nix`).
- `git submodule update --recursive --init`
- `nix-build`
*NOTE:* This should only be necessary when updating dependencies
(For example, edits to build.sbt or project/plugins.sbt will likely need to be regenerated)

### Monitoring

Expand Down
8 changes: 3 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
name := projectName,
organization := "io.iohk",
version := "3.2.1",
scalaVersion := "2.12.12",
scalaVersion := "2.13.4",
// Scalanet snapshots are published to Sonatype after each build.
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
testOptions in Test += Tests
Expand All @@ -26,10 +26,6 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
"-deprecation",
"-feature",
"-Xfatal-warnings",
"-Xlint:unsound-match",
"-Ywarn-inaccessible",
"-Ywarn-unused-import",
"-Ypartial-unification",
"-encoding",
"utf-8"
),
Expand Down Expand Up @@ -210,7 +206,9 @@ lazy val node = {
if (!nixBuild)
node
else
//node.settings(PB.protocExecutable := file("protoc"))
node.settings(PB.runProtoc in Compile := (args => Process("protoc", args) !))

}

coverageExcludedPackages := "io\\.iohk\\.ethereum\\.extvm\\.msg.*"
Expand Down
57 changes: 57 additions & 0 deletions bytes/src/main/scala/io/iohk/ethereum/utils/ByteStringUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,68 @@ package io.iohk.ethereum.utils

import akka.util.ByteString

import scala.collection.mutable
import scala.math.Ordering.Implicits._

object ByteStringUtils {
def hash2string(hash: ByteString): String =
Hex.toHexString(hash.toArray[Byte])

// unsafe
def string2hash(hash: String): ByteString =
ByteString(Hex.decode(hash))


implicit class Padding(val bs: ByteString) extends AnyVal {
def padToByteString(length: Int, b: Byte): ByteString = {
if (length <= bs.length) bs else {
val len = Math.max(bs.length, length)
val result = new Array[Byte](len)
bs.copyToArray(result, 0)
var i = bs.length
while (i < len) {
result.update(i, b)
i += 1
}
ByteString.fromArray(result)
}
}
}


sealed trait ByteStringElement {
def len: Int
def asByteArray: Array[Byte]
}

implicit class ByteStringSelfElement(val bs: ByteString) extends ByteStringElement {
def len: Int = bs.length
def asByteArray: Array[Byte] = bs.toArray
}

implicit class ByteStringArrayElement(val ar: Array[Byte]) extends ByteStringElement {
def len: Int = ar.length
def asByteArray: Array[Byte] = ar
}

implicit class ByteStringByteElement(val b: Byte) extends ByteStringElement {
def len: Int = 1
def asByteArray: Array[Byte] = Array(b)
}

implicit val byteStringOrdering: Ordering[ByteString] = {
Ordering.by[ByteString, Seq[Byte]](_.toSeq)
}

def concatByteStrings(head: ByteStringElement, tail: ByteStringElement*): ByteString = {
val it = Iterator.single(head) ++ tail.iterator
concatByteStrings(it)
}

def concatByteStrings(elements: Iterator[ByteStringElement]): ByteString = {
val builder = new mutable.ArrayBuilder.ofByte
elements.foreach(el => builder.addAll(el.asByteArray))
ByteString(builder.result())
}

}
8 changes: 4 additions & 4 deletions bytes/src/main/scala/io/iohk/ethereum/utils/ByteUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ object ByteUtils {

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

def compactPickledBytesToArray(buffer: ByteBuffer): Array[Byte] = {
Expand Down Expand Up @@ -141,7 +141,7 @@ object ByteUtils {
* @param bigEndian - param specifying which int representation should be used.
* @return Unit
*/
def intsToBytesMut(arr: Array[Int], b: Array[Byte], bigEndian: Boolean) {
def intsToBytesMut(arr: Array[Int], b: Array[Byte], bigEndian: Boolean): Unit = {
if (!bigEndian) {
var off = 0
var i = 0
Expand Down Expand Up @@ -187,7 +187,7 @@ object ByteUtils {
* @param bigEndian - param specifying which int representation should be used.
* @return Unit
*/
def bytesToIntsMut(b: Array[Byte], arr: Array[Int], bigEndian: Boolean) {
def bytesToIntsMut(b: Array[Byte], arr: Array[Int], bigEndian: Boolean): Unit = {
if (!bigEndian) {
var off = 0
var i = 0
Expand Down
2 changes: 1 addition & 1 deletion bytes/src/main/scala/io/iohk/ethereum/utils/Hex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ object Hex {
bytes.map("%02x".format(_)).mkString

def decode(hex: String): Array[Byte] =
hex.replaceAll("[^0-9A-Fa-f]", "").sliding(2, 2).toArray.map(Integer.parseInt(_, 16).toByte)
hex.toSeq.sliding(2, 2).toArray.map(s=> Integer.parseInt(s.unwrap, 16).toByte)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.iohk.ethereum.utils

import akka.util.ByteString
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.should.Matchers
import ByteStringUtils._
import scala.collection.immutable.ArraySeq
import scala.util.{Try, Success, Failure}

class ByteStringUtilsTest extends AnyWordSpec with Matchers {

"ByteStringUtilsTest" should {

"succeed parsing a valid hash string" in {
val validHashString = "00FF00FF"
val parsed = Try(string2hash(validHashString))
val expected = ByteString(Array[Byte](0, -1, 0, -1))
parsed shouldEqual Success(expected)
}

"fail parsing a valid hash string" in {
val invalidHashString = "XXYYZZXX"
val parsed = Try(string2hash(invalidHashString))
parsed shouldBe a[Failure[_]]
}

"concatByteStrings for simple bytestrings" in {
val bs1 = string2hash("0000")
val bs2 = string2hash("FFFF")
val summarized: ByteString = bs1 ++ bs2

val concatenated: ByteString = ByteStringUtils.concatByteStrings(bs1, bs2)
summarized shouldEqual concatenated
}

"concatByteStrings for various argument types" in {
val bs1 = string2hash("0000")
val bs2 = string2hash("FFFF")
val bs3: Byte = 2
val bs4 = Array[Byte](3, 3)
val bs5 = Array[Byte](4, 4)
val summarized: ByteString = bs1 ++ bs2
val concatenated: ByteString = ByteStringUtils.concatByteStrings(bs1, bs2, bs3, bs4, bs5)
concatenated shouldEqual string2hash("0000FFFF0203030404")
}

"apply padding the same way seqOps does" in {
val bsu = string2hash("0000FFFF")
val seq = ArraySeq.unsafeWrapArray(bsu.toArray)
bsu.padToByteString(3, 0) shouldEqual bsu // result is ByteString
bsu.padTo(3,0) shouldEqual seq // result is Seq

val longSeq = ArraySeq[Byte](0, 0, -1, -1, 1 ,1)
val longBsu = string2hash("0000FFFF0101")
bsu.padToByteString(6, 1) shouldEqual longBsu
bsu.padTo(6, 1) shouldEqual longSeq
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ object ECDSASignature {
case Some(id) if v == negativePointSign => (id * 2 + newNegativePointSign).toByte
case Some(id) if v == positivePointSign => (id * 2 + newPositivePointSign).toByte
case None => v
case _ => throw new IllegalStateException(s"Unexpected pointSign. ChainId: ${chainId}, v: ${v}")
}

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

bigInt2Bytes(r) ++ bigInt2Bytes(s) :+ v

bigInt2Bytes(r) ++ bigInt2Bytes(s) ++ ByteString(v)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.bouncycastle.crypto.Digest
class MGF1BytesGeneratorExt(digest: Digest) {
val digestSize: Int = digest.getDigestSize

private def itoOSP(i: Int, sp: Array[Byte]) {
private def itoOSP(i: Int, sp: Array[Byte]): Unit = {
sp(0) = (i >>> 24).toByte
sp(1) = (i >>> 16).toByte
sp(2) = (i >>> 8).toByte
Expand Down
Loading