From fba7bd18f05e06a25d3a40d8d8664bd1726d935f Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Tue, 20 Sep 2022 14:20:04 +0300 Subject: [PATCH 1/2] removing Traverse.sequence --- .../nodeView/state/UtxoState.scala | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala b/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala index 7f73ead979..2c8798415d 100644 --- a/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala +++ b/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala @@ -1,7 +1,6 @@ package org.ergoplatform.nodeView.state import java.io.File -import cats.Traverse import org.ergoplatform.ErgoBox import org.ergoplatform.ErgoLikeContext.Height import org.ergoplatform.modifiers.history.header.Header @@ -76,7 +75,6 @@ class UtxoState(override val persistentProver: PersistentBatchAVLProver[Digest32 headerId: ModifierId, expectedDigest: ADDigest, currentStateContext: ErgoStateContext): Try[Unit] = { - import cats.implicits._ val createdOutputs = transactions.flatMap(_.outputs).map(o => (ByteArrayWrapper(o.id), o)).toMap def checkBoxExistence(id: ErgoBox.BoxId): Try[ErgoBox] = createdOutputs @@ -87,13 +85,23 @@ class UtxoState(override val persistentProver: PersistentBatchAVLProver[Digest32 val txProcessing = ErgoState.execTransactions(transactions, currentStateContext)(checkBoxExistence) if (txProcessing.isValid) { log.debug(s"Cost of block $headerId (${currentStateContext.currentHeight}): ${txProcessing.payload.getOrElse(0)}") - val resultTry = - ErgoState.stateChanges(transactions).map { stateChanges => - val mods = stateChanges.operations - Traverse[List].sequence(mods.map(persistentProver.performOneOperation).toList).map(_ => ()) + val blockOpsTry = ErgoState.stateChanges(transactions).flatMap { stateChanges => + val operations = stateChanges.operations + var opsResult: Try[Unit] = Success(()) + operations.foreach { op => + if (opsResult.isSuccess) { + persistentProver.performOneOperation(op) match { + case Success(_) => + case Failure(t) => + log.error(s"Operation $op failed during $headerId transactions validation in") + opsResult = Failure(t) + } + } } + opsResult + } ModifierValidator(stateContext.validationSettings) - .validateNoFailure(fbOperationFailed, resultTry, Transaction.ModifierTypeId) + .validateNoFailure(fbOperationFailed, blockOpsTry, Transaction.ModifierTypeId) .validateEquals(fbDigestIncorrect, expectedDigest, persistentProver.digest, headerId, Header.modifierTypeId) .result .toTry From 8c862cabfc3c303cb0cc4d0fbb3334cee4de2fbe Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Tue, 20 Sep 2022 14:30:14 +0300 Subject: [PATCH 2/2] typo fixed --- src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala b/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala index 2c8798415d..b585c0bada 100644 --- a/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala +++ b/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala @@ -93,7 +93,7 @@ class UtxoState(override val persistentProver: PersistentBatchAVLProver[Digest32 persistentProver.performOneOperation(op) match { case Success(_) => case Failure(t) => - log.error(s"Operation $op failed during $headerId transactions validation in") + log.error(s"Operation $op failed during $headerId transactions validation") opsResult = Failure(t) } }