Skip to content

Commit

Permalink
Merge branch 'master' into bump-golangci-lint-action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykiselev authored Feb 9, 2024
2 parents cd84e14 + 1b87710 commit f85e903
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/state/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package state
import (
"encoding/binary"
"errors"
"sync"

"go.uber.org/zap"

"github.com/wavesplatform/gowaves/pkg/keyvalue"
"github.com/wavesplatform/gowaves/pkg/proto"
"github.com/wavesplatform/gowaves/pkg/settings"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -82,6 +84,7 @@ type features struct {
settings *settings.BlockchainSettings
definedFeaturesInfo map[settings.Feature]settings.FeatureInfo
activationCache map[settings.Feature]featureActivationState
mu sync.Mutex
}

func newFeatures(rw *blockReadWriter, db keyvalue.IterableKeyVal, hs *historyStorage, stg *settings.BlockchainSettings,
Expand Down Expand Up @@ -219,6 +222,8 @@ func (f *features) newestIsActivatedForNBlocks(featureID int16, n int) (bool, er
}

func (f *features) newestIsActivated(featureID int16) (bool, error) {
defer f.mu.Unlock()
f.mu.Lock()
if as, ok := f.activationCache[settings.Feature(featureID)]; ok {
return as.activated, nil
}
Expand All @@ -235,6 +240,8 @@ func (f *features) newestIsActivated(featureID int16) (bool, error) {
}

func (f *features) isActivated(featureID int16) (bool, error) {
defer f.mu.Unlock()
f.mu.Lock()
if as, ok := f.activationCache[settings.Feature(featureID)]; ok {
return as.activated, nil
}
Expand Down Expand Up @@ -309,6 +316,8 @@ func (f *features) activatedFeaturesRecord(featureID int16) (*activatedFeaturesR
}

func (f *features) newestActivationHeight(featureID int16) (uint64, error) {
defer f.mu.Unlock()
f.mu.Lock()
if as, ok := f.activationCache[settings.Feature(featureID)]; ok {
if as.activated {
return as.height, nil
Expand All @@ -324,6 +333,8 @@ func (f *features) newestActivationHeight(featureID int16) (uint64, error) {
}

func (f *features) activationHeight(featureID int16) (uint64, error) {
defer f.mu.Unlock()
f.mu.Lock()
if as, ok := f.activationCache[settings.Feature(featureID)]; ok {
if as.activated {
return as.height, nil
Expand Down Expand Up @@ -600,5 +611,7 @@ func (f *features) allFeatures() ([]int16, error) {
}

func (f *features) clearCache() {
f.mu.Lock()
f.activationCache = make(map[settings.Feature]featureActivationState)
f.mu.Unlock()
}

0 comments on commit f85e903

Please sign in to comment.