diff --git a/benchmarks/src/test/scala/org/ergoplatform/nodeView/state/TransactionExecutionBenchmark.scala b/benchmarks/src/test/scala/org/ergoplatform/nodeView/state/TransactionExecutionBenchmark.scala index bb5e4b7888..a86aec4d38 100644 --- a/benchmarks/src/test/scala/org/ergoplatform/nodeView/state/TransactionExecutionBenchmark.scala +++ b/benchmarks/src/test/scala/org/ergoplatform/nodeView/state/TransactionExecutionBenchmark.scala @@ -41,7 +41,7 @@ object TransactionExecutionBenchmark extends HistoryTestHelpers with NVBenchmark val boxes = bh.boxes def bench: Long = Utils.time { - assert(ErgoState.execTransactions(txs, emptyStateContext)(id => Try(boxes(ByteArrayWrapper(id)))) == Valid(178665000)) + assert(ErgoState.execTransactions(txs, emptyStateContext, settings.nodeSettings)(id => Try(boxes(ByteArrayWrapper(id)))) == Valid(178665000)) }.toLong (0 to WarmupRuns).foreach(_ => bench) diff --git a/src/main/scala/org/ergoplatform/mining/CandidateGenerator.scala b/src/main/scala/org/ergoplatform/mining/CandidateGenerator.scala index 17ef8af2a9..5d7da2d479 100644 --- a/src/main/scala/org/ergoplatform/mining/CandidateGenerator.scala +++ b/src/main/scala/org/ergoplatform/mining/CandidateGenerator.scala @@ -656,7 +656,7 @@ object CandidateGenerator extends ScorexLogging { stateContext: ErgoStateContext, assets: Coll[(TokenId, Long)] = Colls.emptyColl ): Seq[ErgoTransaction] = { - val chainSettings = stateContext.ergoSettings.chainSettings + val chainSettings = stateContext.chainSettings val propositionBytes = chainSettings.monetary.feePropositionBytes val emission = chainSettings.emissionRules diff --git a/src/main/scala/org/ergoplatform/modifiers/mempool/ErgoTransaction.scala b/src/main/scala/org/ergoplatform/modifiers/mempool/ErgoTransaction.scala index 55fa39b005..6fc78c6e63 100644 --- a/src/main/scala/org/ergoplatform/modifiers/mempool/ErgoTransaction.scala +++ b/src/main/scala/org/ergoplatform/modifiers/mempool/ErgoTransaction.scala @@ -225,7 +225,7 @@ case class ErgoTransaction(override val inputs: IndexedSeq[Input], stateContext: ErgoStateContext): Try[Unit] = { val res: Try[Unit] = Try { - lazy val reemissionSettings = stateContext.ergoSettings.chainSettings.reemission + lazy val reemissionSettings = stateContext.chainSettings.reemission lazy val reemissionRules = reemissionSettings.reemissionRules lazy val reemissionTokenId = ModifierId @@@ reemissionSettings.reemissionTokenId @@ -234,7 +234,7 @@ case class ErgoTransaction(override val inputs: IndexedSeq[Input], lazy val emissionNftId = ModifierId @@@ reemissionSettings.emissionNftId lazy val emissionNftIdBytes = reemissionSettings.emissionNftIdBytes - lazy val chainSettings = stateContext.ergoSettings.chainSettings + lazy val chainSettings = stateContext.chainSettings lazy val emissionRules = chainSettings.emissionRules lazy val height = stateContext.currentHeight @@ -436,7 +436,7 @@ case class ErgoTransaction(override val inputs: IndexedSeq[Input], val currentTxCost = validation.result.payload.get verifyInput(validation, boxesToSpend, dataBoxes, box, idx.toShort, stateContext, currentTxCost) } - .validate(txReemission, !stateContext.ergoSettings.chainSettings.reemission.checkReemissionRules || + .validate(txReemission, !stateContext.chainSettings.reemission.checkReemissionRules || verifyReemissionSpending(boxesToSpend, outputCandidates, stateContext).isSuccess, InvalidModifier(id, id, modifierTypeId)) } diff --git a/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala b/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala index fdcc3bb17f..cb360285df 100644 --- a/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala +++ b/src/main/scala/org/ergoplatform/nodeView/ErgoNodeViewHolder.scala @@ -618,7 +618,7 @@ abstract class ErgoNodeViewHolder[State <: ErgoState[State]](settings: ErgoSetti val recoveredStateTry = firstExtensionOpt .fold[Try[ErgoStateContext]](Failure(new Exception("Could not find extension to recover from")) - )(ext => ErgoStateContext.recover(settings.chainSettings.genesisStateDigest, ext, lastHeaders)(settings)) + )(ext => ErgoStateContext.recover(settings.chainSettings.genesisStateDigest, ext, lastHeaders)(settings.chainSettings)) .flatMap { ctx => val recoverVersion = idToVersion(lastHeaders.last.id) val recoverRoot = bestFullBlock.header.stateRoot diff --git a/src/main/scala/org/ergoplatform/nodeView/state/DigestState.scala b/src/main/scala/org/ergoplatform/nodeView/state/DigestState.scala index 0711bc1a3c..f9d437507a 100644 --- a/src/main/scala/org/ergoplatform/nodeView/state/DigestState.scala +++ b/src/main/scala/org/ergoplatform/nodeView/state/DigestState.scala @@ -57,7 +57,7 @@ class DigestState protected(override val version: VersionTag, .fold[Try[ErgoBox]](Failure(new Exception(s"Box with id ${Algos.encode(id)} not found")))(Success(_)) } - ErgoState.execTransactions(transactions, currentStateContext)(checkBoxExistence) + ErgoState.execTransactions(transactions, currentStateContext, nodeSettings)(checkBoxExistence) .toTry .map(_ => ()) } diff --git a/src/main/scala/org/ergoplatform/nodeView/state/ErgoState.scala b/src/main/scala/org/ergoplatform/nodeView/state/ErgoState.scala index 4290d96ecc..b880bedb4d 100644 --- a/src/main/scala/org/ergoplatform/nodeView/state/ErgoState.scala +++ b/src/main/scala/org/ergoplatform/nodeView/state/ErgoState.scala @@ -13,7 +13,7 @@ import org.ergoplatform.modifiers.state.StateChanges import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages.LocallyGeneratedModifier import org.ergoplatform.nodeView.history.ErgoHistory import org.ergoplatform.settings.ValidationRules._ -import org.ergoplatform.settings.{ChainSettings, Constants, ErgoSettings, LaunchParameters} +import org.ergoplatform.settings.{ChainSettings, Constants, ErgoSettings, LaunchParameters, NodeConfigurationSettings} import org.ergoplatform.wallet.interpreter.ErgoInterpreter import scorex.core.validation.ValidationResult.Valid import scorex.core.validation.{ModifierValidator, ValidationResult} @@ -103,7 +103,8 @@ object ErgoState extends ScorexLogging { * @return Result of transactions execution with total cost inside */ def execTransactions(transactions: Seq[ErgoTransaction], - currentStateContext: ErgoStateContext) + currentStateContext: ErgoStateContext, + nodeSettings: NodeConfigurationSettings) (checkBoxExistence: ErgoBox.BoxId => Try[ErgoBox]): ValidationResult[Long] = { val verifier: ErgoInterpreter = ErgoInterpreter(currentStateContext.currentParameters) @@ -130,7 +131,7 @@ object ErgoState extends ScorexLogging { } } - val checkpointHeight = currentStateContext.ergoSettings.nodeSettings.checkpoint.map(_.height).getOrElse(0) + val checkpointHeight = nodeSettings.checkpoint.map(_.height).getOrElse(0) if (currentStateContext.currentHeight <= checkpointHeight) { Valid(0L) } else { diff --git a/src/main/scala/org/ergoplatform/nodeView/state/ErgoStateContext.scala b/src/main/scala/org/ergoplatform/nodeView/state/ErgoStateContext.scala index ce478458ad..2c15fb5c10 100644 --- a/src/main/scala/org/ergoplatform/nodeView/state/ErgoStateContext.scala +++ b/src/main/scala/org/ergoplatform/nodeView/state/ErgoStateContext.scala @@ -34,9 +34,9 @@ case class UpcomingStateContext(override val lastHeaders: Seq[Header], override val genesisStateDigest: ADDigest, override val currentParameters: Parameters, override val validationSettings: ErgoValidationSettings, - override val votingData: VotingData)(implicit ergoSettings: ErgoSettings) + override val votingData: VotingData)(implicit chainSettings: ChainSettings) extends ErgoStateContext(lastHeaders, lastExtensionOpt, genesisStateDigest, currentParameters, - validationSettings, votingData)(ergoSettings) { + validationSettings, votingData)(chainSettings) { override def sigmaPreHeader: sigma.PreHeader = PreHeader.toSigma(predictedHeader) @@ -65,7 +65,7 @@ class ErgoStateContext(val lastHeaders: Seq[Header], val currentParameters: Parameters, val validationSettings: ErgoValidationSettings, val votingData: VotingData) - (implicit val ergoSettings: ErgoSettings) + (implicit val chainSettings: ChainSettings) extends BlockchainStateContext with BytesSerializable with ScorexEncoding @@ -73,8 +73,8 @@ class ErgoStateContext(val lastHeaders: Seq[Header], override type M = ErgoStateContext - private val votingSettings = ergoSettings.chainSettings.voting - private val popowAlgos = new NipopowAlgos(ergoSettings.chainSettings) + private val votingSettings = chainSettings.voting + private val popowAlgos = new NipopowAlgos(chainSettings) override def sigmaPreHeader: sigma.PreHeader = PreHeader.toSigma(lastHeaders.headOption.getOrElse(PreHeader.fake)) @@ -107,7 +107,7 @@ class ErgoStateContext(val lastHeaders: Seq[Header], def lastHeaderOpt: Option[Header] = lastHeaders.headOption - override def serializer: ErgoSerializer[M] = ErgoStateContextSerializer(ergoSettings) + override def serializer: ErgoSerializer[M] = ErgoStateContextSerializer(chainSettings) /** * @return state context corresponding to a block after last known one with fields provided @@ -134,7 +134,7 @@ class ErgoStateContext(val lastHeaders: Seq[Header], def simplifiedUpcoming(): UpcomingStateContext = { val minerPk = org.ergoplatform.mining.group.generator val version = lastHeaderOpt.map(_.version).getOrElse(Header.InitialVersion) - val nBits = lastHeaderOpt.map(_.nBits).getOrElse(ergoSettings.chainSettings.initialNBits) + val nBits = lastHeaderOpt.map(_.nBits).getOrElse(chainSettings.initialNBits) val timestamp = lastHeaderOpt.map(_.timestamp + 1).getOrElse(System.currentTimeMillis()) val votes = Array.emptyByteArray val proposedUpdate = ErgoValidationSettingsUpdate.empty @@ -227,14 +227,14 @@ class ErgoStateContext(val lastHeaders: Seq[Header], val proposedVotes = votes.map(_ -> 1) val newVoting = VotingData(proposedVotes) new ErgoStateContext(newHeaders, extensionOpt, genesisStateDigest, params, - extractedValidationSettings, newVoting)(ergoSettings) + extractedValidationSettings, newVoting)(chainSettings) } case _ => val newVotes = votes val newVotingResults = newVotes.foldLeft(votingData) { case (v, id) => v.update(id) } state.result.toTry.map { _ => new ErgoStateContext(newHeaders, extensionOpt, genesisStateDigest, currentParameters, validationSettings, - newVotingResults)(ergoSettings) + newVotingResults)(chainSettings) } } }.flatten @@ -332,16 +332,16 @@ object ErgoStateContext { */ val eip27Vote: Byte = 8 - def empty(settings: ErgoSettings, parameters: Parameters): ErgoStateContext = { - empty(settings.chainSettings.genesisStateDigest, settings, parameters) + def empty(chainSettings: ChainSettings, parameters: Parameters): ErgoStateContext = { + empty(chainSettings.genesisStateDigest, chainSettings, parameters) } /** * Initialize empty state context */ - def empty(genesisStateDigest: ADDigest, settings: ErgoSettings, parameters: Parameters): ErgoStateContext = { + def empty(genesisStateDigest: ADDigest, chainSettings: ChainSettings, parameters: Parameters): ErgoStateContext = { new ErgoStateContext(Seq.empty, None, genesisStateDigest, parameters, ErgoValidationSettings.initial, - VotingData.empty)(settings) + VotingData.empty)(chainSettings) } /** @@ -352,14 +352,14 @@ object ErgoStateContext { def recover(genesisStateDigest: ADDigest, extension: Extension, lastHeaders: Seq[Header]) - (settings: ErgoSettings): Try[ErgoStateContext] = { - val vs = settings.chainSettings.voting + (chainSettings: ChainSettings): Try[ErgoStateContext] = { + val vs = chainSettings.voting if (lastHeaders.lastOption.exists(_.height % vs.votingLength == 0)) { val currentHeader = lastHeaders.last Parameters.parseExtension(currentHeader.height, extension).flatMap { params => ErgoValidationSettings.parseExtension(extension).map { validationSettings => new ErgoStateContext(lastHeaders.reverse, Some(extension), genesisStateDigest, params, - validationSettings, VotingData.empty)(settings) + validationSettings, VotingData.empty)(chainSettings) } } } else { @@ -369,7 +369,7 @@ object ErgoStateContext { } -case class ErgoStateContextSerializer(ergoSettings: ErgoSettings) extends ErgoSerializer[ErgoStateContext] { +case class ErgoStateContextSerializer(chainSettings: ChainSettings) extends ErgoSerializer[ErgoStateContext] { private val Eip27SupportValue = 100 // see comment in serialize() @@ -413,7 +413,7 @@ case class ErgoStateContextSerializer(ergoSettings: ErgoSettings) extends ErgoSe } new ErgoStateContext(lastHeaders, lastExtensionOpt, genesisDigest, params, validationSettings, - votingData)(ergoSettings) + votingData)(chainSettings) } } diff --git a/src/main/scala/org/ergoplatform/nodeView/state/ErgoStateReader.scala b/src/main/scala/org/ergoplatform/nodeView/state/ErgoStateReader.scala index 18947880c5..c789accbe5 100644 --- a/src/main/scala/org/ergoplatform/nodeView/state/ErgoStateReader.scala +++ b/src/main/scala/org/ergoplatform/nodeView/state/ErgoStateReader.scala @@ -66,10 +66,10 @@ object ErgoStateReader extends ScorexLogging { */ def storageStateContext(store: LDBVersionedStore, settings: ErgoSettings): ErgoStateContext = { store.get(ErgoStateReader.ContextKey) - .flatMap(b => ErgoStateContextSerializer(settings).parseBytesTry(b).toOption) + .flatMap(b => ErgoStateContextSerializer(settings.chainSettings).parseBytesTry(b).toOption) .getOrElse { log.warn("Can't read blockchain parameters from database") - ErgoStateContext.empty(settings, LaunchParameters) + ErgoStateContext.empty(settings.chainSettings, LaunchParameters) } } @@ -94,13 +94,13 @@ object ErgoStateReader extends ScorexLogging { if (lastHeaders.size != Constants.LastHeadersInContext) { Failure(new Exception(s"Only ${lastHeaders.size} headers found in reconstructStateContextBeforeEpoch")) } else { - val empty = ErgoStateContext.empty(settings, LaunchParameters) + val empty = ErgoStateContext.empty(settings.chainSettings, LaunchParameters) val esc = new ErgoStateContext( lastHeaders, None, empty.genesisStateDigest, empty.currentParameters, empty.validationSettings, - empty.votingData)(settings) + empty.votingData)(settings.chainSettings) Success(esc) } } diff --git a/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala b/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala index a4254f07b0..f0a52230bf 100644 --- a/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala +++ b/src/main/scala/org/ergoplatform/nodeView/state/UtxoState.scala @@ -80,7 +80,7 @@ class UtxoState(override val persistentProver: PersistentBatchAVLProver[Digest32 .orElse(boxById(id)) .fold[Try[ErgoBox]](Failure(new Exception(s"Box with id ${Algos.encode(id)} not found")))(Success(_)) - val txProcessing = ErgoState.execTransactions(transactions, currentStateContext)(checkBoxExistence) + val txProcessing = ErgoState.execTransactions(transactions, currentStateContext, ergoSettings.nodeSettings)(checkBoxExistence) if (txProcessing.isValid) { log.debug(s"Cost of block $headerId (${currentStateContext.currentHeight}): ${txProcessing.payload.getOrElse(0)}") val blockOpsTry = ErgoState.stateChanges(transactions).flatMap { stateChanges => @@ -192,7 +192,7 @@ class UtxoState(override val persistentProver: PersistentBatchAVLProver[Digest32 } if (fb.adProofs.isEmpty) { - if (fb.height >= estimatedTip.getOrElse(Int.MaxValue) - stateContext.ergoSettings.nodeSettings.adProofsSuffixLength) { + if (fb.height >= estimatedTip.getOrElse(Int.MaxValue) - ergoSettings.nodeSettings.adProofsSuffixLength) { val adProofs = ADProofs(fb.header.id, proofBytes) generate(LocallyGeneratedModifier(adProofs)) } @@ -309,7 +309,7 @@ object UtxoState { val store = new LDBVersionedStore(dir, initialKeepVersions = settings.nodeSettings.keepVersions) - val defaultStateContext = ErgoStateContext.empty(settings, parameters) + val defaultStateContext = ErgoStateContext.empty(settings.chainSettings, parameters) val storage = new VersionedLDBAVLStorage(store) val persistentProver = PersistentBatchAVLProver.create( p, diff --git a/src/main/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorage.scala b/src/main/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorage.scala index 617755f474..2f52c218f0 100644 --- a/src/main/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorage.scala +++ b/src/main/scala/org/ergoplatform/nodeView/wallet/persistence/WalletStorage.scala @@ -112,8 +112,8 @@ final class WalletStorage(store: LDBKVStore, settings: ErgoSettings) extends Sco def readStateContext(parameters: Parameters): ErgoStateContext = { cachedStateContext = Some(store .get(StateContextKey) - .flatMap(r => ErgoStateContextSerializer(settings).parseBytesTry(r).toOption) - .getOrElse(ErgoStateContext.empty(settings, parameters)) + .flatMap(r => ErgoStateContextSerializer(settings.chainSettings).parseBytesTry(r).toOption) + .getOrElse(ErgoStateContext.empty(settings.chainSettings, parameters)) ) cachedStateContext.get } diff --git a/src/test/scala/org/ergoplatform/mining/CandidateGeneratorPropSpec.scala b/src/test/scala/org/ergoplatform/mining/CandidateGeneratorPropSpec.scala index 1c666e18e4..0b4f9cd0a7 100644 --- a/src/test/scala/org/ergoplatform/mining/CandidateGeneratorPropSpec.scala +++ b/src/test/scala/org/ergoplatform/mining/CandidateGeneratorPropSpec.scala @@ -203,7 +203,7 @@ class CandidateGeneratorPropSpec extends ErgoPropertyTest { val ms = MonetarySettings(minerRewardDelay = delta) val st = settings.copy(chainSettings = settings.chainSettings.copy(monetary = ms)) - val sc = ErgoStateContext.empty(genesisStateDigest, st, parameters) + val sc = ErgoStateContext.empty(genesisStateDigest, st.chainSettings, parameters) val txBoxes = bh.boxes.grouped(inputsNum).map(_.values.toIndexedSeq).toSeq val blockTx = diff --git a/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoTransactionSpec.scala b/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoTransactionSpec.scala index 4901e7526b..371b356384 100644 --- a/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoTransactionSpec.scala +++ b/src/test/scala/org/ergoplatform/modifiers/mempool/ErgoTransactionSpec.scala @@ -356,7 +356,7 @@ class ErgoTransactionSpec extends ErgoPropertyTest with ErgoTestConstants { val maxCost = (Int.MaxValue - 10) / 10 // cannot use Int.MaxValue directly due to overflow when it is converted to block cost val ps = Parameters(0, DefaultParameters.updated(MaxBlockCostIncrease, maxCost), emptyVSUpdate) val sc = new ErgoStateContext(Seq.empty, None, genesisStateDigest, ps, ErgoValidationSettings.initial, - VotingData.empty)(settings) + VotingData.empty)(settings.chainSettings) .upcoming(org.ergoplatform.mining.group.generator, 0L, settings.chainSettings.initialNBits, @@ -478,7 +478,7 @@ class ErgoTransactionSpec extends ErgoPropertyTest with ErgoTestConstants { LaunchParameters.parametersTable.updated(Parameters.BlockVersion, blockVersion), LaunchParameters.proposedUpdate) new ErgoStateContext(Seq(header), None, genesisStateDigest, params, ErgoValidationSettings.initial, - VotingData.empty)(settings) + VotingData.empty)(settings.chainSettings) } def stateContextForTx(tx: ErgoTransaction, blockVersion: Byte): ErgoStateContext = { diff --git a/src/test/scala/org/ergoplatform/modifiers/mempool/ExpirationSpecification.scala b/src/test/scala/org/ergoplatform/modifiers/mempool/ExpirationSpecification.scala index 7398a9ce5f..e700d43644 100644 --- a/src/test/scala/org/ergoplatform/modifiers/mempool/ExpirationSpecification.scala +++ b/src/test/scala/org/ergoplatform/modifiers/mempool/ExpirationSpecification.scala @@ -49,7 +49,7 @@ class ExpirationSpecification extends ErgoPropertyTest { val updContext = { val inContext = new ErgoStateContext(Seq(fakeHeader), None, genesisStateDigest, parameters, validationSettingsNoIl, - VotingData.empty)(settings) + VotingData.empty)(settings.chainSettings) inContext.appendFullBlock(fb).get } diff --git a/src/test/scala/org/ergoplatform/nodeView/state/ErgoStateSpecification.scala b/src/test/scala/org/ergoplatform/nodeView/state/ErgoStateSpecification.scala index 059b4e0d1c..e166806043 100644 --- a/src/test/scala/org/ergoplatform/nodeView/state/ErgoStateSpecification.scala +++ b/src/test/scala/org/ergoplatform/nodeView/state/ErgoStateSpecification.scala @@ -162,29 +162,31 @@ class ErgoStateSpecification extends ErgoPropertyTest { val stateContext = emptyStateContext val expectedCost = 185160 + val nodeSettings = settings.nodeSettings + // successful validation - ErgoState.execTransactions(txs, stateContext)(id => Try(boxes(ByteArrayWrapper(id)))) shouldBe Valid(expectedCost) + ErgoState.execTransactions(txs, stateContext, nodeSettings)(id => Try(boxes(ByteArrayWrapper(id)))) shouldBe Valid(expectedCost) // cost limit exception expected when crossing MaxBlockCost val tooManyTxs = (1 to 10).flatMap(_ => generateTxs) assert( - ErgoState.execTransactions(tooManyTxs, stateContext)(id => Try(boxes(ByteArrayWrapper(id)))).errors.head.message.contains( + ErgoState.execTransactions(tooManyTxs, stateContext, nodeSettings)(id => Try(boxes(ByteArrayWrapper(id)))).errors.head.message.contains( "Accumulated cost of block transactions should not exceed " ) ) // missing box in state - ErgoState.execTransactions(txs, stateContext)(_ => Failure(new RuntimeException)).errors.head.message shouldBe + ErgoState.execTransactions(txs, stateContext, nodeSettings)(_ => Failure(new RuntimeException)).errors.head.message shouldBe "Every input of the transaction should be in UTXO. null" // tx validation should kick in and detect block height violation val invalidTx = invalidErgoTransactionGen.sample.get assert( - ErgoState.execTransactions(txs :+ invalidTx, stateContext)(id => Try(boxes.getOrElse(ByteArrayWrapper(id), invalidTx.outputs.head))) + ErgoState.execTransactions(txs :+ invalidTx, stateContext, nodeSettings)(id => Try(boxes.getOrElse(ByteArrayWrapper(id), invalidTx.outputs.head))) .errors.head.message.startsWith("Transaction outputs should have creationHeight not exceeding block height.") ) // no transactions are valid - assert(ErgoState.execTransactions(Seq.empty, stateContext)(id => Try(boxes(ByteArrayWrapper(id)))).isValid) + assert(ErgoState.execTransactions(Seq.empty, stateContext, nodeSettings)(id => Try(boxes(ByteArrayWrapper(id)))).isValid) } } diff --git a/src/test/scala/org/ergoplatform/nodeView/wallet/ErgoWalletSpec.scala b/src/test/scala/org/ergoplatform/nodeView/wallet/ErgoWalletSpec.scala index 5f5967d4d3..73ef39d8ee 100644 --- a/src/test/scala/org/ergoplatform/nodeView/wallet/ErgoWalletSpec.scala +++ b/src/test/scala/org/ergoplatform/nodeView/wallet/ErgoWalletSpec.scala @@ -57,7 +57,7 @@ class ErgoWalletSpec extends ErgoPropertyTest with WalletTestOps with Eventually log.info(s"Payment request $req") val tx = await(wallet.generateTransaction(req)).get log.info(s"Generated transaction $tx") - val context = new ErgoStateContext(Seq(genesisBlock.header), Some(genesisBlock.extension), startDigest, parameters, validationSettingsNoIl, VotingData.empty) + val context = new ErgoStateContext(Seq(genesisBlock.header), Some(genesisBlock.extension), startDigest, parameters, validationSettingsNoIl, VotingData.empty)(settings.chainSettings) val boxesToSpend = tx.inputs.map(i => genesisTx.outputs.find(o => java.util.Arrays.equals(o.id, i.boxId)).get) tx.statefulValidity(boxesToSpend, emptyDataBoxes, context) shouldBe 'success val block = makeNextBlock(getUtxoState, Seq(tx)) @@ -112,7 +112,7 @@ class ErgoWalletSpec extends ErgoPropertyTest with WalletTestOps with Eventually startDigest, parameters, validationSettingsNoIl, - VotingData.empty) + VotingData.empty)(settings.chainSettings) val boxesToSpend = tx.inputs.map(i => genesisTx.outputs.find(o => java.util.Arrays.equals(o.id, i.boxId)).get) tx.statefulValidity(boxesToSpend, emptyDataBoxes, context) shouldBe 'success } @@ -371,7 +371,7 @@ class ErgoWalletSpec extends ErgoPropertyTest with WalletTestOps with Eventually startDigest, parameters, validationSettingsNoIl, - VotingData.empty) + VotingData.empty)(settings.chainSettings) val boxesToSpend = tx.inputs.map(i => genesisTx.outputs.find(o => java.util.Arrays.equals(o.id, i.boxId)).get) tx.statefulValidity(boxesToSpend, emptyDataBoxes, context) shouldBe 'success @@ -388,7 +388,7 @@ class ErgoWalletSpec extends ErgoPropertyTest with WalletTestOps with Eventually log.info(s"Payment requests 2 $req2") val tx2 = await(wallet.generateTransaction(req2)).get log.info(s"Generated transaction $tx2") - val context2 = new ErgoStateContext(Seq(block.header), Some(block.extension), startDigest, parameters, validationSettingsNoIl, VotingData.empty) + val context2 = new ErgoStateContext(Seq(block.header), Some(block.extension), startDigest, parameters, validationSettingsNoIl, VotingData.empty)(settings.chainSettings) val knownBoxes = tx.outputs ++ genesisTx.outputs val boxesToSpend2 = tx2.inputs.map(i => knownBoxes.find(o => java.util.Arrays.equals(o.id, i.boxId)).get) tx2.statefulValidity(boxesToSpend2, emptyDataBoxes, context2) shouldBe 'success diff --git a/src/test/scala/org/ergoplatform/serialization/SerializationTests.scala b/src/test/scala/org/ergoplatform/serialization/SerializationTests.scala index 65ac78905d..a792c82c3e 100644 --- a/src/test/scala/org/ergoplatform/serialization/SerializationTests.scala +++ b/src/test/scala/org/ergoplatform/serialization/SerializationTests.scala @@ -48,7 +48,7 @@ class SerializationTests extends ErgoPropertyTest with WalletGenerators with sco } property("ErgoStateContext serialization") { - val serializer = ErgoStateContextSerializer(settings) + val serializer = ErgoStateContextSerializer(settings.chainSettings) val b = ergoStateContextGen.sample.get val recovered = serializer.parseBytes(serializer.toBytes(b)) serializer.toBytes(b) shouldEqual serializer.toBytes(recovered) diff --git a/src/test/scala/org/ergoplatform/settings/VotingSpecification.scala b/src/test/scala/org/ergoplatform/settings/VotingSpecification.scala index 2923aa7b31..1d444969e5 100644 --- a/src/test/scala/org/ergoplatform/settings/VotingSpecification.scala +++ b/src/test/scala/org/ergoplatform/settings/VotingSpecification.scala @@ -38,7 +38,7 @@ class VotingSpecification extends ErgoPropertyTest { Seq(VR.CheckDeserializedScriptType.id -> DisabledRule, VR.CheckValidOpCode.id -> ReplacedRule((VR.FirstRuleId + 11).toShort))) private val proposedUpdate2 = ErgoValidationSettingsUpdate(Seq(ValidationRules.fbOperationFailed), Seq()) val ctx: ErgoStateContext = { - new ErgoStateContext(Seq.empty, None, genesisStateDigest, parameters, validationSettingsNoIl, VotingData.empty)(updSettings) + new ErgoStateContext(Seq.empty, None, genesisStateDigest, parameters, validationSettingsNoIl, VotingData.empty)(updSettings.chainSettings) .upcoming(org.ergoplatform.mining.group.generator, 0L, settings.chainSettings.initialNBits, Array.fill(3)(0.toByte), emptyVSUpdate, 0.toByte) } val initialVs: ErgoValidationSettings = ctx.validationSettings @@ -100,7 +100,7 @@ class VotingSpecification extends ErgoPropertyTest { property("voting for non-existing parameter") { val p: Parameters = Parameters(2, Map(BlockVersion -> 0), proposedUpdate) val vr: VotingData = VotingData.empty - val esc = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), p, validationSettingsNoIl, vr)(updSettings) + val esc = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), p, validationSettingsNoIl, vr)(updSettings.chainSettings) val invalidVote = 100: Byte val votes = Array(invalidVote , NoParameter, NoParameter) @@ -119,7 +119,7 @@ class VotingSpecification extends ErgoPropertyTest { val p: Parameters = Parameters(2, Map(StorageFeeFactorIncrease -> kInit, BlockVersion -> 0), proposedUpdate) val vr: VotingData = VotingData.empty - val esc = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), p, validationSettingsNoIl, vr)(updSettings) + val esc = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), p, validationSettingsNoIl, vr)(updSettings.chainSettings) val votes = Array(StorageFeeFactorIncrease, NoParameter, NoParameter) val h = defaultHeaderGen.sample.get.copy(height = 2, votes = votes, version = 0: Byte) val esc2 = process(esc, p, h).get @@ -152,7 +152,7 @@ class VotingSpecification extends ErgoPropertyTest { val p: Parameters = Parameters(1, Map(BlockVersion -> 0), proposedUpdate) val vr: VotingData = VotingData.empty - val esc0 = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), p, validationSettings, vr)(updSettings) + val esc0 = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), p, validationSettings, vr)(updSettings.chainSettings) checkValidationSettings(esc0.validationSettings, emptyVSUpdate) val forkVote = Array(SoftFork, NoParameter, NoParameter) val emptyVotes = Array(NoParameter, NoParameter, NoParameter) @@ -259,7 +259,7 @@ class VotingSpecification extends ErgoPropertyTest { val forkVote = Array(SoftFork, NoParameter, NoParameter) val emptyVotes = Array(NoParameter, NoParameter, NoParameter) - val esc0 = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), p, validationSettingsNoIl, vr)(updSettings) + val esc0 = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), p, validationSettingsNoIl, vr)(updSettings.chainSettings) val h1 = defaultHeaderGen.sample.get.copy(votes = forkVote, version = 0: Byte, height = 1) val esc1 = process(esc0, p, h1).get @@ -317,7 +317,7 @@ class VotingSpecification extends ErgoPropertyTest { property("hardfork - v2 - activation") { val vr: VotingData = VotingData.empty - val esc0 = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), parameters, ErgoValidationSettings.initial, vr)(updSettings) + val esc0 = new ErgoStateContext(Seq(), None, ADDigest @@ Array.fill(33)(0: Byte), parameters, ErgoValidationSettings.initial, vr)(updSettings.chainSettings) val h1 = defaultHeaderGen.sample.get.copy(votes = Array.empty, version = 1: Byte, height = hfActivationHeight - 1) val expectedParameters1 = Parameters(hfActivationHeight - 1, DefaultParameters, ErgoValidationSettingsUpdate.empty) val esc1 = process(esc0, expectedParameters1, h1).get diff --git a/src/test/scala/org/ergoplatform/utils/ErgoTestConstants.scala b/src/test/scala/org/ergoplatform/utils/ErgoTestConstants.scala index 51d7e80597..302ac4aac5 100644 --- a/src/test/scala/org/ergoplatform/utils/ErgoTestConstants.scala +++ b/src/test/scala/org/ergoplatform/utils/ErgoTestConstants.scala @@ -82,9 +82,9 @@ trait ErgoTestConstants extends ScorexLogging { val defaultVersion: Byte = 0 lazy val powScheme: AutolykosPowScheme = settings.chainSettings.powScheme.ensuring(_.isInstanceOf[DefaultFakePowScheme]) val emptyVSUpdate = ErgoValidationSettingsUpdate.empty - val emptyStateContext: UpcomingStateContext = ErgoStateContext.empty(genesisStateDigest, settings, parameters) + val emptyStateContext: UpcomingStateContext = ErgoStateContext.empty(genesisStateDigest, settings.chainSettings, parameters) .upcoming(defaultMinerPkPoint, defaultTimestamp, defaultNBits, defaultVotes, emptyVSUpdate, defaultVersion) - def stateContextWith(parameters: Parameters): UpcomingStateContext = ErgoStateContext.empty(genesisStateDigest, settings, parameters) + def stateContextWith(parameters: Parameters): UpcomingStateContext = ErgoStateContext.empty(genesisStateDigest, settings.chainSettings, parameters) .upcoming(defaultMinerPkPoint, defaultTimestamp, defaultNBits, defaultVotes, emptyVSUpdate, defaultVersion) val startHeight: Int = emptyStateContext.currentHeight val startDigest: ADDigest = emptyStateContext.genesisStateDigest diff --git a/src/test/scala/org/ergoplatform/utils/Stubs.scala b/src/test/scala/org/ergoplatform/utils/Stubs.scala index b68886a573..556dd034ca 100644 --- a/src/test/scala/org/ergoplatform/utils/Stubs.scala +++ b/src/test/scala/org/ergoplatform/utils/Stubs.scala @@ -257,7 +257,7 @@ trait Stubs extends ErgoGenerators with ErgoTestHelpers with ChainGenerator with sender() ! Success(tx) case SignTransaction(tx, secrets, hints, boxesToSpendOpt, dataBoxesOpt) => - val sc = ErgoStateContext.empty(settings, parameters) + val sc = ErgoStateContext.empty(settings.chainSettings, parameters) sender() ! ergoWalletService.signTransaction(Some(prover), tx, secrets, hints, boxesToSpendOpt, dataBoxesOpt, parameters, sc) { boxId => utxoState.versionedBoxHolder.get(ByteArrayWrapper(boxId)) } diff --git a/src/test/scala/org/ergoplatform/utils/generators/ErgoTransactionGenerators.scala b/src/test/scala/org/ergoplatform/utils/generators/ErgoTransactionGenerators.scala index 978617e43d..1d210f38a0 100644 --- a/src/test/scala/org/ergoplatform/utils/generators/ErgoTransactionGenerators.scala +++ b/src/test/scala/org/ergoplatform/utils/generators/ErgoTransactionGenerators.scala @@ -324,13 +324,13 @@ trait ErgoTransactionGenerators extends ErgoGenerators with Generators { } yield { blocks match { case _ :: _ => - val sc = new ErgoStateContext(Seq(), None, startDigest, parameters, validationSettingsNoIl, VotingData.empty) + val sc = new ErgoStateContext(Seq(), None, startDigest, parameters, validationSettingsNoIl, VotingData.empty)(settings.chainSettings) blocks.foldLeft(sc -> 1) { case ((c, h), b) => val block = b.copy(header = b.header.copy(height = h, votes = votes(h - 1))) c.appendFullBlock(block).get -> (h + 1) }._1 case _ => - ErgoStateContext.empty(stateRoot, settings, parameters) + ErgoStateContext.empty(stateRoot, settings.chainSettings, parameters) } }