diff --git a/node/src/main/scala/com/wavesplatform/Importer.scala b/node/src/main/scala/com/wavesplatform/Importer.scala index 529287f931..f4f0fc4b8c 100644 --- a/node/src/main/scala/com/wavesplatform/Importer.scala +++ b/node/src/main/scala/com/wavesplatform/Importer.scala @@ -351,7 +351,7 @@ object Importer extends ScorexLogging { val utxPool = new UtxPoolImpl(time, blockchainUpdater, settings.utxSettings, settings.maxTxErrorLogSize, settings.minerSettings.enable) val pos = PoSSelector(blockchainUpdater, settings.synchronizationSettings.maxBaseTarget) val extAppender: (Block, Option[BlockSnapshotResponse]) => Task[Either[ValidationError, BlockApplyResult]] = - BlockAppender(blockchainUpdater, time, utxPool, pos, scheduler, importOptions.verify, txSignParCheck = false) + BlockAppender(blockchainUpdater, time, utxPool, pos, scheduler, importOptions.verify) val extensions = initExtensions(settings, blockchainUpdater, scheduler, time, utxPool, rdb) checkGenesis(settings, blockchainUpdater, Miner.Disabled) diff --git a/node/src/main/scala/com/wavesplatform/database/Caches.scala b/node/src/main/scala/com/wavesplatform/database/Caches.scala index 4ee6f9d097..642f6428d5 100644 --- a/node/src/main/scala/com/wavesplatform/database/Caches.scala +++ b/node/src/main/scala/com/wavesplatform/database/Caches.scala @@ -398,6 +398,16 @@ object Caches { lazy val hitSource: Option[ByteStr] = meta.map(toHitSource) } + case class BlockData( + snapshot: StateSnapshot, + carryFee: Long, + totalFee: Long, + reward: Option[Long], + hitSource: ByteStr, + computedBlockStateHash: ByteStr, + block: Block + ) + def toHitSource(m: PBBlockMeta): ByteStr = (if (m.vrf.isEmpty) m.getHeader.generationSignature else m.vrf).toByteStr def toSignedHeader(m: PBBlockMeta): SignedBlockHeader = SignedBlockHeader(PBBlocks.vanilla(m.getHeader), m.signature.toByteStr) diff --git a/node/src/main/scala/com/wavesplatform/state/BlockchainUpdaterImpl.scala b/node/src/main/scala/com/wavesplatform/state/BlockchainUpdaterImpl.scala index 46a381d035..f5d52092cf 100644 --- a/node/src/main/scala/com/wavesplatform/state/BlockchainUpdaterImpl.scala +++ b/node/src/main/scala/com/wavesplatform/state/BlockchainUpdaterImpl.scala @@ -8,7 +8,7 @@ import com.wavesplatform.block.Block.BlockId import com.wavesplatform.block.{Block, BlockSnapshot, MicroBlock, MicroBlockSnapshot, SignedBlockHeader} import com.wavesplatform.common.state.ByteStr import com.wavesplatform.common.utils.EitherExt2 -import com.wavesplatform.database.RocksDBWriter +import com.wavesplatform.database.{Caches, RocksDBWriter} import com.wavesplatform.events.BlockchainUpdateTriggers import com.wavesplatform.features.BlockchainFeatures import com.wavesplatform.features.BlockchainFeatures.ConsensusImprovements @@ -196,231 +196,258 @@ class BlockchainUpdaterImpl( .orElse(lastBlockReward) } + private def buildBlockSnapshot( + referencedBlockchain: Blockchain, + maybePrevBlock: Option[Block], + thisBlock: Block, + maybeSnapshot: Option[BlockSnapshot], + hitSource: ByteStr, + challengedHitSource: Option[ByteStr], + verify: Boolean = true + ) = BlockDiffer + .fromBlock( + referencedBlockchain, + maybePrevBlock, + thisBlock, + maybeSnapshot, + MiningConstraints(referencedBlockchain, referencedBlockchain.height).total, + hitSource, + challengedHitSource, + rocksdb.loadCacheData, + verify + ) + override def processBlock( block: Block, hitSource: ByteStr, snapshot: Option[BlockSnapshot], challengedHitSource: Option[ByteStr] = None, - verify: Boolean = true, - txSignParCheck: Boolean = true - ): Either[ValidationError, BlockApplyResult] = - writeLock { - val height = rocksdb.height - val notImplementedFeatures: Set[Short] = rocksdb.activatedFeaturesAt(height).diff(BlockchainFeatures.implemented) - - Either - .cond( - !wavesSettings.featuresSettings.autoShutdownOnUnsupportedFeature || notImplementedFeatures.isEmpty, - (), - GenericError(s"UNIMPLEMENTED ${displayFeatures(notImplementedFeatures)} ACTIVATED ON BLOCKCHAIN, UPDATE THE NODE IMMEDIATELY") - ) - .flatMap[ValidationError, BlockApplyResult](_ => - (ngState match { - case None => - rocksdb.lastBlockId match { - case Some(uniqueId) if uniqueId != block.header.reference => - val logDetails = s"The referenced block(${block.header.reference})" + - s" ${if (rocksdb.contains(block.header.reference)) "exists, it's not last persisted" else "doesn't exist"}" - Left(BlockAppendError(s"References incorrect or non-existing block: " + logDetails, block)) - case lastBlockId => - val height = lastBlockId.fold(0)(rocksdb.unsafeHeightOf) - val miningConstraints = MiningConstraints(rocksdb, height) - val reward = computeNextReward - - val referencedBlockchain = SnapshotBlockchain(rocksdb, reward) - BlockDiffer - .fromBlock( - referencedBlockchain, - rocksdb.lastBlock, - block, - snapshot, - miningConstraints.total, - hitSource, - challengedHitSource, - rocksdb.loadCacheData, - verify, - txSignParCheck = txSignParCheck - ) - .map { r => - val updatedBlockchain = SnapshotBlockchain(rocksdb, r.snapshot, block, hitSource, r.carry, reward, Some(r.computedStateHash)) - miner.scheduleMining(Some(updatedBlockchain)) - blockchainUpdateTriggers.onProcessBlock(block, r.keyBlockSnapshot, reward, hitSource, referencedBlockchain) - Option((r, Nil, reward, hitSource)) - } - } - case Some(ng) => - if (ng.base.header.reference == block.header.reference) { - if (block.header.timestamp < ng.base.header.timestamp) { - val height = rocksdb.unsafeHeightOf(ng.base.header.reference) - val miningConstraints = MiningConstraints(rocksdb, height) - - val referencedBlockchain = SnapshotBlockchain(rocksdb, ng.reward) - BlockDiffer - .fromBlock( - referencedBlockchain, - rocksdb.lastBlock, - block, - snapshot, - miningConstraints.total, - hitSource, - challengedHitSource, - rocksdb.loadCacheData, - verify, - txSignParCheck = txSignParCheck - ) - .map { r => - log.trace( - s"Better liquid block(timestamp=${block.header.timestamp}) received and applied instead of existing(timestamp=${ng.base.header.timestamp})" - ) - BlockStats.replaced(ng.base, block) - val (mbs, mbSnapshots) = ng.allSnapshots.unzip - val allSnapshots = ng.baseBlockSnapshot +: mbSnapshots - log.trace(s"Discarded microblocks = $mbs, snapshots = ${allSnapshots.map(_.hashString)}") + verify: Boolean = true + ): Either[ValidationError, BlockApplyResult] = { + for { + _ <- checkUnimplementedFeatures() + blockDiff <- buildBlockDiff(block, hitSource, snapshot, challengedHitSource, verify) + } yield blockDiff.fold[BlockApplyResult](Ignored) { case (result, discDiffs, reward, hitSource, maybeBlockData) => + updateNgState(block, result, discDiffs, reward, hitSource, maybeBlockData) + } + } - val updatedBlockchain = SnapshotBlockchain(referencedBlockchain, r.snapshot, block, hitSource, r.carry, None, None) - miner.scheduleMining(Some(updatedBlockchain)) + private def checkUnimplementedFeatures(): Either[ValidationError, Unit] = { + val notImplementedFeatures: Set[Short] = rocksdb.activatedFeaturesAt(rocksdb.height).diff(BlockchainFeatures.implemented) - blockchainUpdateTriggers.onRollback(this, ng.base.header.reference, rocksdb.height) - blockchainUpdateTriggers.onProcessBlock(block, r.keyBlockSnapshot, ng.reward, hitSource, referencedBlockchain) - Some((r, allSnapshots, ng.reward, hitSource)) - } - } else if (areVersionsOfSameBlock(block, ng.base)) { - // silently ignore - Right(None) - } else - Left( - BlockAppendError( - s"Competitors liquid block $block(timestamp=${block.header.timestamp}) is not better than existing (ng.base ${ng.base}(timestamp=${ng.base.header.timestamp}))", - block - ) - ) - } else - metrics.forgeBlockTimeStats.measureOptional(ng.snapshotOf(block.header.reference)) match { - case None => Left(BlockAppendError(s"References incorrect or non-existing block", block)) - case Some((referencedForgedBlock, referencedLiquidSnapshot, carry, totalFee, referencedComputedStateHash, discarded)) => - if (!verify || referencedForgedBlock.signatureValid()) { - val height = rocksdb.heightOf(referencedForgedBlock.header.reference).getOrElse(0) - - val constraint: MiningConstraint = { - val miningConstraints = MiningConstraints(rocksdb, height) - miningConstraints.total - } - - val prevReward = ng.reward - val reward = computeNextReward - - val prevHitSource = ng.hitSource - val liquidSnapshotWithCancelledLeases = ng.cancelExpiredLeases(referencedLiquidSnapshot) - val referencedBlockchain = SnapshotBlockchain( - rocksdb, - liquidSnapshotWithCancelledLeases, - referencedForgedBlock, - ng.hitSource, - carry, - reward, - Some(referencedComputedStateHash) - ) + if (!wavesSettings.featuresSettings.autoShutdownOnUnsupportedFeature || notImplementedFeatures.isEmpty) Right(()) + else Left(GenericError(s"UNIMPLEMENTED ${displayFeatures(notImplementedFeatures)} ACTIVATED ON BLOCKCHAIN, UPDATE THE NODE IMMEDIATELY")) + } - for { - differResult <- BlockDiffer - .fromBlock( - referencedBlockchain, - Some(referencedForgedBlock), - block, - snapshot, - constraint, - hitSource, - challengedHitSource, - rocksdb.loadCacheData, - verify, - txSignParCheck = txSignParCheck - ) - } yield { - val tempBlockchain = SnapshotBlockchain( - referencedBlockchain, - differResult.snapshot, - block, - hitSource, - differResult.carry, - None, - Some(differResult.computedStateHash) - ) - miner.scheduleMining(Some(tempBlockchain)) - - log.trace( - s"Persisting block ${referencedForgedBlock.id()}, discarded microblock refs: ${discarded.map(_._1.reference).mkString("[", ",", "]")}" - ) - - if (discarded.nonEmpty) { - blockchainUpdateTriggers.onMicroBlockRollback(this, block.header.reference) - metrics.microBlockForkStats.increment() - metrics.microBlockForkHeightStats.record(discarded.size) - } - - rocksdb.append( - liquidSnapshotWithCancelledLeases, - carry, - totalFee, - prevReward, - prevHitSource, - referencedComputedStateHash, - referencedForgedBlock - ) - BlockStats.appended(referencedForgedBlock, referencedLiquidSnapshot.scriptsComplexity) - TxsInBlockchainStats.record(ng.transactions.size) - blockchainUpdateTriggers.onProcessBlock(block, differResult.keyBlockSnapshot, reward, hitSource, rocksdb) - val (discardedMbs, discardedSnapshots) = discarded.unzip - if (discardedMbs.nonEmpty) { - log.trace(s"Discarded microblocks: $discardedMbs") - } - - Some((differResult, discardedSnapshots, reward, hitSource)) - } - } else { - val errorText = s"Forged block has invalid signature. Base: ${ng.base}, requested reference: ${block.header.reference}" - log.error(errorText) - Left(BlockAppendError(errorText, block)) - } - } - }).map { - _ map { - case ( - BlockDiffer.Result(newBlockSnapshot, carry, totalFee, updatedTotalConstraint, _, computedStateHash), - discDiffs, - reward, - hitSource - ) => - val newHeight = rocksdb.height + 1 + private def updateNgState( + block: Block, + result: BlockDiffer.Result, + discDiffs: Seq[StateSnapshot], + reward: Option[TxTimestamp], + hitSource: BlockId, + zzz: Option[Caches.BlockData] + ): BlockApplyResult = writeLock { + val newHeight = rocksdb.height + 1 + val BlockDiffer.Result(newBlockSnapshot, carry, totalFee, updatedTotalConstraint, _, computedStateHash) = result + + zzz.foreach(z => rocksdb.append(z.snapshot, z.carryFee, z.totalFee, z.reward, z.hitSource, z.computedBlockStateHash, z.block)) + + restTotalConstraint = updatedTotalConstraint + ngState = Some( + new NgState( + block, + newBlockSnapshot, + carry, + totalFee, + computedStateHash, + featuresApprovedWithBlock(block), + reward, + hitSource, + cancelLeases(collectLeasesToCancel(newHeight), newHeight) + ) + ) + + publishLastBlockInfo() + + if ( + block.header.timestamp > time.getTimestamp() - wavesSettings.minerSettings.intervalAfterLastBlockThenGenerationIsAllowed.toMillis || + newHeight % 100 == 0 + ) { + log.info(s"New height: $newHeight") + } + + Applied(discDiffs, this.score) + } - restTotalConstraint = updatedTotalConstraint - ngState = Some( - new NgState( + private def buildBlockDiff( + block: Block, + hitSource: BlockId, + snapshot: Option[BlockSnapshot], + challengedHitSource: Option[BlockId], + verify: Boolean + ): Either[ValidationError, Option[(BlockDiffer.Result, Seq[StateSnapshot], Option[TxTimestamp], BlockId, Option[Caches.BlockData])]] = ngState match { + case None => + rocksdb.lastBlockId match { + case Some(uniqueId) if uniqueId != block.header.reference => + val logDetails = s"The referenced block(${block.header.reference})" + + s" ${if (rocksdb.contains(block.header.reference)) "exists, it's not last persisted" else "doesn't exist"}" + Left(BlockAppendError(s"References incorrect or non-existing block: " + logDetails, block)) + case _ => + val reward = computeNextReward + + buildBlockSnapshot( + SnapshotBlockchain(rocksdb, reward), + rocksdb.lastBlock, + block, + snapshot, + hitSource, + challengedHitSource, + verify + ) + .map { r => + val updatedBlockchain = SnapshotBlockchain(rocksdb, r.snapshot, block, hitSource, r.carry, reward, Some(r.computedStateHash)) + miner.scheduleMining(Some(updatedBlockchain)) + blockchainUpdateTriggers.onProcessBlock(block, r.keyBlockSnapshot, reward, hitSource, SnapshotBlockchain(rocksdb, reward)) + Some((r, Nil, reward, hitSource, None)) + } + } + case Some(ng) => + if (ng.base.header.reference == block.header.reference) { + if (block.header.timestamp < ng.base.header.timestamp) { + BlockDiffer + .fromBlock( + SnapshotBlockchain(rocksdb, ng.reward), + rocksdb.lastBlock, + block, + snapshot, + MiningConstraints(rocksdb, rocksdb.height).total, + hitSource, + challengedHitSource, + rocksdb.loadCacheData, + verify + ) + .map { r => + log.trace( + s"Better liquid block(timestamp=${block.header.timestamp}) received and applied instead of existing(timestamp=${ng.base.header.timestamp})" + ) + BlockStats.replaced(ng.base, block) + val (mbs, mbSnapshots) = ng.allSnapshots.unzip + val allSnapshots = ng.baseBlockSnapshot +: mbSnapshots + log.trace(s"Discarded microblocks = $mbs, snapshots = ${allSnapshots.map(_.hashString)}") + + val updatedBlockchain = + SnapshotBlockchain(SnapshotBlockchain(rocksdb, ng.reward), r.snapshot, block, hitSource, r.carry, None, None) + miner.scheduleMining(Some(updatedBlockchain)) + + blockchainUpdateTriggers.onRollback(this, ng.base.header.reference, rocksdb.height) + blockchainUpdateTriggers.onProcessBlock(block, r.keyBlockSnapshot, ng.reward, hitSource, SnapshotBlockchain(rocksdb, ng.reward)) + Some((r, allSnapshots, ng.reward, hitSource, None)) + } + } else if (areVersionsOfSameBlock(block, ng.base)) { + // silently ignore + Right(None) + } else + Left( + BlockAppendError( + s"Competitors liquid block $block(timestamp=${block.header.timestamp}) is not better than existing (ng.base ${ng.base}(timestamp=${ng.base.header.timestamp}))", + block + ) + ) + } else + metrics.forgeBlockTimeStats.measureOptional(ng.snapshotOf(block.header.reference)) match { + case None => Left(BlockAppendError(s"References incorrect or non-existing block", block)) + case Some((referencedForgedBlock, referencedLiquidSnapshot, carry, totalFee, referencedComputedStateHash, discarded)) => + if (!verify || referencedForgedBlock.signatureValid()) { + val height = rocksdb.heightOf(referencedForgedBlock.header.reference).getOrElse(0) + + val prevReward = ng.reward + val reward = computeNextReward + + val prevHitSource = ng.hitSource + val liquidSnapshotWithCancelledLeases = ng.cancelExpiredLeases(referencedLiquidSnapshot) + val referencedBlockchain = SnapshotBlockchain( + rocksdb, + liquidSnapshotWithCancelledLeases, + referencedForgedBlock, + ng.hitSource, + carry, + reward, + Some(referencedComputedStateHash) + ) + + for { + differResult <- BlockDiffer + .fromBlock( + referencedBlockchain, + Some(referencedForgedBlock), block, - newBlockSnapshot, - carry, - totalFee, - computedStateHash, - featuresApprovedWithBlock(block), - reward, + snapshot, + MiningConstraints(rocksdb, height).total, hitSource, - cancelLeases(collectLeasesToCancel(newHeight), newHeight) + challengedHitSource, + rocksdb.loadCacheData, + verify ) + } yield { + val blockchainWithNewBlock = SnapshotBlockchain( + referencedBlockchain, + differResult.snapshot, + block, + hitSource, + differResult.carry, + None, + Some(differResult.computedStateHash) ) - publishLastBlockInfo() + miner.scheduleMining(Some(blockchainWithNewBlock)) + + log.trace( + s"Persisting block ${referencedForgedBlock.id()}, discarded microblock refs: ${discarded.map(_._1.reference).mkString("[", ",", "]")}" + ) - if ( - (block.header.timestamp > time - .getTimestamp() - wavesSettings.minerSettings.intervalAfterLastBlockThenGenerationIsAllowed.toMillis) || (newHeight % 100 == 0) - ) { - log.info(s"New height: $newHeight") + if (discarded.nonEmpty) { + blockchainUpdateTriggers.onMicroBlockRollback(this, block.header.reference) + metrics.microBlockForkStats.increment() + metrics.microBlockForkHeightStats.record(discarded.size) } - Applied(discDiffs, this.score) - } getOrElse Ignored - } - ) - } + BlockStats.appended(referencedForgedBlock, referencedLiquidSnapshot.scriptsComplexity) + TxsInBlockchainStats.record(referencedForgedBlock.transactionData.size) + + blockchainUpdateTriggers.onProcessBlock(block, differResult.keyBlockSnapshot, reward, hitSource, referencedBlockchain) + + val (discardedMbs, discardedSnapshots) = discarded.unzip + if (discardedMbs.nonEmpty) { + log.trace(s"Discarded microblocks: $discardedMbs") + } + + Some( + ( + differResult, + discardedSnapshots, + reward, + hitSource, + Some( + Caches.BlockData( + liquidSnapshotWithCancelledLeases, + carry, + totalFee, + prevReward, + prevHitSource, + referencedComputedStateHash, + referencedForgedBlock + ) + ) + ) + ) + } + } else { + val errorText = s"Forged block has invalid signature. Base: ${ng.base}, requested reference: ${block.header.reference}" + log.error(errorText) + Left(BlockAppendError(errorText, block)) + } + } + } private def collectLeasesToCancel(newHeight: Int): Map[ByteStr, LeaseDetails] = if (rocksdb.isFeatureActivated(BlockchainFeatures.LeaseExpiration, newHeight)) { diff --git a/node/src/main/scala/com/wavesplatform/state/appender/BlockAppender.scala b/node/src/main/scala/com/wavesplatform/state/appender/BlockAppender.scala index 5adacff6ff..b9549d0830 100644 --- a/node/src/main/scala/com/wavesplatform/state/appender/BlockAppender.scala +++ b/node/src/main/scala/com/wavesplatform/state/appender/BlockAppender.scala @@ -31,8 +31,7 @@ object BlockAppender extends ScorexLogging { utxStorage: UtxPool, pos: PoSSelector, scheduler: Scheduler, - verify: Boolean = true, - txSignParCheck: Boolean = true + verify: Boolean = true )(newBlock: Block, snapshot: Option[BlockSnapshotResponse]): Task[Either[ValidationError, BlockApplyResult]] = Task { if ( @@ -40,9 +39,9 @@ object BlockAppender extends ScorexLogging { .isLastBlockId(newBlock.header.reference) || blockchainUpdater.lastBlockHeader.exists(_.header.reference == newBlock.header.reference) ) { if (newBlock.header.challengedHeader.isDefined) { - appendChallengeBlock(blockchainUpdater, utxStorage, pos, time, log, verify, txSignParCheck)(newBlock, snapshot) + appendChallengeBlock(blockchainUpdater, utxStorage, pos, time, log, verify)(newBlock, snapshot) } else { - appendKeyBlock(blockchainUpdater, utxStorage, pos, time, log, verify, txSignParCheck)(newBlock, snapshot) + appendKeyBlock(blockchainUpdater, utxStorage, pos, time, log, verify)(newBlock, snapshot) } } else if (blockchainUpdater.contains(newBlock.id()) || blockchainUpdater.isLastBlockId(newBlock.id())) Right(Ignored) diff --git a/node/src/main/scala/com/wavesplatform/state/appender/ExtensionAppender.scala b/node/src/main/scala/com/wavesplatform/state/appender/ExtensionAppender.scala index 3368c17309..4d31c8b0b5 100644 --- a/node/src/main/scala/com/wavesplatform/state/appender/ExtensionAppender.scala +++ b/node/src/main/scala/com/wavesplatform/state/appender/ExtensionAppender.scala @@ -63,7 +63,7 @@ object ExtensionAppender extends ScorexLogging { val forkApplicationResultEi = { newBlocks.view .map { b => - b -> appendExtensionBlock(blockchainUpdater, pos, time, verify = true, txSignParCheck = false)( + b -> appendExtensionBlock(blockchainUpdater, pos, time, verify = true)( b, extension.snapshots.get(b.id()) ) diff --git a/node/src/main/scala/com/wavesplatform/state/appender/package.scala b/node/src/main/scala/com/wavesplatform/state/appender/package.scala index b4a78165cd..1a3e8a866e 100644 --- a/node/src/main/scala/com/wavesplatform/state/appender/package.scala +++ b/node/src/main/scala/com/wavesplatform/state/appender/package.scala @@ -40,8 +40,7 @@ package object appender { pos: PoSSelector, time: Time, log: LoggerFacade, - verify: Boolean, - txSignParCheck: Boolean + verify: Boolean )(block: Block, snapshot: Option[BlockSnapshotResponse]): Either[ValidationError, BlockApplyResult] = for { hitSource <- if (verify) validateBlock(blockchainUpdater, pos, time)(block) else pos.validateGenerationSignature(block) @@ -49,7 +48,7 @@ package object appender { metrics.appendBlock .measureSuccessful( blockchainUpdater - .processBlock(block, hitSource, snapshot.map(responseToSnapshot(block, blockchainUpdater.height + 1)), None, verify, txSignParCheck) + .processBlock(block, hitSource, snapshot.map(responseToSnapshot(block, blockchainUpdater.height + 1)), None, verify) ) .map { case res @ Applied(discardedDiffs, _) => @@ -71,11 +70,10 @@ package object appender { blockchainUpdater: BlockchainUpdater & Blockchain, pos: PoSSelector, time: Time, - verify: Boolean, - txSignParCheck: Boolean + verify: Boolean )(block: Block, snapshot: Option[BlockSnapshotResponse]): Either[ValidationError, (BlockApplyResult, Int)] = { if (block.header.challengedHeader.nonEmpty) { - processBlockWithChallenge(blockchainUpdater, pos, time, verify, txSignParCheck)(block, snapshot) + processBlockWithChallenge(blockchainUpdater, pos, time, verify)(block, snapshot) } else { for { hitSource <- if (verify) validateBlock(blockchainUpdater, pos, time)(block) else pos.validateGenerationSignature(block) @@ -85,8 +83,7 @@ package object appender { hitSource, snapshot.map(responseToSnapshot(block, blockchainUpdater.height + 1)), None, - verify, - txSignParCheck + verify ) ) } yield applyResult -> blockchainUpdater.height @@ -99,10 +96,9 @@ package object appender { pos: PoSSelector, time: Time, log: LoggerFacade, - verify: Boolean, - txSignParCheck: Boolean + verify: Boolean )(block: Block, snapshot: Option[BlockSnapshotResponse]): Either[ValidationError, BlockApplyResult] = - processBlockWithChallenge(blockchainUpdater, pos, time, verify, txSignParCheck)(block, snapshot).map { + processBlockWithChallenge(blockchainUpdater, pos, time, verify)(block, snapshot).map { case (res @ Applied(discardedDiffs, _), _) => if (block.transactionData.nonEmpty) { utx.removeAll(block.transactionData) @@ -120,8 +116,7 @@ package object appender { blockchainUpdater: BlockchainUpdater & Blockchain, pos: PoSSelector, time: Time, - verify: Boolean, - txSignParCheck: Boolean + verify: Boolean )(block: Block, snapshot: Option[BlockSnapshotResponse]): Either[ValidationError, (BlockApplyResult, Int)] = { val challengedBlock = block.toOriginal for { @@ -136,8 +131,7 @@ package object appender { hitSource, snapshot.map(responseToSnapshot(block, blockchainUpdater.height + 1)), Some(challengedHitSource), - verify, - txSignParCheck + verify ) ) } yield applyResult -> blockchainUpdater.height diff --git a/node/src/main/scala/com/wavesplatform/state/diffs/BlockDiffer.scala b/node/src/main/scala/com/wavesplatform/state/diffs/BlockDiffer.scala index 5b6b69f867..aeeab210f8 100644 --- a/node/src/main/scala/com/wavesplatform/state/diffs/BlockDiffer.scala +++ b/node/src/main/scala/com/wavesplatform/state/diffs/BlockDiffer.scala @@ -53,7 +53,6 @@ object BlockDiffer { loadCacheData: (Set[Address], Set[ByteStr]) => Unit = (_, _) => (), verify: Boolean = true, enableExecutionLog: Boolean = false, - txSignParCheck: Boolean = true ): Either[ValidationError, Result] = { challengedHitSource match { case Some(hs) if snapshot.isEmpty => @@ -67,7 +66,6 @@ object BlockDiffer { loadCacheData, verify, enableExecutionLog, - txSignParCheck ).resultE match { case Left(_: InvalidStateHash) => fromBlockTraced( @@ -80,7 +78,6 @@ object BlockDiffer { loadCacheData, verify, enableExecutionLog, - txSignParCheck ).resultE case Left(err) => Left(GenericError(s"Invalid block challenge: $err")) case _ => Left(GenericError("Invalid block challenge")) @@ -96,7 +93,6 @@ object BlockDiffer { loadCacheData, verify, enableExecutionLog, - txSignParCheck ).resultE } } @@ -111,7 +107,6 @@ object BlockDiffer { loadCacheData: (Set[Address], Set[ByteStr]) => Unit, verify: Boolean, enableExecutionLog: Boolean, - txSignParCheck: Boolean ): TracedResult[ValidationError, Result] = { val stateHeight = blockchain.height val heightWithNewBlock = stateHeight + 1 @@ -202,7 +197,6 @@ object BlockDiffer { loadCacheData, verify = verify, enableExecutionLog = enableExecutionLog, - txSignParCheck = txSignParCheck ) } _ <- checkStateHash(blockchainWithNewBlock, block.header.stateHash, r.computedStateHash) @@ -269,7 +263,6 @@ object BlockDiffer { loadCacheData, verify = verify, enableExecutionLog = enableExecutionLog, - txSignParCheck = true ) } _ <- checkStateHash(blockchain, micro.stateHash, r.computedStateHash) @@ -334,7 +327,6 @@ object BlockDiffer { loadCacheData: (Set[Address], Set[ByteStr]) => Unit, verify: Boolean, enableExecutionLog: Boolean, - txSignParCheck: Boolean ): TracedResult[ValidationError, Result] = { val timestamp = blockchain.lastBlockTimestamp.get val blockGenerator = blockchain.lastBlockHeader.get.header.generator.toAddress @@ -342,7 +334,7 @@ object BlockDiffer { val txDiffer = TransactionDiffer(prevBlockTimestamp, timestamp, verify, enableExecutionLog = enableExecutionLog) _ - if (verify && txSignParCheck) + if (verify) ParSignatureChecker.checkTxSignatures(txs, rideV6Activated) prepareCaches(blockGenerator, txs, loadCacheData) diff --git a/node/src/main/scala/com/wavesplatform/transaction/BlockchainUpdater.scala b/node/src/main/scala/com/wavesplatform/transaction/BlockchainUpdater.scala index 7e00728af2..5e1fb87f74 100644 --- a/node/src/main/scala/com/wavesplatform/transaction/BlockchainUpdater.scala +++ b/node/src/main/scala/com/wavesplatform/transaction/BlockchainUpdater.scala @@ -13,7 +13,6 @@ trait BlockchainUpdater { snapshot: Option[BlockSnapshot], challengedHitSource: Option[ByteStr] = None, verify: Boolean = true, - txSignParCheck: Boolean = true ): Either[ValidationError, BlockApplyResult] def processMicroBlock(microBlock: MicroBlock, snapshot: Option[MicroBlockSnapshot], verify: Boolean = true): Either[ValidationError, BlockId] def computeNextReward: Option[Long] diff --git a/node/testkit/src/main/scala/com/wavesplatform/db/WithState.scala b/node/testkit/src/main/scala/com/wavesplatform/db/WithState.scala index cab873284e..4aaa5788a8 100644 --- a/node/testkit/src/main/scala/com/wavesplatform/db/WithState.scala +++ b/node/testkit/src/main/scala/com/wavesplatform/db/WithState.scala @@ -180,8 +180,7 @@ trait WithState extends BeforeAndAfterAll with DBCacheSettings with Matchers wit b.header.generationSignature, (_, _) => (), verify = true, - enableExecutionLog = enableExecutionLog, - txSignParCheck = true + enableExecutionLog = enableExecutionLog ) preconditions.foreach { precondition => diff --git a/node/tests/src/test/scala/com/wavesplatform/mining/MiningFailuresSuite.scala b/node/tests/src/test/scala/com/wavesplatform/mining/MiningFailuresSuite.scala index 9aa7ad379a..820c202205 100644 --- a/node/tests/src/test/scala/com/wavesplatform/mining/MiningFailuresSuite.scala +++ b/node/tests/src/test/scala/com/wavesplatform/mining/MiningFailuresSuite.scala @@ -99,10 +99,10 @@ class MiningFailuresSuite extends FlatSpec with PathMockFactory with WithNewDBFo ) var minedBlock: Block = null - (blockchainUpdater.processBlock _).when(*, *, *, *, *, *).returning(Left(BlockFromFuture(100, 100))).repeated(10) + (blockchainUpdater.processBlock _).when(*, *, *, *, *).returning(Left(BlockFromFuture(100, 100))).repeated(10) (blockchainUpdater.processBlock _) - .when(*, *, *, *, *, *) - .onCall { (block, _, _, _, _, _) => + .when(*, *, *, *, *) + .onCall { (block, _, _, _, _) => minedBlock = block Right(Applied(Nil, 0)) }