From 586e0c25d9a90507afe5c3f1bbc3bdc331c7c1a6 Mon Sep 17 00:00:00 2001 From: Sergey Nazarov Date: Mon, 23 Oct 2023 11:12:21 +0400 Subject: [PATCH] Build system cleanup (#3901) --- .github/workflows/check-pr.yaml | 2 +- .github/workflows/publish-docker-node.yaml | 20 ++++ .../com/wavesplatform/lang/v1/DataFuncs.scala | 70 +++++++++--- .../v1/EnvironmentFunctionsBenchmark.scala | 4 +- .../lang/v1/ScriptEvaluatorBenchmark.scala | 2 +- build.sbt | 76 +++++++------ .../api/grpc/test/BlocksApiGrpcSpec.scala | 2 +- .../events/BlockchainUpdatesSpec.scala | 1 + .../common/ByteStrComparator.scala | 8 -- .../wavesplatform/common/state/ByteStr.scala | 7 +- .../lang/contract/meta/MetaVersion.scala | 4 +- .../lang/script/v1/ExprScript.scala | 2 - .../lang/v1/compiler/Terms.scala | 6 +- .../lang/v1/compiler/Types.scala | 97 ++++++++-------- .../v1/evaluator/ctx/impl/PureContext.scala | 2 - .../lang/v1/parser/BinaryOperation.scala | 10 +- .../scala/com/wavesplatform/JsAPITest.scala | 5 +- .../tests/src/test/resources/logback-test.xml | 14 +++ .../ContractCompilerCompactorTest.scala | 36 +++--- .../com/wavesplatform/it/api/model.scala | 2 +- node/build.sbt | 1 - .../scala/com/wavesplatform/Exporter.scala | 2 +- .../scala/com/wavesplatform/Importer.scala | 3 +- .../com/wavesplatform/api/http/ApiError.scala | 106 +++++++++--------- .../wavesplatform/api/http/`X-Api-Key`.scala | 14 +-- .../wavesplatform/database/SortedBatch.scala | 1 + .../com/wavesplatform/settings/package.scala | 6 +- .../state/BlockRewardCalculator.scala | 2 + .../scala/com/wavesplatform/state/Diff.scala | 2 + .../state/StateHashBuilder.scala | 1 + .../transaction/CreateAliasTransaction.scala | 3 +- .../assets/exchange/ExchangeTransaction.scala | 3 +- .../transaction/lease/LeaseTransaction.scala | 5 +- .../transaction/smart/WavesEnvironment.scala | 1 + .../scala/com/wavesplatform/utils/Time.scala | 4 +- .../com/wavesplatform/utils/package.scala | 7 +- node/src/test/resources/application.conf | 2 + .../http/DebugApiRouteSpec.scala | 1 + .../mining/MicroBlockMinerSpec.scala | 9 +- project/Dependencies.scala | 53 +++++---- project/build.properties | 2 +- project/plugins.sbt | 18 +-- repl/jvm/src/test/logback-test.xml | 14 +++ ride-runner/README.md | 6 +- ride-runner/build.sbt | 3 +- .../ride/runner/RideTestSuite.scala | 3 +- .../ride/runner/caches/RemoteData.scala | 4 +- .../caches/WeighedAccountScriptInfo.scala | 3 + .../runner/entrypoints/AppInitializer.scala | 4 +- .../WavesRideRunnerWithPreparedStateApp.scala | 2 +- .../disk/AccountDataDiskCacheTestSuite.scala | 8 +- .../runner/tests/RideTestSuiteTestSuite.scala | 30 ++--- 52 files changed, 387 insertions(+), 306 deletions(-) delete mode 100644 lang/jvm/src/main/scala/com/wavesplatform/common/ByteStrComparator.scala create mode 100644 lang/tests/src/test/resources/logback-test.xml create mode 100644 repl/jvm/src/test/logback-test.xml diff --git a/.github/workflows/check-pr.yaml b/.github/workflows/check-pr.yaml index 14c9c3365b4..b14e3f1e00d 100644 --- a/.github/workflows/check-pr.yaml +++ b/.github/workflows/check-pr.yaml @@ -27,7 +27,7 @@ jobs: path: ~/.cache/coursier key: coursier-cache - name: Check PR - run: sbt --mem 6144 --batch checkPR + run: sbt --mem 6144 --batch ";checkPR;completeQaseRun" env: QASE_ENABLE: true QASE_RUN_NAME: checkPR diff --git a/.github/workflows/publish-docker-node.yaml b/.github/workflows/publish-docker-node.yaml index 2b35cca1b36..804c39d8b5c 100644 --- a/.github/workflows/publish-docker-node.yaml +++ b/.github/workflows/publish-docker-node.yaml @@ -64,6 +64,17 @@ jobs: type=ref,event=tag type=raw,value=latest,enable=${{ github.event.release.prerelease == false }} + - name: Extract Docker RIDE runner metadata + id: meta-ride-runner + uses: docker/metadata-action@v4 + with: + images: wavesplatform/ride-runner + flavor: | + latest=false + tags: | + type=match,pattern=v(.*),group=1 + type=raw,value=latest,enable=${{ github.event.release.prerelease == false }} + - name: Build and push Docker public image id: build-and-push-public uses: docker/build-push-action@v3 @@ -83,3 +94,12 @@ jobs: tags: ${{ steps.meta-private.outputs.tags }} build-args: | NODE_TAG=${{ steps.meta-public.outputs.version }} + + - name: Build and push Docker RIDE runner image + id: build-and-push-ride-runner + uses: docker/build-push-action@v3 + with: + context: ./ride-runner/docker + push: true + pull: true + tags: ${{ steps.meta-ride-runner.outputs.tags }} diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/DataFuncs.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/DataFuncs.scala index 9edcfc50fa4..ba963912aee 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/DataFuncs.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/DataFuncs.scala @@ -1,31 +1,69 @@ package com.wavesplatform.lang.v1 -import java.util.concurrent.TimeUnit - -import com.wavesplatform.common.utils._ -import com.wavesplatform.lang.v1.DataFuncs._ +import com.esaulpaugh.headlong.util.FastHex +import com.sun.org.apache.xerces.internal.impl.dv.util.HexBin +import com.wavesplatform.common.utils.* +import com.wavesplatform.lang.v1.DataFuncs.* import com.wavesplatform.lang.v1.EnvironmentFunctionsBenchmark.randomBytes -import org.openjdk.jmh.annotations._ +import org.openjdk.jmh.annotations.* import org.openjdk.jmh.infra.Blackhole +import java.util.concurrent.TimeUnit + @OutputTimeUnit(TimeUnit.MICROSECONDS) @BenchmarkMode(Array(Mode.AverageTime)) @Threads(1) @Fork(1) -@Warmup(iterations = 30) -@Measurement(iterations = 30) +@Warmup(iterations = 10, time = 1) +@Measurement(iterations = 10, time = 1) class DataFuncs { @Benchmark def decode64_35Kb(st: StrSt35K, bh: Blackhole): Unit = bh.consume(Base64.decode(st.message)) + @Benchmark + def decode16_32kb_bcprov(st: StrSt32K, bh: Blackhole): Unit = + bh.consume(org.bouncycastle.util.encoders.Hex.decode(st.message)) + + @Benchmark + def decode16_32kb_guava(st: StrSt32K, bh: Blackhole): Unit = + bh.consume(com.google.common.io.BaseEncoding.base16.decode(st.message)) + + @Benchmark + def decode16_32kb_commons_codec(st: StrSt32K, bh: Blackhole): Unit = + bh.consume(org.apache.commons.codec.binary.Hex.decodeHex(st.message)) + + @Benchmark + def decode16_32kb_web3j(st: StrSt32K, bh: Blackhole): Unit = + bh.consume(org.web3j.utils.Numeric.hexStringToByteArray(st.message)) + + @Benchmark + def decode16_32kb_headlong(st: StrSt32K, bh: Blackhole): Unit = + bh.consume(FastHex.decode(st.message)) + + @Benchmark + def decode16_32kb_jdk_hexbin(st: StrSt105K, bh: Blackhole): Unit = + bh.consume(HexBin.decode(st.message)) + @Benchmark def decode64_70Kb(st: StrSt70K, bh: Blackhole): Unit = bh.consume(Base64.decode(st.message)) @Benchmark - def decode64_105Kb(st: StrSt105K, bh: Blackhole): Unit = - bh.consume(Base64.decode(st.message)) + def decode64_105Kb_jdk(st: StrSt105K, bh: Blackhole): Unit = + bh.consume(java.util.Base64.getDecoder.decode(st.message)) + + @Benchmark + def decode64_105Kb_bcprov(st: StrSt105K, bh: Blackhole): Unit = + bh.consume(org.bouncycastle.util.encoders.Base64.decode(st.message)) + + @Benchmark + def decode64_105Kb_guava(st: StrSt105K, bh: Blackhole): Unit = + bh.consume(com.google.common.io.BaseEncoding.base64().decode(st.message)) + + @Benchmark + def decode64_105Kb_commons_codec(st: StrSt105K, bh: Blackhole): Unit = + bh.consume(org.apache.commons.codec.binary.Base64.decodeBase64(st.message)) @Benchmark def decode64_140Kb(st: StrSt140K, bh: Blackhole): Unit = @@ -95,7 +133,6 @@ class DataFuncs { def concatr_175Kb(st: StrSt175K, bh: Blackhole): Unit = bh.consume("q" ++ st.message) - @Benchmark def decode58_16b(st: StrSt16b, bh: Blackhole): Unit = bh.consume(Base58.decode(st.message)) @@ -144,10 +181,11 @@ class DataFuncs { def encode58_896b(st: StrSt896b, bh: Blackhole): Unit = bh.consume(Base58.encode(st.bmessage)) - } object DataFuncs { + @State(Scope.Benchmark) + class StrSt8K extends StrSt(8) @State(Scope.Benchmark) class StrSt35K extends StrSt(35) @State(Scope.Benchmark) @@ -155,12 +193,14 @@ object DataFuncs { @State(Scope.Benchmark) class StrSt105K extends StrSt(105) @State(Scope.Benchmark) + class StrSt32K extends StrSt(32) + @State(Scope.Benchmark) class StrSt140K extends StrSt(140) @State(Scope.Benchmark) class StrSt175K extends StrSt(175) class StrSt(size: Int) { - val message = "B" * (size * 1024) + val message = "B" * (size * 1024) } @State(Scope.Benchmark) @@ -177,8 +217,8 @@ object DataFuncs { class StrSt896b extends StrStS(896) class StrStS(size: Int) { - val message = "B" * size - val bmessage = randomBytes(size) + val message = "B" * size + val bmessage = randomBytes(size) } @State(Scope.Benchmark) @@ -193,6 +233,6 @@ object DataFuncs { class BinSt130K extends BinSt(130) class BinSt(size: Int) { - val message = randomBytes(size * 1024) + val message = randomBytes(size * 1024) } } diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala index 12f86e74549..d1897ef02b8 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/EnvironmentFunctionsBenchmark.scala @@ -34,8 +34,8 @@ import scala.util.Random @BenchmarkMode(Array(Mode.AverageTime)) @Threads(1) @Fork(1) -@Warmup(iterations = 10) -@Measurement(iterations = 10) +@Warmup(iterations = 10, time = 1) +@Measurement(iterations = 10, time = 1) class EnvironmentFunctionsBenchmark { @Benchmark diff --git a/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala b/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala index 1ebc949f183..5a8eedaa874 100644 --- a/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala +++ b/benchmark/src/test/scala/com/wavesplatform/lang/v1/ScriptEvaluatorBenchmark.scala @@ -35,7 +35,7 @@ object ScriptEvaluatorBenchmark { @BenchmarkMode(Array(Mode.AverageTime)) @Threads(1) @Fork(1) -@Warmup(iterations = 10) +@Warmup(iterations = 10, time = 1) @Measurement(iterations = 10) class ScriptEvaluatorBenchmark { @Benchmark diff --git a/build.sbt b/build.sbt index 1896241299f..d6d7c333748 100644 --- a/build.sbt +++ b/build.sbt @@ -6,11 +6,14 @@ 2. You've checked "Make project before run" */ -import sbt.{Compile, Def} -import sbt.Keys.{concurrentRestrictions, _} - Global / onChangedBuildSource := ReloadOnSourceChanges +enablePlugins(GitVersioning) + +git.uncommittedSignifier := Some("DIRTY") +git.useGitDescribe := true +ThisBuild / git.useGitDescribe := true + lazy val lang = crossProject(JSPlatform, JVMPlatform) .withoutSuffixFor(JVMPlatform) @@ -119,12 +122,13 @@ lazy val `waves-node` = (project in file(".")) `node-generator`, benchmark, `repl-js`, - `repl-jvm` + `repl-jvm`, + `ride-runner` ) inScope(Global)( Seq( - scalaVersion := "2.13.11", + scalaVersion := "2.13.12", organization := "com.wavesplatform", organizationName := "Waves Platform", organizationHomepage := Some(url("https://wavesplatform.com")), @@ -172,9 +176,6 @@ inScope(Global)( ) ) -// ThisBuild options -git.uncommittedSignifier := Some("DIRTY") - lazy val packageAll = taskKey[Unit]("Package all artifacts") packageAll := { (node / assembly).value @@ -185,8 +186,14 @@ packageAll := { lazy val buildTarballsForDocker = taskKey[Unit]("Package node and grpc-server tarballs and copy them to docker/target") buildTarballsForDocker := { - IO.copyFile((node / Universal / packageZipTarball).value, new File(baseDirectory.value, "docker/target/waves.tgz")) - IO.copyFile((`grpc-server` / Universal / packageZipTarball).value, new File(baseDirectory.value, "docker/target/waves-grpc-server.tgz")) + IO.copyFile( + (node / Universal / packageZipTarball).value, + baseDirectory.value / "docker" / "target" / "waves.tgz" + ) + IO.copyFile( + (`grpc-server` / Universal / packageZipTarball).value, + baseDirectory.value / "docker" / "target" / "waves-grpc-server.tgz" + ) IO.copyFile( (`ride-runner` / Universal / packageZipTarball).value, (`ride-runner` / baseDirectory).value / "docker" / "target" / s"${(`ride-runner` / name).value}.tgz" @@ -194,34 +201,24 @@ buildTarballsForDocker := { } lazy val checkPRRaw = taskKey[Unit]("Build a project and run unit tests") -checkPRRaw := Def.taskDyn { - val res = Def - .sequential( - `waves-node` / clean, - Def.task { - (`lang-tests` / Test / test).value - (`repl-jvm` / Test / test).value - (`lang-js` / Compile / fastOptJS).value - (`lang-tests-js` / Test / test).value - (`grpc-server` / Test / test).value - (node / Test / test).value - (`repl-js` / Compile / fastOptJS).value - (`node-it` / Test / compile).value - (benchmark / Test / compile).value - (`node-generator` / Compile / compile).value - } - ) - .result - .value - - Def.task { - (`lang-testkit` / Test / runMain).toTask(" com.wavesplatform.report.QaseRunCompleter").value - res match { - case Inc(inc: Incomplete) => throw inc - case Value(v) => v +checkPRRaw := Def + .sequential( + `waves-node` / clean, + Def.task { + (`lang-tests` / Test / test).value + (`repl-jvm` / Test / test).value + (`lang-js` / Compile / fastOptJS).value + (`lang-tests-js` / Test / test).value + (`grpc-server` / Test / test).value + (node / Test / test).value + (`repl-js` / Compile / fastOptJS).value + (`node-it` / Test / compile).value + (benchmark / Test / compile).value + (`node-generator` / Compile / compile).value + (`ride-runner` / Test / compile).value } - } -}.value + ) + .value def checkPR: Command = Command.command("checkPR") { state => val newState = Project @@ -234,6 +231,11 @@ def checkPR: Command = Command.command("checkPR") { state => state } +lazy val completeQaseRun = taskKey[Unit]("Complete Qase run") +completeQaseRun := Def.task { + (`lang-testkit` / Test / runMain).toTask(" com.wavesplatform.report.QaseRunCompleter").value +}.value + lazy val buildDebPackages = taskKey[Unit]("Build debian packages") buildDebPackages := { (`grpc-server` / Debian / packageBin).value diff --git a/grpc-server/src/test/scala/com/wavesplatform/api/grpc/test/BlocksApiGrpcSpec.scala b/grpc-server/src/test/scala/com/wavesplatform/api/grpc/test/BlocksApiGrpcSpec.scala index f5c47e3d1fc..fff808bd37b 100644 --- a/grpc-server/src/test/scala/com/wavesplatform/api/grpc/test/BlocksApiGrpcSpec.scala +++ b/grpc-server/src/test/scala/com/wavesplatform/api/grpc/test/BlocksApiGrpcSpec.scala @@ -18,7 +18,7 @@ import com.wavesplatform.transaction.TxHelpers import com.wavesplatform.utils.DiffMatchers import monix.execution.Scheduler.Implicits.global import org.scalatest.{Assertion, BeforeAndAfterAll} - +import com.wavesplatform.utils.byteStrOrdering import scala.concurrent.Await import scala.concurrent.duration.{DurationInt, FiniteDuration} diff --git a/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala b/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala index 23d3721445c..f1ca1c30e2a 100644 --- a/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala +++ b/grpc-server/src/test/scala/com/wavesplatform/events/BlockchainUpdatesSpec.scala @@ -9,6 +9,7 @@ import com.wavesplatform.common.utils.* import com.wavesplatform.db.InterferableDB import com.wavesplatform.events.FakeObserver.* import com.wavesplatform.events.StateUpdate.LeaseUpdate.LeaseStatus +import com.wavesplatform.utils.byteStrOrdering import com.wavesplatform.events.StateUpdate.{ AssetInfo, AssetStateUpdate, diff --git a/lang/jvm/src/main/scala/com/wavesplatform/common/ByteStrComparator.scala b/lang/jvm/src/main/scala/com/wavesplatform/common/ByteStrComparator.scala deleted file mode 100644 index fd1d2144e4d..00000000000 --- a/lang/jvm/src/main/scala/com/wavesplatform/common/ByteStrComparator.scala +++ /dev/null @@ -1,8 +0,0 @@ -package com.wavesplatform.common - -import com.google.common.primitives.UnsignedBytes -import com.wavesplatform.common.state.ByteStr - -object ByteStrComparator { - def compare(bs1: ByteStr, bs2: ByteStr): Int = UnsignedBytes.lexicographicalComparator().compare(bs1.arr, bs2.arr) -} diff --git a/lang/shared/src/main/scala/com/wavesplatform/common/state/ByteStr.scala b/lang/shared/src/main/scala/com/wavesplatform/common/state/ByteStr.scala index 7cf6ab579db..523ad161604 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/common/state/ByteStr.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/common/state/ByteStr.scala @@ -1,10 +1,9 @@ package com.wavesplatform.common.state -import scala.util.Try - -import com.wavesplatform.common._ import com.wavesplatform.common.utils.{Base58, Base64} +import scala.util.Try + case class ByteStr(arr: Array[Byte]) { private[this] lazy val base58: String = Base58.encode(arr) lazy val base64Raw: String = Base64.encode(arr) @@ -86,6 +85,4 @@ object ByteStr { def decodeBase64(s: String): Try[ByteStr] = Base64.tryDecode(s).map { bs => ByteStr(bs) } - - implicit val byteStrOrdering: Ordering[ByteStr] = (x, y) => ByteStrComparator.compare(x, y) } diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/contract/meta/MetaVersion.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/contract/meta/MetaVersion.scala index 1124ff4b8b7..5861f93a86b 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/contract/meta/MetaVersion.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/contract/meta/MetaVersion.scala @@ -8,12 +8,12 @@ sealed trait MetaVersion { object V1 extends MetaVersion { override type Self = V1.type - override val strategy = MetaMapperStrategyV1 + override val strategy: MetaMapperStrategy[Self] = MetaMapperStrategyV1 override val number: Int = 1 } object V2 extends MetaVersion { override type Self = V2.type - override val strategy = MetaMapperStrategyV2 + override val strategy: MetaMapperStrategy[Self] = MetaMapperStrategyV2 override val number: Int = 2 } diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/script/v1/ExprScript.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/script/v1/ExprScript.scala index f6671d672c0..b59aa393c63 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/script/v1/ExprScript.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/script/v1/ExprScript.scala @@ -3,7 +3,6 @@ package com.wavesplatform.lang.script.v1 import cats.instances.either._ import cats.syntax.either._ import cats.syntax.flatMap._ -import com.google.common.annotations.VisibleForTesting import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.directives.values._ import com.wavesplatform.lang.script.Script @@ -29,7 +28,6 @@ object ExprScript { s"Script is too large: ${bs.length} bytes > $limit bytes" ) } - @VisibleForTesting def apply(x: EXPR): Either[String, Script] = apply(V1, x) def apply(version: StdLibVersion, x: EXPR, isFreeCall: Boolean = false, checkSize: Boolean = true): Either[String, ExprScript] = diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/compiler/Terms.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/compiler/Terms.scala index f1d1a8ec214..bc7456e3ab1 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/compiler/Terms.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/compiler/Terms.scala @@ -1,18 +1,19 @@ package com.wavesplatform.lang.v1.compiler import java.nio.charset.StandardCharsets - import cats.Eval import cats.instances.list.* import cats.syntax.traverse.* import com.wavesplatform.common.state.ByteStr -import com.wavesplatform.lang.{ExecutionError, CommonError} +import com.wavesplatform.lang.{CommonError, ExecutionError} import com.wavesplatform.lang.v1.ContractLimits.* import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.Types.* import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext.MaxListLengthV4 import monix.eval.Coeval +import scala.annotation.nowarn + object Terms { val DataTxMaxBytes: Int = 150 * 1024 // should be the same as DataTransaction.MaxBytes val DataTxMaxProtoBytes: Int = 165947 // depends from DataTransaction.MaxProtoBytes @@ -242,6 +243,7 @@ object Terms { lazy val TRUE: CONST_BOOLEAN = CONST_BOOLEAN(true) lazy val FALSE: CONST_BOOLEAN = CONST_BOOLEAN(false) + @nowarn // do not warn about private constructor case class CaseObj private (caseType: CASETYPEREF, fields: Map[String, EVALUATED]) extends EVALUATED { // must be with fixArrIndentation = false, because of makeString behavior before RideV6 (NODE-2370) override def toString: String = TermPrinter().string(this) diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/compiler/Types.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/compiler/Types.scala index ee1a4d55834..1632cdad484 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/compiler/Types.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/compiler/Types.scala @@ -1,7 +1,7 @@ package com.wavesplatform.lang.v1.compiler -import cats.syntax.traverse.* import cats.instances.list.* +import cats.syntax.traverse.* import scala.annotation.tailrec @@ -14,36 +14,36 @@ object Types { def fields: List[(String, FINAL)] = List() def typeList: List[REAL] def unfold: FINAL = this - def union: UNION = UNION(typeList) + def union: UNION = UNION(typeList) def name: String override def toString: String = name } sealed trait PARAMETERIZED extends TYPE - case class TYPEPARAM(char: Byte) extends PARAMETERIZED with SINGLE { override def toString: String = char.toChar.toString } - case class PARAMETERIZEDLIST(t: TYPE) extends PARAMETERIZED with SINGLE { override def toString: String = s"List[$t]" } + case class TYPEPARAM(char: Byte) extends PARAMETERIZED with SINGLE { override def toString: String = char.toChar.toString } + case class PARAMETERIZEDLIST(t: TYPE) extends PARAMETERIZED with SINGLE { override def toString: String = s"List[$t]" } case class PARAMETERIZEDTUPLE(t: List[TYPE]) extends PARAMETERIZED with SINGLE { override def toString: String = t.mkString("(", ", ", ")") } - case class PARAMETERIZEDUNION(l: List[SINGLE]) extends PARAMETERIZED { override def toString: String = l.mkString("|")} - case object NOTHING extends REAL { override val name = "Nothing"; override val typeList = List() } - case object LONG extends REAL { override val name = "Int"; override val typeList = List(this) } - case object BIGINT extends REAL { override val name = "BigInt"; override val typeList = List(this) } - case object BYTESTR extends REAL { override val name = "ByteVector"; override val typeList = List(this) } - case object BOOLEAN extends REAL { override val name = "Boolean"; override val typeList = List(this) } - case object STRING extends REAL { override val name = "String"; override val typeList = List(this) } + case class PARAMETERIZEDUNION(l: List[SINGLE]) extends PARAMETERIZED { override def toString: String = l.mkString("|") } + case object NOTHING extends REAL { override val name = "Nothing"; override val typeList: List[REAL] = List() } + case object LONG extends REAL { override val name = "Int"; override val typeList: List[REAL] = List(this) } + case object BIGINT extends REAL { override val name = "BigInt"; override val typeList: List[REAL] = List(this) } + case object BYTESTR extends REAL { override val name = "ByteVector"; override val typeList: List[REAL] = List(this) } + case object BOOLEAN extends REAL { override val name = "Boolean"; override val typeList: List[REAL] = List(this) } + case object STRING extends REAL { override val name = "String"; override val typeList: List[REAL] = List(this) } case class LIST(innerType: FINAL) extends REAL { override lazy val name: String = "List[" ++ innerType.toString ++ "]" override def typeList: List[REAL] = List(this) } sealed trait UNIONLIKE extends FINAL - case object ANY extends UNIONLIKE { override val name = "Any"; override val typeList = List() } + case object ANY extends UNIONLIKE { override val name = "Any"; override val typeList: List[REAL] = List() } case class UNION(override val typeList: List[REAL], n: Option[String] = None) extends UNIONLIKE { - override lazy val fields = typeList.map(_.fields.toSet).reduce(_ intersect _).toList - override val name = if (n.nonEmpty) n.get else typeList.sortBy(_.toString).mkString("|") + override lazy val fields: List[(String, FINAL)] = typeList.map(_.fields.toSet).reduce(_ intersect _).toList + override val name: String = if (n.nonEmpty) n.get else typeList.sortBy(_.toString).mkString("|") override def equals(obj: Any): Boolean = obj match { case UNION(typeList, _) if typeList.sortBy(_.toString) == this.typeList.sortBy(_.toString) => true - case _ => false + case _ => false } override def unfold: UNIONLIKE = { @@ -60,7 +60,7 @@ object Types { } case class TUPLE(types: List[FINAL]) extends REAL { - override def name: String = types.mkString("(", ", ", ")") + override def name: String = types.mkString("(", ", ", ")") override def typeList: List[REAL] = List(this) override def fields: List[(String, FINAL)] = @@ -71,7 +71,7 @@ object Types { || \/ (A1, ..., Z1) | ... | (A1, ..., Zk) | ... | (An, ..., Zk) - */ + */ override def unfold: FINAL = { val regrouped = regroup(types.map(_.typeList)).map(t => TUPLE(t.toList)) UNION.reduce(UNION.create(regrouped)) @@ -100,27 +100,28 @@ object Types { object UNION { def create(l: Seq[FINAL], n: Option[String] = None): UNIONLIKE = { - if(l.contains(ANY)) { + if (l.contains(ANY)) { ANY } else { - new UNION(l.flatMap { - case NOTHING => List.empty - case UNION(inner, _) => inner - case s: REAL => List(s) - case ANY => ??? - } - .toList - .distinct , - n) + new UNION( + l.flatMap { + case NOTHING => List.empty + case UNION(inner, _) => inner + case s: REAL => List(s) + case ANY => ??? + }.toList + .distinct, + n + ) } } def apply(l: FINAL*): UNIONLIKE = create(l.toList) def reduce(u: UNIONLIKE): FINAL = u match { - case UNION(Nil, _) => throw new Exception("Empty union") + case UNION(Nil, _) => throw new Exception("Empty union") case UNION(x :: Nil, _) => x - case _ => u + case _ => u } } @@ -128,29 +129,29 @@ object Types { def equivalent(l2: FINAL): Boolean = (l1, l2) match { case (l1: TUPLE, l2: TUPLE) => (l1.types.length == l2.types.length) && { - val unfolded = l1.unfold - if (l1 == unfolded) - (l1.types zip l2.types).forall { case (t1, t2) => t1 equivalent t2 } - else - unfolded equivalent l2.unfold - } - case (l1: LIST, l2: LIST) => l1.innerType equivalent l2.innerType - case (l1: REAL, l2: REAL) => l1 == l2 + val unfolded = l1.unfold + if (l1 == unfolded) + (l1.types zip l2.types).forall { case (t1, t2) => t1 equivalent t2 } + else + unfolded equivalent l2.unfold + } + case (l1: LIST, l2: LIST) => l1.innerType equivalent l2.innerType + case (l1: REAL, l2: REAL) => l1 == l2 case (l1: UNION, l2: UNION) => - l1.typeList.length == l2.typeList.length && + l1.typeList.length == l2.typeList.length && (l1.unfold.typeList.sortBy(_.name) zip l2.unfold.typeList.sortBy(_.name)) .forall { case (t1, t2) => t1 equivalent t2 } case (l1: FINAL, l2: FINAL) => l1.union equivalent l2.union } def >=(l2: FINAL): Boolean = (l1, l2) match { - case (ANY, _) => true - case (l1, UNION(l2, _)) => l2.forall(l1 >= _) - case (UNION(l1, _), l2) => l1.exists(_ >= l2) - case (_, ANY) => false - case (_, NOTHING) => true - case (NOTHING, _) => false - case (LIST(t1), LIST(t2)) => t1 >= t2 + case (ANY, _) => true + case (l1, UNION(l2, _)) => l2.forall(l1 >= _) + case (UNION(l1, _), l2) => l1.exists(_ >= l2) + case (_, ANY) => false + case (_, NOTHING) => true + case (NOTHING, _) => false + case (LIST(t1), LIST(t2)) => t1 >= t2 case (TUPLE(types1), TUPLE(types2)) => types1.length == types2.length && (types1 zip types2).forall { case (t1, t2) => t1 >= t2 } case (l1: REAL, l2: REAL) => l1 equivalent l2 @@ -162,10 +163,10 @@ object Types { @tailrec def check(tpe: FINAL): Boolean = { tpe match { - case Types.UNION(types, _) if types.size > 1 => true + case Types.UNION(types, _) if types.size > 1 => true case Types.LIST(Types.UNION(types, _)) if types.size > 1 => true - case Types.LIST(inner@Types.LIST(_)) => check(inner) - case _ => false + case Types.LIST(inner @ Types.LIST(_)) => check(inner) + case _ => false } } check(l1) diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala index 3c96cb795c1..980d27a6ebc 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/impl/PureContext.scala @@ -2,7 +2,6 @@ package com.wavesplatform.lang.v1.evaluator.ctx.impl import cats.implicits.* import cats.{Id, Monad} -import com.google.common.annotations.VisibleForTesting import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.lang.* @@ -1471,7 +1470,6 @@ object PureContext { notImplemented[Id, EVALUATED]("removeByIndex(list: List[T], index: Int)", xs) } - @VisibleForTesting private[v1] def genericListIndexOf( element: EVALUATED, indexOf: EVALUATED => Int, diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/parser/BinaryOperation.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/parser/BinaryOperation.scala index 39f6d3311d7..9adfa106971 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/parser/BinaryOperation.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/parser/BinaryOperation.scala @@ -46,7 +46,7 @@ object BinaryOperation { } case object GT_OP extends BinaryOperation { val func = ">" - override def parser[A: P] = P(">" ~ !P("=")).map(_ => this) + override def parser[A: P]: P[BinaryOperation] = P(">" ~ !P("=")).map(_ => this) } case object SUM_OP extends BinaryOperation { val func = "+" @@ -64,15 +64,15 @@ object BinaryOperation { override val func: String = "%" } case object LE_OP extends BinaryOperation { - val func = ">=" - override def parser[A: P] = P("<=").map(_ => this) + val func = ">=" + override def parser[A: P]: P[BinaryOperation] = P("<=").map(_ => this) override def expr(shiftedStart: Int, shiftedEnd: Int, op1: EXPR, op2: EXPR): EXPR = { BINARY_OP(Pos.fromShifted(shiftedStart, shiftedEnd), op2, LE_OP, op1) } } case object LT_OP extends BinaryOperation { - val func = ">" - override def parser[A: P] = P("<" ~ !P("=")).map(_ => this) + val func = ">" + override def parser[A: P]: P[BinaryOperation] = P("<" ~ !P("=")).map(_ => this) override def expr(shiftedStart: Int, shiftedEnd: Int, op1: EXPR, op2: EXPR): EXPR = { BINARY_OP(Pos.fromShifted(shiftedStart, shiftedEnd), op2, LT_OP, op1) } diff --git a/lang/tests-js/src/test/scala/com/wavesplatform/JsAPITest.scala b/lang/tests-js/src/test/scala/com/wavesplatform/JsAPITest.scala index 67dada4cda3..d7394c16103 100644 --- a/lang/tests-js/src/test/scala/com/wavesplatform/JsAPITest.scala +++ b/lang/tests-js/src/test/scala/com/wavesplatform/JsAPITest.scala @@ -224,14 +224,15 @@ object JsAPITest extends JsTestBase { } test("ill-formed characters") { + val invalidChar = '\ud87e' val script = - """ + s""" |{-# STDLIB_VERSION 6 #-} |{-# CONTENT_TYPE DAPP #-} |{-# SCRIPT_TYPE ACCOUNT #-} | |func call(a: String, b: Int) = { - | let zzz = "aaa\ud87ebbb" + | let zzz = "aaa${invalidChar}bbb" | ([], zzz) |} """.stripMargin diff --git a/lang/tests/src/test/resources/logback-test.xml b/lang/tests/src/test/resources/logback-test.xml new file mode 100644 index 00000000000..b1f394b2e41 --- /dev/null +++ b/lang/tests/src/test/resources/logback-test.xml @@ -0,0 +1,14 @@ + + + + + %date %-5level [%.15thread] %logger{26} - %msg%n + + + + + + + + + diff --git a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerCompactorTest.scala b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerCompactorTest.scala index 02d294b4951..65a8b222920 100644 --- a/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerCompactorTest.scala +++ b/lang/tests/src/test/scala/com/wavesplatform/lang/compiler/ContractCompilerCompactorTest.scala @@ -4,22 +4,22 @@ import cats.syntax.semigroup.* import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.lang.Global import com.wavesplatform.lang.contract.DApp -import com.wavesplatform.lang.directives.{Directive, DirectiveParser, DirectiveSet} import com.wavesplatform.lang.directives.values.{DApp as DAppType, *} -import com.wavesplatform.lang.script.{Script, ScriptPreprocessor} +import com.wavesplatform.lang.directives.{Directive, DirectiveParser, DirectiveSet} import com.wavesplatform.lang.script.ContractScript.ContractScriptImpl +import com.wavesplatform.lang.script.{Script, ScriptPreprocessor} import com.wavesplatform.lang.v1.FunctionHeader.User -import com.wavesplatform.lang.v1.compiler.Terms.{CONST_LONG, CaseObj} +import com.wavesplatform.lang.v1.compiler.Terms.{CONST_LONG, CaseObj, FUNC} import com.wavesplatform.lang.v1.compiler.Types.{ANY, BIGINT, BOOLEAN, LIST, LONG, PARAMETERIZED, PARAMETERIZEDLIST, STRING, UNION} import com.wavesplatform.lang.v1.compiler.{ContractScriptCompactor, TestCompiler} import com.wavesplatform.lang.v1.evaluator.Contextful.NoContext import com.wavesplatform.lang.v1.evaluator.ContextfulVal import com.wavesplatform.lang.v1.evaluator.ctx.impl.Rounding.Down -import com.wavesplatform.lang.v1.{CTX, compiler} -import com.wavesplatform.lang.v1.evaluator.ctx.impl.{CryptoContext, GlobalValNames, PureContext} import com.wavesplatform.lang.v1.evaluator.ctx.impl.waves.{Types, WavesContext} +import com.wavesplatform.lang.v1.evaluator.ctx.impl.{CryptoContext, GlobalValNames, PureContext} import com.wavesplatform.lang.v1.parser.{Expressions, Parser} import com.wavesplatform.lang.v1.traits.Environment +import com.wavesplatform.lang.v1.{CTX, compiler} import com.wavesplatform.protobuf.dapp.DAppMeta import com.wavesplatform.protobuf.dapp.DAppMeta.CompactNameAndOriginalNamePair import com.wavesplatform.test.* @@ -438,28 +438,18 @@ class ContractCompilerCompactorTest extends PropSpec { """.stripMargin def checkForV(version: StdLibVersion): Assertion = { - // noinspection RedundantDefaultArgument - val compilationResult = for { + val declarations = for { directives <- DirectiveParser(scriptForV(version)) ds <- Directive.extractDirectives(directives) (linked, _) <- ScriptPreprocessor(scriptForV(version), libraries, ds.imports) expr = Parser.parseContract(linked).get.value - r <- compiler.ContractCompiler(ctxForV(version).compilerContext, expr, version, needCompaction = false, removeUnusedCode = true) - } yield r.compactedSource(version) - - compilationResult.explicitGet() shouldBe s"""{-# STDLIB_VERSION ${version.id} #-} - |{-# SCRIPT_TYPE ACCOUNT #-} - |{-# CONTENT_TYPE DAPP #-} - |func bar () = 2 - | - | - |func foo () = 40 - | - | - | - |@Verifier(tx) - |func verify () = ((foo() + bar()) == 42) - |""".stripMargin + r <- compiler.ContractCompiler(ctxForV(version).compilerContext, expr, version, removeUnusedCode = true) + } yield r.decs + + declarations.explicitGet() should contain.only( + FUNC("foo", Nil, CONST_LONG(40)), + FUNC("bar", Nil, CONST_LONG(2)) + ) } checkForV(V5) diff --git a/node-it/src/test/scala/com/wavesplatform/it/api/model.scala b/node-it/src/test/scala/com/wavesplatform/it/api/model.scala index ed0bef0be71..b224b8036e2 100644 --- a/node-it/src/test/scala/com/wavesplatform/it/api/model.scala +++ b/node-it/src/test/scala/com/wavesplatform/it/api/model.scala @@ -441,7 +441,7 @@ object AttachedPayment { case class Invocation(dApp: String, call: Call, payments: Seq[AttachedPayment], stateChanges: StateChangesDetails) object Invocation { implicit val invokationFormat: Reads[Invocation] = new Reads[Invocation] { - override def reads(json: JsValue) = + override def reads(json: JsValue): JsResult[Invocation] = JsSuccess( Invocation( (json \ "dApp").as[String], diff --git a/node/build.sbt b/node/build.sbt index 500f025f027..5a6fdbeb673 100644 --- a/node/build.sbt +++ b/node/build.sbt @@ -6,7 +6,6 @@ enablePlugins( UniversalDeployPlugin, JDebPackaging, SystemdPlugin, - GitVersioning, VersionObject, JavaAgent ) diff --git a/node/src/main/scala/com/wavesplatform/Exporter.scala b/node/src/main/scala/com/wavesplatform/Exporter.scala index ba572002bbc..306736f8673 100644 --- a/node/src/main/scala/com/wavesplatform/Exporter.scala +++ b/node/src/main/scala/com/wavesplatform/Exporter.scala @@ -72,7 +72,7 @@ object Exporter extends ScorexLogging { } exportedBytes += IO.writeFooter(bos, format) val duration = System.currentTimeMillis() - start - log.info(s"Finished exporting $height blocks in ${humanReadableDuration(duration)}, ${humanReadableSize(exportedBytes)} written") + log.info(s"Finished exporting $height blocks in ${java.time.Duration.ofMillis(duration)}, ${humanReadableSize(exportedBytes)} written") } } } diff --git a/node/src/main/scala/com/wavesplatform/Importer.scala b/node/src/main/scala/com/wavesplatform/Importer.scala index 5aa94c1dfd6..57c5a182fb9 100644 --- a/node/src/main/scala/com/wavesplatform/Importer.scala +++ b/node/src/main/scala/com/wavesplatform/Importer.scala @@ -36,6 +36,7 @@ import scopt.OParser import java.io.* import java.net.{MalformedURLException, URL} +import java.time import scala.concurrent.duration.* import scala.concurrent.{Await, Future} import scala.util.{Failure, Success, Try} @@ -191,7 +192,7 @@ object Importer extends ScorexLogging { import scala.concurrent.duration.* val millis = (System.nanoTime() - start).nanos.toMillis log.info( - s"Imported $counter block(s) from $startHeight to ${startHeight + counter} in ${humanReadableDuration(millis)}" + s"Imported $counter block(s) from $startHeight to ${startHeight + counter} in ${time.Duration.ofMillis(millis)}" ) } diff --git a/node/src/main/scala/com/wavesplatform/api/http/ApiError.scala b/node/src/main/scala/com/wavesplatform/api/http/ApiError.scala index d88819e0837..33301d68283 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/ApiError.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/ApiError.scala @@ -70,9 +70,9 @@ object ApiError { } case object Unknown extends ApiError { - override val id = 0 - override val code = StatusCodes.InternalServerError - override val message = "Error is unknown" + override val id = 0 + override val code: StatusCode = StatusCodes.InternalServerError + override val message = "Error is unknown" } final case class WrongJson( @@ -80,9 +80,9 @@ object ApiError { errors: scala.collection.Seq[(JsPath, scala.collection.Seq[JsonValidationError])] = Seq.empty, msg: Option[String] = None ) extends ApiError { - override val id = WrongJson.Id - override val code = StatusCodes.BadRequest - override val message: String = msg.getOrElse(WrongJson.WrongJsonMessage) + override val id = WrongJson.Id + override val code: StatusCode = StatusCodes.BadRequest + override val message: String = msg.getOrElse(WrongJson.WrongJsonMessage) override lazy val json: JsObject = Json.obj( "error" -> id, "message" -> message, @@ -98,9 +98,9 @@ object ApiError { // API Auth case object ApiKeyNotValid extends ApiError { - override val id = 2 - override val code = StatusCodes.Forbidden - override val message: String = "Provided API key is not correct" + override val id = 2 + override val code: StatusCode = StatusCodes.Forbidden + override val message: String = "Provided API key is not correct" } case object TooBigArrayAllocation extends ApiError { @@ -117,32 +117,32 @@ object ApiError { // VALIDATION case object InvalidSignature extends ApiError { - override val id = 101 - override val code = StatusCodes.BadRequest - override val message = "invalid signature" + override val id = 101 + override val code: StatusCode = StatusCodes.BadRequest + override val message = "invalid signature" } case object InvalidAddress extends ApiError { - override val id = 102 - override val code = StatusCodes.BadRequest - override val message = "invalid address" + override val id = 102 + override val code: StatusCode = StatusCodes.BadRequest + override val message = "invalid address" } case class TooBigInBytes(message: String) extends ApiError { - override val id = 107 - override val code = StatusCodes.BadRequest + override val id = 107 + override val code: StatusCode = StatusCodes.BadRequest } case object InvalidPublicKey extends ApiError { - override val id = 108 - override val code = StatusCodes.BadRequest - override val message = "invalid public key" + override val id = 108 + override val code: StatusCode = StatusCodes.BadRequest + override val message = "invalid public key" } case object InvalidMessage extends ApiError { - override val id = 110 - override val code = StatusCodes.BadRequest - override val message = "invalid message" + override val id = 110 + override val code: StatusCode = StatusCodes.BadRequest + override val message = "invalid message" } case object InvalidName extends ApiError { @@ -210,14 +210,14 @@ object ApiError { } case object BlockDoesNotExist extends ApiError { - override val id: Int = 301 - override val code = StatusCodes.NotFound - override val message: String = "block does not exist" + override val id: Int = 301 + override val code: StatusCode = StatusCodes.NotFound + override val message: String = "block does not exist" } final case class AliasDoesNotExist(alias: Alias) extends ApiError { - override val id: Int = AliasDoesNotExist.Id - override val code = StatusCodes.NotFound + override val id: Int = AliasDoesNotExist.Id + override val code: StatusCode = StatusCodes.NotFound override lazy val message: String = s"alias '$alias' doesn't exist" } @@ -238,9 +238,9 @@ object ApiError { } case object DataKeyDoesNotExist extends ApiError { - override val id: Int = 304 - override val code = StatusCodes.NotFound - override val message: String = "no data for this key" + override val id: Int = 304 + override val code: StatusCode = StatusCodes.NotFound + override val message: String = "no data for this key" } final case class ScriptCompilerError(errorMessage: String) extends ApiError { @@ -303,9 +303,9 @@ object ApiError { } case object UnsupportedTransactionType extends ApiError { - override val id: Int = 312 - override val code = StatusCodes.NotImplemented - override val message: String = "transaction type not supported" + override val id: Int = 312 + override val code: StatusCode = StatusCodes.NotImplemented + override val message: String = "transaction type not supported" } case class AssetDoesNotExist(assetId: IssuedAsset) extends ApiError { @@ -418,42 +418,42 @@ object ApiError { } case class InvalidTransactionId(message: String) extends ApiError { - override val id = 4001 - override val code = StatusCodes.BadRequest + override val id = 4001 + override val code: StatusCode = StatusCodes.BadRequest } case class InvalidBlockId(message: String) extends ApiError { - override val id = 4002 - override val code = StatusCodes.BadRequest + override val id = 4002 + override val code: StatusCode = StatusCodes.BadRequest } case object InvalidAssetId extends ApiError { - override val id = 4007 - override val message = "Invalid asset id" - override val code = StatusCodes.BadRequest + override val id = 4007 + override val message = "Invalid asset id" + override val code: StatusCode = StatusCodes.BadRequest } case object ServerRequestTimeout extends ApiError { - override val id: Int = 5031 - override val code = StatusCodes.ServiceUnavailable - override val message: String = "The server was not able to produce a timely response to request" + override val id: Int = 5031 + override val code: StatusCode = StatusCodes.ServiceUnavailable + override val message: String = "The server was not able to produce a timely response to request" } case object DataKeysNotSpecified extends ApiError { - override val id = 4008 - override val message = "Key was not specified" - override val code = StatusCodes.BadRequest + override val id = 4008 + override val message = "Key was not specified" + override val code: StatusCode = StatusCodes.BadRequest } case object AssetIdNotSpecified extends ApiError { - override val id = 4009 - override val message = "Asset ID was not specified" - override val code = StatusCodes.BadRequest + override val id = 4009 + override val message = "Asset ID was not specified" + override val code: StatusCode = StatusCodes.BadRequest } case object ConflictingRequestStructure extends ApiError { - override val id = 198 - override val message = "Conflicting request structure. Both expression and invocation structure were sent" - override val code = StatusCodes.BadRequest + override val id = 198 + override val message = "Conflicting request structure. Both expression and invocation structure were sent" + override val code: StatusCode = StatusCodes.BadRequest } } diff --git a/node/src/main/scala/com/wavesplatform/api/http/`X-Api-Key`.scala b/node/src/main/scala/com/wavesplatform/api/http/`X-Api-Key`.scala index b0933086cb2..bfed6c67d1b 100644 --- a/node/src/main/scala/com/wavesplatform/api/http/`X-Api-Key`.scala +++ b/node/src/main/scala/com/wavesplatform/api/http/`X-Api-Key`.scala @@ -1,6 +1,6 @@ package com.wavesplatform.api.http -import akka.http.scaladsl.model.headers._ +import akka.http.scaladsl.model.headers.* import scala.util.Try @@ -11,9 +11,9 @@ object `X-Api-Key` extends ModeledCustomHeaderCompanion[`X-Api-Key`] { } final class `X-Api-Key`(val value: String) extends ModeledCustomHeader[`X-Api-Key`] { - override def companion = `X-Api-Key` - override def renderInRequests = true - override def renderInResponses = false + override def companion: ModeledCustomHeaderCompanion[`X-Api-Key`] = `X-Api-Key` + override def renderInRequests = true + override def renderInResponses = false } object api_key extends ModeledCustomHeaderCompanion[api_key] { @@ -23,7 +23,7 @@ object api_key extends ModeledCustomHeaderCompanion[api_key] { } final class api_key(val value: String) extends ModeledCustomHeader[api_key] { - override def companion = api_key - override def renderInRequests = true - override def renderInResponses = false + override def companion: ModeledCustomHeaderCompanion[api_key] = api_key + override def renderInRequests = true + override def renderInResponses = false } diff --git a/node/src/main/scala/com/wavesplatform/database/SortedBatch.scala b/node/src/main/scala/com/wavesplatform/database/SortedBatch.scala index d06dafc01ce..9e74e5ae3cc 100644 --- a/node/src/main/scala/com/wavesplatform/database/SortedBatch.scala +++ b/node/src/main/scala/com/wavesplatform/database/SortedBatch.scala @@ -6,6 +6,7 @@ import org.iq80.leveldb.WriteBatch import scala.collection.mutable class SortedBatch extends WriteBatch { + import com.wavesplatform.utils.byteStrOrdering val addedEntries: mutable.Map[ByteStr, Array[Byte]] = mutable.TreeMap[ByteStr, Array[Byte]]() val deletedEntries: mutable.Set[ByteStr] = mutable.TreeSet[ByteStr]() diff --git a/node/src/main/scala/com/wavesplatform/settings/package.scala b/node/src/main/scala/com/wavesplatform/settings/package.scala index ccb29624f01..0319dd40e51 100644 --- a/node/src/main/scala/com/wavesplatform/settings/package.scala +++ b/node/src/main/scala/com/wavesplatform/settings/package.scala @@ -9,7 +9,6 @@ import com.wavesplatform.common.state.ByteStr import net.ceedubs.ficus.Ficus.traversableReader import net.ceedubs.ficus.readers.namemappers.HyphenNameMapper import net.ceedubs.ficus.readers.{NameMapper, ValueReader} -import org.apache.commons.lang3.SystemUtils import scala.jdk.CollectionConverters.* import scala.util.Try @@ -111,9 +110,10 @@ package object settings { s"waves-$suffix" } + val osName = sys.props.get("os.name").map(_.toLowerCase) val parent = - if (SystemUtils.IS_OS_WINDOWS) winDefaultDirectory - else if (SystemUtils.IS_OS_MAC) osxDefaultDirectory + if (osName.exists(_.contains("win"))) winDefaultDirectory + else if (osName.exists(_.contains("mac"))) osxDefaultDirectory else nixDefaultDirectory s"$parent/${withNetwork(config)}" diff --git a/node/src/main/scala/com/wavesplatform/state/BlockRewardCalculator.scala b/node/src/main/scala/com/wavesplatform/state/BlockRewardCalculator.scala index 9fdf2c69ac3..4b1f5c606ee 100644 --- a/node/src/main/scala/com/wavesplatform/state/BlockRewardCalculator.scala +++ b/node/src/main/scala/com/wavesplatform/state/BlockRewardCalculator.scala @@ -58,6 +58,8 @@ object BlockRewardCalculator { val rewardShares = getBlockRewardShares(height, fullBlockReward, daoAddress, xtnBuybackAddress, blockchain) + import com.wavesplatform.utils.byteStrOrdering + (Seq(generator -> rewardShares.miner) ++ daoAddress.map(_ -> rewardShares.daoAddress) ++ xtnBuybackAddress.map(_ -> rewardShares.xtnBuybackAddress)) diff --git a/node/src/main/scala/com/wavesplatform/state/Diff.scala b/node/src/main/scala/com/wavesplatform/state/Diff.scala index 663b84a8bb0..e177e5bad16 100755 --- a/node/src/main/scala/com/wavesplatform/state/Diff.scala +++ b/node/src/main/scala/com/wavesplatform/state/Diff.scala @@ -20,6 +20,7 @@ import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.transaction.smart.InvokeTransaction import com.wavesplatform.transaction.{Asset, EthereumTransaction, Transaction} +import scala.annotation.nowarn import scala.collection.immutable.VectorMap import scala.util.chaining.* @@ -144,6 +145,7 @@ case class NewTransactionInfo(transaction: Transaction, affected: Set[Address], case class NewAssetInfo(static: AssetStaticInfo, dynamic: AssetInfo, volume: AssetVolumeInfo) +@nowarn case class Diff private ( transactions: Vector[NewTransactionInfo], portfolios: Map[Address, Portfolio], diff --git a/node/src/main/scala/com/wavesplatform/state/StateHashBuilder.scala b/node/src/main/scala/com/wavesplatform/state/StateHashBuilder.scala index 286a3d7bdfd..f69f612b485 100644 --- a/node/src/main/scala/com/wavesplatform/state/StateHashBuilder.scala +++ b/node/src/main/scala/com/wavesplatform/state/StateHashBuilder.scala @@ -36,6 +36,7 @@ object StateHashBuilder { } class StateHashBuilder { + import com.wavesplatform.utils.byteStrOrdering private[this] val maps = Vector.fill(SectionId.maxId)(mutable.TreeMap.empty[ByteStr, Array[Byte]]) private[this] def addEntry(section: SectionId.Value, key: Array[Byte]*)(value: Array[Byte]*): Unit = { diff --git a/node/src/main/scala/com/wavesplatform/transaction/CreateAliasTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/CreateAliasTransaction.scala index 1e553352538..c1328176772 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/CreateAliasTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/CreateAliasTransaction.scala @@ -7,6 +7,7 @@ import com.wavesplatform.common.utils.EitherExt2 import com.wavesplatform.crypto import com.wavesplatform.lang.ValidationError import com.wavesplatform.transaction.serialization.impl.CreateAliasTxSerializer +import com.wavesplatform.transaction.validation.TxValidator import com.wavesplatform.transaction.validation.impl.CreateAliasTxValidator import monix.eval.Coeval import play.api.libs.json.JsObject @@ -47,7 +48,7 @@ object CreateAliasTransaction extends TransactionParser { val supportedVersions: Set[TxVersion] = Set(1, 2, 3) val typeId: TxType = 10: Byte - implicit val validator = CreateAliasTxValidator + implicit val validator: TxValidator[CreateAliasTransaction] = CreateAliasTxValidator implicit def sign(tx: CreateAliasTransaction, privateKey: PrivateKey): CreateAliasTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) diff --git a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/ExchangeTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/ExchangeTransaction.scala index 224fe4aa44d..42be1dd6d5a 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/ExchangeTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/assets/exchange/ExchangeTransaction.scala @@ -6,6 +6,7 @@ import com.wavesplatform.lang.ValidationError import com.wavesplatform.transaction.* import com.wavesplatform.transaction.TxValidationError.GenericError import com.wavesplatform.transaction.serialization.impl.ExchangeTxSerializer +import com.wavesplatform.transaction.validation.TxValidator import com.wavesplatform.transaction.validation.impl.ExchangeTxValidator import monix.eval.Coeval import play.api.libs.json.JsObject @@ -44,7 +45,7 @@ case class ExchangeTransaction( object ExchangeTransaction extends TransactionParser { type TransactionT = ExchangeTransaction - implicit val validator = ExchangeTxValidator + implicit val validator: TxValidator[ExchangeTransaction] = ExchangeTxValidator implicit def sign(tx: ExchangeTransaction, privateKey: PrivateKey): ExchangeTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) diff --git a/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseTransaction.scala b/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseTransaction.scala index 4b478e7508c..b81bbbc4cc7 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseTransaction.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/lease/LeaseTransaction.scala @@ -3,8 +3,9 @@ package com.wavesplatform.transaction.lease import com.wavesplatform.account.{AddressOrAlias, KeyPair, PrivateKey, PublicKey} import com.wavesplatform.crypto import com.wavesplatform.lang.ValidationError -import com.wavesplatform.transaction._ +import com.wavesplatform.transaction.* import com.wavesplatform.transaction.serialization.impl.LeaseTxSerializer +import com.wavesplatform.transaction.validation.TxValidator import com.wavesplatform.transaction.validation.impl.LeaseTxValidator import monix.eval.Coeval import play.api.libs.json.JsObject @@ -37,7 +38,7 @@ object LeaseTransaction extends TransactionParser { val supportedVersions: Set[TxVersion] = Set(1, 2, 3) val typeId: TxType = 8: Byte - implicit val validator = LeaseTxValidator + implicit val validator: TxValidator[LeaseTransaction] = LeaseTxValidator implicit def sign(tx: LeaseTransaction, privateKey: PrivateKey): LeaseTransaction = tx.copy(proofs = Proofs(crypto.sign(privateKey, tx.bodyBytes()))) diff --git a/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala b/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala index 3c5ff00e1d3..d27986841f6 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/smart/WavesEnvironment.scala @@ -278,6 +278,7 @@ class WavesEnvironment( } val minerReward = Address(ByteStr(generator.toAddress.bytes)) -> (fullBlockReward - configAddressesReward.map(_._2).sum) + import com.wavesplatform.utils.byteStrOrdering (configAddressesReward :+ minerReward).sortBy(_._1.bytes) } } diff --git a/node/src/main/scala/com/wavesplatform/utils/Time.scala b/node/src/main/scala/com/wavesplatform/utils/Time.scala index dc796b2fdd8..dc5740b0f12 100644 --- a/node/src/main/scala/com/wavesplatform/utils/Time.scala +++ b/node/src/main/scala/com/wavesplatform/utils/Time.scala @@ -1,12 +1,12 @@ package com.wavesplatform.utils import java.net.{InetAddress, SocketTimeoutException} - import monix.eval.Task import monix.execution.ExecutionModel import monix.execution.schedulers.SchedulerService import org.apache.commons.net.ntp.NTPUDPClient +import java.time.Duration import scala.concurrent.duration.DurationInt trait Time { @@ -23,7 +23,7 @@ class NTP(ntpServer: String) extends Time with ScorexLogging with AutoCloseable Schedulers.singleThread(name = "time-impl", reporter = log.error("Error in NTP", _), ExecutionModel.AlwaysAsyncExecution) private[this] val client = new NTPUDPClient() - client.setDefaultTimeout(ResponseTimeout.toMillis.toInt) + client.setDefaultTimeout(Duration.ofMillis(ResponseTimeout.toMillis)) @volatile private[this] var ntpTimestamp = System.currentTimeMillis() @volatile private[this] var nanoTime = System.nanoTime() diff --git a/node/src/main/scala/com/wavesplatform/utils/package.scala b/node/src/main/scala/com/wavesplatform/utils/package.scala index a7bbcc8ab41..b1b781adde5 100644 --- a/node/src/main/scala/com/wavesplatform/utils/package.scala +++ b/node/src/main/scala/com/wavesplatform/utils/package.scala @@ -1,11 +1,11 @@ package com.wavesplatform import com.google.common.base.Charsets +import com.google.common.primitives.UnsignedBytes import com.google.protobuf.ByteString import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.{Base58, Base64} import com.wavesplatform.lang.v1.compiler.Terms.* -import org.apache.commons.lang3.time.DurationFormatUtils import play.api.libs.json.* import java.security.SecureRandom @@ -47,9 +47,6 @@ package object utils { f"${bytes / divisor}%.1f $unitString" } - def humanReadableDuration(duration: Long): String = - DurationFormatUtils.formatDurationHMS(duration) - implicit class Tap[A](a: A) { def tap(g: A => Unit): A = { g(a) @@ -100,4 +97,6 @@ package object utils { case ARR(xs) => Json.obj("type" -> "Array", "value" -> xs.map(evaluatedWrites.writes)) case FAIL(reason) => Json.obj("error" -> ApiError.ScriptExecutionError.Id, "error" -> reason) } + + implicit val byteStrOrdering: Ordering[ByteStr] = (x, y) => UnsignedBytes.lexicographicalComparator().compare(x.arr, y.arr) } diff --git a/node/src/test/resources/application.conf b/node/src/test/resources/application.conf index baab6776c0e..14081cca0c5 100644 --- a/node/src/test/resources/application.conf +++ b/node/src/test/resources/application.conf @@ -1,4 +1,6 @@ waves { utx.allow-transactions-from-smart-accounts = true + utx-synchronizer.network-tx-cache-size = 20 + wallet.password = "some string as password" } diff --git a/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala b/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala index 4cf8346ca12..07c890a9261 100644 --- a/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala +++ b/node/src/test/scala/com/wavesplatform/http/DebugApiRouteSpec.scala @@ -84,6 +84,7 @@ class DebugApiRouteSpec val block: Block = TestBlock.create(Nil) val testStateHash: StateHash = { + import com.wavesplatform.utils.byteStrOrdering def randomHash: ByteStr = ByteStr(Array.fill(32)(Random.nextInt(256).toByte)) val hashes = SectionId.values.map((_, randomHash)).toMap StateHash(randomHash, hashes) diff --git a/node/src/test/scala/com/wavesplatform/mining/MicroBlockMinerSpec.scala b/node/src/test/scala/com/wavesplatform/mining/MicroBlockMinerSpec.scala index 28231bbbb8f..076042c4953 100644 --- a/node/src/test/scala/com/wavesplatform/mining/MicroBlockMinerSpec.scala +++ b/node/src/test/scala/com/wavesplatform/mining/MicroBlockMinerSpec.scala @@ -107,7 +107,7 @@ class MicroBlockMinerSpec extends FlatSpec with PathMockFactory with WithDomain "Micro block miner" should "retry packing UTX regardless of when event has been sent" in { withDomain(RideV6, Seq(AddrWithBalance(defaultAddress, TestValues.bigMoney))) { d => import Scheduler.Implicits.global - val utxEvents = ConcurrentSubject.publish[UtxEvent] + val utxEvents = ConcurrentSubject.publish[UtxEvent] val eventHasBeenSent = new CountDownLatch(1) val inner = new UtxPoolImpl( ntpTime, @@ -123,7 +123,6 @@ class MicroBlockMinerSpec extends FlatSpec with PathMockFactory with WithDomain val utxPool = new UtxPool { - override def packUnconfirmed( rest: MultiDimensionalMiningConstraint, strategy: UtxPool.PackStrategy, @@ -131,9 +130,9 @@ class MicroBlockMinerSpec extends FlatSpec with PathMockFactory with WithDomain ): (Option[Seq[Transaction]], MiningConstraint) = { val (txs, constraint) = inner.packUnconfirmed(rest, strategy, cancelled) val waitingConstraint = new MiningConstraint { - def isFull = { eventHasBeenSent.await(); constraint.isFull } - def isOverfilled = constraint.isOverfilled - def put(b: Blockchain, tx: Transaction, diff: Diff) = constraint.put(b, tx, diff) + def isFull: Boolean = { eventHasBeenSent.await(); constraint.isFull } + def isOverfilled: Boolean = constraint.isOverfilled + def put(b: Blockchain, tx: Transaction, diff: Diff): MiningConstraint = constraint.put(b, tx, diff) } (txs, waitingConstraint) } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index d1a8feef3c2..b55314263f9 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -5,17 +5,15 @@ import sbt.{Def, *} object Dependencies { // Node protobuf schemas private[this] val protoSchemasLib = - "com.wavesplatform" % "protobuf-schemas" % "1.4.6-SNAPSHOT" classifier "protobuf-src" intransitive () + "com.wavesplatform" % "protobuf-schemas" % "1.4.6" classifier "protobuf-src" intransitive () - def akkaModule(module: String): ModuleID = "com.typesafe.akka" %% s"akka-$module" % "2.6.21" + private def akkaModule(module: String) = "com.typesafe.akka" %% s"akka-$module" % "2.6.21" - def akkaHttpModule(module: String) = "com.typesafe.akka" %% module % "10.2.10" + private def akkaHttpModule(module: String) = "com.typesafe.akka" %% module % "10.2.10" - private def kamonModule(module: String) = "io.kamon" %% s"kamon-$module" % "2.6.3" + private def kamonModule(module: String) = "io.kamon" %% s"kamon-$module" % "2.6.5" - private def jacksonModule(group: String, module: String) = s"com.fasterxml.jackson.$group" % s"jackson-$module" % "2.15.2" - - private def catsModule(module: String, version: String = "2.6.1") = Def.setting("org.typelevel" %%% s"cats-$module" % version) + private def jacksonModule(group: String, module: String) = s"com.fasterxml.jackson.$group" % s"jackson-$module" % "2.15.3" private def web3jModule(module: String) = "org.web3j" % module % "4.9.8" // https://github.com/web3j/web3j/issues/1907 @@ -25,21 +23,20 @@ object Dependencies { val akkaHttp = akkaHttpModule("akka-http") val jacksonModuleScala = jacksonModule("module", "module-scala").withCrossVersion(CrossVersion.Binary()) - val googleGuava = "com.google.guava" % "guava" % "32.0.1-jre" + val googleGuava = "com.google.guava" % "guava" % "32.1.3-jre" val kamonCore = kamonModule("core") val machinist = "org.typelevel" %% "machinist" % "0.6.8" val logback = "ch.qos.logback" % "logback-classic" % "1.3.11" // 1.4.x and later is built for Java 11 val janino = "org.codehaus.janino" % "janino" % "3.1.10" val asyncHttpClient = "org.asynchttpclient" % "async-http-client" % "2.12.3" val curve25519 = "com.wavesplatform" % "curve25519-java" % "0.6.6" - val nettyHandler = "io.netty" % "netty-handler" % "4.1.94.Final" + val nettyHandler = "io.netty" % "netty-handler" % "4.1.100.Final" - val catsCore = catsModule("core", "2.9.0") val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.10") - val playJson = "com.typesafe.play" %% "play-json" % "2.9.4" + val playJson = "com.typesafe.play" %% "play-json" % "2.9.4" // 2.10.x and later is built for Java 11 - val scalaTest = "org.scalatest" %% "scalatest" % "3.2.16" % Test + val scalaTest = "org.scalatest" %% "scalatest" % "3.2.17" % Test val scalaJsTest = Def.setting("com.lihaoyi" %%% "utest" % "0.8.1" % Test) val sttp3 = "com.softwaremill.sttp.client3" % "core_2.13" % "3.5.2" // 3.6.x and later is built for Java 11 @@ -61,12 +58,12 @@ object Dependencies { // defined here because %%% can only be used within a task or setting macro // explicit dependency can likely be removed when monix 3 is released monixModule("eval").value, - catsCore.value, - "com.lihaoyi" %%% "fastparse" % "2.3.3", + "org.typelevel" %%% s"cats-core" % "2.10.0", + "com.lihaoyi" %%% "fastparse" % "2.3.3", shapeless.value, "org.typelevel" %%% "cats-mtl" % "1.3.1", "ch.obermuhlner" % "big-math" % "2.3.2", - googleGuava, + googleGuava, // BaseEncoding.base16() curve25519, bouncyCastleProvider, "com.wavesplatform" % "zwaves" % "0.2.1", @@ -91,7 +88,7 @@ object Dependencies { lazy val qaseReportDeps = Seq( playJson, - ("io.qase" % "qase-api" % "3.0.5").excludeAll(ExclusionRule(organization = "javax.ws.rs")) + ("io.qase" % "qase-api" % "3.1.1").excludeAll(ExclusionRule(organization = "javax.ws.rs")) ).map(_ % Test) lazy val logDeps = Seq( @@ -100,7 +97,7 @@ object Dependencies { akkaModule("slf4j") % Runtime ) - def leveldbJava(module: String = "") = "org.iq80.leveldb" % s"leveldb${if (module.nonEmpty) "-" else ""}$module" % "0.12" + private def leveldbJava(module: String = "") = "org.iq80.leveldb" % s"leveldb${if (module.nonEmpty) "-" else ""}$module" % "0.12" private[this] val levelDBJNA = { val levelDbVersion = "1.23.1" @@ -114,8 +111,7 @@ object Dependencies { lazy val node = Def.setting( Seq( ("org.rudogma" %%% "supertagged" % "2.0-RC2").exclude("org.scala-js", "scalajs-library_2.13"), - "commons-net" % "commons-net" % "3.9.0", - "org.apache.commons" % "commons-lang3" % "3.12.0", + "commons-net" % "commons-net" % "3.10.0", "com.iheart" %% "ficus" % "1.5.2", "net.logstash.logback" % "logstash-logback-encoder" % "7.4" % Runtime, kamonCore, @@ -136,7 +132,7 @@ object Dependencies { nettyHandler, "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5", "eu.timepit" %% "refined" % "0.11.0", - "com.esaulpaugh" % "headlong" % "9.3.0", + "com.esaulpaugh" % "headlong" % "9.4.0", web3jModule("abi"), akkaModule("testkit") % Test, akkaHttpModule("akka-http-testkit") % Test, @@ -174,18 +170,19 @@ object Dependencies { "org.ehcache" % "sizeof" % "0.4.3", // Weighing caches kamonModule("caffeine"), kamonModule("prometheus"), - Dependencies.sttp3, - Dependencies.sttp3Monix, - "org.scala-lang.modules" %% "scala-xml" % "2.2.0", // JUnit reports - Dependencies.leveldbJava().exclude("com.google.guava", "guava") % Test, - Dependencies.akkaHttpModule("akka-http-testkit") % Test, - "com.softwaremill.diffx" %% "diffx-core" % "0.8.3" % Test, - "com.softwaremill.diffx" %% "diffx-scalatest-should" % "0.8.3" % Test + sttp3, + sttp3Monix, + "org.scala-lang.modules" %% "scala-xml" % "2.2.0", // JUnit reports + leveldbJava().exclude("com.google.guava", "guava") % Test, + akkaHttpModule("akka-http-testkit") % Test, + "com.softwaremill.diffx" %% "diffx-core" % "0.8.3" % Test, + "com.softwaremill.diffx" %% "diffx-scalatest-should" % "0.8.3" % Test, + "io.grpc" % "grpc-inprocess" % scalapb.compiler.Version.grpcJavaVersion % Test ) ++ Dependencies.console ++ Dependencies.logDeps ++ Dependencies.test ) lazy val circe = Def.setting { - val circeVersion = "0.14.5" + val circeVersion = "0.14.6" Seq( "io.circe" %%% "circe-core", "io.circe" %%% "circe-generic", diff --git a/project/build.properties b/project/build.properties index 40b3b8e7b65..27430827bc2 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.0 +sbt.version=1.9.6 diff --git a/project/plugins.sbt b/project/plugins.sbt index 1fa663ffaa5..94eeb1a889c 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -6,24 +6,24 @@ resolvers ++= Seq( // Should go before Scala.js addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6") -libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.13" +libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.14" Seq( - "com.eed3si9n" % "sbt-assembly" % "2.1.1", + "com.eed3si9n" % "sbt-assembly" % "2.1.3", "com.github.sbt" % "sbt-native-packager" % "1.9.16", - "se.marcuslonnberg" % "sbt-docker" % "1.10.0", - "org.scala-js" % "sbt-scalajs" % "1.13.2", - "org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.1", - "pl.project13.scala" % "sbt-jmh" % "0.4.5", + "se.marcuslonnberg" % "sbt-docker" % "1.11.0", + "org.scala-js" % "sbt-scalajs" % "1.14.0", + "org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2", + "pl.project13.scala" % "sbt-jmh" % "0.4.6", "com.github.sbt" % "sbt-ci-release" % "1.5.12", "com.lightbend.sbt" % "sbt-javaagent" % "0.1.6" ).map(addSbtPlugin) libraryDependencies ++= Seq( - "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.15.2", - "org.hjson" % "hjson" % "3.0.0", + "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.15.3", + "org.hjson" % "hjson" % "3.1.0", "org.vafer" % "jdeb" % "1.10" artifacts Artifact("jdeb", "jar", "jar"), - "org.slf4j" % "jcl-over-slf4j" % "2.0.7", + "org.slf4j" % "jcl-over-slf4j" % "2.0.9", ("com.spotify" % "docker-client" % "8.16.0") .exclude("commons-logging", "commons-logging") ) diff --git a/repl/jvm/src/test/logback-test.xml b/repl/jvm/src/test/logback-test.xml new file mode 100644 index 00000000000..8b4e22b2f22 --- /dev/null +++ b/repl/jvm/src/test/logback-test.xml @@ -0,0 +1,14 @@ + + + + + %date %-5level [%.15thread] %logger{26} - %msg%n + + + + + + + + + diff --git a/ride-runner/README.md b/ride-runner/README.md index 2630534151f..eda7e0aadbc 100644 --- a/ride-runner/README.md +++ b/ride-runner/README.md @@ -13,7 +13,7 @@ Allows running Ride without a local Waves Node: ### Artifacts * DEB package: `ride-runner/target/waves-ride-runner_${version}_all.deb` -* Fat JAR for running RIDE with a prepared state: `ride-runner/target/waves-ride-runner-${version}.jar` +* Fat JAR for running RIDE with a prepared state: `ride-runner/target/waves-ride-runner-all-${version}.jar` * Standalone app and service: `ride-runner/docker/ride-runner-targer/waves-ride-runner.tgz`. It has the `waves-ride-runner_${version}` directory. Notable: * `/bin/waves-ride-runner` - main entrypoint. @@ -165,7 +165,7 @@ See: How to run: ```shell -java -jar waves-ride-runner-${version}.jar ./sample-input.conf +java -jar waves-ride-runner-all-${version}.jar ./sample-input.conf ``` You should see the result in JSON. @@ -173,7 +173,7 @@ You should see the result in JSON. Help: ```shell -java -jar waves-ride-runner-1.4.18-8f8a0f98d3a2304d9b05c369bd333c8f85044e75-DIRTY.jar --help +java -jar waves-ride-runner-all-${version}.jar --help ``` **Important note**: using multiple different networks may cause errors if you run multiple scripts (for example, if you diff --git a/ride-runner/build.sbt b/ride-runner/build.sbt index 7414218eef3..6b7d11a732f 100644 --- a/ride-runner/build.sbt +++ b/ride-runner/build.sbt @@ -6,7 +6,6 @@ enablePlugins( UniversalDeployPlugin, JDebPackaging, SystemdPlugin, - GitVersioning, JavaAgent ) @@ -90,7 +89,7 @@ inTask(assembly)( Seq( test := {}, mainClass := Some("com.wavesplatform.ride.runner.entrypoints.WavesRideRunnerWithPreparedStateApp"), - assemblyJarName := s"waves-ride-runner-${version.value}.jar", + assemblyJarName := s"waves-ride-runner-all-${version.value}.jar", assemblyMergeStrategy := { case p if p.endsWith(".proto") || diff --git a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/RideTestSuite.scala b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/RideTestSuite.scala index 8dcedce551d..8388eea6505 100644 --- a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/RideTestSuite.scala +++ b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/RideTestSuite.scala @@ -1,5 +1,6 @@ package com.wavesplatform.ride.runner +import java.io.File import java.nio.file.Path import scala.annotation.tailrec import scala.collection.immutable.SortedSet @@ -16,7 +17,7 @@ object RideTestSuite { def getTestSuites(testCases: List[Path]): RideTestSuite = { val testSuites = mutable.Map.empty[Path, RideTestSuite] - val rootPath = Path.of("") // Dummy path if test cases just file names + val rootPath = new File("").toPath // Dummy path if test cases just file names testSuites.put(rootPath, RideTestSuite(path = rootPath)) // Adding test cases diff --git a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/caches/RemoteData.scala b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/caches/RemoteData.scala index 7362917d5e8..fb288950fea 100644 --- a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/caches/RemoteData.scala +++ b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/caches/RemoteData.scala @@ -13,12 +13,12 @@ object RemoteData { case object Absence extends RemoteData[Nothing] { override val loaded = true - override val mayBeValue = None + override val mayBeValue: Option[Nothing] = None } case object Unknown extends RemoteData[Nothing] { override val loaded = false - override val mayBeValue = None + override val mayBeValue: Option[Nothing] = None } def apply[T](x: Option[Option[T]]): RemoteData[T] = x match { diff --git a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/caches/WeighedAccountScriptInfo.scala b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/caches/WeighedAccountScriptInfo.scala index 6f99e52b427..60e7fed4ead 100644 --- a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/caches/WeighedAccountScriptInfo.scala +++ b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/caches/WeighedAccountScriptInfo.scala @@ -3,6 +3,9 @@ package com.wavesplatform.ride.runner.caches import com.google.common.collect.Interners import com.wavesplatform.state.AccountScriptInfo +import scala.annotation.nowarn + +@nowarn case class WeighedAccountScriptInfo private (scriptInfoWeight: Int, accountScriptInfo: AccountScriptInfo) object WeighedAccountScriptInfo { diff --git a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/entrypoints/AppInitializer.scala b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/entrypoints/AppInitializer.scala index 5f1b3b1e09c..10448c227cb 100644 --- a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/entrypoints/AppInitializer.scala +++ b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/entrypoints/AppInitializer.scala @@ -60,7 +60,7 @@ object AppInitializer extends ScorexLogging { val versionFilePath = rootPath.resolve("version") val (cleanup, updateVersion) = if (versionFilePath.toFile.exists()) { - val rawVersion = Files.readString(versionFilePath, StandardCharsets.UTF_8).trim + val rawVersion = new String(Files.readAllBytes(versionFilePath), StandardCharsets.UTF_8).trim rawVersion.toIntOption match { case Some(version) => if (version != settings.rideRunner.db.version) { @@ -90,6 +90,6 @@ object AppInitializer extends ScorexLogging { } } - if (updateVersion) Files.writeString(versionFilePath, settings.rideRunner.db.version.toString) + if (updateVersion) Files.write(versionFilePath, settings.rideRunner.db.version.toString.getBytes(StandardCharsets.UTF_8)) } } diff --git a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/entrypoints/WavesRideRunnerWithPreparedStateApp.scala b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/entrypoints/WavesRideRunnerWithPreparedStateApp.scala index 17d36bfe7d1..36d9943ba56 100644 --- a/ride-runner/src/main/scala/com/wavesplatform/ride/runner/entrypoints/WavesRideRunnerWithPreparedStateApp.scala +++ b/ride-runner/src/main/scala/com/wavesplatform/ride/runner/entrypoints/WavesRideRunnerWithPreparedStateApp.scala @@ -30,7 +30,7 @@ import scala.xml.{Elem, PCData} object WavesRideRunnerWithPreparedStateApp { def main(args: Array[String]): Unit = { val setup = new DefaultOParserSetup { - override val showUsageOnError = Some(true) + override val showUsageOnError: Option[Boolean] = Some(true) } OParser.parse(commandParser, args, Args(), setup).foreach { args => diff --git a/ride-runner/src/test/scala/com/wavesplatform/ride/runner/caches/disk/AccountDataDiskCacheTestSuite.scala b/ride-runner/src/test/scala/com/wavesplatform/ride/runner/caches/disk/AccountDataDiskCacheTestSuite.scala index cfbdf3f988a..90161306c59 100644 --- a/ride-runner/src/test/scala/com/wavesplatform/ride/runner/caches/disk/AccountDataDiskCacheTestSuite.scala +++ b/ride-runner/src/test/scala/com/wavesplatform/ride/runner/caches/disk/AccountDataDiskCacheTestSuite.scala @@ -6,10 +6,10 @@ import com.wavesplatform.ride.runner.db.{Heights, ReadOnly, ReadWrite} import com.wavesplatform.state.{BooleanDataEntry, DataEntry} class AccountDataDiskCacheTestSuite extends DiskCacheWithHistoryTestSuite[(Address, String), DataEntry[?]] { - private val defaultAddressId = AddressId(0L) // There is only one addressId - private val defaultPairDataKey = "foo" - protected override val defaultKey = (aliceAddr, defaultPairDataKey) - protected override val defaultValue = BooleanDataEntry(defaultPairDataKey, value = true) + private val defaultAddressId = AddressId(0L) // There is only one addressId + private val defaultPairDataKey = "foo" + protected override val defaultKey: (Address, String) = (aliceAddr, defaultPairDataKey) + protected override val defaultValue: DataEntry[?] = BooleanDataEntry(defaultPairDataKey, value = true) protected override def test(f: DiskCache[(Address, String), DataEntry[?]] => ReadWrite => Unit): Unit = withDb { db => db.directReadWrite { implicit ctx => diff --git a/ride-runner/src/test/scala/com/wavesplatform/ride/runner/tests/RideTestSuiteTestSuite.scala b/ride-runner/src/test/scala/com/wavesplatform/ride/runner/tests/RideTestSuiteTestSuite.scala index 59d62ffe5f7..e9aa7655b3e 100644 --- a/ride-runner/src/test/scala/com/wavesplatform/ride/runner/tests/RideTestSuiteTestSuite.scala +++ b/ride-runner/src/test/scala/com/wavesplatform/ride/runner/tests/RideTestSuiteTestSuite.scala @@ -4,29 +4,29 @@ import com.wavesplatform.ride.runner.RideTestSuite import com.wavesplatform.ride.runner.RideTestSuite.getTestSuites import com.wavesplatform.{BaseTestSuite, HasTestAccounts} -import java.nio.file.Path +import java.io.File import scala.collection.immutable.SortedSet class RideTestSuiteTestSuite extends BaseTestSuite with HasTestAccounts { - private val rootPath = Path.of("") + private val rootPath = new File("").toPath "RideTestSuite" - { "getTestSuites" - { "one" in { - val aTest = Path.of("a.test") + val aTest = new File("a.test").toPath getTestSuites(List(aTest)) shouldBe RideTestSuite(path = rootPath, testCases = SortedSet(aTest)) } "one nested" in { - val aTest = Path.of("foo/bar/a.test") + val aTest = new File("foo/bar/a.test").toPath getTestSuites(List(aTest)) shouldBe RideTestSuite( path = rootPath, testSuites = SortedSet( RideTestSuite( - path = Path.of("foo"), + path = new File("foo").toPath, testSuites = SortedSet( RideTestSuite( - path = Path.of("foo/bar"), + path = new File("foo/bar").toPath, testCases = SortedSet(aTest) ) ) @@ -36,33 +36,33 @@ class RideTestSuiteTestSuite extends BaseTestSuite with HasTestAccounts { } "complex" in { - val aTest = Path.of("foo/bar/a.test") - val bTest = Path.of("foo/bar/baz/b.test") - val cTest = Path.of("bar/c.test") - val dTest = Path.of("foo/baz/d.test") + val aTest = new File("foo/bar/a.test").toPath + val bTest = new File("foo/bar/baz/b.test").toPath + val cTest = new File("bar/c.test").toPath + val dTest = new File("foo/baz/d.test").toPath getTestSuites(List(aTest, bTest, cTest, dTest)) shouldBe RideTestSuite( path = rootPath, testSuites = SortedSet( RideTestSuite( - path = Path.of("bar"), + path = new File("bar").toPath, testCases = SortedSet(cTest) ), RideTestSuite( - path = Path.of("foo"), + path = new File("foo").toPath, testSuites = SortedSet( RideTestSuite( - path = Path.of("foo/bar"), + path = new File("foo/bar").toPath, testCases = SortedSet(aTest), testSuites = SortedSet( RideTestSuite( - path = Path.of("foo/bar/baz"), + path = new File("foo/bar/baz").toPath, testCases = SortedSet(bTest) ) ) ), RideTestSuite( - path = Path.of("foo/baz"), + path = new File("foo/baz").toPath, testCases = SortedSet(dTest) ) )