Skip to content

Commit ea25f01

Browse files
author
Jaap van der Plas
committed
Merge remote-tracking branch 'origin/develop' into feature/ETCM-680-retesteth-ci
2 parents 88b1e79 + 00a4442 commit ea25f01

114 files changed

Lines changed: 1468 additions & 711 deletions

File tree

Some content is hidden

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

.buildkite/pipeline.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,15 @@ in
161161
nix-shell --run '$SBT benchmark:compile dist'
162162
'';
163163
};
164+
165+
publish = commonAttrs // {
166+
dependsOn = [ test-crypto test-rlp test-unit ];
167+
label = "Publishing libraries to Maven";
168+
command = ''
169+
nix-env -iA nixpkgs.gnupg && nix-shell --run '.buildkite/publish.sh'
170+
'';
171+
branches = "master develop";
172+
timeoutInMinutes = 30;
173+
};
164174
};
165175
}

.buildkite/publish.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
3+
set -euv
4+
5+
# The build agents have gpg 2.0.22, which doesn't have the `--pinentry-mode` option, but
6+
# the sbt-pgp plugin assumes that 2.x has it, and generates an invalid command.
7+
# We can either create a wrapper script that removes that option, or update gpg
8+
# somewhere in pipeline.nix
9+
10+
# Force a restart of the agent becuase it may be out of sync with what Nix installed.
11+
gpgconf --kill all
12+
13+
gpg --version
14+
15+
16+
# The build agent might have this key from before.
17+
GPG_EXISTS=$(gpg --list-keys "$GPG_KEY_ID" >&2 && echo "yes" || echo "no")
18+
19+
if [[ "$GPG_EXISTS" == "no" ]]; then
20+
echo "$GPG_KEY" | base64 --decode | gpg --batch --import
21+
# Local testing showed that without this the SBT plugin got "Bad passphrase".
22+
gpg --passphrase $GPG_PASSPHRASE --batch --yes -a -b LICENSE
23+
fi
24+
25+
# https://github.com/olafurpg/sbt-ci-release#secrets
26+
export PGP_SECRET="$GPG_KEY"
27+
export PGP_PASSPHRASE="$GPG_PASSPHRASE"
28+
export SONATYPE_USERNAME="$OSS_USERNAME"
29+
export SONATYPE_PASSWORD="$OSS_PASSWORD"
30+
31+
set +u
32+
33+
#https://github.com/sbt/sbt/issues/3570
34+
export JAVA_OPTS="$JAVA_OPTS -Dsbt.gigahorse=false"
35+
36+
# ci-release cannot be called on individual modules, but it looks like
37+
# with `publish / skip := true` in build.sbt for the default project,
38+
# without any aggregation, by default it would publish nothing, so
39+
# let's tell it here by using `sbt-ci-release` env vars.
40+
# NOTE: +rlp/publishSigned with the `+` would cross publish,
41+
# but it doesn't work because of scapegoat (see below).
42+
export CI_SNAPSHOT_RELEASE="; bytes/publishSigned; rlp/publishSigned; crypto/publishSigned"
43+
export CI_RELEASE=$CI_SNAPSHOT_RELEASE
44+
export CI_SONATYPE_RELEASE=$"; bytes/sonatypeBundleRelease; rlp/sonatypeBundleRelease; crypto/sonatypeBundleRelease"
45+
46+
# Scala 2.12 has up to scapegoat 1.4.5, while Scala 2.13 starts with 1.4.7.
47+
# I couldn't make build.sbt vary the scapegoat version by the current cross build,
48+
# so as a workaround the combos are called here explicitly.
49+
function release {
50+
SCALA_VERSION=$1
51+
export SCAPEGOAT_VERSION=$2
52+
53+
sbt "++ $SCALA_VERSION ; ci-release"
54+
}
55+
56+
function releaseAll {
57+
release 2.12.10 1.4.5
58+
release 2.13.4 1.4.7
59+
}
60+
61+
if [[ "$BUILDKITE_BRANCH" == "develop" ]]; then
62+
63+
# Publish the -SNAPSHOT version.
64+
releaseAll
65+
66+
elif [[ "$BUILDKITE_BRANCH" == "master" ]]; then
67+
68+
# Remove the -SNAPSHOT from the version file, then publish and release.
69+
sed -i 's/-SNAPSHOT//' version.sbt
70+
71+
# Whether ci-release does a release or a snapshot depends on whether it thinks the build is tagged; setting a dummy value.
72+
# Check https://github.com/olafurpg/sbt-ci-release/blob/main/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala for the rules.
73+
export CI_COMMIT_TAG=$(sbt -Dsbt.supershell=false -error "print version")
74+
75+
releaseAll
76+
77+
else
78+
79+
echo "Skipping the publish step."
80+
81+
fi

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Possible networks: `etc`, `eth`, `mordor`, `testnet-internal`
3232
### Command Line Interface
3333

3434
`cli` is a tool that can be used to:
35-
35+
3636
- generate a new private key
3737
```
3838
./bin/mantis cli generate-private-key
@@ -124,10 +124,12 @@ will need to be updated so that it includes the new dependency state.
124124
To do so, please run:
125125
```
126126
./update-nix.sh
127-
git add ./nix/pkgs/mantis.nix
127+
git add ./nix/overlay.nix
128128
git commit -m "Update nix-sbt sha"
129129
```
130130

131+
For this command to work you'll need the [Flakes](https://nixos.wiki/wiki/Flakes) feature enabled in your `nix` environment.
132+
131133
*NOTE:* This should only be necessary when updating dependencies
132134
(For example, edits to build.sbt or project/plugins.sbt will likely need to be regenerated)
133135

@@ -159,9 +161,9 @@ If a new certificate is required, create a new keystore with a certificate by ru
159161
1. Configure the certificate and password file to be used at `mantis.network.rpc.http.certificate` key on the `application.conf` file:
160162

161163
keystore-path: path to the keystore storing the certificates (if generated through our script they are by default located in "./tls/mantisCA.p12")
162-
164+
163165
keystore-type: type of certificate keystore being used (if generated through our script use "pkcs12")
164-
166+
165167
password-file: path to the file with the password used for accessing the certificate keystore (if generated through our script they are by default located in "./tls/password")
166168
2. Enable TLS in specific config:
167169
- For JSON RPC: `mantis.network.rpc.http.mode=https`
@@ -171,9 +173,9 @@ If a new certificate is required, create a new keystore with a certificate by ru
171173
1. Configure the certificate and password file to be used at `mantis.network.rpc.http.certificate` key on the `faucet.conf` file:
172174

173175
keystore-path: path to the keystore storing the certificates (if generated through our script they are by default located in "./tls/mantisCA.p12")
174-
176+
175177
keystore-type: type of certificate keystore being used (if generated through our script use "pkcs12")
176-
178+
177179
password-file: path to the file with the password used for accessing the certificate keystore (if generated through our script they are by default located in "./tls/password")
178180
2. Enable TLS in specific config:
179181
- For JSON RPC: `mantis.network.rpc.http.mode=https`
@@ -200,7 +202,7 @@ volumes:
200202
- $HOME/.mantis:/home/demiourgos728/.mantis/
201203
command: -Dconfig.file=./conf/sagano.conf
202204
```
203-
205+
204206
2. Create a wallet address. Run the following curl command, replacing `<password>` by a password of your choice:
205207
```
206208
curl --request POST \
@@ -209,7 +211,7 @@ curl --request POST \
209211
--header 'Content-Type: application/json' \
210212
--data '{
211213
"jsonrpc": "2.0",
212-
"method": "personal_newAccount",
214+
"method": "personal_newAccount",
213215
"params": ["<password>"],
214216
"id": 1
215217
}'
@@ -244,7 +246,7 @@ curl --request POST \
244246
--header 'Content-Type: application/json' \
245247
--data '{
246248
"jsonrpc": "2.0",
247-
"method": "faucet_sendFunds",
249+
"method": "faucet_sendFunds",
248250
"params": ["<address>"],
249251
"id": 1
250252
}'

build.sbt

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,39 @@ val nixBuild = sys.props.isDefinedAt("nix")
1212
// Enable dev mode: disable certain flags, etc.
1313
val mantisDev = sys.props.get("mantisDev").contains("true") || sys.env.get("MANTIS_DEV").contains("true")
1414

15+
lazy val compilerOptimizationsForProd = Seq(
16+
"-opt:l:method", // method-local optimizations
17+
"-opt:l:inline", // inlining optimizations
18+
"-opt-inline-from:io.iohk.**" // inlining the project only
19+
)
20+
21+
// Releasing. https://github.com/olafurpg/sbt-ci-release
22+
inThisBuild(
23+
List(
24+
organization := "io.iohk",
25+
homepage := Some(url("https://github.com/input-output-hk/mantis")),
26+
scmInfo := Some(
27+
ScmInfo(url("https://github.com/input-output-hk/mantis"), "[email protected]:input-output-hk/mantis.git")
28+
),
29+
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
30+
developers := List()
31+
)
32+
)
33+
34+
// https://github.com/sbt/sbt/issues/3570
35+
updateOptions := updateOptions.value.withGigahorse(false)
36+
37+
// artifact name will include scala version
38+
crossPaths := true
39+
40+
val `scala-2.12` = "2.12.10"
41+
val `scala-2.13` = "2.13.4"
42+
val supportedScalaVersions = List(`scala-2.12`, `scala-2.13`)
43+
1544
def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
1645
name := projectName,
1746
organization := "io.iohk",
18-
version := "3.2.1",
19-
scalaVersion := "2.13.4",
47+
scalaVersion := `scala-2.13`,
2048
// Scalanet snapshots are published to Sonatype after each build.
2149
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
2250
testOptions in Test += Tests
@@ -29,6 +57,7 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
2957
"-encoding",
3058
"utf-8"
3159
),
60+
scalacOptions ++= (if (mantisDev) Seq.empty else compilerOptimizationsForProd),
3261
scalacOptions in (Compile, console) ~= (_.filterNot(
3362
Set(
3463
"-Ywarn-unused-import",
@@ -38,7 +67,14 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
3867
scalacOptions ~= (options => if (mantisDev) options.filterNot(_ == "-Xfatal-warnings") else options),
3968
Test / parallelExecution := true,
4069
testOptions in Test += Tests.Argument("-oDG"),
41-
(scalastyleConfig in Test) := file("scalastyle-test-config.xml")
70+
(scalastyleConfig in Test) := file("scalastyle-test-config.xml"),
71+
// Only publish selected libraries.
72+
skip in publish := true
73+
)
74+
75+
val publishSettings = Seq(
76+
publish / skip := false,
77+
crossScalaVersions := supportedScalaVersions
4278
)
4379

4480
// Adding an "it" config because in `Dependencies.scala` some are declared with `% "it,test"`
@@ -50,6 +86,7 @@ lazy val bytes = {
5086
.in(file("bytes"))
5187
.configs(Integration)
5288
.settings(commonSettings("mantis-bytes"))
89+
.settings(publishSettings)
5390
.settings(
5491
libraryDependencies ++=
5592
Dependencies.akkaUtil ++
@@ -65,6 +102,7 @@ lazy val crypto = {
65102
.configs(Integration)
66103
.dependsOn(bytes)
67104
.settings(commonSettings("mantis-crypto"))
105+
.settings(publishSettings)
68106
.settings(
69107
libraryDependencies ++=
70108
Dependencies.akkaUtil ++
@@ -81,6 +119,7 @@ lazy val rlp = {
81119
.configs(Integration)
82120
.dependsOn(bytes)
83121
.settings(commonSettings("mantis-rlp"))
122+
.settings(publishSettings)
84123
.settings(
85124
libraryDependencies ++=
86125
Dependencies.akkaUtil ++
@@ -201,6 +240,9 @@ lazy val node = {
201240
batScriptExtraDefines += """call :add_java "-Dconfig.file=%APP_HOME%\conf\app.conf"""",
202241
batScriptExtraDefines += """call :add_java "-Dlogback.configurationFile=%APP_HOME%\conf\logback.xml""""
203242
)
243+
.settings(
244+
crossScalaVersions := List(`scala-2.13`)
245+
)
204246

205247
if (!nixBuild)
206248
node
@@ -252,5 +294,7 @@ addCommandAlias(
252294
|""".stripMargin
253295
)
254296

255-
scapegoatVersion in ThisBuild := "1.4.7"
297+
// Scala 2.12 only has up to 1.4.5, while 2.13 only from 1.4.7
298+
// In theory we should be able to switch on `scalaVersion.value` but it doesn't seem to work.
299+
scapegoatVersion in ThisBuild := (sys.env.getOrElse("SCAPEGOAT_VERSION", "1.4.7"))
256300
scapegoatReports := Seq("xml")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ object ByteStringUtils {
6161

6262
def concatByteStrings(elements: Iterator[ByteStringElement]): ByteString = {
6363
val builder = new mutable.ArrayBuilder.ofByte
64-
elements.foreach(el => builder.addAll(el.asByteArray))
64+
elements.foreach(el => builder ++= el.asByteArray)
6565
ByteString(builder.result())
6666
}
6767

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

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

77
def decode(hex: String): Array[Byte] =
8-
hex.toSeq.sliding(2, 2).toArray.map(s => Integer.parseInt(s.unwrap, 16).toByte)
8+
hex.toSeq.sliding(2, 2).toArray.map { s =>
9+
Integer.parseInt(s.mkString(""), 16).toByte
10+
}
911
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ package object crypto {
4141
def kec256(input: ByteString): ByteString =
4242
ByteString(kec256(input.toArray))
4343

44+
def kec256PoW(header: Array[Byte], nonce: Array[Byte]): Array[Byte] = {
45+
val digest = new KeccakDigest(256)
46+
digest.update(header, 0, header.length)
47+
digest.update(nonce, 0, nonce.length)
48+
val output = Array.ofDim[Byte](32)
49+
digest.doFinal(output, 0)
50+
output
51+
}
52+
4453
def kec512(input: Array[Byte]): Array[Byte] = synchronized {
4554
val out = Array.ofDim[Byte](kec512.getDigestSize)
4655
kec512.update(input, 0, input.length)

0 commit comments

Comments
 (0)