Skip to content

Commit

Permalink
Merge pull request #1883 from ergoplatform/v5.0.2
Browse files Browse the repository at this point in the history
Candidate for 5.0.2
  • Loading branch information
kushti authored Nov 2, 2022
2 parents 670b283 + 061b786 commit b7507c4
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,5 +34,6 @@ jobs:
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mozilla/sbt:11.0.8_1.3.13 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/
Expand All @@ -12,15 +12,15 @@ COPY . ./
RUN sbt assembly
RUN mv `find target/scala-*/stripped/ -name ergo-*.jar` ergo.jar

FROM openjdk:11-jre-slim
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 9052 9030 9053
EXPOSE 9020 9021 9022 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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ To run specific Ergo version `<VERSION>` as a service with custom config `/path/
-e MAX_HEAP=3G \
ergoplatform/ergo:<VERSION> --<networkId> -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 `--<networkId>`. 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.ergoplatform.wallet.transactions.TransactionBuilder._

import scala.annotation.tailrec
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.
Expand Down Expand Up @@ -84,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)
Expand All @@ -108,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
}
Expand All @@ -135,31 +138,33 @@ 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 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 (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))
boxesToAdd += cand
boxesToDrop ++= dropped
replaceStep(cs, remain)
}
}

val (toAdd, toDrop) = replaceStep(bigBoxes, sorted, (Seq(), Seq()))
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 {
Expand All @@ -170,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
}
2 changes: 1 addition & 1 deletion src/main/resources/api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mainnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit b7507c4

Please sign in to comment.