Skip to content

Commit

Permalink
Adapted light node mining
Browse files Browse the repository at this point in the history
  • Loading branch information
xrtm000 committed Dec 5, 2023
1 parent 1fab951 commit 69165db
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package com.wavesplatform.it.sync.lightnode

import com.typesafe.config.Config
import com.wavesplatform.features.BlockchainFeatures.LightNode
import com.wavesplatform.it.api.SyncHttpApi.*
import com.wavesplatform.it.{BaseFunSuite, NodeConfigs, TransferSending}
import com.wavesplatform.test.NumericExt

class LightNodeMiningSuite extends BaseFunSuite with TransferSending {
override def nodeConfigs: Seq[Config] =
NodeConfigs.newBuilder
.overrideBase(_.lightNode)
.withDefault(2)
.overrideBase(_.preactivatedFeatures(LightNode.id.toInt -> 2))
.overrideBase(_.raw("waves.blockchain.custom.functionality.light-node-block-fields-absence-interval = 2"))
.withDefault(1)
.withSpecial(1, _.lightNode)
.buildNonConflicting()

test("nodes can mine in light mode") {
val first = nodes.head
val second = nodes.last
test("node can mine in light mode after light-node-block-fields-absence-interval") {
val lightNode = nodes.find(_.settings.enableLightMode).get
val fullNode = nodes.find(!_.settings.enableLightMode).get
val lightNodeAddress = lightNode.keyPair.toAddress.toString
val fullNodeAddress = fullNode.keyPair.toAddress.toString

val tx1 = first.transfer(first.keyPair, second.address, 1, waitForTx = true)
nodes.waitForHeightArise()
second.transactionStatus(tx1.id).applicationStatus.get shouldBe "succeeded"
nodes.waitForHeight(5)
fullNode.transfer(fullNode.keyPair, lightNodeAddress, fullNode.balance(fullNodeAddress).balance - 1.waves)
lightNode.blockSeq(2, 5).foreach(_.generator shouldBe fullNodeAddress)

val tx2 = second.transfer(second.keyPair, first.address, 1, waitForTx = true)
nodes.waitForHeightArise()
first.transactionStatus(tx2.id).applicationStatus.get shouldBe "succeeded"
lightNode.waitForHeight(6)
lightNode.blockAt(6).generator shouldBe lightNodeAddress
}
}
2 changes: 1 addition & 1 deletion node/src/main/scala/com/wavesplatform/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Application(val actorSystem: ActorSystem, val settings: WavesSettings, con

val pos = PoSSelector(blockchainUpdater, settings.synchronizationSettings.maxBaseTarget)

if (settings.minerSettings.enable)
if (settings.minerSettings.enable && (!settings.enableLightMode || blockchainUpdater.supportsLightNodeBlockFields()))
miner = new MinerImpl(
allChannels,
blockchainUpdater,
Expand Down
39 changes: 20 additions & 19 deletions node/src/main/scala/com/wavesplatform/mining/Miner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,28 @@ class MinerImpl(
def getNextBlockGenerationOffset(account: KeyPair): Either[String, FiniteDuration] =
this.nextBlockGenOffsetWithConditions(account, blockchainUpdater)

def scheduleMining(tempBlockchain: Option[Blockchain]): Unit = {
Miner.blockMiningStarted.increment()

val accounts = if (settings.minerSettings.privateKeys.nonEmpty) {
settings.minerSettings.privateKeys.map(PKKeyPair(_))
} else {
wallet.privateKeyAccounts
def scheduleMining(tempBlockchain: Option[Blockchain]): Unit =
if (!settings.enableLightMode || blockchainUpdater.supportsLightNodeBlockFields()) {
Miner.blockMiningStarted.increment()

val accounts = if (settings.minerSettings.privateKeys.nonEmpty) {
settings.minerSettings.privateKeys.map(PKKeyPair(_))
} else {
wallet.privateKeyAccounts
}

val hasAllowedForMiningScriptsAccounts =
accounts.filter(kp => hasAllowedForMiningScript(kp.toAddress, tempBlockchain.getOrElse(blockchainUpdater)))
scheduledAttempts := CompositeCancelable.fromSet(hasAllowedForMiningScriptsAccounts.map { account =>
generateBlockTask(account, tempBlockchain)
.onErrorHandle(err => log.warn(s"Error mining Block", err))
.runAsyncLogErr(appenderScheduler)
}.toSet)
microBlockAttempt := SerialCancelable()

debugStateRef = MinerDebugInfo.MiningBlocks
}

val hasAllowedForMiningScriptsAccounts =
accounts.filter(kp => hasAllowedForMiningScript(kp.toAddress, tempBlockchain.getOrElse(blockchainUpdater)))
scheduledAttempts := CompositeCancelable.fromSet(hasAllowedForMiningScriptsAccounts.map { account =>
generateBlockTask(account, tempBlockchain)
.onErrorHandle(err => log.warn(s"Error mining Block", err))
.runAsyncLogErr(appenderScheduler)
}.toSet)
microBlockAttempt := SerialCancelable()

debugStateRef = MinerDebugInfo.MiningBlocks
}

override def state: MinerDebugInfo.State = debugStateRef

private def checkAge(parentHeight: Int, parentTimestamp: Long): Either[String, Unit] =
Expand Down

0 comments on commit 69165db

Please sign in to comment.