diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index af066035..4563687d 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -52,6 +52,8 @@ jobs: pull: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max - uses: actions/attest-build-provenance@v1 with: subject-name: ${{ env.IMAGE_NAME}} diff --git a/build.sbt b/build.sbt index 3fd39805..d0bf068b 100644 --- a/build.sbt +++ b/build.sbt @@ -1,21 +1,22 @@ Global / onChangedBuildSource := ReloadOnSourceChanges -enablePlugins(UniversalDeployPlugin, JavaAppPackaging, GitVersioning) +enablePlugins(UniversalDeployPlugin, GitVersioning) -git.useGitDescribe := true -git.baseVersion := "1.0.0" +git.useGitDescribe := true +git.baseVersion := "1.0.0" git.uncommittedSignifier := Some("DIRTY") -scalaVersion := "2.13.14" -organization := "network.units" +scalaVersion := "2.13.14" +organization := "network.units" organizationName := "Units Network" -name := "consensus-client" +name := "consensus-client" +maintainer := "Units Network Team" resolvers ++= Resolver.sonatypeOssRepos("releases") ++ Resolver.sonatypeOssRepos("snapshots") ++ Seq(Resolver.mavenLocal) libraryDependencies ++= Seq( - "com.wavesplatform" % "node" % "1.5.7" % "provided", - "com.softwaremill.sttp.client3" % "core_2.13" % "3.9.8", - "com.softwaremill.sttp.client3" %% "play-json" % "3.9.8", - "com.github.jwt-scala" %% "jwt-play-json" % "10.0.1" + "com.wavesplatform" % "node" % "1.5.7" % "provided", + "com.softwaremill.sttp.client3" % "core_2.13" % "3.9.8", + "com.softwaremill.sttp.client3" %% "play-json" % "3.9.8", + "com.github.jwt-scala" %% "jwt-play-json" % "10.0.1" ) scalacOptions ++= Seq( @@ -30,7 +31,49 @@ scalacOptions ++= Seq( "-Xlint" ) -lazy val buildTarballsForDocker = taskKey[Unit]("Package node and grpc-server tarballs and copy them to docker/target") +Compile / packageDoc / publishArtifact := false + +def makeJarName( + org: String, + name: String, + revision: String, + artifactName: String, + artifactClassifier: Option[String] +): String = + org + "." + + name + "-" + + Option(artifactName.replace(name, "")).filterNot(_.isEmpty).map(_ + "-").getOrElse("") + + revision + + artifactClassifier.filterNot(_.isEmpty).map("-" + _).getOrElse("") + + ".jar" + +def getJarFullFilename(dep: Attributed[File]): String = { + val filename: Option[String] = for { + module <- dep.metadata.get(AttributeKey[ModuleID]("moduleID")) + artifact <- dep.metadata.get(AttributeKey[Artifact]("artifact")) + } yield makeJarName(module.organization, module.name, module.revision, artifact.name, artifact.classifier) + filename.getOrElse(dep.data.getName) +} + +def universalDepMappings(deps: Seq[Attributed[File]]): Seq[(File, String)] = + for { + dep <- deps + } yield dep.data -> ("lib/" + getJarFullFilename(dep)) + +Universal / mappings += { + val jar = (Compile / packageBin).value + val id = projectID.value + val art = (Compile / packageBin / artifact).value + jar -> ("lib/" + makeJarName(id.organization, id.name, id.revision, art.name, art.classifier)) +} +Universal / mappings ++= universalDepMappings((Runtime / dependencyClasspath).value.filterNot { p => + p.get(AttributeKey[ModuleID]("moduleID")).exists { m => + m.organization == "org.scala-lang" || + m.organization.startsWith("com.fasterxml.jackson") + } +}) + +lazy val buildTarballsForDocker = taskKey[Unit]("Package consensus-client tarball and copy it to docker/target") buildTarballsForDocker := { IO.copyFile( (Universal / packageZipTarball).value, diff --git a/src/main/scala/units/ELUpdater.scala b/src/main/scala/units/ELUpdater.scala index 908bde03..eb98944d 100644 --- a/src/main/scala/units/ELUpdater.scala +++ b/src/main/scala/units/ELUpdater.scala @@ -280,7 +280,7 @@ class ELUpdater( } } - private def checkRandao(networkBlock: NetworkL2Block, epochNumber: Int): Either[String, Unit] = + private def validateRandao(networkBlock: NetworkL2Block, epochNumber: Int): Either[String, Unit] = blockchain.vrf(epochNumber) match { case None => s"VRF of $epochNumber epoch is empty".asLeft case Some(vrf) => @@ -288,7 +288,7 @@ class ELUpdater( Either.cond( expectedPrevRandao == networkBlock.prevRandao, (), - s"expected prevRandao $expectedPrevRandao, got ${networkBlock.prevRandao}, VRF=$vrf of $epochNumber. Wrong epoch?" + s"expected prevRandao $expectedPrevRandao, got ${networkBlock.prevRandao}, VRF=$vrf of $epochNumber" ) } @@ -988,7 +988,7 @@ class ELUpdater( s"block miner ${networkBlock.minerRewardL2Address} doesn't equal to ${epochInfo.rewardAddress}" ) _ <- checkSignature(networkBlock, isConfirmed) - _ <- checkRandao(networkBlock, contractBlock.fold(epochInfo.number)(_.epoch)) + _ <- if (contractBlock.isEmpty) validateRandao(networkBlock, epochInfo.number) else Either.unit result <- preValidateWithdrawals(networkBlock, epochInfo, contractBlock) } yield result).leftMap { err => s"Block ${networkBlock.hash} validation error: $err, ignoring block" @@ -998,12 +998,14 @@ class ELUpdater( private def validateBlock( networkBlock: NetworkL2Block, parentEcBlock: EcBlock, + contractBlock: Option[ContractBlock], expectReward: Boolean, chainContractOptions: ChainContractOptions ): Job[Unit] = { (for { _ <- validateTimestamp(networkBlock, parentEcBlock) _ <- validateWithdrawals(networkBlock, parentEcBlock, expectReward, chainContractOptions) + _ <- contractBlock.fold(Either.unit[String])(cb => validateRandao(networkBlock, cb.epoch)) } yield ()).leftMap(err => ClientError(s"Network block ${networkBlock.hash} validation error: $err")) } @@ -1092,7 +1094,7 @@ class ELUpdater( logger.debug(err) case Right(preValidationResult) => val applyResult = for { - _ <- validateBlock(networkBlock, expectedParent, preValidationResult.expectReward, prevState.options) + _ <- validateBlock(networkBlock, expectedParent, contractBlock, preValidationResult.expectReward, prevState.options) _ = logger.debug(s"Block ${networkBlock.hash} was partially validated, trying to apply and broadcast") _ <- engineApiClient.applyNewPayload(networkBlock.payload) } yield () diff --git a/src/main/scala/units/client/contract/ContractFunction.scala b/src/main/scala/units/client/contract/ContractFunction.scala index e0de83c5..b469a4ed 100644 --- a/src/main/scala/units/client/contract/ContractFunction.scala +++ b/src/main/scala/units/client/contract/ContractFunction.scala @@ -6,7 +6,7 @@ import com.wavesplatform.common.state.ByteStr import com.wavesplatform.lang.CommonError import com.wavesplatform.lang.v1.FunctionHeader import com.wavesplatform.lang.v1.compiler.Terms.{CONST_BYTESTR, CONST_LONG, CONST_STRING, EVALUATED, FUNCTION_CALL} -import com.wavesplatform.utils.EthEncoding.cleanHexPrefix +import org.web3j.utils.Numeric.cleanHexPrefix import units.util.HexBytesConverter.toHexNoPrefix import units.{BlockHash, ClientError, Job}