Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/src/main/scala/com/wavesplatform/Importer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions node/src/main/scala/com/wavesplatform/database/Caches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
420 changes: 200 additions & 220 deletions node/src/main/scala/com/wavesplatform/state/BlockchainUpdaterImpl.scala

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@ 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 (
blockchainUpdater.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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ 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)
newHeight <-
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, _) =>
Expand All @@ -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)
Expand All @@ -85,8 +83,7 @@ package object appender {
hitSource,
snapshot.map(responseToSnapshot(block, blockchainUpdater.height + 1)),
None,
verify,
txSignParCheck
verify
)
)
} yield applyResult -> blockchainUpdater.height
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -136,8 +131,7 @@ package object appender {
hitSource,
snapshot.map(responseToSnapshot(block, blockchainUpdater.height + 1)),
Some(challengedHitSource),
verify,
txSignParCheck
verify
)
)
} yield applyResult -> blockchainUpdater.height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ object BlockDiffer {
challengedHitSource: Option[ByteStr] = None,
loadCacheData: (Set[Address], Set[ByteStr]) => Unit = (_, _) => (),
verify: Boolean = true,
enableExecutionLog: Boolean = false,
txSignParCheck: Boolean = true
enableExecutionLog: Boolean = false
): Either[ValidationError, Result] = {
challengedHitSource match {
case Some(hs) if snapshot.isEmpty =>
Expand All @@ -66,8 +65,7 @@ object BlockDiffer {
hs,
loadCacheData,
verify,
enableExecutionLog,
txSignParCheck
enableExecutionLog
).resultE match {
case Left(_: InvalidStateHash) =>
fromBlockTraced(
Expand All @@ -79,8 +77,7 @@ object BlockDiffer {
hitSource,
loadCacheData,
verify,
enableExecutionLog,
txSignParCheck
enableExecutionLog
).resultE
case Left(err) => Left(GenericError(s"Invalid block challenge: $err"))
case _ => Left(GenericError("Invalid block challenge"))
Expand All @@ -95,8 +92,7 @@ object BlockDiffer {
hitSource,
loadCacheData,
verify,
enableExecutionLog,
txSignParCheck
enableExecutionLog
).resultE
}
}
Expand All @@ -110,8 +106,7 @@ object BlockDiffer {
hitSource: ByteStr,
loadCacheData: (Set[Address], Set[ByteStr]) => Unit,
verify: Boolean,
enableExecutionLog: Boolean,
txSignParCheck: Boolean
enableExecutionLog: Boolean
): TracedResult[ValidationError, Result] = {
val stateHeight = blockchain.height
val heightWithNewBlock = stateHeight + 1
Expand Down Expand Up @@ -201,8 +196,7 @@ object BlockDiffer {
block.transactionData,
loadCacheData,
verify = verify,
enableExecutionLog = enableExecutionLog,
txSignParCheck = txSignParCheck
enableExecutionLog = enableExecutionLog
)
}
_ <- checkStateHash(blockchainWithNewBlock, block.header.stateHash, r.computedStateHash)
Expand Down Expand Up @@ -268,8 +262,7 @@ object BlockDiffer {
micro.transactionData,
loadCacheData,
verify = verify,
enableExecutionLog = enableExecutionLog,
txSignParCheck = true
enableExecutionLog = enableExecutionLog
)
}
_ <- checkStateHash(blockchain, micro.stateHash, r.computedStateHash)
Expand Down Expand Up @@ -333,16 +326,15 @@ object BlockDiffer {
txs: Seq[Transaction],
loadCacheData: (Set[Address], Set[ByteStr]) => Unit,
verify: Boolean,
enableExecutionLog: Boolean,
txSignParCheck: Boolean
enableExecutionLog: Boolean
): TracedResult[ValidationError, Result] = {
val timestamp = blockchain.lastBlockTimestamp.get
val blockGenerator = blockchain.lastBlockHeader.get.header.generator.toAddress
val rideV6Activated = blockchain.isFeatureActivated(BlockchainFeatures.RideV6)

val txDiffer = TransactionDiffer(prevBlockTimestamp, timestamp, verify, enableExecutionLog = enableExecutionLog)

if (verify && txSignParCheck)
if (verify)
ParSignatureChecker.checkTxSignatures(txs, rideV6Activated)

prepareCaches(blockGenerator, txs, loadCacheData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ trait BlockchainUpdater {
hitSource: ByteStr,
snapshot: Option[BlockSnapshot],
challengedHitSource: Option[ByteStr] = None,
verify: Boolean = true,
txSignParCheck: Boolean = true
verify: Boolean = true
): Either[ValidationError, BlockApplyResult]
def processMicroBlock(microBlock: MicroBlock, snapshot: Option[MicroBlockSnapshot], verify: Boolean = true): Either[ValidationError, BlockId]
def computeNextReward: Option[Long]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Loading