Skip to content

Commit

Permalink
TooHighCostError rework
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Sep 12, 2023
1 parent 32d7eb1 commit c713aef
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import scorex.core.validation.MalformedModifierError
import scorex.util.{ModifierId, ScorexLogging}
import scorex.core.network.DeliveryTracker
import scorex.core.network.peer.PenaltyType
import scorex.core.transaction.state.TooHighCostError
import scorex.core.app.Version
import scorex.crypto.hash.Digest32
import org.ergoplatform.nodeView.state.UtxoState.{ManifestId, SubtreeId}
import org.ergoplatform.ErgoLikeContext.Height
import scorex.core.serialization.{ErgoSerializer, ManifestSerializer, SubtreeSerializer}
import scorex.core.transaction.TooHighCostError
import scorex.crypto.authds.avltree.batch.VersionedLDBAVLStorage.splitDigest

import scala.annotation.tailrec
Expand Down Expand Up @@ -1412,7 +1412,7 @@ class ErgoNodeViewSynchronizer(networkControllerRef: ActorRef,
utx.source.foreach { peer =>
// no need to call deliveryTracker.setInvalid, as mempool will consider invalidated tx in contains()
error match {
case TooHighCostError(_) =>
case TooHighCostError(_, _) =>
log.info(s"Penalize spamming peer $peer for too costly transaction $id")
penalizeSpammingPeer(peer)
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.ergoplatform.settings.{Algos, ErgoSettings}
import org.ergoplatform.settings.Algos.HF
import org.ergoplatform.wallet.boxes.ErgoBoxSerializer
import org.ergoplatform.wallet.interpreter.ErgoInterpreter
import scorex.core.transaction.state.TooHighCostError
import scorex.core.transaction.TooHighCostError
import scorex.core.validation.MalformedModifierError
import scorex.crypto.authds.avltree.batch.{Lookup, PersistentBatchAVLProver, VersionedLDBAVLStorage}
import scorex.crypto.authds.{ADDigest, ADKey, SerializedAdProof}
Expand Down Expand Up @@ -60,11 +60,11 @@ trait UtxoStateReader extends ErgoStateReader with UtxoSetSnapshotPersistence {
context,
accumulatedCost = 0L)(verifier) match {
case Success(txCost) if txCost > costLimit =>
Failure(TooHighCostError(s"Transaction $tx has too high cost $txCost"))
Failure(TooHighCostError(tx, Some(txCost)))
case Success(txCost) =>
Success(txCost)
case Failure(mme: MalformedModifierError) if mme.message.contains("CostLimitException") =>
Failure(TooHighCostError(s"Transaction $tx has too high cost"))
Failure(TooHighCostError(tx, None))
case f: Failure[_] => f
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/scala/scorex/core/transaction/TooHighCostError.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scorex.core.transaction

import org.ergoplatform.modifiers.mempool.ErgoTransaction

/**
* Exception which is indicating that transaction had too high cost during validation
*/
case class TooHighCostError(tx: ErgoTransaction, txCost: Option[Int])
extends Exception(s"Transaction $tx has too high cost ${txCost.map(_.toString).getOrElse("")}")

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.ergoplatform.settings.Constants
import org.ergoplatform.utils.{ErgoPropertyTest, RandomWrapper}
import org.ergoplatform.utils.generators.ErgoTransactionGenerators
import scorex.core._
import scorex.core.transaction.state.TooHighCostError
import scorex.core.transaction.TooHighCostError
import scorex.crypto.authds.ADKey
import scorex.db.ByteArrayWrapper
import scorex.util.{ModifierId, bytesToId}
Expand Down

0 comments on commit c713aef

Please sign in to comment.