Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot committed Jun 29, 2024
1 parent 70ecc4c commit 80dfee0
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,7 @@ object BlockAppended {

// updatedWavesAmount can change as a result of either genesis transactions or miner rewards
val wavesAmount = blockchainBeforeWithReward.wavesAmount(height).toLong
val rewardBoost = if (blockchainBeforeWithReward.isBlockRewardBoostActive(height + 1)) BlockRewardCalculator.RewardBoost else 1
val updatedWavesAmount = wavesAmount + reward.filter(_ => height > 0).getOrElse(0L) * rewardBoost
val updatedWavesAmount = wavesAmount + reward.filter(_ => height > 0).getOrElse(0L) * blockchainBeforeWithReward.blockRewardBoost(height + 1)
val activatedFeatures = blockchainBeforeWithReward.activatedFeatures.collect {
case (id, activationHeight) if activationHeight == height + 1 => id.toInt
}.toSeq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ class BlockchainUpdatesSpec extends FreeSpec with WithBUDomain with ScalaFutures
subscription
.fetchAllEvents(d.blockchain)
.map(_.getUpdate.getAppend.getBlock.updatedWavesAmount) shouldBe
(2 to 16).scanLeft(100_000_000.waves) { (total, height) => total + 6.waves * (if (d.blockchain.isBlockRewardBoostActive(height)) BlockRewardCalculator.RewardBoost else 1) }
(2 to 16).scanLeft(100_000_000.waves) { (total, height) => total + 6.waves * d.blockchain.blockRewardBoost(height) }


}
Expand Down
3 changes: 1 addition & 2 deletions node/src/main/scala/com/wavesplatform/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,9 @@ object Application extends ScorexLogging {
.orElse(db.get(Keys.blockMetaAt(Height(height))).flatMap(BlockMeta.fromPb))
.map { blockMeta =>
val rewardShares = BlockRewardCalculator.getSortedBlockRewardShares(height, blockMeta.header.generator.toAddress, blockchainUpdater)
val rewardBoost = if (blockchainUpdater.isBlockRewardBoostActive(height)) BlockRewardCalculator.RewardBoost else 1
blockMeta.copy(
rewardShares = rewardShares,
reward = blockMeta.reward.map(_ * rewardBoost)
reward = blockMeta.reward.map(_ * blockchainUpdater.blockRewardBoost(height))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ abstract class Caches extends Blockchain with Storage {
if (block.header.version >= Block.ProtoBlockVersion) ByteString.copyFrom(hitSource.arr) else ByteString.EMPTY,
ByteString.copyFrom(newScore.toByteArray),
current.meta.fold(settings.genesisSettings.initialBalance)(_.totalWavesAmount) +
(reward.getOrElse(0L) * (if (this.isBlockRewardBoostActive(newHeight)) BlockRewardCalculator.RewardBoost else 1))
(reward.getOrElse(0L) * this.blockRewardBoost(newHeight))
)
current = CurrentBlockInfo(Height(newHeight), Some(newMeta), block.transactionData)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object BlockRewardCalculator {
calculateRewards(fullBlockReward, CurrentBlockRewardPart.apply(fullBlockReward), daoAddress, modifiedXtnBuybackAddress)
}
} else BlockRewardShares(fullBlockReward, 0, 0)
}.multiply(if (blockchain.isBlockRewardBoostActive(height)) RewardBoost else 1)
}.multiply(blockchain.blockRewardBoost(height))

def getSortedBlockRewardShares(height: Int, fullBlockReward: Long, generator: Address, blockchain: Blockchain): Seq[(Address, Long)] = {
val daoAddress = blockchain.settings.functionalitySettings.daoAddressParsed.toOption.flatten
Expand Down
6 changes: 3 additions & 3 deletions node/src/main/scala/com/wavesplatform/state/Blockchain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ object Blockchain {
def supportsLightNodeBlockFields(height: Int = blockchain.height): Boolean =
blockchain.featureActivationHeight(LightNode.id).exists(height >= _ + blockchain.settings.functionalitySettings.lightNodeBlockFieldsAbsenceInterval)

def isBlockRewardBoostActive(height: Int): Boolean =
def blockRewardBoost(height: Int): Int =
blockchain
.featureActivationHeight(BlockchainFeatures.BoostBlockReward.id)
.exists { boostHeight =>
.filter { boostHeight =>
boostHeight <= height && height < boostHeight + blockchain.settings.functionalitySettings.blockRewardBoostPeriod
}
}.fold(1)(_ => BlockRewardCalculator.RewardBoost)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ class BlockchainUpdaterImpl(
ngState match {
case Some(ng) if this.height == height =>
rocksdb.wavesAmount(height - 1) +
BigInt(ng.reward.getOrElse(0L)) * (if (this.isBlockRewardBoostActive(height)) BlockRewardCalculator.RewardBoost else 1)
BigInt(ng.reward.getOrElse(0L)) * this.blockRewardBoost(height)
case _ =>
rocksdb.wavesAmount(height)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wavesplatform.http

import akka.http.scaladsl.testkit.RouteTestTimeout
import com.google.protobuf.ByteString
import com.wavesplatform.api.http.ApiError.TooBigArrayAllocation
import com.wavesplatform.api.http.requests.ScriptWithImportsRequest
Expand Down Expand Up @@ -38,6 +39,7 @@ import scala.concurrent.duration.*

class UtilsRouteSpec extends RouteSpec("/utils") with RestAPISettingsHelper with PropertyChecks with PathMockFactory with Inside with WithDomain {
private val estimator = ScriptEstimatorV2
protected override implicit val routeTestTimeout: RouteTestTimeout = RouteTestTimeout(20.seconds)

private val timeBounded: SchedulerService = Schedulers.timeBoundedFixedPool(
new HashedWheelTimer(),
Expand Down

0 comments on commit 80dfee0

Please sign in to comment.