From 52a0085eb6fd6d61a01350cf00b5bcca40b24480 Mon Sep 17 00:00:00 2001 From: antonijzelinskij Date: Mon, 22 Jul 2024 19:47:30 +0200 Subject: [PATCH 1/7] Added validator exclusion --- .../nova/common/utils/KotlinExt.kt | 4 +- feature-staking-impl/build.gradle | 2 + .../data/validators/KnownNovaValidators.kt | 61 ---------------- .../data/validators/NovaValidatorsApi.kt | 5 +- .../validators/ValidatorsPreferencesRemote.kt | 6 ++ .../validators/ValidatorsPreferencesSource.kt | 71 +++++++++++++++++++ .../di/StakingFeatureModule.kt | 14 ++-- .../parachain/ParachainStakingModule.kt | 4 +- .../recommendations/CollatorRecommendator.kt | 8 +-- .../recommendations/ValidatorRecommender.kt | 2 +- .../ValidatorRecommenderFactory.kt | 12 ++-- .../domain/validators/ValidatorProvider.kt | 15 ++-- .../SearchCustomValidatorsInteractor.kt | 2 +- 13 files changed, 117 insertions(+), 89 deletions(-) delete mode 100644 feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/KnownNovaValidators.kt create mode 100644 feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesRemote.kt create mode 100644 feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt diff --git a/common/src/main/java/io/novafoundation/nova/common/utils/KotlinExt.kt b/common/src/main/java/io/novafoundation/nova/common/utils/KotlinExt.kt index e90cab5b44..4cea3e8b25 100644 --- a/common/src/main/java/io/novafoundation/nova/common/utils/KotlinExt.kt +++ b/common/src/main/java/io/novafoundation/nova/common/utils/KotlinExt.kt @@ -446,9 +446,9 @@ inline fun Iterable.foldToSet(mapper: (T) -> Iterable): Set = fo inline fun Iterable.mapNotNullToSet(mapper: (T) -> R?): Set = mapNotNullTo(mutableSetOf(), mapper) -fun List.indexOfFirstOrNull(predicate: (T) -> Boolean) = indexOfFirst(predicate).takeIf { it >= 0 } +fun Collection.indexOfFirstOrNull(predicate: (T) -> Boolean) = indexOfFirst(predicate).takeIf { it >= 0 } -fun List.indexOfOrNull(value: T) = indexOf(value).takeIf { it >= 0 } +fun Collection.indexOfOrNull(value: T) = indexOf(value).takeIf { it >= 0 } @Suppress("IfThenToElvis") fun ByteArray?.optionalContentEquals(other: ByteArray?): Boolean { diff --git a/feature-staking-impl/build.gradle b/feature-staking-impl/build.gradle index d8831fda10..be08bcf948 100644 --- a/feature-staking-impl/build.gradle +++ b/feature-staking-impl/build.gradle @@ -15,6 +15,7 @@ android { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" buildConfigField "String", "GLOBAL_CONFIG_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/global_config_dev.json\"" + buildConfigField "String", "RECOMMENDED_VALIDATORS_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/nova_validators_dev.json\"" } buildTypes { @@ -23,6 +24,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' buildConfigField "String", "GLOBAL_CONFIG_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/global_config.json\"" + buildConfigField "String", "RECOMMENDED_VALIDATORS_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/nova_validators.json\"" } } diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/KnownNovaValidators.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/KnownNovaValidators.kt deleted file mode 100644 index b5ad74964e..0000000000 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/KnownNovaValidators.kt +++ /dev/null @@ -1,61 +0,0 @@ -package io.novafoundation.nova.feature_staking_impl.data.validators - -import io.novafoundation.nova.common.utils.filterNotNull -import io.novafoundation.nova.runtime.ext.accountIdOf -import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry -import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain -import io.novafoundation.nova.runtime.multiNetwork.chain.model.ChainId -import io.novafoundation.nova.runtime.multiNetwork.chainsById -import io.novasama.substrate_sdk_android.extensions.toHexString -import kotlinx.coroutines.sync.Mutex -import kotlinx.coroutines.sync.withLock - -interface KnownNovaValidators { - - suspend fun getValidatorIds(chainId: ChainId): List -} - -class RemoteKnownNovaValidators( - private val validatorsApi: NovaValidatorsApi, - private val chainRegistry: ChainRegistry, -) : KnownNovaValidators { - - private var validatorsByNetwork: Map>? = null - private val validatorsMutex = Mutex() - - override suspend fun getValidatorIds(chainId: ChainId): List { - return getValidators()[chainId].orEmpty() - } - - private suspend fun getValidators(): Map> { - return validatorsMutex.withLock { - if (validatorsByNetwork == null) { - validatorsByNetwork = fetchValidators() - } - - requireNotNull(validatorsByNetwork) - } - } - - private suspend fun fetchValidators(): Map> { - return runCatching { - val chainsById = chainRegistry.chainsById() - - validatorsApi.getValidators().mapValues { (chainId, addresses) -> - chainsById[chainId]?.let { chain -> - addresses.convertAddressesToAccountIds(chain) - } - }.filterNotNull() - }.getOrDefault(emptyMap()) - } - - private fun List.convertAddressesToAccountIds(chain: Chain): List { - return mapNotNull { - chain.tryConvertAddressToAccountIdHex(it) - } - } - - private fun Chain.tryConvertAddressToAccountIdHex(address: String): String? { - return runCatching { accountIdOf(address).toHexString() }.getOrNull() - } -} diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/NovaValidatorsApi.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/NovaValidatorsApi.kt index 4e17fa9245..01115476bd 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/NovaValidatorsApi.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/NovaValidatorsApi.kt @@ -1,9 +1,10 @@ package io.novafoundation.nova.feature_staking_impl.data.validators +import io.novafoundation.nova.feature_staking_impl.BuildConfig import retrofit2.http.GET interface NovaValidatorsApi { - @GET("https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/nova_validators.json") - suspend fun getValidators(): Map> + @GET(BuildConfig.RECOMMENDED_VALIDATORS_URL) + suspend fun getValidators(): ValidatorsPreferencesRemote } diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesRemote.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesRemote.kt new file mode 100644 index 0000000000..17f7c34c4e --- /dev/null +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesRemote.kt @@ -0,0 +1,6 @@ +package io.novafoundation.nova.feature_staking_impl.data.validators + +class ValidatorsPreferencesRemote( + val preferred: Map>, + val excluded: Map> +) diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt new file mode 100644 index 0000000000..8efa104b09 --- /dev/null +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt @@ -0,0 +1,71 @@ +package io.novafoundation.nova.feature_staking_impl.data.validators + +import io.novafoundation.nova.common.utils.mapNotNullToSet +import io.novafoundation.nova.common.utils.mapValuesNotNull +import io.novafoundation.nova.runtime.ext.accountIdOf +import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain +import io.novafoundation.nova.runtime.multiNetwork.chain.model.ChainId +import io.novafoundation.nova.runtime.multiNetwork.chainsById +import io.novasama.substrate_sdk_android.extensions.toHexString +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock + +interface ValidatorsPreferencesSource { + + suspend fun getValidatorIds(chainId: ChainId): Set + + suspend fun getExcludedValidators(chainId: ChainId): Set +} + +class RemoteValidatorsPreferencesSource( + private val validatorsApi: NovaValidatorsApi, + private val chainRegistry: ChainRegistry, +) : ValidatorsPreferencesSource { + + private var validatorsPreferences: ValidatorsPreferencesRemote? = null + private val validatorsMutex = Mutex() + + override suspend fun getValidatorIds(chainId: ChainId): Set { + return getValidators().preferred[chainId].orEmpty() + } + + override suspend fun getExcludedValidators(chainId: ChainId): Set { + return getValidators().excluded[chainId].orEmpty() + } + + private suspend fun getValidators(): ValidatorsPreferencesRemote { + return validatorsMutex.withLock { + if (validatorsPreferences == null) { + validatorsPreferences = fetchValidators() + } + + requireNotNull(validatorsPreferences) + } + } + + private suspend fun fetchValidators(): ValidatorsPreferencesRemote { + return runCatching { + val chainsById = chainRegistry.chainsById() + val preferences = validatorsApi.getValidators() + val recommended = preferences.preferred.mapValuesNotNull { (chainId, addresses) -> + chainsById[chainId]?.convertAddressesToAccountIds(addresses) + } + val excluded = preferences.excluded.mapValuesNotNull { (chainId, addresses) -> + chainsById[chainId]?.convertAddressesToAccountIds(addresses) + } + + ValidatorsPreferencesRemote(recommended, excluded) + }.getOrDefault(ValidatorsPreferencesRemote(emptyMap(), emptyMap())) + } + + private fun Chain.convertAddressesToAccountIds(addresses: Set): Set { + return addresses.mapNotNullToSet { + this.tryConvertAddressToAccountIdHex(it) + } + } + + private fun Chain.tryConvertAddressToAccountIdHex(address: String): String? { + return runCatching { accountIdOf(address).toHexString() }.getOrNull() + } +} diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/di/StakingFeatureModule.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/di/StakingFeatureModule.kt index 79016e0fd9..492950cbc0 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/di/StakingFeatureModule.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/di/StakingFeatureModule.kt @@ -70,9 +70,9 @@ import io.novafoundation.nova.feature_staking_impl.data.repository.datasource.re import io.novafoundation.nova.feature_staking_impl.data.repository.datasource.reward.PoolStakingRewardsDataSource import io.novafoundation.nova.feature_staking_impl.data.repository.datasource.reward.RealStakingRewardsDataSourceRegistry import io.novafoundation.nova.feature_staking_impl.data.repository.datasource.reward.StakingRewardsDataSourceRegistry -import io.novafoundation.nova.feature_staking_impl.data.validators.KnownNovaValidators +import io.novafoundation.nova.feature_staking_impl.data.validators.ValidatorsPreferencesSource import io.novafoundation.nova.feature_staking_impl.data.validators.NovaValidatorsApi -import io.novafoundation.nova.feature_staking_impl.data.validators.RemoteKnownNovaValidators +import io.novafoundation.nova.feature_staking_impl.data.validators.RemoteValidatorsPreferencesSource import io.novafoundation.nova.feature_staking_impl.di.staking.DefaultBulkRetriever import io.novafoundation.nova.feature_staking_impl.di.staking.PayoutsBulkRetriever import io.novafoundation.nova.feature_staking_impl.domain.StakingInteractor @@ -334,7 +334,7 @@ class StakingFeatureModule { fun provideKnownNovaValidators( novaValidatorsApi: NovaValidatorsApi, chainRegistry: ChainRegistry - ): KnownNovaValidators = RemoteKnownNovaValidators(novaValidatorsApi, chainRegistry) + ): ValidatorsPreferencesSource = RemoteValidatorsPreferencesSource(novaValidatorsApi, chainRegistry) @Provides @FeatureScope @@ -342,8 +342,8 @@ class StakingFeatureModule { validatorProvider: ValidatorProvider, computationalCache: ComputationalCache, sharedState: StakingSharedState, - knownNovaValidators: KnownNovaValidators - ) = ValidatorRecommenderFactory(validatorProvider, sharedState, computationalCache, knownNovaValidators) + validatorsPreferencesSource: ValidatorsPreferencesSource + ) = ValidatorRecommenderFactory(validatorProvider, sharedState, computationalCache, validatorsPreferencesSource) @Provides @FeatureScope @@ -353,14 +353,14 @@ class StakingFeatureModule { rewardCalculatorFactory: RewardCalculatorFactory, stakingConstantsRepository: StakingConstantsRepository, stakingSharedComputation: StakingSharedComputation, - knownNovaValidators: KnownNovaValidators + validatorsPreferencesSource: ValidatorsPreferencesSource ) = ValidatorProvider( stakingRepository = stakingRepository, identityRepository = identityRepository, rewardCalculatorFactory = rewardCalculatorFactory, stakingConstantsRepository = stakingConstantsRepository, stakingSharedComputation = stakingSharedComputation, - knownNovaValidators = knownNovaValidators + validatorsPreferencesSource = validatorsPreferencesSource ) @Provides diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/di/staking/parachain/ParachainStakingModule.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/di/staking/parachain/ParachainStakingModule.kt index 77eab9ede3..782e59ec82 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/di/staking/parachain/ParachainStakingModule.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/di/staking/parachain/ParachainStakingModule.kt @@ -24,7 +24,7 @@ import io.novafoundation.nova.feature_staking_impl.data.parachainStaking.reposit import io.novafoundation.nova.feature_staking_impl.data.parachainStaking.turing.repository.TuringStakingRewardsRepository import io.novafoundation.nova.feature_staking_impl.data.repository.StakingPeriodRepository import io.novafoundation.nova.feature_staking_impl.data.repository.StakingRewardsRepository -import io.novafoundation.nova.feature_staking_impl.data.validators.KnownNovaValidators +import io.novafoundation.nova.feature_staking_impl.data.validators.ValidatorsPreferencesSource import io.novafoundation.nova.feature_staking_impl.di.staking.parachain.start.StartParachainStakingFlowModule import io.novafoundation.nova.feature_staking_impl.di.staking.parachain.turing.TuringStakingModule import io.novafoundation.nova.feature_staking_impl.di.staking.parachain.unbond.ParachainStakingUnbondModule @@ -149,7 +149,7 @@ class ParachainStakingModule { fun provideCollatorRecommendatorFactory( collatorProvider: CollatorProvider, computationalCache: ComputationalCache, - knownNovaCollators: KnownNovaValidators + knownNovaCollators: ValidatorsPreferencesSource ) = CollatorRecommendatorFactory(collatorProvider, computationalCache, knownNovaCollators) @Provides diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/parachainStaking/common/recommendations/CollatorRecommendator.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/parachainStaking/common/recommendations/CollatorRecommendator.kt index 859595fea5..2732a7b731 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/parachainStaking/common/recommendations/CollatorRecommendator.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/parachainStaking/common/recommendations/CollatorRecommendator.kt @@ -4,13 +4,13 @@ import io.novafoundation.nova.common.data.memory.ComputationalCache import io.novafoundation.nova.common.utils.indexOfOrNull import io.novafoundation.nova.feature_staking_impl.data.StakingOption import io.novafoundation.nova.feature_staking_impl.data.chain -import io.novafoundation.nova.feature_staking_impl.data.validators.KnownNovaValidators +import io.novafoundation.nova.feature_staking_impl.data.validators.ValidatorsPreferencesSource import io.novafoundation.nova.feature_staking_impl.domain.parachainStaking.common.CollatorProvider import io.novafoundation.nova.feature_staking_impl.domain.parachainStaking.common.CollatorProvider.CollatorSource import io.novafoundation.nova.feature_staking_impl.domain.parachainStaking.common.model.Collator import kotlinx.coroutines.CoroutineScope -class CollatorRecommendator(private val allCollators: List, private val novaCollatorIds: List) { +class CollatorRecommendator(private val allCollators: List, private val novaCollatorIds: Set) { fun recommendations(config: CollatorRecommendationConfig): List { return allCollators.sortedWith(config.sorting) @@ -29,13 +29,13 @@ private const val COLLATORS_CACHE = "COLLATORS_CACHE" class CollatorRecommendatorFactory( private val collatorProvider: CollatorProvider, private val computationalCache: ComputationalCache, - private val knownNovaValidators: KnownNovaValidators + private val validatorsPreferencesSource: ValidatorsPreferencesSource ) { suspend fun create(stakingOption: StakingOption, scope: CoroutineScope) = computationalCache.useCache(COLLATORS_CACHE, scope) { val collators = collatorProvider.getCollators(stakingOption, CollatorSource.Elected) - val knownNovaCollators = knownNovaValidators.getValidatorIds(stakingOption.chain.id) + val knownNovaCollators = validatorsPreferencesSource.getValidatorIds(stakingOption.chain.id) CollatorRecommendator(collators, knownNovaCollators) } diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt index b6e1029d18..fc035e1fd3 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt @@ -10,7 +10,7 @@ import kotlinx.coroutines.withContext class ValidatorRecommender( val availableValidators: List, - private val novaValidatorIds: List, + private val novaValidatorIds: Set, ) { suspend fun recommendations(settings: RecommendationSettings) = withContext(Dispatchers.Default) { diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt index 3387fca25a..51de514714 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt @@ -3,7 +3,7 @@ package io.novafoundation.nova.feature_staking_impl.domain.recommendations import io.novafoundation.nova.common.data.memory.ComputationalCache import io.novafoundation.nova.feature_staking_impl.data.StakingSharedState import io.novafoundation.nova.feature_staking_impl.data.chain -import io.novafoundation.nova.feature_staking_impl.data.validators.KnownNovaValidators +import io.novafoundation.nova.feature_staking_impl.data.validators.ValidatorsPreferencesSource import io.novafoundation.nova.feature_staking_impl.domain.validators.ValidatorProvider import io.novafoundation.nova.feature_staking_impl.domain.validators.ValidatorSource import io.novafoundation.nova.runtime.state.selectedOption @@ -17,7 +17,7 @@ class ValidatorRecommenderFactory( private val validatorProvider: ValidatorProvider, private val sharedState: StakingSharedState, private val computationalCache: ComputationalCache, - private val knownNovaValidators: KnownNovaValidators, + private val validatorsPreferencesSource: ValidatorsPreferencesSource, ) { suspend fun awaitRecommendatorLoading(scope: CoroutineScope) = withContext(Dispatchers.IO) { @@ -32,9 +32,13 @@ class ValidatorRecommenderFactory( val stakingOption = sharedState.selectedOption() val sources = listOf(ValidatorSource.Elected, ValidatorSource.NovaValidators) + + val excludedValidators = validatorsPreferencesSource.getExcludedValidators(stakingOption.chain.id) + val recommendedValidators = validatorsPreferencesSource.getValidatorIds(stakingOption.chain.id) + val validators = validatorProvider.getValidators(stakingOption, sources, scope) - val knownNovaValidatorIds = knownNovaValidators.getValidatorIds(stakingOption.chain.id) + .filter { it.address !in excludedValidators } - ValidatorRecommender(validators, knownNovaValidatorIds) + ValidatorRecommender(validators, recommendedValidators) } } diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt index af5e116bbc..1301b0dc04 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt @@ -9,7 +9,7 @@ import io.novafoundation.nova.feature_staking_api.domain.model.Exposure import io.novafoundation.nova.feature_staking_api.domain.model.Validator import io.novafoundation.nova.feature_staking_impl.data.StakingOption import io.novafoundation.nova.feature_staking_impl.data.repository.StakingConstantsRepository -import io.novafoundation.nova.feature_staking_impl.data.validators.KnownNovaValidators +import io.novafoundation.nova.feature_staking_impl.data.validators.ValidatorsPreferencesSource import io.novafoundation.nova.feature_staking_impl.domain.common.StakingSharedComputation import io.novafoundation.nova.feature_staking_impl.domain.common.electedExposuresInActiveEra import io.novafoundation.nova.feature_staking_impl.domain.rewards.RewardCalculatorFactory @@ -33,7 +33,7 @@ class ValidatorProvider( private val rewardCalculatorFactory: RewardCalculatorFactory, private val stakingConstantsRepository: StakingConstantsRepository, private val stakingSharedComputation: StakingSharedComputation, - private val knownNovaValidators: KnownNovaValidators, + private val validatorsPreferencesSource: ValidatorsPreferencesSource, ) { suspend fun getValidators( @@ -44,10 +44,12 @@ class ValidatorProvider( val chain = stakingOption.assetWithChain.chain val chainId = chain.id - val novaValidatorIds = knownNovaValidators.getValidatorIds(chainId).toSet() + val novaValidatorIds = validatorsPreferencesSource.getValidatorIds(chainId) + val excludedValidators = validatorsPreferencesSource.getExcludedValidators(chainId) val electedValidatorExposures = stakingSharedComputation.electedExposuresInActiveEra(chainId, scope) val requestedValidatorIds = sources.allValidatorIds(chainId, electedValidatorExposures, novaValidatorIds) + .filter { it !in excludedValidators } // we always need validator prefs for elected validators to construct reward calculator val validatorIdsToQueryPrefs = electedValidatorExposures.keys + requestedValidatorIds @@ -81,7 +83,7 @@ class ValidatorProvider( } } - suspend fun getValidatorWithoutElectedInfo(chainId: ChainId, address: String): Validator { + suspend fun getValidatorWithoutElectedInfo(chainId: ChainId, address: String): Validator? { val accountId = address.toHexAccountId() val accountIdBridged = listOf(accountId) @@ -91,7 +93,10 @@ class ValidatorProvider( val slashes = stakingRepository.getSlashes(chainId, accountIdBridged) - val novaValidatorIds = knownNovaValidators.getValidatorIds(chainId).toSet() + val novaValidatorIds = validatorsPreferencesSource.getValidatorIds(chainId) + val excludedValidators = validatorsPreferencesSource.getExcludedValidators(chainId) + + if (address in excludedValidators) return null return Validator( slashed = slashes.getOrDefault(accountId, false), diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/current/search/SearchCustomValidatorsInteractor.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/current/search/SearchCustomValidatorsInteractor.kt index 27cb750b86..e7a8e44fb0 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/current/search/SearchCustomValidatorsInteractor.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/current/search/SearchCustomValidatorsInteractor.kt @@ -33,7 +33,7 @@ class SearchCustomValidatorsInteractor( if (chain.isValidAddress(query)) { val validator = validatorProvider.getValidatorWithoutElectedInfo(chain.id, query) - if (validator.prefs != null) { + if (validator?.prefs != null) { listOf(validator) } else { emptyList() From a9ecc3da493e31b3cfa6e98c9dbdc6a219e7c50f Mon Sep 17 00:00:00 2001 From: antonijzelinskij Date: Mon, 22 Jul 2024 19:53:12 +0200 Subject: [PATCH 2/7] Clean code --- .../data/validators/ValidatorsPreferencesSource.kt | 8 ++++---- .../common/recommendations/CollatorRecommendator.kt | 2 +- .../domain/recommendations/ValidatorRecommenderFactory.kt | 4 ++-- .../domain/validators/ValidatorProvider.kt | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt index 8efa104b09..f994231a75 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt @@ -13,9 +13,9 @@ import kotlinx.coroutines.sync.withLock interface ValidatorsPreferencesSource { - suspend fun getValidatorIds(chainId: ChainId): Set + suspend fun getRecommendedValidatorIds(chainId: ChainId): Set - suspend fun getExcludedValidators(chainId: ChainId): Set + suspend fun getExcludedValidatorIds(chainId: ChainId): Set } class RemoteValidatorsPreferencesSource( @@ -26,11 +26,11 @@ class RemoteValidatorsPreferencesSource( private var validatorsPreferences: ValidatorsPreferencesRemote? = null private val validatorsMutex = Mutex() - override suspend fun getValidatorIds(chainId: ChainId): Set { + override suspend fun getRecommendedValidatorIds(chainId: ChainId): Set { return getValidators().preferred[chainId].orEmpty() } - override suspend fun getExcludedValidators(chainId: ChainId): Set { + override suspend fun getExcludedValidatorIds(chainId: ChainId): Set { return getValidators().excluded[chainId].orEmpty() } diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/parachainStaking/common/recommendations/CollatorRecommendator.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/parachainStaking/common/recommendations/CollatorRecommendator.kt index 2732a7b731..a7fb342cce 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/parachainStaking/common/recommendations/CollatorRecommendator.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/parachainStaking/common/recommendations/CollatorRecommendator.kt @@ -35,7 +35,7 @@ class CollatorRecommendatorFactory( suspend fun create(stakingOption: StakingOption, scope: CoroutineScope) = computationalCache.useCache(COLLATORS_CACHE, scope) { val collators = collatorProvider.getCollators(stakingOption, CollatorSource.Elected) - val knownNovaCollators = validatorsPreferencesSource.getValidatorIds(stakingOption.chain.id) + val knownNovaCollators = validatorsPreferencesSource.getRecommendedValidatorIds(stakingOption.chain.id) CollatorRecommendator(collators, knownNovaCollators) } diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt index 51de514714..c4aa45224e 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt @@ -33,8 +33,8 @@ class ValidatorRecommenderFactory( val sources = listOf(ValidatorSource.Elected, ValidatorSource.NovaValidators) - val excludedValidators = validatorsPreferencesSource.getExcludedValidators(stakingOption.chain.id) - val recommendedValidators = validatorsPreferencesSource.getValidatorIds(stakingOption.chain.id) + val excludedValidators = validatorsPreferencesSource.getExcludedValidatorIds(stakingOption.chain.id) + val recommendedValidators = validatorsPreferencesSource.getRecommendedValidatorIds(stakingOption.chain.id) val validators = validatorProvider.getValidators(stakingOption, sources, scope) .filter { it.address !in excludedValidators } diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt index 1301b0dc04..d0b781f3e5 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt @@ -44,8 +44,8 @@ class ValidatorProvider( val chain = stakingOption.assetWithChain.chain val chainId = chain.id - val novaValidatorIds = validatorsPreferencesSource.getValidatorIds(chainId) - val excludedValidators = validatorsPreferencesSource.getExcludedValidators(chainId) + val novaValidatorIds = validatorsPreferencesSource.getRecommendedValidatorIds(chainId) + val excludedValidators = validatorsPreferencesSource.getExcludedValidatorIds(chainId) val electedValidatorExposures = stakingSharedComputation.electedExposuresInActiveEra(chainId, scope) val requestedValidatorIds = sources.allValidatorIds(chainId, electedValidatorExposures, novaValidatorIds) @@ -93,8 +93,8 @@ class ValidatorProvider( val slashes = stakingRepository.getSlashes(chainId, accountIdBridged) - val novaValidatorIds = validatorsPreferencesSource.getValidatorIds(chainId) - val excludedValidators = validatorsPreferencesSource.getExcludedValidators(chainId) + val novaValidatorIds = validatorsPreferencesSource.getRecommendedValidatorIds(chainId) + val excludedValidators = validatorsPreferencesSource.getExcludedValidatorIds(chainId) if (address in excludedValidators) return null From 858eca0fe4dbe74b8fe66645823a751960dbc787 Mon Sep 17 00:00:00 2001 From: antonijzelinskij Date: Mon, 22 Jul 2024 21:36:52 +0200 Subject: [PATCH 3/7] Fixed validators url --- feature-staking-impl/build.gradle | 4 ++-- .../data/validators/ValidatorsPreferencesSource.kt | 6 +++--- .../domain/recommendations/ValidatorRecommender.kt | 2 ++ .../recommendations/ValidatorRecommenderFactory.kt | 9 ++++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/feature-staking-impl/build.gradle b/feature-staking-impl/build.gradle index be08bcf948..4ae0c91a04 100644 --- a/feature-staking-impl/build.gradle +++ b/feature-staking-impl/build.gradle @@ -15,7 +15,7 @@ android { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" buildConfigField "String", "GLOBAL_CONFIG_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/global_config_dev.json\"" - buildConfigField "String", "RECOMMENDED_VALIDATORS_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/nova_validators_dev.json\"" + buildConfigField "String", "RECOMMENDED_VALIDATORS_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/validators/v1/nova_validators_dev.json\"" } buildTypes { @@ -24,7 +24,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' buildConfigField "String", "GLOBAL_CONFIG_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/global_config.json\"" - buildConfigField "String", "RECOMMENDED_VALIDATORS_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/nova_validators.json\"" + buildConfigField "String", "RECOMMENDED_VALIDATORS_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/staking/validators/v1/nova_validators.json\"" } } diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt index f994231a75..61341a9e64 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/data/validators/ValidatorsPreferencesSource.kt @@ -40,11 +40,11 @@ class RemoteValidatorsPreferencesSource( validatorsPreferences = fetchValidators() } - requireNotNull(validatorsPreferences) + validatorsPreferences ?: ValidatorsPreferencesRemote(emptyMap(), emptyMap()) } } - private suspend fun fetchValidators(): ValidatorsPreferencesRemote { + private suspend fun fetchValidators(): ValidatorsPreferencesRemote? { return runCatching { val chainsById = chainRegistry.chainsById() val preferences = validatorsApi.getValidators() @@ -56,7 +56,7 @@ class RemoteValidatorsPreferencesSource( } ValidatorsPreferencesRemote(recommended, excluded) - }.getOrDefault(ValidatorsPreferencesRemote(emptyMap(), emptyMap())) + }.getOrNull() } private fun Chain.convertAddressesToAccountIds(addresses: Set): Set { diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt index fc035e1fd3..60ba19c240 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt @@ -11,10 +11,12 @@ import kotlinx.coroutines.withContext class ValidatorRecommender( val availableValidators: List, private val novaValidatorIds: Set, + private val excludedValidators: Set, ) { suspend fun recommendations(settings: RecommendationSettings) = withContext(Dispatchers.Default) { val all = availableValidators.applyFiltersAdaptingToEmptyResult(settings.allFilters) + .filter { it.address !in excludedValidators } .sortedWith(settings.sorting) val postprocessed = settings.postProcessors.fold(all) { acc, postProcessor -> diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt index c4aa45224e..8a29e0f159 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommenderFactory.kt @@ -33,12 +33,11 @@ class ValidatorRecommenderFactory( val sources = listOf(ValidatorSource.Elected, ValidatorSource.NovaValidators) - val excludedValidators = validatorsPreferencesSource.getExcludedValidatorIds(stakingOption.chain.id) - val recommendedValidators = validatorsPreferencesSource.getRecommendedValidatorIds(stakingOption.chain.id) - val validators = validatorProvider.getValidators(stakingOption, sources, scope) - .filter { it.address !in excludedValidators } - ValidatorRecommender(validators, recommendedValidators) + val recommendedValidators = validatorsPreferencesSource.getRecommendedValidatorIds(stakingOption.chain.id) + val excludedValidators = validatorsPreferencesSource.getExcludedValidatorIds(stakingOption.chain.id) + + ValidatorRecommender(validators, recommendedValidators, excludedValidators) } } From 8de3149fd2bc77239eb9ae836c27e8f6b2a4f5df Mon Sep 17 00:00:00 2001 From: antonijzelinskij Date: Mon, 22 Jul 2024 21:39:32 +0200 Subject: [PATCH 4/7] Bump version --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 5cb067f0bc..f9791affae 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ buildscript { ext { // App version - versionName = '8.2.2' - versionCode = 146 + versionName = '8.3.0' + versionCode = 147 applicationId = "io.novafoundation.nova" releaseApplicationSuffix = "market" From d8a31050a77fbf50410fd8e07ace45fdcbe7951a Mon Sep 17 00:00:00 2001 From: antonijzelinskij Date: Tue, 23 Jul 2024 10:39:25 +0200 Subject: [PATCH 5/7] Fixed excluded validators --- .../domain/recommendations/ValidatorRecommender.kt | 8 +++++++- .../recommendations/settings/RecommendationSettings.kt | 1 + .../settings/RecommendationSettingsProvider.kt | 4 +++- .../setupAmount/direct/DirectStakingRecommendation.kt | 2 +- .../domain/validators/ValidatorProvider.kt | 2 -- .../custom/select/SelectCustomValidatorsViewModel.kt | 2 +- .../change/recommended/RecommendedValidatorsViewModel.kt | 2 +- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt index 60ba19c240..e418fdf530 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/ValidatorRecommender.kt @@ -16,7 +16,7 @@ class ValidatorRecommender( suspend fun recommendations(settings: RecommendationSettings) = withContext(Dispatchers.Default) { val all = availableValidators.applyFiltersAdaptingToEmptyResult(settings.allFilters) - .filter { it.address !in excludedValidators } + .filterExcludedIfNeeded(settings) .sortedWith(settings.sorting) val postprocessed = settings.postProcessors.fold(all) { acc, postProcessor -> @@ -52,4 +52,10 @@ class ValidatorRecommender( return filtered } + + private fun List.filterExcludedIfNeeded(settings: RecommendationSettings): List { + if (!settings.filterExcluded) return this + + return filter { it.accountIdHex !in excludedValidators } + } } diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/settings/RecommendationSettings.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/settings/RecommendationSettings.kt index ebd728c889..703cee2386 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/settings/RecommendationSettings.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/settings/RecommendationSettings.kt @@ -21,6 +21,7 @@ data class RecommendationSettings( val customEnabledFilters: List, val postProcessors: List, val sorting: RecommendationSorting, + val filterExcluded: Boolean, val limit: Int? = null ) { diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/settings/RecommendationSettingsProvider.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/settings/RecommendationSettingsProvider.kt index ada660e279..113e569b45 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/settings/RecommendationSettingsProvider.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/recommendations/settings/RecommendationSettingsProvider.kt @@ -56,12 +56,13 @@ class RecommendationSettingsProvider( fun currentSettings() = customSettingsFlow.value - fun defaultSettings(maximumValidatorsPerNominator: Int): RecommendationSettings { + fun recommendedSettings(maximumValidatorsPerNominator: Int): RecommendationSettings { return RecommendationSettings( alwaysEnabledFilters = alwaysEnabledFilters, customEnabledFilters = customizableFilters, sorting = APYSorting, postProcessors = allPostProcessors, + filterExcluded = true, limit = maximumValidatorsPerNominator ) } @@ -71,6 +72,7 @@ class RecommendationSettingsProvider( customEnabledFilters = customizableFilters, sorting = APYSorting, postProcessors = allPostProcessors, + filterExcluded = false, limit = null ) diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/staking/start/setupAmount/direct/DirectStakingRecommendation.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/staking/start/setupAmount/direct/DirectStakingRecommendation.kt index 9b63c831b1..81256962e2 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/staking/start/setupAmount/direct/DirectStakingRecommendation.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/staking/start/setupAmount/direct/DirectStakingRecommendation.kt @@ -30,7 +30,7 @@ class DirectStakingRecommendation( override suspend fun recommendedSelection(stake: Balance): StartMultiStakingSelection { val provider = recommendationSettingsProvider.await() val maximumValidatorsPerNominator = stakingConstantsRepository.maxValidatorsPerNominator(stakingOption.chain.id, stake) - val recommendationSettings = provider.defaultSettings(maximumValidatorsPerNominator) + val recommendationSettings = provider.recommendedSettings(maximumValidatorsPerNominator) val recommendator = recommendator.await() val recommendedValidators = recommendator.recommendations(recommendationSettings) diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt index d0b781f3e5..db6696ab92 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt @@ -45,11 +45,9 @@ class ValidatorProvider( val chainId = chain.id val novaValidatorIds = validatorsPreferencesSource.getRecommendedValidatorIds(chainId) - val excludedValidators = validatorsPreferencesSource.getExcludedValidatorIds(chainId) val electedValidatorExposures = stakingSharedComputation.electedExposuresInActiveEra(chainId, scope) val requestedValidatorIds = sources.allValidatorIds(chainId, electedValidatorExposures, novaValidatorIds) - .filter { it !in excludedValidators } // we always need validator prefs for elected validators to construct reward calculator val validatorIdsToQueryPrefs = electedValidatorExposures.keys + requestedValidatorIds diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/validators/change/custom/select/SelectCustomValidatorsViewModel.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/validators/change/custom/select/SelectCustomValidatorsViewModel.kt index 676068addb..040c4caf3d 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/validators/change/custom/select/SelectCustomValidatorsViewModel.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/validators/change/custom/select/SelectCustomValidatorsViewModel.kt @@ -209,7 +209,7 @@ class SelectCustomValidatorsViewModel( fun fillRestWithRecommended() { mutateSelected { selected -> val maxValidatorsPerNominator = maxSelectedValidatorsFlow.first() - val defaultSettings = recommendationSettingsProvider().defaultSettings(maxValidatorsPerNominator) + val defaultSettings = recommendationSettingsProvider().recommendedSettings(maxValidatorsPerNominator) val recommended = recommendator().recommendations(defaultSettings) val missingFromRecommended = recommended.asSetItems() - selected diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/validators/change/recommended/RecommendedValidatorsViewModel.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/validators/change/recommended/RecommendedValidatorsViewModel.kt index 2fa2e71d1b..f4219e0997 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/validators/change/recommended/RecommendedValidatorsViewModel.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/validators/change/recommended/RecommendedValidatorsViewModel.kt @@ -48,7 +48,7 @@ class RecommendedValidatorsViewModel( } private val recommendedSettings by lazyAsync { - recommendationSettingsProviderFactory.create(scope = viewModelScope).defaultSettings(maxValidatorsPerNominator()) + recommendationSettingsProviderFactory.create(scope = viewModelScope).recommendedSettings(maxValidatorsPerNominator()) } private val recommendedValidators = flow { From 05622afbcdba968061a3c4d1d7e5f2f05cf0ca1d Mon Sep 17 00:00:00 2001 From: antonijzelinskij Date: Tue, 23 Jul 2024 11:17:43 +0200 Subject: [PATCH 6/7] Fixed pr notes --- .../domain/validators/ValidatorProvider.kt | 5 +---- .../current/search/SearchCustomValidatorsInteractor.kt | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt index db6696ab92..2c01a3d0ba 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/ValidatorProvider.kt @@ -81,7 +81,7 @@ class ValidatorProvider( } } - suspend fun getValidatorWithoutElectedInfo(chainId: ChainId, address: String): Validator? { + suspend fun getValidatorWithoutElectedInfo(chainId: ChainId, address: String): Validator { val accountId = address.toHexAccountId() val accountIdBridged = listOf(accountId) @@ -92,9 +92,6 @@ class ValidatorProvider( val slashes = stakingRepository.getSlashes(chainId, accountIdBridged) val novaValidatorIds = validatorsPreferencesSource.getRecommendedValidatorIds(chainId) - val excludedValidators = validatorsPreferencesSource.getExcludedValidatorIds(chainId) - - if (address in excludedValidators) return null return Validator( slashed = slashes.getOrDefault(accountId, false), diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/current/search/SearchCustomValidatorsInteractor.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/current/search/SearchCustomValidatorsInteractor.kt index e7a8e44fb0..27cb750b86 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/current/search/SearchCustomValidatorsInteractor.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/validators/current/search/SearchCustomValidatorsInteractor.kt @@ -33,7 +33,7 @@ class SearchCustomValidatorsInteractor( if (chain.isValidAddress(query)) { val validator = validatorProvider.getValidatorWithoutElectedInfo(chain.id, query) - if (validator?.prefs != null) { + if (validator.prefs != null) { listOf(validator) } else { emptyList() From 628e34bb97827d13dbd98959986dd452cda016bf Mon Sep 17 00:00:00 2001 From: antonijzelinskij Date: Tue, 23 Jul 2024 11:56:17 +0200 Subject: [PATCH 7/7] Update build.gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f9791affae..e89b768888 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ buildscript { ext { // App version versionName = '8.3.0' - versionCode = 147 + versionCode = 148 applicationId = "io.novafoundation.nova" releaseApplicationSuffix = "market"