Skip to content

Commit

Permalink
Merge pull request #1942 from ergoplatform/v5.0.7
Browse files Browse the repository at this point in the history
Candidate for 5.0.7
  • Loading branch information
kushti authored Feb 16, 2023
2 parents fc292f6 + 3bce9e7 commit 1b0d72e
Show file tree
Hide file tree
Showing 139 changed files with 3,705 additions and 1,272 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.10, 2.11.12]
scala: [2.13.8, 2.12.10, 2.11.12]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ local.conf
.metals/
.vscode/
project/metals.sbt
null/

# scala worksheets
*.worksheet.sc
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM sbtscala/scala-sbt:eclipse-temurin-11.0.15_1.6.2_2.12.16 as builder
FROM sbtscala/scala-sbt:eclipse-temurin-11.0.15_1.7.1_2.13.8 as builder
WORKDIR /mnt
COPY build.sbt findbugs-exclude.xml ./
COPY project/ project/
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ heavy validation attacks
A [White Paper](https://ergoplatform.org/docs/whitepaper.pdf) with a brief description is available. A Yellow Paper with detailed specification is underway and will be available shortly. At the moment, there are [drafts of the Yellow Paper](https://github.com/ergoplatform/ergo/tree/master/papers/yellow) available,
and currently the reference implementation code should be considered as the specification.

## Security assumptions

This client relies on some assumptions in regards with its environment:

* execution environment is trusted. While seed is stored in encrypted files, and the client's
wallet tries to remove secret key from memory as soon as possible when it is not needed, the
client has no protection from side-channel attacks, memory scans etc.
* clocks should be more or less synchronized. If timestamp of a block is more than 20 minutes
in future, the block will be temporarily rejected. The client does not use NTP or other time
syncing protocols.

## Building and Running Node and UI

See [documentation](https://docs.ergoplatform.com/node/install/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object Helper {
type HF = Blake2b256.type
type Prover = PersistentBatchAVLProver[Digest32, HF]

implicit val hf = Blake2b256
implicit val hf: HF = Blake2b256

val kl = 32
val vl = 8
Expand Down
3 changes: 2 additions & 1 deletion avldb/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ libraryDependencies ++= Seq(
)

libraryDependencies ++= Seq(
"org.ethereum" % "leveldbjni-all" % "1.18.3"
"org.ethereum" % "leveldbjni-all" % "1.18.3",
"org.typelevel" %% "spire" % "0.14.1"
)

testOptions in Test := Seq(Tests.Filter(t => !t.matches(".*Benchmark$")))
Expand Down
13 changes: 8 additions & 5 deletions avldb/src/main/scala/scorex/db/LDBKVStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.iq80.leveldb.DB
import scorex.util.ScorexLogging

import scala.util.{Failure, Success, Try}
import spire.syntax.all.cfor


/**
Expand All @@ -13,11 +14,13 @@ import scala.util.{Failure, Success, Try}
*/
class LDBKVStore(protected val db: DB) extends KVStoreReader with ScorexLogging {

def update(toInsert: Seq[(K, V)], toRemove: Seq[K]): Try[Unit] = {
def update(toInsert: Array[(K, V)], toRemove: Array[K]): Try[Unit] = {
val batch = db.createWriteBatch()
val insertLen = toInsert.length
val removeLen = toRemove.length
try {
toInsert.foreach { case (k, v) => batch.put(k, v) }
toRemove.foreach(batch.delete)
cfor(0)(_ < insertLen, _ + 1) { i => batch.put(toInsert(i)._1, toInsert(i)._2)}
cfor(0)(_ < removeLen, _ + 1) { i => batch.delete(toRemove(i))}
db.write(batch)
Success(())
} catch {
Expand All @@ -42,9 +45,9 @@ class LDBKVStore(protected val db: DB) extends KVStoreReader with ScorexLogging
}
}

def insert(values: Seq[(K, V)]): Try[Unit] = update(values, Seq.empty)
def insert(values: Array[(K, V)]): Try[Unit] = update(values, Array.empty)

def remove(keys: Seq[K]): Try[Unit] = update(Seq.empty, keys)
def remove(keys: Array[K]): Try[Unit] = update(Array.empty, keys)

/**
* Get last key within some range (inclusive) by used comparator.
Expand Down
7 changes: 5 additions & 2 deletions avldb/src/main/scala/scorex/db/LDBVersionedStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ class LDBVersionedStore(protected val dir: File, val initialKeepVersions: Int) e
Undo(versionID, key, value)
}

/**
* Write versioned batch update to the database, removing keys from the database and adding new key -> value pairs
*/
def update(versionID: VersionID,
toRemove: Iterable[Array[Byte]],
toUpdate: Iterable[(Array[Byte], Array[Byte])]): Try[Unit] = Try {
toRemove: TraversableOnce[Array[Byte]],
toUpdate: TraversableOnce[(Array[Byte], Array[Byte])]): Try[Unit] = Try {
lock.writeLock().lock()
val lastLsn = lsn // remember current LSN value
val batch = db.createWriteBatch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object BatchingBenchmark extends App with FileHelper {
val NumMods = 200000


implicit val hf = Blake2b256
implicit val hf: HF = Blake2b256
type HF = Blake2b256.type

val store = new LDBVersionedStore(getRandomTempDir, initialKeepVersions = 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ import org.ergoplatform.nodeView.{ErgoNodeViewRef, NVBenchmark}
import org.ergoplatform.settings.{Args, ErgoSettings}
import org.ergoplatform.nodeView.ErgoNodeViewHolder.CurrentView
import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages.{GetDataFromCurrentView, LocallyGeneratedModifier}
import scorex.core.utils.{NetworkTimeProvider, NetworkTimeProviderSettings}
import scorex.util.ScorexLogging

import scala.concurrent.ExecutionContextExecutor
import scala.concurrent.duration._
import scala.language.postfixOps

object BenchRunner extends ScorexLogging with NVBenchmark {

Expand All @@ -41,10 +37,7 @@ object BenchRunner extends ScorexLogging with NVBenchmark {
log.info(s"Setting that being used:")
log.info(s"$ergoSettings")

val ntpSettings = NetworkTimeProviderSettings("pool.ntp.org", 30 minutes, 30 seconds)
val timeProvider = new NetworkTimeProvider(ntpSettings)

val nodeViewHolderRef: ActorRef = ErgoNodeViewRef(ergoSettings, timeProvider)
val nodeViewHolderRef: ActorRef = ErgoNodeViewRef(ergoSettings)

/**
* It's a hack to set minimalFullBlockHeightVar to 0 and to avoid "Header Is Not Synced" error, cause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import java.io.FileOutputStream
import org.ergoplatform.bench.misc.ModifierWriter
import org.ergoplatform.nodeView.history.ErgoHistory
import org.ergoplatform.settings.{Args, ErgoSettings}
import scorex.core.settings.ScorexSettings
import scorex.core.utils.NetworkTimeProvider
import scorex.util.ScorexLogging

import scala.concurrent.ExecutionContext.Implicits.global

object HistoryExtractor extends ScorexLogging {

Expand All @@ -18,11 +15,9 @@ object HistoryExtractor extends ScorexLogging {
lazy val cfgPath: Option[String] = args.headOption
lazy val outputFile: String = args.lift(1).getOrElse("blocks.dat")
lazy val ergoSettings: ErgoSettings = ErgoSettings.read(Args(cfgPath, None))
lazy val settings: ScorexSettings = ergoSettings.scorexSettings

val timeProvider = new NetworkTimeProvider(settings.ntp)
val os = new FileOutputStream(outputFile)
val h = ErgoHistory.readOrGenerate(ergoSettings, timeProvider)
val h = ErgoHistory.readOrGenerate(ergoSettings)(null)
val wholeChain = h.chainToHeader(None, h.bestHeaderOpt.get)

var counter = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.ergoplatform.bench.misc

import java.io.{InputStream, OutputStream}

import com.google.common.primitives.Ints
import org.ergoplatform.Utils._
import org.ergoplatform.modifiers.BlockSection
import org.ergoplatform.modifiers.{BlockSection, NetworkObjectTypeId}
import org.ergoplatform.modifiers.history._
import org.ergoplatform.modifiers.history.header.{Header, HeaderSerializer}
import scorex.core.serialization.ScorexSerializer
import scorex.core.{ModifierTypeId, NodeViewModifier}
import scorex.core.NodeViewModifier

object ModifierWriter {

val modifierSerializers: Map[ModifierTypeId, ScorexSerializer[_ <: BlockSection]] =
val modifierSerializers: Map[NetworkObjectTypeId.Value, ScorexSerializer[_ <: BlockSection]] =
Map(Header.modifierTypeId -> HeaderSerializer,
BlockTransactions.modifierTypeId -> BlockTransactionsSerializer,
ADProofs.modifierTypeId -> ADProofsSerializer)
Expand All @@ -34,9 +33,9 @@ object ModifierWriter {
mod <- modifierSerializers(typeId).parseBytesTry(bytes).toOption
} yield mod

private def readModId(implicit fis: InputStream): Option[ModifierTypeId] = {
private def readModId(implicit fis: InputStream): Option[NetworkObjectTypeId.Value] = {
val int = fis.read()
if (int == -1) { None } else { Some(ModifierTypeId @@ int.toByte) }
if (int == -1) { None } else { Some(NetworkObjectTypeId.fromByte(int.toByte)) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object LDBStoreBench
}

val txsWithDbGen: Gen[(Seq[BlockTransactions], LDBKVStore)] = txsGen.map { bts =>
val toInsert = bts.map(bt => idToBytes(bt.headerId) -> bt.bytes)
val toInsert = bts.map(bt => idToBytes(bt.headerId) -> bt.bytes).toArray
val db = storeLDB()
toInsert.grouped(5).foreach(db.insert(_).get)
bts -> storeLDB
Expand All @@ -53,7 +53,7 @@ object LDBStoreBench
private def randomVersion: Digest32 = Algos.hash(Longs.toByteArray(Random.nextLong()))

private def benchWriteLDB(bts: Seq[BlockTransactions]): Unit = {
val toInsert = bts.map(bt => idToBytes(bt.headerId) -> bt.bytes)
val toInsert = bts.map(bt => idToBytes(bt.headerId) -> bt.bytes).toArray
val db = storeLDB()
toInsert.grouped(5).foreach(db.insert(_).get)
}
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ logLevel := Level.Debug
// this values should be in sync with ergo-wallet/build.sbt
val scala211 = "2.11.12"
val scala212 = "2.12.10"
val scala213 = "2.13.8"

lazy val commonSettings = Seq(
organization := "org.ergoplatform",
Expand Down Expand Up @@ -36,7 +37,7 @@ val circeVersion = "0.13.0"
val akkaVersion = "2.6.10"
val akkaHttpVersion = "10.2.4"

val sigmaStateVersion = "5.0.3"
val sigmaStateVersion = "5.0.5"

// for testing current sigmastate build (see sigmastate-ergo-it jenkins job)
val effectiveSigmaStateVersion = Option(System.getenv().get("SIGMASTATE_VERSION")).getOrElse(sigmaStateVersion)
Expand All @@ -61,7 +62,6 @@ libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-parsing" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"org.bitlet" % "weupnp" % "0.1.4",
"commons-net" % "commons-net" % "3.6",

// api dependencies
"io.circe" %% "circe-core" % circeVersion,
Expand Down Expand Up @@ -265,7 +265,7 @@ lazy val avldb_benchmarks = (project in file("avldb/benchmarks"))
lazy val ergoWallet = (project in file("ergo-wallet"))
.disablePlugins(ScapegoatSbtPlugin) // not compatible with crossScalaVersions
.settings(
crossScalaVersions := Seq(scalaVersion.value, scala211),
crossScalaVersions := Seq(scala213, scalaVersion.value, scala211),
commonSettings,
name := "ergo-wallet",
libraryDependencies ++= Seq(
Expand Down
3 changes: 2 additions & 1 deletion ergo-wallet/build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// this values should be in sync with root (i.e. ../build.sbt)
val scala211 = "2.11.12"
val scala212 = "2.12.10"
val scala213 = "2.13.8"

val circeVersion = "0.13.0"
val circeVersion211 = "0.10.0"

libraryDependencies ++= Seq(
"org.scodec" %% "scodec-bits" % "1.1.6",
"org.scodec" %% "scodec-bits" % "1.1.34",

"io.circe" %% "circe-core" % (if (scalaVersion.value == scala211) circeVersion211 else circeVersion),
"io.circe" %% "circe-generic" % (if (scalaVersion.value == scala211) circeVersion211 else circeVersion),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.ergoplatform.ErgoLikeTransaction;
import org.ergoplatform.UnsignedErgoLikeTransaction;
import scala.collection.JavaConversions;
import scala.collection.JavaConverters;
import sigmastate.basics.DLogProtocol;
import java.util.Map;

Expand All @@ -26,8 +26,10 @@ public ErgoLikeTransaction prove(UnsignedErgoLikeTransaction unsignedTx, DLogPro
* @return signed transaction
*/
public ErgoLikeTransaction prove(UnsignedErgoLikeTransaction unsignedTx, Map<String, DLogProtocol.DLogProverInput> sks) {
// JavaConversions used to support Scala 2.11
return org.ergoplatform.wallet.interpreter.ErgoUnsafeProver.prove(unsignedTx, JavaConversions.mapAsScalaMap(sks));
// This method of JavaConverters is supported across Scala 2.11-2.13
return org.ergoplatform.wallet.interpreter.ErgoUnsafeProver.prove(
unsignedTx,
JavaConverters.mapAsScalaMapConverter(sks).asScala());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DefaultBoxSelector(override val reemissionDataOpt: Option[ReemissionData])
assetsMet
)) {
formChangeBoxes(currentBalance, targetBalance, currentAssets, targetAssets).mapRight { changeBoxes =>
selectionResultWithEip27Output(res, changeBoxes)
selectionResultWithEip27Output(res.toSeq, changeBoxes)
}
} else {
Left(NotEnoughTokensError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.ergoplatform.wallet.boxes
import org.ergoplatform.ErgoBoxCandidate
import sigmastate.eval.Extensions._
import java7.compat.Math

import scala.collection.compat.immutable.ArraySeq
import scala.collection.mutable
import scala.util.Try

Expand All @@ -29,7 +31,7 @@ object ErgoBoxAssetExtractor {
)
box.additionalTokens.foreach {
case (assetId, amount) =>
val aiWrapped = mutable.WrappedArray.make(assetId)
val aiWrapped = ArraySeq.unsafeWrapArray(assetId)
val total = map.getOrElse(aiWrapped, 0L)
map.put(aiWrapped, Math.addExact(total, amount))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ object Mnemonic {
* Converts mnemonic phrase to seed it was derived from.
*/
def toSeed(mnemonic: SecretString, passOpt: Option[SecretString] = None): Array[Byte] = {
val normalizedMnemonic = normalize(mnemonic.getData(), NFKD).toCharArray
val normalizedPass = normalize(("mnemonic".toCharArray ++ passOpt.fold("".toCharArray())(_.getData())), NFKD)
val normalizedMnemonic = normalize(ArrayCharSequence(mnemonic.getData()), NFKD).toCharArray
val normalizedPass = normalize(ArrayCharSequence("mnemonic".toCharArray ++ passOpt.fold("".toCharArray())(_.getData())), NFKD)

passOpt.fold(())(_.erase())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ object TransactionBuilder {

// add burnTokens to target assets so that they are excluded from the change outputs
// thus total outputs assets will be reduced which is interpreted as _token burning_
val tokensOutWithBurned = AssetUtils.mergeAssets(tokensOutNoMinted, burnTokens)
val tokensOutWithBurned = AssetUtils.mergeAssets(tokensOutNoMinted.toMap, burnTokens)

val selection = boxSelector.select(inputs.toIterator, outputTotal, tokensOutWithBurned) match {
case Left(err) => throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class MnemonicSpec
val strength = Mnemonic.AllowedStrengths.zip(Mnemonic.MnemonicSentenceSizes).find(_._2 == sentenceSize).map(_._1).get
val mnemonic = new Mnemonic(langId, strength)
Base16.encode(Mnemonic.toSeed(SecretString.create(sentence), Some(SecretString.create(pass)))) shouldEqual seed
normalize(mnemonic.toMnemonic(Base16.decode(entropy).get).get.getData(), NFKD) shouldEqual normalize(sentence, NFKD)
normalize(ArrayCharSequence(mnemonic.toMnemonic(Base16.decode(entropy).get).get.getData()), NFKD) shouldEqual normalize(sentence, NFKD)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import sigmastate.basics.DLogProtocol.ProveDlog
import sigmastate.{SByte, SType}
import org.ergoplatform.wallet.Constants.{ScanId, PaymentsScanId}
import scorex.util._
import scala.collection.IndexedSeq
import org.ergoplatform.ErgoBox
import org.ergoplatform.ErgoBoxCandidate
import org.ergoplatform.ErgoScriptPredef
Expand Down
4 changes: 2 additions & 2 deletions src/it/scala/org/ergoplatform/it/WalletSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class WalletSpec extends AsyncWordSpec with IntegrationSuite with WalletTestOps

val encodedBox = Base16.encode(ErgoBoxSerializer.toBytes(input))

val paymentRequest = PaymentRequest(P2PKAddress(pk), 50000000, Seq.empty, Map.empty)
val requestsHolder = RequestsHolder(Seq(paymentRequest), feeOpt = Some(100000L), Seq(encodedBox), dataInputsRaw = Seq.empty, minerRewardDelay = 720)
val paymentRequest = PaymentRequest(P2PKAddress(pk)(addressEncoder), 50000000, Seq.empty, Map.empty)
val requestsHolder = RequestsHolder(Seq(paymentRequest), feeOpt = Some(100000L), Seq(encodedBox), dataInputsRaw = Seq.empty, minerRewardDelay = 720)(addressEncoder)

node.waitForStartup.flatMap { node: Node =>
for {
Expand Down
Loading

0 comments on commit 1b0d72e

Please sign in to comment.