Skip to content

Commit

Permalink
Merge branch 'version-1.4.x' into remove-guava-from-lang
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot authored Oct 20, 2023
2 parents 50c6c5e + e311af4 commit f5f2431
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 33 deletions.
3 changes: 2 additions & 1 deletion node/src/main/scala/com/wavesplatform/database/Caches.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.wavesplatform.database

import java.util
import cats.data.Ior
import cats.syntax.monoid.*
import cats.syntax.option.*
Expand All @@ -20,6 +19,7 @@ import com.wavesplatform.transaction.{Asset, Transaction}
import com.wavesplatform.utils.ObservedLoadingCache
import monix.reactive.Observer

import java.util
import scala.collection.immutable.VectorMap
import scala.concurrent.duration.*
import scala.jdk.CollectionConverters.*
Expand Down Expand Up @@ -152,6 +152,7 @@ abstract class Caches(spendableBalanceChanged: Observer[(Address, Asset)]) exten
protected def loadApprovedFeatures(): Map[Short, Int]
override def approvedFeatures: Map[Short, Int] = approvedFeaturesCache

// Also contains features those will be activated in the future (activationHeight > currentHeight), because they were approved now or before.
@volatile
protected var activatedFeaturesCache: Map[Short, Int] = loadActivatedFeatures()
protected def loadActivatedFeatures(): Map[Short, Int]
Expand Down
13 changes: 11 additions & 2 deletions node/src/main/scala/com/wavesplatform/database/LevelDBWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,10 @@ abstract class LevelDBWriter private[database] (
}

if (newlyApprovedFeatures.nonEmpty) {
approvedFeaturesCache = newlyApprovedFeatures ++ rw.get(Keys.approvedFeatures)
approvedFeaturesCache = newlyApprovedFeatures ++ approvedFeaturesCache
rw.put(Keys.approvedFeatures, approvedFeaturesCache)

val featuresToSave = (newlyApprovedFeatures.view.mapValues(_ + activationWindowSize) ++ rw.get(Keys.activatedFeatures)).toMap
val featuresToSave = (newlyApprovedFeatures.view.mapValues(_ + activationWindowSize) ++ activatedFeaturesCache).toMap

activatedFeaturesCache = featuresToSave ++ settings.functionalitySettings.preActivatedFeatures
rw.put(Keys.activatedFeatures, featuresToSave)
Expand Down Expand Up @@ -750,6 +750,15 @@ abstract class LevelDBWriter private[database] (
disabledAliases = DisableHijackedAliases.revert(rw)
}

val disapprovedFeatures = approvedFeaturesCache.collect { case (id, approvalHeight) if approvalHeight > targetHeight => id }
if (disapprovedFeatures.nonEmpty) {
approvedFeaturesCache --= disapprovedFeatures
rw.put(Keys.approvedFeatures, approvedFeaturesCache)

activatedFeaturesCache --= disapprovedFeatures // We won't activate them in the future
rw.put(Keys.activatedFeatures, activatedFeaturesCache)
}

val hitSource = rw.get(Keys.hitSource(currentHeight)).get
val block = createBlock(discardedMeta.header, discardedMeta.signature, loadTransactions(currentHeight, rw).map(_._2)).explicitGet()

Expand Down
Loading

0 comments on commit f5f2431

Please sign in to comment.