Skip to content

Commit

Permalink
NODE-2632 Removed excessive conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 committed Dec 7, 2023
1 parent b9c794d commit 3e7c2d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 52 deletions.
29 changes: 13 additions & 16 deletions node/src/main/scala/com/wavesplatform/mining/BlockChallenger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import com.wavesplatform.state.BlockchainUpdaterImpl.BlockApplyResult
import com.wavesplatform.state.BlockchainUpdaterImpl.BlockApplyResult.Applied
import com.wavesplatform.state.appender.MaxTimeDrift
import com.wavesplatform.state.diffs.BlockDiffer
import com.wavesplatform.state.SnapshotBlockchain
import com.wavesplatform.state.{Blockchain, StateSnapshot, TxStateSnapshotHashBuilder}
import com.wavesplatform.state.{Blockchain, SnapshotBlockchain, StateSnapshot, TxStateSnapshotHashBuilder}
import com.wavesplatform.transaction.TxValidationError.GenericError
import com.wavesplatform.transaction.{BlockchainUpdater, Transaction}
import com.wavesplatform.utils.{ScorexLogging, Time}
Expand Down Expand Up @@ -227,21 +226,19 @@ class BlockChallengerImpl(
acc,
blockFeatures(blockchainUpdater, settings),
blockRewardVote(settings),
if (blockchainWithNewBlock.supportsLightNodeBlockFields()) Some(stateHash) else None,
if (blockchainWithNewBlock.supportsLightNodeBlockFields())
Some(
ChallengedHeader(
challengedBlock.header.timestamp,
challengedBlock.header.baseTarget,
challengedBlock.header.generationSignature,
challengedBlock.header.featureVotes,
challengedBlock.header.generator,
challengedBlock.header.rewardVote,
challengedStateHash,
challengedSignature
)
Some(stateHash),
Some(
ChallengedHeader(
challengedBlock.header.timestamp,
challengedBlock.header.baseTarget,
challengedBlock.header.generationSignature,
challengedBlock.header.featureVotes,
challengedBlock.header.generator,
challengedBlock.header.rewardVote,
challengedStateHash,
challengedSignature
)
else None
)
)
} yield {
log.debug(s"Forged challenging block $challengingBlock")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.wavesplatform.mining

import com.wavesplatform.account.SeedKeyPair
import com.wavesplatform.block.Block.ProtoBlockVersion
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils.EitherExt2
Expand All @@ -13,10 +12,6 @@ import com.wavesplatform.mining.microblocks.MicroBlockMinerImpl
import com.wavesplatform.test.DomainPresets.*
import com.wavesplatform.test.{PropSpec, produce}
import com.wavesplatform.transaction.TxHelpers.{defaultSigner, secondSigner, transfer}
import com.wavesplatform.transaction.TxValidationError.GenericError
import io.netty.channel.group.DefaultChannelGroup
import io.netty.util.concurrent.GlobalEventExecutor
import monix.eval.Task
import monix.execution.Scheduler.Implicits.global
import monix.reactive.Observable

Expand Down Expand Up @@ -48,28 +43,12 @@ class LightNodeBlockFieldsTest extends PropSpec with WithDomain {
Observable.empty,
identity
)
val challenger = new BlockChallengerImpl(
d.blockchain,
new DefaultChannelGroup(GlobalEventExecutor.INSTANCE),
d.wallet,
d.settings,
d.testTime,
d.posSelector,
b => Task.now(append(b)),
timeDrift = Int.MaxValue
) {
override def pickBestAccount(accounts: Seq[(SeedKeyPair, Long)]): Either[GenericError, (SeedKeyPair, Long)] = Right((defaultSigner, 0))
}
def block(height: Int) = d.blocksApi.blockAtHeight(height).get._1.header
def appendBlock() = append(miner.forgeBlock(defaultSigner).explicitGet()._1).explicitGet()
def appendMicro() = {
d.utxPool.putIfNew(transfer()).resultE.explicitGet()
microBlockMiner.generateOneMicroBlockTask(defaultSigner, d.lastBlock, Unlimited, 0).runSyncUnsafe()
}
def challengeBlock() = {
val invalidBlock = d.createBlock(ProtoBlockVersion, Seq(), strictTime = true, stateHash = invalidStateHash)
challenger.challengeBlock(invalidBlock, null).runSyncUnsafe()
}

appendBlock()
d.blockchain.height shouldBe 2
Expand All @@ -79,12 +58,7 @@ class LightNodeBlockFieldsTest extends PropSpec with WithDomain {
appendMicro()
block(2).stateHash shouldBe None

challengeBlock()
d.blockchain.height shouldBe 3
block(3).stateHash shouldBe None
block(3).challengedHeader shouldBe None

(1 to 8).foreach(_ => appendBlock())
(1 to 9).foreach(_ => appendBlock())
d.blockchain.height shouldBe 11
block(11).stateHash shouldBe None

Expand All @@ -100,15 +74,6 @@ class LightNodeBlockFieldsTest extends PropSpec with WithDomain {
val hash2 = block(12).stateHash
hash2 shouldBe defined
hash2 should not be hash1

d.rollbackTo(10)
challengeBlock()
block(11).stateHash shouldBe None
block(11).challengedHeader shouldBe None

challengeBlock()
block(12).stateHash shouldBe defined
block(12).challengedHeader shouldBe defined
}
}
}
Expand Down

0 comments on commit 3e7c2d6

Please sign in to comment.