From 3e7c2d6f557613ab1d1989ecc137c6e48cda39ee Mon Sep 17 00:00:00 2001 From: Artyom Sayadyan Date: Thu, 7 Dec 2023 14:09:40 +0300 Subject: [PATCH] NODE-2632 Removed excessive conditions --- .../mining/BlockChallenger.scala | 29 +++++++-------- .../mining/LightNodeBlockFieldsTest.scala | 37 +------------------ 2 files changed, 14 insertions(+), 52 deletions(-) diff --git a/node/src/main/scala/com/wavesplatform/mining/BlockChallenger.scala b/node/src/main/scala/com/wavesplatform/mining/BlockChallenger.scala index b13fe31c25..df30549fae 100644 --- a/node/src/main/scala/com/wavesplatform/mining/BlockChallenger.scala +++ b/node/src/main/scala/com/wavesplatform/mining/BlockChallenger.scala @@ -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} @@ -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") diff --git a/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala b/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala index 34ef6e178c..14bb2ad96c 100644 --- a/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala +++ b/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 } } }