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-2619 Feature activation fixes #3900

Merged
merged 5 commits into from
Oct 20, 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
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