From 3e7c2d6f557613ab1d1989ecc137c6e48cda39ee Mon Sep 17 00:00:00 2001 From: Artyom Sayadyan Date: Thu, 7 Dec 2023 14:09:40 +0300 Subject: [PATCH 1/4] 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 } } } From 5c51537d2074c6d5b8c0fd3fe312aa366150f9a1 Mon Sep 17 00:00:00 2001 From: Artyom Sayadyan Date: Thu, 7 Dec 2023 14:17:13 +0300 Subject: [PATCH 2/4] Removed verify = false from test --- .../wavesplatform/mining/LightNodeBlockFieldsTest.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala b/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala index 14bb2ad96c..2c4c0522ba 100644 --- a/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala +++ b/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala @@ -29,7 +29,6 @@ class LightNodeBlockFieldsTest extends PropSpec with WithDomain { d.blockchain, d.testTime, d.settings.copy(minerSettings = d.settings.minerSettings.copy(quorum = 0, minMicroBlockAge = 0.seconds)), - verify = false, timeDrift = Int.MaxValue ) { case (miner, append) => val microBlockMiner = new MicroBlockMinerImpl( @@ -44,7 +43,11 @@ class LightNodeBlockFieldsTest extends PropSpec with WithDomain { identity ) def block(height: Int) = d.blocksApi.blockAtHeight(height).get._1.header - def appendBlock() = append(miner.forgeBlock(defaultSigner).explicitGet()._1).explicitGet() + def appendBlock() = { + val block = miner.forgeBlock(defaultSigner).explicitGet()._1 + d.testTime.setTime(block.header.timestamp) + append(block).explicitGet() + } def appendMicro() = { d.utxPool.putIfNew(transfer()).resultE.explicitGet() microBlockMiner.generateOneMicroBlockTask(defaultSigner, d.lastBlock, Unlimited, 0).runSyncUnsafe() From 91e0ce6f7198190809e5a77c80177c5701902b22 Mon Sep 17 00:00:00 2001 From: Artyom Sayadyan Date: Thu, 14 Dec 2023 12:20:49 +0300 Subject: [PATCH 3/4] Check challenging block fields excistence --- .../com/wavesplatform/mining/LightNodeBlockFieldsTest.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala b/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala index 2c4c0522ba..3fd17bc5f6 100644 --- a/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala +++ b/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala @@ -115,6 +115,8 @@ class LightNodeBlockFieldsTest extends PropSpec with WithDomain { val challengingBlock2 = d.createChallengingBlock(secondSigner, invalidBlock, strictTime = true) d.testTime.setTime(challengingBlock2.header.timestamp) append(challengingBlock2) shouldBe a[Right[?, ?]] + challengingBlock2.header.challengedHeader shouldBe defined + challengingBlock2.header.stateHash shouldBe defined } } } From b9434cf6f4d8ffaaa9d20792e2f4a7e5a0c20b94 Mon Sep 17 00:00:00 2001 From: Artyom Sayadyan Date: Thu, 14 Dec 2023 15:56:03 +0300 Subject: [PATCH 4/4] Rollback test --- .../com/wavesplatform/mining/LightNodeBlockFieldsTest.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala b/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala index 3fd17bc5f6..19641be7e0 100644 --- a/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala +++ b/node/src/test/scala/com/wavesplatform/mining/LightNodeBlockFieldsTest.scala @@ -77,6 +77,11 @@ class LightNodeBlockFieldsTest extends PropSpec with WithDomain { val hash2 = block(12).stateHash hash2 shouldBe defined hash2 should not be hash1 + + d.rollbackTo(11) + d.lastBlock.header.stateHash shouldBe empty + appendBlock() + d.lastBlock.header.stateHash shouldBe defined } } }