From 74244b5f7a0bb63e630047e285ee3aeb8281d11d Mon Sep 17 00:00:00 2001 From: Boris P Date: Tue, 18 Oct 2022 21:56:26 -0600 Subject: [PATCH 01/11] move to oraclelinux + add aarch64 support --- Dockerfile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1c724297cf..b8f6390c1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mozilla/sbt:11.0.8_1.3.13 as builder +FROM mozilla/sbt:11.0.13_1.6.2 as builder WORKDIR /mnt COPY build.sbt findbugs-exclude.xml ./ COPY project/ project/ @@ -11,16 +11,17 @@ RUN sbt update COPY . ./ RUN sbt assembly RUN mv `find target/scala-*/stripped/ -name ergo-*.jar` ergo.jar - -FROM openjdk:11-jre-slim -RUN apt-get update && apt-get install -y curl jq && rm -rf /var/lib/apt/lists/* -RUN adduser --disabled-password --home /home/ergo --uid 9052 --gecos "ErgoPlatform" ergo && \ +FROM openjdk:11-oraclelinux8 +RUN microdnf --nodocs -y upgrade +RUN microdnf --nodocs -y install --setopt=install_weak_deps=0 jq curl +RUN microdnf clean all +RUN adduser --home-dir /home/ergo --uid 9052 ergo && \ install -m 0750 -o ergo -g ergo -d /home/ergo/.ergo USER ergo -EXPOSE 9020 9052 9030 9053 +EXPOSE 9020 9021 9052 9030 9053 WORKDIR /home/ergo VOLUME ["/home/ergo/.ergo"] ENV MAX_HEAP 3G -ENV _JAVA_OPTIONS "-Xmx${MAX_HEAP}" +ENV _JAVA_OPTIONS "-Xms${MAX_HEAP} -Xmx${MAX_HEAP}" COPY --from=builder /mnt/ergo.jar /home/ergo/ergo.jar ENTRYPOINT ["java", "-jar", "/home/ergo/ergo.jar"] From 4c48ca9508fe5c2d1c2565f46f9e5f43388f302a Mon Sep 17 00:00:00 2001 From: Boris P Date: Tue, 18 Oct 2022 22:03:45 -0600 Subject: [PATCH 02/11] Update docker workflow for aarch64 --- .github/workflows/docker-publish.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index d222647106..b2ed2b3d16 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -11,6 +11,11 @@ jobs: steps: - name: Check out the repo uses: actions/checkout@v2 + + - name: qemu + uses: docker/setup-qemu-action@v1 + + - uses: docker/setup-buildx-action@v1 - name: Docker Login uses: docker/login-action@v1.10.0 @@ -29,5 +34,6 @@ jobs: with: context: . push: true + platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From f4b5a7084740ecc400788f4398fb64d3f34e4ff9 Mon Sep 17 00:00:00 2001 From: Boris P Date: Thu, 20 Oct 2022 12:15:52 -0600 Subject: [PATCH 03/11] Dockerfile: revert to debian-based image --- Dockerfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index b8f6390c1d..e8687f9e45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,11 +11,10 @@ RUN sbt update COPY . ./ RUN sbt assembly RUN mv `find target/scala-*/stripped/ -name ergo-*.jar` ergo.jar -FROM openjdk:11-oraclelinux8 -RUN microdnf --nodocs -y upgrade -RUN microdnf --nodocs -y install --setopt=install_weak_deps=0 jq curl -RUN microdnf clean all -RUN adduser --home-dir /home/ergo --uid 9052 ergo && \ + +FROM eclipse-temurin:11-jre-jammy +RUN apt-get update && apt-get install -y curl jq && rm -rf /var/lib/apt/lists/* +RUN adduser --disabled-password --home /home/ergo --uid 9052 --gecos "ErgoPlatform" ergo && \ install -m 0750 -o ergo -g ergo -d /home/ergo/.ergo USER ergo EXPOSE 9020 9021 9052 9030 9053 From 57e800215579cd7fa02e8edcf89ff59b6bc037ec Mon Sep 17 00:00:00 2001 From: Boris P Date: Thu, 20 Oct 2022 22:26:17 -0600 Subject: [PATCH 04/11] Dockerfile: change sbt repo to new official --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e8687f9e45..49ed5d5def 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mozilla/sbt:11.0.13_1.6.2 as builder +FROM sbtscala/scala-sbt:eclipse-temurin-11.0.15_1.6.2_2.12.16 as builder WORKDIR /mnt COPY build.sbt findbugs-exclude.xml ./ COPY project/ project/ From aad45f6c30c0f7c7652e678b5e22dcdf1deb0d20 Mon Sep 17 00:00:00 2001 From: pragmaxim Date: Tue, 25 Oct 2022 16:38:41 +0200 Subject: [PATCH 05/11] i1881 use 400 for non-existing endpoints and 404 for non-existing resource --- src/main/scala/scorex/core/api/http/ApiRejectionHandler.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/scorex/core/api/http/ApiRejectionHandler.scala b/src/main/scala/scorex/core/api/http/ApiRejectionHandler.scala index d0427015c0..628316b301 100644 --- a/src/main/scala/scorex/core/api/http/ApiRejectionHandler.scala +++ b/src/main/scala/scorex/core/api/http/ApiRejectionHandler.scala @@ -31,6 +31,6 @@ object ApiRejectionHandler { } .handle { case ValidationRejection(msg, _) => ApiError.BadRequest(msg) } .handle { case x => ApiError.InternalError(s"Unhandled rejection: $x") } - .handleNotFound { ApiError.NotExists("The requested resource could not be found.") } + .handleNotFound { ApiError.BadRequest("The requested resource/endpoint could not be found.") } .result() } From 307989c8cd3e41bbe8707afb049e0b68d42860df Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Tue, 25 Oct 2022 21:19:50 +0300 Subject: [PATCH 06/11] 5.0.2 version set --- README.md | 2 +- src/main/resources/api/openapi.yaml | 2 +- src/main/resources/application.conf | 2 +- src/main/resources/mainnet.conf | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3e748ba742..199be06110 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ To run specific Ergo version `` as a service with custom config `/path/ -e MAX_HEAP=3G \ ergoplatform/ergo: -- -c /etc/myergo.conf -Available versions can be found on [Ergo Docker image page](https://hub.docker.com/r/ergoplatform/ergo/tags), for example, `v5.0.1`. +Available versions can be found on [Ergo Docker image page](https://hub.docker.com/r/ergoplatform/ergo/tags), for example, `v5.0.2`. This will connect to the Ergo mainnet or testnet following your configuration passed in `myergo.conf` and network flag `--`. Every default config value would be overwritten with corresponding value in `myergo.conf`. `MAX_HEAP` variable can be used to control how much memory can the node consume. diff --git a/src/main/resources/api/openapi.yaml b/src/main/resources/api/openapi.yaml index 9e991dbc31..8af3cddf33 100644 --- a/src/main/resources/api/openapi.yaml +++ b/src/main/resources/api/openapi.yaml @@ -1,7 +1,7 @@ openapi: "3.0.2" info: - version: "5.0.1" + version: "5.0.2" title: Ergo Node API description: API docs for Ergo Node. Models are shared between all Ergo products contact: diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 9588f2eb1c..1d29375973 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -408,7 +408,7 @@ scorex { nodeName = "ergo-node" # Network protocol version to be sent in handshakes - appVersion = 5.0.1 + appVersion = 5.0.2 # Network agent name. May contain information about client code # stack, starting from core code-base up to the end graphical interface. diff --git a/src/main/resources/mainnet.conf b/src/main/resources/mainnet.conf index 5972a679c8..59b8dff5c1 100644 --- a/src/main/resources/mainnet.conf +++ b/src/main/resources/mainnet.conf @@ -78,7 +78,7 @@ scorex { network { magicBytes = [1, 0, 2, 4] bindAddress = "0.0.0.0:9030" - nodeName = "ergo-mainnet-5.0.1" + nodeName = "ergo-mainnet-5.0.2" nodeName = ${?NODENAME} knownPeers = [ "213.239.193.208:9030", From 9b71c00ab06baf64ba972e82e41f1234dd598ccf Mon Sep 17 00:00:00 2001 From: Boris P Date: Tue, 25 Oct 2022 17:22:22 -0600 Subject: [PATCH 07/11] Dockerfile: Open port 9022 for paiNet --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 49ed5d5def..1c5f95e3c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN apt-get update && apt-get install -y curl jq && rm -rf /var/lib/apt/lists/* RUN adduser --disabled-password --home /home/ergo --uid 9052 --gecos "ErgoPlatform" ergo && \ install -m 0750 -o ergo -g ergo -d /home/ergo/.ergo USER ergo -EXPOSE 9020 9021 9052 9030 9053 +EXPOSE 9020 9021 9022 9052 9030 9053 WORKDIR /home/ergo VOLUME ["/home/ergo/.ergo"] ENV MAX_HEAP 3G From 9d9e15c784b8f11a5812a9c7edf63d30b8c2eca5 Mon Sep 17 00:00:00 2001 From: pragmaxim Date: Thu, 27 Oct 2022 18:28:49 +0200 Subject: [PATCH 08/11] i1885 wallet timeout repro --- .../boxes/ReplaceCompactCollectBoxSelectorSpec.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ergo-wallet/src/test/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelectorSpec.scala b/ergo-wallet/src/test/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelectorSpec.scala index 3474329fb3..253fcfb490 100644 --- a/ergo-wallet/src/test/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelectorSpec.scala +++ b/ergo-wallet/src/test/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelectorSpec.scala @@ -97,12 +97,12 @@ class ReplaceCompactCollectBoxSelectorSpec extends AnyPropSpec with Matchers wit } property("dust collection under select()") { - val optimalInputs = 5 - val selector = new ReplaceCompactCollectBoxSelector(20, optimalInputs, None) - val inputValues = (1 to 10).map(v => trackedBox(v)) + val optimalInputs = 3000 + val selector = new ReplaceCompactCollectBoxSelector(3000, optimalInputs, None) + val inputValues = (1 to 30000).map(v => trackedBox(v)) { - val targetBalance = 6 + val targetBalance = 10000000 val res = selector.select(inputValues.toIterator, noFilter, targetBalance, Map()).right.value res.boxes.length shouldBe optimalInputs } From ff60f689262bfb00d7d13c1494b95944409b8ea1 Mon Sep 17 00:00:00 2001 From: pragmaxim Date: Thu, 27 Oct 2022 19:23:32 +0200 Subject: [PATCH 09/11] i1885 profiling - removing expensive ops like appending to List and contains --- .../boxes/ReplaceCompactCollectBoxSelector.scala | 14 +++++++++----- .../ReplaceCompactCollectBoxSelectorSpec.scala | 8 ++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala index afe406cbf4..03ed59dd39 100644 --- a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala +++ b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala @@ -7,8 +7,11 @@ import org.ergoplatform.wallet.{AssetUtils, TokensMap} import scorex.util.ModifierId import org.ergoplatform.wallet.transactions.TransactionBuilder._ +import scala.:+ import scala.annotation.tailrec +import scala.collection.immutable.VectorBuilder import scala.collection.mutable +import scala.collection.mutable.ListBuffer /** * A box selector which is parameterized by maximum number of inputs a transaction can have, and optimal number of inputs. @@ -135,8 +138,8 @@ class ReplaceCompactCollectBoxSelector(maxInputs: Int, val boxesToThrowAway = bsr.boxes.filter(!_.tokens.keySet.exists(tid => targetAssets.keySet.contains(tid))) val sorted = boxesToThrowAway.sortBy(b => BoxSelector.valueOf(b, reemissionDataOpt)) - type BoxesToAdd = Seq[T] - type BoxesToDrop = Seq[T] + type BoxesToAdd = ListBuffer[T] + type BoxesToDrop = Set[T] type Operations = (BoxesToAdd, BoxesToDrop) @tailrec @@ -149,15 +152,16 @@ class ReplaceCompactCollectBoxSelector(maxInputs: Int, currentOps case Seq(cand, cs@_*) => var collected = 0L - val (dropped, remain) = toDrop.partition { b => + val candValue = BoxSelector.valueOf(cand, reemissionDataOpt) + val (dropped, remain) = toDrop.span { b => collected = collected + BoxSelector.valueOf(b, reemissionDataOpt) - collected <= BoxSelector.valueOf(cand, reemissionDataOpt) + collected <= candValue } replaceStep(cs, remain, (currentOps._1 :+ cand, currentOps._2 ++ dropped)) } } - val (toAdd, toDrop) = replaceStep(bigBoxes, sorted, (Seq(), Seq())) + val (toAdd, toDrop) = replaceStep(bigBoxes, sorted, (ListBuffer.empty[T], Set.empty[T])) if (toAdd.nonEmpty) { val compactedBoxes = bsr.boxes.filter(b => !toDrop.contains(b)) ++ toAdd calcChange(compactedBoxes, targetBalance, targetAssets) diff --git a/ergo-wallet/src/test/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelectorSpec.scala b/ergo-wallet/src/test/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelectorSpec.scala index 253fcfb490..3474329fb3 100644 --- a/ergo-wallet/src/test/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelectorSpec.scala +++ b/ergo-wallet/src/test/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelectorSpec.scala @@ -97,12 +97,12 @@ class ReplaceCompactCollectBoxSelectorSpec extends AnyPropSpec with Matchers wit } property("dust collection under select()") { - val optimalInputs = 3000 - val selector = new ReplaceCompactCollectBoxSelector(3000, optimalInputs, None) - val inputValues = (1 to 30000).map(v => trackedBox(v)) + val optimalInputs = 5 + val selector = new ReplaceCompactCollectBoxSelector(20, optimalInputs, None) + val inputValues = (1 to 10).map(v => trackedBox(v)) { - val targetBalance = 10000000 + val targetBalance = 6 val res = selector.select(inputValues.toIterator, noFilter, targetBalance, Map()).right.value res.boxes.length shouldBe optimalInputs } From a97845273b0234738d0c12a504861e2147cf89d7 Mon Sep 17 00:00:00 2001 From: pragmaxim Date: Thu, 27 Oct 2022 19:24:50 +0200 Subject: [PATCH 10/11] i1885 removing unused imports --- .../wallet/boxes/ReplaceCompactCollectBoxSelector.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala index 03ed59dd39..7857d72e9c 100644 --- a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala +++ b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala @@ -7,9 +7,7 @@ import org.ergoplatform.wallet.{AssetUtils, TokensMap} import scorex.util.ModifierId import org.ergoplatform.wallet.transactions.TransactionBuilder._ -import scala.:+ import scala.annotation.tailrec -import scala.collection.immutable.VectorBuilder import scala.collection.mutable import scala.collection.mutable.ListBuffer From 1c9ee95cfdda6a3a98ac43816254fd7c31411faa Mon Sep 17 00:00:00 2001 From: pragmaxim Date: Fri, 28 Oct 2022 14:55:44 +0200 Subject: [PATCH 11/11] i1885 another bunch of optimizations --- .../wallet/boxes/BoxSelector.scala | 4 +- .../wallet/boxes/DefaultBoxSelector.scala | 2 +- .../ReplaceCompactCollectBoxSelector.scala | 37 ++++++++++--------- .../nodeView/wallet/ErgoWalletSupport.scala | 2 +- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/BoxSelector.scala b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/BoxSelector.scala index 00fff87838..c678893907 100644 --- a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/BoxSelector.scala +++ b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/BoxSelector.scala @@ -48,9 +48,7 @@ trait BoxSelector extends ScorexLogging { */ def reemissionAmount[T <: ErgoBoxAssets](boxes: Seq[T]): Long = { reemissionDataOpt.map { reemissionData => - boxes - .flatMap(_.tokens.get(reemissionData.reemissionTokenId)) - .sum + boxes.foldLeft(0L) { case (sum, b) => sum + b.tokens.getOrElse(reemissionData.reemissionTokenId, 0L) } }.getOrElse(0L) } diff --git a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/DefaultBoxSelector.scala b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/DefaultBoxSelector.scala index a70c1c8bdb..a4aad20681 100644 --- a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/DefaultBoxSelector.scala +++ b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/DefaultBoxSelector.scala @@ -136,7 +136,7 @@ class DefaultBoxSelector(override val reemissionDataOpt: Option[ReemissionData]) targetBoxAssets: TokensMap, reemissionAmt: Long): Either[BoxSelectionError, Seq[ErgoBoxAssets]] = { AssetUtils.subtractAssetsMut(foundBoxAssets, targetBoxAssets) - val changeBoxesAssets: Seq[mutable.Map[ModifierId, Long]] = foundBoxAssets.grouped(MaxAssetsPerBox).toSeq + val changeBoxesAssets: Seq[mutable.Map[ModifierId, Long]] = foundBoxAssets.grouped(MaxAssetsPerBox).toIndexedSeq val changeBalance = foundBalance - targetBalance //at least a minimum amount of ERG should be assigned per a created box if (changeBoxesAssets.size * MinBoxValue > changeBalance) { diff --git a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala index 7857d72e9c..16a010ba5e 100644 --- a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala +++ b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/boxes/ReplaceCompactCollectBoxSelector.scala @@ -85,7 +85,7 @@ class ReplaceCompactCollectBoxSelector(maxInputs: Int, targetBalance: Long, targetAssets: TokensMap ): Either[BoxSelectionError, Seq[ErgoBoxAssets]] = { - val compactedBalance = boxes.map(b => BoxSelector.valueOf(b, reemissionDataOpt)).sum + val compactedBalance = boxes.foldLeft(0L) { case (sum, b) => sum + BoxSelector.valueOf(b, reemissionDataOpt) } val compactedAssets = mutable.Map[ModifierId, Long]() AssetUtils.mergeAssetsMut(compactedAssets, boxes.map(_.tokens): _*) val ra = reemissionAmount(boxes) @@ -109,14 +109,16 @@ class ReplaceCompactCollectBoxSelector(maxInputs: Int, targetBalance: Long, targetAssets: TokensMap): Either[BoxSelectionError, BoxSelectionResult[T]] = { val boxes = bsr.boxes - val diff = boxes.map(b => BoxSelector.valueOf(b,reemissionDataOpt)).sum - targetBalance + val diff = boxes.foldLeft(0L) { case (sum, b) => sum + BoxSelector.valueOf(b, reemissionDataOpt) } - targetBalance - val boxesToThrowAway = boxes.filter(!_.tokens.keySet.exists(tid => targetAssets.keySet.contains(tid))) - val sorted = boxesToThrowAway.sortBy(b => BoxSelector.valueOf(b, reemissionDataOpt)) + val targetAssetsKeys = targetAssets.keySet + val sortedBoxesToThrowAway = + boxes.filter(!_.tokens.keySet.exists(tid => targetAssetsKeys.contains(tid))) + .sortBy(b => BoxSelector.valueOf(b, reemissionDataOpt)) - if (diff >= BoxSelector.valueOf(sorted.head, reemissionDataOpt)) { + if (diff >= BoxSelector.valueOf(sortedBoxesToThrowAway.head, reemissionDataOpt)) { var thrownValue = 0L - val thrownBoxes = sorted.takeWhile { b => + val thrownBoxes = sortedBoxesToThrowAway.takeWhile { b => thrownValue = thrownValue + BoxSelector.valueOf(b, reemissionDataOpt) thrownValue <= diff } @@ -136,18 +138,17 @@ class ReplaceCompactCollectBoxSelector(maxInputs: Int, val boxesToThrowAway = bsr.boxes.filter(!_.tokens.keySet.exists(tid => targetAssets.keySet.contains(tid))) val sorted = boxesToThrowAway.sortBy(b => BoxSelector.valueOf(b, reemissionDataOpt)) - type BoxesToAdd = ListBuffer[T] - type BoxesToDrop = Set[T] - type Operations = (BoxesToAdd, BoxesToDrop) + val boxesToAdd = ListBuffer.empty[T] + val boxesToDrop = mutable.HashSet.empty[T] @tailrec - def replaceStep(candidates: Seq[T], toDrop: Seq[T], currentOps: Operations): Operations = { + def replaceStep(candidates: Seq[T], toDrop: Seq[T]): Unit = { candidates match { - case Seq() => currentOps + case Seq() => () case Seq(cand) if BoxSelector.valueOf(cand, reemissionDataOpt) <= toDrop.headOption.map(b => BoxSelector.valueOf(b, reemissionDataOpt)).getOrElse(Long.MaxValue) => - currentOps + () case Seq(cand, cs@_*) => var collected = 0L val candValue = BoxSelector.valueOf(cand, reemissionDataOpt) @@ -155,13 +156,15 @@ class ReplaceCompactCollectBoxSelector(maxInputs: Int, collected = collected + BoxSelector.valueOf(b, reemissionDataOpt) collected <= candValue } - replaceStep(cs, remain, (currentOps._1 :+ cand, currentOps._2 ++ dropped)) + boxesToAdd += cand + boxesToDrop ++= dropped + replaceStep(cs, remain) } } - val (toAdd, toDrop) = replaceStep(bigBoxes, sorted, (ListBuffer.empty[T], Set.empty[T])) - if (toAdd.nonEmpty) { - val compactedBoxes = bsr.boxes.filter(b => !toDrop.contains(b)) ++ toAdd + replaceStep(bigBoxes, sorted) + if (boxesToAdd.nonEmpty) { + val compactedBoxes = bsr.boxes.filter(b => !boxesToDrop.contains(b)) ++ boxesToAdd calcChange(compactedBoxes, targetBalance, targetAssets) .mapRight(changeBoxes => BoxSelectionResult(compactedBoxes, changeBoxes)) } else { @@ -172,5 +175,5 @@ class ReplaceCompactCollectBoxSelector(maxInputs: Int, } object ReplaceCompactCollectBoxSelector { - final case class MaxInputsExceededError(message: String) extends BoxSelectionError + final case class MaxInputsExceededError(message: String) extends BoxSelectionError } diff --git a/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletSupport.scala b/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletSupport.scala index 5b94f72c72..059807554f 100644 --- a/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletSupport.scala +++ b/src/main/scala/org/ergoplatform/nodeView/wallet/ErgoWalletSupport.scala @@ -256,7 +256,7 @@ trait ErgoWalletSupport extends ScorexLogging { } val inputBoxes = selectionResult.boxes.toIndexedSeq new UnsignedErgoTransaction( - inputBoxes.map(_.box.id).map(id => new UnsignedInput(id)), + inputBoxes.map(tx => new UnsignedInput(tx.box.id)), dataInputs, (payTo ++ changeBoxCandidates).toIndexedSeq )