Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NODE-2633 Allowed mining by light node #3918

Merged
merged 4 commits into from
Dec 1, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.wavesplatform.it.sync.lightnode

import com.typesafe.config.Config
import com.wavesplatform.it.api.SyncHttpApi.*
import com.wavesplatform.it.{BaseFunSuite, NodeConfigs, TransferSending}

class LightNodeMiningSuite extends BaseFunSuite with TransferSending {
override def nodeConfigs: Seq[Config] =
NodeConfigs.newBuilder
.overrideBase(_.lightNode)
.withDefault(2)
.buildNonConflicting()

test("nodes can mine in light mode") {
val first = nodes.head
val second = nodes.last

val tx1 = first.transfer(first.keyPair, second.address, 1, waitForTx = true)
nodes.waitForHeightArise()
second.transactionStatus(tx1.id).applicationStatus.get shouldBe "succeeded"

val tx2 = second.transfer(second.keyPair, first.address, 1, waitForTx = true)
nodes.waitForHeightArise()
first.transactionStatus(tx2.id).applicationStatus.get shouldBe "succeeded"
}
}
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 && !settings.enableLightMode)
if (settings.minerSettings.enable)
miner = new MinerImpl(
allChannels,
blockchainUpdater,
Expand Down
2 changes: 1 addition & 1 deletion node/src/main/scala/com/wavesplatform/mining/Miner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class MinerImpl(
reference: ByteStr,
prevStateHash: Option[ByteStr]
): (Seq[Transaction], MiningConstraint, Option[ByteStr]) = {
val estimators = MiningConstraints(blockchainUpdater, blockchainUpdater.height, settings.enableLightMode, Some(minerSettings))
val estimators = MiningConstraints(blockchainUpdater, blockchainUpdater.height, Some(minerSettings))
val keyBlockStateHash = prevStateHash.flatMap { prevHash =>
BlockDiffer
.createInitialBlockSnapshot(blockchainUpdater, reference, miner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.wavesplatform.state.Blockchain
case class MiningConstraints(total: MiningConstraint, keyBlock: MiningConstraint, micro: MiningConstraint)

object MiningConstraints {
val MaxScriptRunsInBlock = 100
object MaxScriptsComplexityInBlock {
val BeforeRideV5 = 1000000
val AfterRideV5 = 2500000
Expand All @@ -18,41 +17,37 @@ object MiningConstraints {
val ClassicAmountOfTxsInBlock = 100
val MaxTxsSizeInBytes = 1 * 1024 * 1024 // 1 megabyte

def apply(blockchain: Blockchain, height: Int, isLightNode: Boolean, minerSettings: Option[MinerSettings] = None): MiningConstraints = {
if (isLightNode) {
MiningConstraints(MiningConstraint.Unlimited, MiningConstraint.Unlimited, MiningConstraint.Unlimited)
} else {
val activatedFeatures = blockchain.activatedFeaturesAt(height)
val isNgEnabled = activatedFeatures.contains(BlockchainFeatures.NG.id)
val isMassTransferEnabled = activatedFeatures.contains(BlockchainFeatures.MassTransfer.id)
val isDAppsEnabled = activatedFeatures.contains(BlockchainFeatures.Ride4DApps.id)
def apply(blockchain: Blockchain, height: Int, minerSettings: Option[MinerSettings] = None): MiningConstraints = {
val activatedFeatures = blockchain.activatedFeaturesAt(height)
val isNgEnabled = activatedFeatures.contains(BlockchainFeatures.NG.id)
val isMassTransferEnabled = activatedFeatures.contains(BlockchainFeatures.MassTransfer.id)
val isDAppsEnabled = activatedFeatures.contains(BlockchainFeatures.Ride4DApps.id)

val total: MiningConstraint =
if (isMassTransferEnabled) OneDimensionalMiningConstraint(MaxTxsSizeInBytes, TxEstimators.sizeInBytes, "MaxTxsSizeInBytes")
else {
val maxTxs = if (isNgEnabled) Block.MaxTransactionsPerBlockVer3 else ClassicAmountOfTxsInBlock
OneDimensionalMiningConstraint(maxTxs, TxEstimators.one, "MaxTxs")
}
val total: MiningConstraint =
if (isMassTransferEnabled) OneDimensionalMiningConstraint(MaxTxsSizeInBytes, TxEstimators.sizeInBytes, "MaxTxsSizeInBytes")
else {
val maxTxs = if (isNgEnabled) Block.MaxTransactionsPerBlockVer3 else ClassicAmountOfTxsInBlock
OneDimensionalMiningConstraint(maxTxs, TxEstimators.one, "MaxTxs")
}

new MiningConstraints(
total = if (isDAppsEnabled) {
val complexityLimit =
if (blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls)) MaxScriptsComplexityInBlock.AfterRideV5
else MaxScriptsComplexityInBlock.BeforeRideV5
MultiDimensionalMiningConstraint(
NonEmptyList
.of(OneDimensionalMiningConstraint(complexityLimit, TxEstimators.scriptsComplexity, "MaxScriptsComplexityInBlock"), total)
)
} else
total,
keyBlock =
if (isNgEnabled) OneDimensionalMiningConstraint(0, TxEstimators.one, "MaxTxsInKeyBlock")
else OneDimensionalMiningConstraint(ClassicAmountOfTxsInBlock, TxEstimators.one, "MaxTxsInKeyBlock"),
micro =
if (isNgEnabled && minerSettings.isDefined)
OneDimensionalMiningConstraint(minerSettings.get.maxTransactionsInMicroBlock, TxEstimators.one, "MaxTxsInMicroBlock")
else MiningConstraint.Unlimited
)
}
new MiningConstraints(
total = if (isDAppsEnabled) {
val complexityLimit =
if (blockchain.isFeatureActivated(BlockchainFeatures.SynchronousCalls)) MaxScriptsComplexityInBlock.AfterRideV5
else MaxScriptsComplexityInBlock.BeforeRideV5
MultiDimensionalMiningConstraint(
NonEmptyList
.of(OneDimensionalMiningConstraint(complexityLimit, TxEstimators.scriptsComplexity, "MaxScriptsComplexityInBlock"), total)
)
} else
total,
keyBlock =
if (isNgEnabled) OneDimensionalMiningConstraint(0, TxEstimators.one, "MaxTxsInKeyBlock")
else OneDimensionalMiningConstraint(ClassicAmountOfTxsInBlock, TxEstimators.one, "MaxTxsInKeyBlock"),
micro =
if (isNgEnabled && minerSettings.isDefined)
OneDimensionalMiningConstraint(minerSettings.get.maxTransactionsInMicroBlock, TxEstimators.one, "MaxTxsInMicroBlock")
else MiningConstraint.Unlimited
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class BlockchainUpdaterImpl(
private[this] var ngState: Option[NgState] = Option.empty

@volatile
private[this] var restTotalConstraint: MiningConstraint = MiningConstraints(rocksdb, rocksdb.height, wavesSettings.enableLightMode).total
private[this] var restTotalConstraint: MiningConstraint = MiningConstraints(rocksdb, rocksdb.height).total

private val internalLastBlockInfo = ReplaySubject.createLimited[LastBlockInfo](1)

Expand Down Expand Up @@ -223,7 +223,7 @@ class BlockchainUpdaterImpl(
Left(BlockAppendError(s"References incorrect or non-existing block: " + logDetails, block))
case lastBlockId =>
val height = lastBlockId.fold(0)(rocksdb.unsafeHeightOf)
val miningConstraints = MiningConstraints(rocksdb, height, wavesSettings.enableLightMode)
val miningConstraints = MiningConstraints(rocksdb, height)
val reward = computeNextReward

val referencedBlockchain = SnapshotBlockchain(rocksdb, reward)
Expand Down Expand Up @@ -251,7 +251,7 @@ class BlockchainUpdaterImpl(
if (ng.base.header.reference == block.header.reference) {
if (block.header.timestamp < ng.base.header.timestamp) {
val height = rocksdb.unsafeHeightOf(ng.base.header.reference)
val miningConstraints = MiningConstraints(rocksdb, height, wavesSettings.enableLightMode)
val miningConstraints = MiningConstraints(rocksdb, height)

val referencedBlockchain = SnapshotBlockchain(rocksdb, ng.reward)
BlockDiffer
Expand Down Expand Up @@ -301,7 +301,7 @@ class BlockchainUpdaterImpl(
val height = rocksdb.heightOf(referencedForgedBlock.header.reference).getOrElse(0)

val constraint: MiningConstraint = {
val miningConstraints = MiningConstraints(rocksdb, height, wavesSettings.enableLightMode)
val miningConstraints = MiningConstraints(rocksdb, height)
miningConstraints.total
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class RideV5LimitsChangeTest extends FlatSpec with WithDomain {
MiningConstraints(
d.blockchain,
d.blockchain.height,
SettingsFromDefaultConfig.enableLightMode,
Some(SettingsFromDefaultConfig.minerSettings)
).total,
block.header.generationSignature
Expand Down Expand Up @@ -65,7 +64,6 @@ class RideV5LimitsChangeTest extends FlatSpec with WithDomain {
MiningConstraints(
d.blockchain,
d.blockchain.height,
SettingsFromDefaultConfig.enableLightMode,
Some(SettingsFromDefaultConfig.minerSettings)
).total,
block.header.generationSignature
Expand Down