diff --git a/AElf.All.sln b/AElf.All.sln index 34ad27a9ac..275924af46 100644 --- a/AElf.All.sln +++ b/AElf.All.sln @@ -361,9 +361,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Contracts.NFT", "contr EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Contracts.TestContract.BigIntValue", "test\AElf.Contracts.TestContract.BigIntValue\AElf.Contracts.TestContract.BigIntValue.csproj", "{F50AF512-69E2-46B5-87C6-E058CE2C2D8A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureManager", "src\AElf.Kernel.FeatureManager\AElf.Kernel.FeatureManager.csproj", "{B24BC602-DAFD-4941-A913-8B0725691681}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureManagement", "src\AElf.Kernel.FeatureManagement\AElf.Kernel.FeatureManagement.csproj", "{B24BC602-DAFD-4941-A913-8B0725691681}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureManager.Tests", "test\AElf.Kernel.FeatureManager.Tests\AElf.Kernel.FeatureManager.Tests.csproj", "{1B44277E-74EB-49B2-B8FD-05C29EE51985}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureManagement.Tests", "test\AElf.Kernel.FeatureManagement.Tests\AElf.Kernel.FeatureManagement.Tests.csproj", "{1B44277E-74EB-49B2-B8FD-05C29EE51985}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.CSharp.CodeOps.UnitTests", "test\AElf.CSharp.CodeOps.UnitTests\AElf.CSharp.CodeOps.UnitTests.csproj", "{D1A00CD6-958E-4E9F-8325-354309E3029E}" EndProject @@ -379,11 +379,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Contracts.TestContract EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Contracts.VirtualTransactionEventContract.Tests", "test\AElf.Contracts.VirtualTransactionEventContract.Tests\AElf.Contracts.VirtualTransactionEventContract.Tests.csproj", "{6981684D-450C-412B-9082-0B0A67A679B9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureDisable", "src\AElf.Kernel.FeatureDisable\AElf.Kernel.FeatureDisable.csproj", "{A4ACE6D2-4CF8-4B52-93C9-BB8BEC0C098E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureDisable.Tests", "test\AElf.Kernel.FeatureDisable.Tests\AElf.Kernel.FeatureDisable.Tests.csproj", "{8C0D86A4-D1A7-4B61-AC44-755F5AC75D67}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureDisable.Core", "src\AElf.Kernel.FeatureDisable.Core\AElf.Kernel.FeatureDisable.Core.csproj", "{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureManagement.Core", "src\AElf.Kernel.FeatureManagement.Core\AElf.Kernel.FeatureManagement.Core.csproj", "{EB2EE653-B268-481B-9C5A-096E939E07E1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -1095,18 +1091,10 @@ Global {6981684D-450C-412B-9082-0B0A67A679B9}.Debug|Any CPU.Build.0 = Debug|Any CPU {6981684D-450C-412B-9082-0B0A67A679B9}.Release|Any CPU.ActiveCfg = Release|Any CPU {6981684D-450C-412B-9082-0B0A67A679B9}.Release|Any CPU.Build.0 = Release|Any CPU - {A4ACE6D2-4CF8-4B52-93C9-BB8BEC0C098E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A4ACE6D2-4CF8-4B52-93C9-BB8BEC0C098E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A4ACE6D2-4CF8-4B52-93C9-BB8BEC0C098E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A4ACE6D2-4CF8-4B52-93C9-BB8BEC0C098E}.Release|Any CPU.Build.0 = Release|Any CPU - {8C0D86A4-D1A7-4B61-AC44-755F5AC75D67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8C0D86A4-D1A7-4B61-AC44-755F5AC75D67}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8C0D86A4-D1A7-4B61-AC44-755F5AC75D67}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8C0D86A4-D1A7-4B61-AC44-755F5AC75D67}.Release|Any CPU.Build.0 = Release|Any CPU - {659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Release|Any CPU.Build.0 = Release|Any CPU + {EB2EE653-B268-481B-9C5A-096E939E07E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB2EE653-B268-481B-9C5A-096E939E07E1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB2EE653-B268-481B-9C5A-096E939E07E1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB2EE653-B268-481B-9C5A-096E939E07E1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1298,8 +1286,6 @@ Global {64498F8C-B827-4E1C-B5FB-4B9188C839A8} = {D3950CC9-808F-4ED8-946A-79A992F3F8EF} {0F10B838-C363-4F55-A5BB-B7F9F80565AB} = {D3950CC9-808F-4ED8-946A-79A992F3F8EF} {6981684D-450C-412B-9082-0B0A67A679B9} = {D3950CC9-808F-4ED8-946A-79A992F3F8EF} - {A4ACE6D2-4CF8-4B52-93C9-BB8BEC0C098E} = {90B310B4-C2DB-419E-B5EE-97FA096B62CC} - {8C0D86A4-D1A7-4B61-AC44-755F5AC75D67} = {4E54480A-D155-43ED-9736-1A5BE7957211} - {659A7C7A-44C9-424E-B4F6-D1D3656F7AD4} = {90B310B4-C2DB-419E-B5EE-97FA096B62CC} + {EB2EE653-B268-481B-9C5A-096E939E07E1} = {90B310B4-C2DB-419E-B5EE-97FA096B62CC} EndGlobalSection EndGlobal diff --git a/AElf.sln b/AElf.sln index 9584d4d06e..6af24b2e20 100644 --- a/AElf.sln +++ b/AElf.sln @@ -37,7 +37,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.Consensus.Sched EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.Consensus.Scheduler.RxNet", "src\AElf.Kernel.Consensus.Scheduler.RxNet\AElf.Kernel.Consensus.Scheduler.RxNet.csproj", "{0396B229-C6D6-4CCC-BCD2-0158A93193D3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureManager", "src\AElf.Kernel.FeatureManager\AElf.Kernel.FeatureManager.csproj", "{CFDA6378-7EA0-4DAB-BE1F-CE10E0072718}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureManagement", "src\AElf.Kernel.FeatureManagement\AElf.Kernel.FeatureManagement.csproj", "{CFDA6378-7EA0-4DAB-BE1F-CE10E0072718}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeeCalculation", "src\AElf.Kernel.FeeCalculation\AElf.Kernel.FeeCalculation.csproj", "{7308E633-AA3E-4CB9-87BE-E4345562C45C}" EndProject @@ -157,7 +157,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.Consensus.AEDPo EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.Consensus.Tests", "test\AElf.Kernel.Consensus.Tests\AElf.Kernel.Consensus.Tests.csproj", "{D2F63569-51D7-449D-A632-8DD7B5DA5378}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureManager.Tests", "test\AElf.Kernel.FeatureManager.Tests\AElf.Kernel.FeatureManager.Tests.csproj", "{BEDA2B8B-3C65-4C74-8650-1A208A7B1300}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureManagement.Tests", "test\AElf.Kernel.FeatureManagement.Tests\AElf.Kernel.FeatureManagement.Tests.csproj", "{BEDA2B8B-3C65-4C74-8650-1A208A7B1300}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.WebApp.Application.Chain.Tests", "test\AElf.WebApp.Application.Chain.Tests\AElf.WebApp.Application.Chain.Tests.csproj", "{5198D134-A58C-417F-946E-8D6CEB410991}" EndProject diff --git a/src/AElf.ContractTestKit.AEDPoSExtension/UnitTestPlainTransactionExecutingService.cs b/src/AElf.ContractTestKit.AEDPoSExtension/UnitTestPlainTransactionExecutingService.cs index 37f1b50c43..3657274d21 100644 --- a/src/AElf.ContractTestKit.AEDPoSExtension/UnitTestPlainTransactionExecutingService.cs +++ b/src/AElf.ContractTestKit.AEDPoSExtension/UnitTestPlainTransactionExecutingService.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; using AElf.Kernel; -using AElf.Kernel.FeatureDisable.Core; +using AElf.Kernel.FeatureManagement.Core; using AElf.Kernel.SmartContract; using AElf.Kernel.SmartContract.Application; using AElf.Kernel.SmartContractExecution.Events; @@ -13,8 +13,8 @@ public class UnitTestPlainTransactionExecutingService : PlainTransactionExecutin { public UnitTestPlainTransactionExecutingService(ISmartContractExecutiveService smartContractExecutiveService, IEnumerable postPlugins, IEnumerable prePlugins, - ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) : base( - smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService) + ITransactionContextFactory transactionContextFactory, IFeatureManagementService featureManagementService) : base( + smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureManagementService) { } diff --git a/src/AElf.Kernel.FeatureDisable.Core/FeatureDisableConstants.cs b/src/AElf.Kernel.FeatureDisable.Core/FeatureDisableConstants.cs deleted file mode 100644 index 84ce24c6fa..0000000000 --- a/src/AElf.Kernel.FeatureDisable.Core/FeatureDisableConstants.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace AElf.Kernel.FeatureDisable.Core; - -public class FeatureDisableConstants -{ - public const string FeatureDisableConfigurationName = "DisableFeatureNameList"; -} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureDisable.Core/IFeatureDisableService.cs b/src/AElf.Kernel.FeatureDisable.Core/IFeatureDisableService.cs deleted file mode 100644 index 0131adc57b..0000000000 --- a/src/AElf.Kernel.FeatureDisable.Core/IFeatureDisableService.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Volo.Abp.DependencyInjection; - -namespace AElf.Kernel.FeatureDisable.Core; - -public interface IFeatureDisableService -{ - Task IsFeatureDisabledAsync(params string[] featureNames); -} - -public class DefaultFeatureDisableService : IFeatureDisableService, ITransientDependency -{ - public Task IsFeatureDisabledAsync(params string[] featureNames) - { - return Task.FromResult(false); - } -} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureDisable/AElf.Kernel.FeatureDisable.csproj b/src/AElf.Kernel.FeatureDisable/AElf.Kernel.FeatureDisable.csproj deleted file mode 100644 index fae7fc0cdf..0000000000 --- a/src/AElf.Kernel.FeatureDisable/AElf.Kernel.FeatureDisable.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - - - diff --git a/src/AElf.Kernel.FeatureDisable/DisableFeatureOptions.cs b/src/AElf.Kernel.FeatureDisable/DisableFeatureOptions.cs deleted file mode 100644 index f5968ba95a..0000000000 --- a/src/AElf.Kernel.FeatureDisable/DisableFeatureOptions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace AElf.Kernel.FeatureDisable; - -public class DisableFeatureOptions -{ - public List FeatureNameList { get; set; } -} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureDisable/FeatureDisableAElfModule.cs b/src/AElf.Kernel.FeatureDisable/FeatureDisableAElfModule.cs deleted file mode 100644 index 705246e612..0000000000 --- a/src/AElf.Kernel.FeatureDisable/FeatureDisableAElfModule.cs +++ /dev/null @@ -1,15 +0,0 @@ -using AElf.Kernel.Configuration; -using AElf.Kernel.FeatureDisable.Core; -using AElf.Modularity; -using Volo.Abp.Modularity; - -namespace AElf.Kernel.FeatureDisable; - -[DependsOn(typeof(FeatureDisableCoreAElfModule), - typeof(ConfigurationAElfModule))] -public class FeatureDisableAElfModule : AElfModule -{ - public override void ConfigureServices(ServiceConfigurationContext context) - { - } -} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureDisable/FeatureDisableService.cs b/src/AElf.Kernel.FeatureDisable/FeatureDisableService.cs deleted file mode 100644 index 2ac30dbe73..0000000000 --- a/src/AElf.Kernel.FeatureDisable/FeatureDisableService.cs +++ /dev/null @@ -1,41 +0,0 @@ -using AElf.Kernel.Blockchain.Application; -using AElf.Kernel.FeatureDisable.Core; -using Volo.Abp.DependencyInjection; - -namespace AElf.Kernel.FeatureDisable; - -public class FeatureDisableService : IFeatureDisableService, ITransientDependency -{ - private readonly IDisabledFeatureListProvider _disabledFeatureListProvider; - private readonly IBlockchainService _blockchainService; - - public FeatureDisableService(IDisabledFeatureListProvider disabledFeatureListProvider, - IBlockchainService blockchainService) - { - _disabledFeatureListProvider = disabledFeatureListProvider; - _blockchainService = blockchainService; - } - - public async Task IsFeatureDisabledAsync(params string[] featureNames) - { - var chain = await _blockchainService.GetChainAsync(); - if (chain == null || chain.BestChainHeight <= 1) - { - // Which means chain hasn't been created yet or only genesis block exists. - return false; - } - - var nameList = await _disabledFeatureListProvider.GetDisabledFeatureListAsync(new BlockIndex - { - BlockHash = chain.BestChainHash, - BlockHeight = chain.BestChainHeight - }); - if (nameList.Length == 0) - { - return false; - } - - var isDisabled = nameList.Select(n => n.Trim()).Intersect(featureNames).Any(); - return isDisabled; - } -} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureDisable.Core/AElf.Kernel.FeatureDisable.Core.csproj b/src/AElf.Kernel.FeatureManagement.Core/AElf.Kernel.FeatureManagement.Core.csproj similarity index 67% rename from src/AElf.Kernel.FeatureDisable.Core/AElf.Kernel.FeatureDisable.Core.csproj rename to src/AElf.Kernel.FeatureManagement.Core/AElf.Kernel.FeatureManagement.Core.csproj index 7b39f518d5..8ae10ac224 100644 --- a/src/AElf.Kernel.FeatureDisable.Core/AElf.Kernel.FeatureDisable.Core.csproj +++ b/src/AElf.Kernel.FeatureManagement.Core/AElf.Kernel.FeatureManagement.Core.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -7,7 +7,7 @@ - + diff --git a/src/AElf.Kernel.FeatureManagement.Core/FeatureManagementConstants.cs b/src/AElf.Kernel.FeatureManagement.Core/FeatureManagementConstants.cs new file mode 100644 index 0000000000..1abb74cc4a --- /dev/null +++ b/src/AElf.Kernel.FeatureManagement.Core/FeatureManagementConstants.cs @@ -0,0 +1,7 @@ +namespace AElf.Kernel.FeatureManagement; + +public class FeatureManagementConstants +{ + public const string FeatureConfigurationNamePrefix = "AElfFeature_"; + public const string FeatureDisableConfigurationName = "DisableFeatureNameList"; +} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureDisable.Core/FeatureDisableCoreAElfModule.cs b/src/AElf.Kernel.FeatureManagement.Core/FeatureManagementCoreAElfModule.cs similarity index 59% rename from src/AElf.Kernel.FeatureDisable.Core/FeatureDisableCoreAElfModule.cs rename to src/AElf.Kernel.FeatureManagement.Core/FeatureManagementCoreAElfModule.cs index c9e524ec01..a3669e0415 100644 --- a/src/AElf.Kernel.FeatureDisable.Core/FeatureDisableCoreAElfModule.cs +++ b/src/AElf.Kernel.FeatureManagement.Core/FeatureManagementCoreAElfModule.cs @@ -1,9 +1,9 @@ using AElf.Modularity; using Volo.Abp.Modularity; -namespace AElf.Kernel.FeatureDisable.Core; +namespace AElf.Kernel.FeatureManagement.Core; -public class FeatureDisableCoreAElfModule : AElfModule +public class FeatureManagementCoreAElfModule : AElfModule { public override void ConfigureServices(ServiceConfigurationContext context) { diff --git a/src/AElf.Kernel.FeatureManagement.Core/IFeatureManagementService.cs b/src/AElf.Kernel.FeatureManagement.Core/IFeatureManagementService.cs new file mode 100644 index 0000000000..6317046a08 --- /dev/null +++ b/src/AElf.Kernel.FeatureManagement.Core/IFeatureManagementService.cs @@ -0,0 +1,22 @@ +using Volo.Abp.DependencyInjection; + +namespace AElf.Kernel.FeatureManagement.Core; + +public interface IFeatureManagementService +{ + Task IsFeatureActive(string featureName); + Task IsFeatureDisabledAsync(params string[] featureNames); +} + +public class DefaultFeatureManagementService : IFeatureManagementService, ITransientDependency +{ + public Task IsFeatureActive(string featureName) + { + return Task.FromResult(false); + } + + public Task IsFeatureDisabledAsync(params string[] featureNames) + { + return Task.FromResult(false); + } +} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureManager/AElf.Kernel.FeatureManager.csproj b/src/AElf.Kernel.FeatureManagement/AElf.Kernel.FeatureManagement.csproj similarity index 72% rename from src/AElf.Kernel.FeatureManager/AElf.Kernel.FeatureManager.csproj rename to src/AElf.Kernel.FeatureManagement/AElf.Kernel.FeatureManagement.csproj index 20260d21b7..a8774c8deb 100644 --- a/src/AElf.Kernel.FeatureManager/AElf.Kernel.FeatureManager.csproj +++ b/src/AElf.Kernel.FeatureManagement/AElf.Kernel.FeatureManagement.csproj @@ -3,13 +3,14 @@ net8.0 latest - AElf.Kernel.FeatureManager + AElf.Kernel.FeatureManagement true Module that contains code to enable or disable new features of AElf. + diff --git a/src/AElf.Kernel.FeatureDisable/FeatureDisableConfigurationProcessor.cs b/src/AElf.Kernel.FeatureManagement/FeatureDisableConfigurationProcessor.cs similarity index 82% rename from src/AElf.Kernel.FeatureDisable/FeatureDisableConfigurationProcessor.cs rename to src/AElf.Kernel.FeatureManagement/FeatureDisableConfigurationProcessor.cs index 1adb8c45a9..79cefeb915 100644 --- a/src/AElf.Kernel.FeatureDisable/FeatureDisableConfigurationProcessor.cs +++ b/src/AElf.Kernel.FeatureManagement/FeatureDisableConfigurationProcessor.cs @@ -1,10 +1,10 @@ +using System.Threading.Tasks; using AElf.Kernel.Configuration; -using AElf.Kernel.FeatureDisable.Core; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; using Volo.Abp.DependencyInjection; -namespace AElf.Kernel.FeatureDisable; +namespace AElf.Kernel.FeatureManagement; public class FeatureDisableConfigurationProcessor : IConfigurationProcessor, ITransientDependency { @@ -15,7 +15,7 @@ public FeatureDisableConfigurationProcessor(IDisabledFeatureListProvider disable _disabledFeatureListProvider = disabledFeatureListProvider; } - public string ConfigurationName => FeatureDisableConstants.FeatureDisableConfigurationName; + public string ConfigurationName => FeatureManagementConstants.FeatureDisableConfigurationName; public async Task ProcessConfigurationAsync(ByteString byteString, BlockIndex blockIndex) { diff --git a/src/AElf.Kernel.FeatureManagement/FeatureManagementAElfModule.cs b/src/AElf.Kernel.FeatureManagement/FeatureManagementAElfModule.cs new file mode 100644 index 0000000000..87aeeb8bd4 --- /dev/null +++ b/src/AElf.Kernel.FeatureManagement/FeatureManagementAElfModule.cs @@ -0,0 +1,14 @@ +using AElf.Kernel.Configuration; +using AElf.Kernel.FeatureManagement.Core; +using AElf.Modularity; +using Volo.Abp.Modularity; + +namespace AElf.Kernel.FeatureManagement; + +[DependsOn( + typeof(FeatureManagementCoreAElfModule), + typeof(ConfigurationAElfModule) +)] +public class FeatureManagementAElfModule : AElfModule +{ +} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureManagement/FeatureManagementOptions.cs b/src/AElf.Kernel.FeatureManagement/FeatureManagementOptions.cs new file mode 100644 index 0000000000..4405d239e8 --- /dev/null +++ b/src/AElf.Kernel.FeatureManagement/FeatureManagementOptions.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; + +namespace AElf.Kernel.FeatureManagement; + +public class FeatureManagementOptions +{ + public List DisableFeatureNameList { get; set; } +} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureManagement/FeatureManagementService.cs b/src/AElf.Kernel.FeatureManagement/FeatureManagementService.cs new file mode 100644 index 0000000000..c485b66aa4 --- /dev/null +++ b/src/AElf.Kernel.FeatureManagement/FeatureManagementService.cs @@ -0,0 +1,70 @@ +using System.Linq; +using System.Threading.Tasks; +using AElf.Kernel.Blockchain.Application; +using AElf.Kernel.Configuration; +using AElf.Kernel.FeatureManagement.Core; +using Google.Protobuf; +using Google.Protobuf.WellKnownTypes; +using Volo.Abp.DependencyInjection; + +namespace AElf.Kernel.FeatureManagement; + +public class FeatureManagementService : IFeatureManagementService, ITransientDependency +{ + private readonly IBlockchainService _blockchainService; + private readonly IConfigurationService _configurationService; + private readonly IDisabledFeatureListProvider _disabledFeatureListProvider; + + public FeatureManagementService(IConfigurationService configurationService, IBlockchainService blockchainService, + IDisabledFeatureListProvider disabledFeatureListProvider) + { + _configurationService = configurationService; + _blockchainService = blockchainService; + _disabledFeatureListProvider = disabledFeatureListProvider; + } + + public async Task IsFeatureActive(string featureName) + { + var featureConfigurationName = GetFeatureConfigurationName(featureName); + var chain = await _blockchainService.GetChainAsync(); + var activeHeightByteString = await _configurationService.GetConfigurationDataAsync(featureConfigurationName, + new ChainContext + { + BlockHeight = chain.BestChainHeight, + BlockHash = chain.BestChainHash + }); + var activeHeight = new Int64Value(); + activeHeight.MergeFrom(activeHeightByteString); + if (activeHeight.Value == 0) return false; + + return chain.BestChainHeight >= activeHeight.Value; + } + + private string GetFeatureConfigurationName(string featureName) + { + return $"{FeatureManagementConstants.FeatureConfigurationNamePrefix}{featureName}"; + } + + public async Task IsFeatureDisabledAsync(params string[] featureNames) + { + var chain = await _blockchainService.GetChainAsync(); + if (chain == null || chain.BestChainHeight <= 1) + { + // Which means chain hasn't been created yet or only genesis block exists. + return false; + } + + var nameList = await _disabledFeatureListProvider.GetDisabledFeatureListAsync(new BlockIndex + { + BlockHash = chain.BestChainHash, + BlockHeight = chain.BestChainHeight + }); + if (nameList.Length == 0) + { + return false; + } + + var isDisabled = nameList.Select(n => n.Trim()).Intersect(featureNames).Any(); + return isDisabled; + } +} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureDisable/IDisabledFeatureListProvider.cs b/src/AElf.Kernel.FeatureManagement/IDisabledFeatureListProvider.cs similarity index 95% rename from src/AElf.Kernel.FeatureDisable/IDisabledFeatureListProvider.cs rename to src/AElf.Kernel.FeatureManagement/IDisabledFeatureListProvider.cs index 36b05ecad1..960c8881cb 100644 --- a/src/AElf.Kernel.FeatureDisable/IDisabledFeatureListProvider.cs +++ b/src/AElf.Kernel.FeatureManagement/IDisabledFeatureListProvider.cs @@ -1,10 +1,12 @@ +using System; +using System.Threading.Tasks; using AElf.Kernel.SmartContract.Application; using Google.Protobuf.WellKnownTypes; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.DependencyInjection; -namespace AElf.Kernel.FeatureDisable; +namespace AElf.Kernel.FeatureManagement; public interface IDisabledFeatureListProvider { diff --git a/src/AElf.Kernel.FeatureManager/FeatureActiveService.cs b/src/AElf.Kernel.FeatureManager/FeatureActiveService.cs deleted file mode 100644 index b8912e62dc..0000000000 --- a/src/AElf.Kernel.FeatureManager/FeatureActiveService.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Threading.Tasks; -using AElf.Kernel.Blockchain.Application; -using AElf.Kernel.Configuration; -using Google.Protobuf; -using Google.Protobuf.WellKnownTypes; -using Volo.Abp.DependencyInjection; - -namespace AElf.Kernel.FeatureManager; - -public class FeatureActiveService : IFeatureActiveService, ITransientDependency -{ - private readonly IBlockchainService _blockchainService; - private readonly IConfigurationService _configurationService; - - public FeatureActiveService(IConfigurationService configurationService, IBlockchainService blockchainService) - { - _configurationService = configurationService; - _blockchainService = blockchainService; - } - - public async Task IsFeatureActive(string featureName) - { - var featureConfigurationName = GetFeatureConfigurationName(featureName); - var chain = await _blockchainService.GetChainAsync(); - var activeHeightByteString = await _configurationService.GetConfigurationDataAsync(featureConfigurationName, - new ChainContext - { - BlockHeight = chain.BestChainHeight, - BlockHash = chain.BestChainHash - }); - var activeHeight = new Int64Value(); - activeHeight.MergeFrom(activeHeightByteString); - if (activeHeight.Value == 0) return false; - - return chain.BestChainHeight >= activeHeight.Value; - } - - private string GetFeatureConfigurationName(string featureName) - { - return $"{FeatureManagerConstants.FeatureConfigurationNamePrefix}{featureName}"; - } -} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs b/src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs deleted file mode 100644 index ce74c7f47e..0000000000 --- a/src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using AElf.Kernel.Configuration; -using AElf.Modularity; -using Volo.Abp.Modularity; - -namespace AElf.Kernel.FeatureManager; - -[DependsOn( - typeof(ConfigurationAElfModule) -)] -public class FeatureManagerAElfModule : AElfModule -{ -} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureManager/FeatureManagerConstants.cs b/src/AElf.Kernel.FeatureManager/FeatureManagerConstants.cs deleted file mode 100644 index b433ec58bf..0000000000 --- a/src/AElf.Kernel.FeatureManager/FeatureManagerConstants.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace AElf.Kernel.FeatureManager; - -public class FeatureManagerConstants -{ - public const string FeatureConfigurationNamePrefix = "AElfFeature_"; -} \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureManager/IFeatureActiveService.cs b/src/AElf.Kernel.FeatureManager/IFeatureActiveService.cs deleted file mode 100644 index c2f6c2febb..0000000000 --- a/src/AElf.Kernel.FeatureManager/IFeatureActiveService.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Threading.Tasks; - -namespace AElf.Kernel.FeatureManager; - -public interface IFeatureActiveService -{ - Task IsFeatureActive(string featureName); -} \ No newline at end of file diff --git a/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj b/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj index ab2cf443cf..cb3ea88f56 100644 --- a/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj +++ b/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/AElf.Kernel.SmartContract/Application/PlainTransactionExecutingService.cs b/src/AElf.Kernel.SmartContract/Application/PlainTransactionExecutingService.cs index 79b09034f9..29b7d0262d 100644 --- a/src/AElf.Kernel.SmartContract/Application/PlainTransactionExecutingService.cs +++ b/src/AElf.Kernel.SmartContract/Application/PlainTransactionExecutingService.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using AElf.Kernel.FeatureDisable.Core; +using AElf.Kernel.FeatureManagement.Core; using AElf.Kernel.SmartContract.Domain; using AElf.Kernel.SmartContract.Infrastructure; using AElf.Types; @@ -22,15 +22,15 @@ public class PlainTransactionExecutingService : IPlainTransactionExecutingServic private readonly List _prePlugins; private readonly ISmartContractExecutiveService _smartContractExecutiveService; private readonly ITransactionContextFactory _transactionContextFactory; - private readonly IFeatureDisableService _featureDisableService; + private readonly IFeatureManagementService _featureManagementService; public PlainTransactionExecutingService(ISmartContractExecutiveService smartContractExecutiveService, IEnumerable postPlugins, IEnumerable prePlugins, - ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) + ITransactionContextFactory transactionContextFactory, IFeatureManagementService featureManagementService) { _smartContractExecutiveService = smartContractExecutiveService; _transactionContextFactory = transactionContextFactory; - _featureDisableService = featureDisableService; + _featureManagementService = featureManagementService; _prePlugins = GetUniquePlugins(prePlugins); _postPlugins = GetUniquePlugins(postPlugins); Logger = NullLogger.Instance; @@ -253,7 +253,7 @@ private async Task ExecutePluginOnPreTransactionStageAsync(IExecutive exec TieredStateCache internalStateCache, CancellationToken cancellationToken) { - if (await _featureDisableService.IsFeatureDisabledAsync("TxPlugin", "PrePlugin")) + if (await _featureManagementService.IsFeatureDisabledAsync("TxPlugin", "PrePlugin")) { return true; } @@ -304,7 +304,7 @@ private async Task ExecutePluginOnPostTransactionStageAsync(IExecutive exe TieredStateCache internalStateCache, CancellationToken cancellationToken) { - if (await _featureDisableService.IsFeatureDisabledAsync("TxPlugin", "PostPlugin")) + if (await _featureManagementService.IsFeatureDisabledAsync("TxPlugin", "PostPlugin")) { return true; } diff --git a/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs b/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs index 670ee60cdb..609500e02e 100644 --- a/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs +++ b/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs @@ -1,4 +1,5 @@ -using AElf.Kernel.FeatureDisable.Core; +using AElf.Kernel.FeatureManagement; +using AElf.Kernel.FeatureManagement.Core; using AElf.Kernel.SmartContract.Application; using AElf.Kernel.SmartContract.Infrastructure; using AElf.Modularity; @@ -8,7 +9,7 @@ namespace AElf.Kernel.SmartContract; [DependsOn(typeof(CoreKernelAElfModule), - typeof(FeatureDisableCoreAElfModule))] + typeof(FeatureManagementCoreAElfModule))] public class SmartContractAElfModule : AElfModule { public override void ConfigureServices(ServiceConfigurationContext context) diff --git a/src/AElf.Kernel/AElf.Kernel.csproj b/src/AElf.Kernel/AElf.Kernel.csproj index d45c62fa75..a00dd93ebb 100644 --- a/src/AElf.Kernel/AElf.Kernel.csproj +++ b/src/AElf.Kernel/AElf.Kernel.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/AElf.Kernel/KernelAElfModule.cs b/src/AElf.Kernel/KernelAElfModule.cs index 5e27d0dd72..99cd4c8a7e 100644 --- a/src/AElf.Kernel/KernelAElfModule.cs +++ b/src/AElf.Kernel/KernelAElfModule.cs @@ -1,6 +1,6 @@ using AElf.Kernel.ChainController; using AElf.Kernel.Configuration; -using AElf.Kernel.FeatureDisable; +using AElf.Kernel.FeatureManagement; using AElf.Kernel.Miner; using AElf.Kernel.Node; using AElf.Kernel.Proposal; @@ -18,7 +18,7 @@ namespace AElf.Kernel; typeof(CoreKernelAElfModule), typeof(ChainControllerAElfModule), typeof(SmartContractAElfModule), - typeof(FeatureDisableAElfModule), + typeof(FeatureManagementAElfModule), typeof(NodeAElfModule), typeof(SmartContractExecutionAElfModule), typeof(TransactionPoolAElfModule), diff --git a/test/AElf.Kernel.FeatureDisable.Tests/AElf.Kernel.FeatureDisable.Tests.csproj b/test/AElf.Kernel.FeatureDisable.Tests/AElf.Kernel.FeatureDisable.Tests.csproj deleted file mode 100644 index b4e597e5e3..0000000000 --- a/test/AElf.Kernel.FeatureDisable.Tests/AElf.Kernel.FeatureDisable.Tests.csproj +++ /dev/null @@ -1,85 +0,0 @@ - - - - net8.0 - enable - enable - false - AElf.Kernel.FeatureDisable.Tests - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - false - Contract - PreserveNewest - - - false - Contract - PreserveNewest - - - False - Contract - PreserveNewest - - - - - - - - - Protobuf\Proto\authority_info.proto - - - - - Protobuf\Proto\acs3.proto - - - Protobuf\Proto\acs4.proto - - - Protobuf\Proto\acs6.proto - - - Protobuf\Proto\reference\acs10.proto - - - Protobuf\Proto\reference\acs11.proto - - - - - Protobuf\Proto\aedpos_contract.proto - - - Protobuf\Proto\aedpos_contract_impl.proto - - - Protobuf\Proto\parliament_contract.proto - - - Protobuf\Proto\parliament_contract_impl.proto - - - Protobuf\Proto\configuration_contract.proto - - - - diff --git a/test/AElf.Kernel.FeatureDisable.Tests/FeatureDisableTest.cs b/test/AElf.Kernel.FeatureDisable.Tests/FeatureDisableTest.cs deleted file mode 100644 index 2343599aeb..0000000000 --- a/test/AElf.Kernel.FeatureDisable.Tests/FeatureDisableTest.cs +++ /dev/null @@ -1,55 +0,0 @@ -using AElf.Contracts.Configuration; -using AElf.CSharp.Core.Extension; -using AElf.Kernel.Blockchain.Application; -using AElf.Kernel.FeatureDisable.Core; -using AElf.Standards.ACS3; -using AElf.TestBase; -using Google.Protobuf; -using Google.Protobuf.WellKnownTypes; -using Shouldly; -using Xunit; - -namespace AElf.Kernel.FeatureDisable.Tests; - -public class FeatureDisableTest : KernelFeatureDisableTestBase -{ - private readonly IMockService _mockService; - private readonly IBlockchainService _blockchainService; - - public FeatureDisableTest() - { - _mockService = GetRequiredService(); - _blockchainService = GetRequiredService(); - } - - [Fact] - public async Task IsFeatureDisabledTest() - { - await DeployContractsAsync(); - await ConfigDisabledFeaturesAsync("FeatureA, FeatureB, FeatureBAndC"); - (await _mockService.IsFeatureADisabledAsync()).ShouldBeTrue(); - (await _mockService.IsFeatureBDisabledAsync()).ShouldBeTrue(); - (await _mockService.IsFeatureCDisabledAsync()).ShouldBeTrue(); - (await _mockService.IsFeatureDDisabledAsync()).ShouldBeFalse(); - } - - private async Task ConfigDisabledFeaturesAsync(string disableFeatureNames) - { - var chain = await _blockchainService.GetChainAsync(); - await _blockchainService.SetIrreversibleBlockAsync(chain, chain.BestChainHeight, chain.BestChainHash); - var proposalId = (await ParliamentContractStub.CreateProposal.SendAsync(new CreateProposalInput - { - ContractMethodName = "SetConfiguration", - ExpiredTime = TimestampHelper.GetUtcNow().AddDays(1), - Params = new SetConfigurationInput - { - Key = FeatureDisableConstants.FeatureDisableConfigurationName, - Value = new StringValue { Value = disableFeatureNames }.ToByteString() - }.ToByteString(), - ToAddress = ConfigurationContractAddress, - OrganizationAddress = await ParliamentContractStub.GetDefaultOrganizationAddress.CallAsync(new Empty()) - })).Output; - await ParliamentContractStub.Approve.SendAsync(proposalId); - await ParliamentContractStub.Release.SendAsync(proposalId); - } -} \ No newline at end of file diff --git a/test/AElf.Kernel.FeatureDisable.Tests/FeatureDisableTestModule.cs b/test/AElf.Kernel.FeatureDisable.Tests/FeatureDisableTestModule.cs deleted file mode 100644 index 63bd29b6ee..0000000000 --- a/test/AElf.Kernel.FeatureDisable.Tests/FeatureDisableTestModule.cs +++ /dev/null @@ -1,25 +0,0 @@ -using AElf.ContractTestKit; -using AElf.Kernel.SmartContract; -using AElf.Kernel.SmartContract.Application; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Volo.Abp.Modularity; - -namespace AElf.Kernel.FeatureDisable.Tests; - -[DependsOn( - typeof(ContractTestModule), - typeof(FeatureDisableAElfModule), - typeof(KernelAElfModule))] -public class FeatureDisableTestModule : ContractTestModule -{ - public override void ConfigureServices(ServiceConfigurationContext context) - { - context.Services.AddSingleton(typeof(LogEventProcessingService<>)); - context.Services - .Replace(ServiceDescriptor - .Singleton, - OptionalLogEventProcessingService>()); - Configure(o => o.ContractDeploymentAuthorityRequired = false); - } -} \ No newline at end of file diff --git a/test/AElf.Kernel.FeatureDisable.Tests/IMockService.cs b/test/AElf.Kernel.FeatureDisable.Tests/IMockService.cs deleted file mode 100644 index ee837e1ad5..0000000000 --- a/test/AElf.Kernel.FeatureDisable.Tests/IMockService.cs +++ /dev/null @@ -1,44 +0,0 @@ -using AElf.Kernel.FeatureDisable.Core; -using Volo.Abp.DependencyInjection; - -namespace AElf.Kernel.FeatureDisable.Tests; - -public interface IMockService -{ - Task IsFeatureADisabledAsync(); - Task IsFeatureBDisabledAsync(); - Task IsFeatureCDisabledAsync(); - Task IsFeatureDDisabledAsync(); -} - -public class MockService : IMockService, ITransientDependency -{ - private readonly IFeatureDisableService _featureDisableService; - - public MockService(IFeatureDisableService featureDisableService) - { - _featureDisableService = featureDisableService; - } - - public Task IsFeatureADisabledAsync() - { - return _featureDisableService.IsFeatureDisabledAsync("FeatureA"); - } - - public Task IsFeatureBDisabledAsync() - { - return _featureDisableService.IsFeatureDisabledAsync("FeatureB", "FeatureBAndC"); - - } - - public Task IsFeatureCDisabledAsync() - { - return _featureDisableService.IsFeatureDisabledAsync("FeatureC", "FeatureBAndC"); - - } - - public Task IsFeatureDDisabledAsync() - { - return _featureDisableService.IsFeatureDisabledAsync("FeatureD"); - } -} \ No newline at end of file diff --git a/test/AElf.Kernel.FeatureDisable.Tests/KernelFeatureManagerTestBase.cs b/test/AElf.Kernel.FeatureDisable.Tests/KernelFeatureManagerTestBase.cs deleted file mode 100644 index 7a81535514..0000000000 --- a/test/AElf.Kernel.FeatureDisable.Tests/KernelFeatureManagerTestBase.cs +++ /dev/null @@ -1,60 +0,0 @@ -using AElf.Contracts.Configuration; -using AElf.Contracts.Consensus.AEDPoS; -using AElf.Contracts.Parliament; -using AElf.ContractTestKit; -using AElf.Cryptography.ECDSA; -using AElf.Kernel.Configuration; -using AElf.Kernel.Consensus; -using AElf.Kernel.Proposal; -using AElf.Kernel.SmartContract.Application; -using AElf.Types; -using Google.Protobuf; - -namespace AElf.Kernel.FeatureDisable.Tests; - -public class KernelFeatureDisableTestBase : ContractTestBase -{ - internal ConfigurationContainer.ConfigurationStub ConfigurationStub; - internal ParliamentContractImplContainer.ParliamentContractImplStub ParliamentContractStub; - internal Address ParliamentContractAddress { get; set; } - internal Address ConfigurationContractAddress { get; set; } - internal ECKeyPair DefaultSenderKeyPair => Accounts[0].KeyPair; - - protected async Task DeployContractsAsync() - { - const int category = KernelConstants.CodeCoverageRunnerCategory; - var code = Codes.Single(kv => kv.Key.Split(",").First().EndsWith("Configuration")).Value; - OptionalLogEventProcessingService.Enabled = true; - ConfigurationContractAddress = await DeploySystemSmartContract(category, code, - ConfigurationSmartContractAddressNameProvider.Name, DefaultSenderKeyPair); - ConfigurationStub = - GetTester(ConfigurationContractAddress, - DefaultSenderKeyPair); - - var consensusContractCode = Codes.Single(kv => kv.Key.Split(",").First().EndsWith("Consensus.AEDPoS")).Value; - var consensusContractAddress = await DeploySystemSmartContract(category, consensusContractCode, - ConsensusSmartContractAddressNameProvider.Name, DefaultSenderKeyPair); - var consensusStub = GetTester(consensusContractAddress, - DefaultSenderKeyPair); - - await consensusStub.FirstRound.SendAsync( - new MinerList - { - Pubkeys = { ByteString.CopyFrom(DefaultSenderKeyPair.PublicKey) } - }.GenerateFirstRoundOfNewTerm(4000, TimestampHelper.GetUtcNow()) - ); - - var parliamentContractCode = Codes.Single(kv => kv.Key.Split(",").First().EndsWith("Parliament")).Value; - ParliamentContractAddress = await DeploySystemSmartContract(category, parliamentContractCode, - ParliamentSmartContractAddressNameProvider.Name, DefaultSenderKeyPair); - ParliamentContractStub = GetTester( - ParliamentContractAddress, - DefaultSenderKeyPair); - - await ParliamentContractStub.Initialize.SendAsync(new InitializeInput - { - ProposerAuthorityRequired = true, - PrivilegedProposer = Address.FromPublicKey(DefaultSenderKeyPair.PublicKey) - }); - } -} \ No newline at end of file diff --git a/test/AElf.Kernel.FeatureDisable.Tests/OptionalLogEventProcessingService.cs b/test/AElf.Kernel.FeatureDisable.Tests/OptionalLogEventProcessingService.cs deleted file mode 100644 index 4a5d9a0bb9..0000000000 --- a/test/AElf.Kernel.FeatureDisable.Tests/OptionalLogEventProcessingService.cs +++ /dev/null @@ -1,21 +0,0 @@ -using AElf.Kernel.Blockchain; -using AElf.Kernel.SmartContract.Application; - -namespace AElf.Kernel.FeatureDisable.Tests; - -public class OptionalLogEventProcessingService : ILogEventProcessingService where T : ILogEventProcessor -{ - private readonly LogEventProcessingService _inner; - - public OptionalLogEventProcessingService(LogEventProcessingService inner) - { - _inner = inner; - } - - public static bool Enabled { get; set; } - - public async Task ProcessAsync(List blockExecutedSets) - { - if (Enabled) await _inner.ProcessAsync(blockExecutedSets); - } -} \ No newline at end of file diff --git a/test/AElf.Kernel.FeatureManager.Tests/AElf.Kernel.FeatureManager.Tests.csproj b/test/AElf.Kernel.FeatureManagement.Tests/AElf.Kernel.FeatureManagement.Tests.csproj similarity index 98% rename from test/AElf.Kernel.FeatureManager.Tests/AElf.Kernel.FeatureManager.Tests.csproj rename to test/AElf.Kernel.FeatureManagement.Tests/AElf.Kernel.FeatureManagement.Tests.csproj index d85c33fa68..6098bee162 100644 --- a/test/AElf.Kernel.FeatureManager.Tests/AElf.Kernel.FeatureManager.Tests.csproj +++ b/test/AElf.Kernel.FeatureManagement.Tests/AElf.Kernel.FeatureManagement.Tests.csproj @@ -3,7 +3,6 @@ net8.0 enable - false @@ -42,7 +41,7 @@ PreserveNewest - + diff --git a/test/AElf.Kernel.FeatureManager.Tests/FeatureActiveServiceTest.cs b/test/AElf.Kernel.FeatureManagement.Tests/FeatureManagementServiceTest.cs similarity index 64% rename from test/AElf.Kernel.FeatureManager.Tests/FeatureActiveServiceTest.cs rename to test/AElf.Kernel.FeatureManagement.Tests/FeatureManagementServiceTest.cs index e72b332dbc..a6e1670db2 100644 --- a/test/AElf.Kernel.FeatureManager.Tests/FeatureActiveServiceTest.cs +++ b/test/AElf.Kernel.FeatureManagement.Tests/FeatureManagementServiceTest.cs @@ -8,14 +8,14 @@ using Shouldly; using Xunit; -namespace AElf.Kernel.FeatureManager.Tests; +namespace AElf.Kernel.FeatureManagement.Tests; -public class FeatureActiveServiceTest : KernelFeatureManagerTestBase +public class FeatureManagementServiceTest : KernelFeatureManagementTestBase { private readonly IBlockchainService _blockchainService; private readonly IMockService _mockService; - public FeatureActiveServiceTest() + public FeatureManagementServiceTest() { _mockService = GetRequiredService(); _blockchainService = GetRequiredService(); @@ -87,7 +87,7 @@ private async Task ConfigFeatureActiveHeight(string featureName, long activeHeig ExpiredTime = TimestampHelper.GetUtcNow().AddDays(1), Params = new SetConfigurationInput { - Key = $"{FeatureManagerConstants.FeatureConfigurationNamePrefix}{featureName}", + Key = $"{FeatureManagementConstants.FeatureConfigurationNamePrefix}{featureName}", Value = new Int64Value { Value = activeHeight }.ToByteString() }.ToByteString(), ToAddress = ConfigurationContractAddress, @@ -102,4 +102,35 @@ private async Task GetCurrentHeight() var chain = await _blockchainService.GetChainAsync(); return chain.BestChainHeight; } + + [Fact] + public async Task IsFeatureDisabledTest() + { + await DeployContractsAsync(); + await ConfigDisabledFeaturesAsync("FeatureA, FeatureB, FeatureBAndC"); + (await _mockService.IsFeatureADisabledAsync()).ShouldBeTrue(); + (await _mockService.IsFeatureBDisabledAsync()).ShouldBeTrue(); + (await _mockService.IsFeatureCDisabledAsync()).ShouldBeTrue(); + (await _mockService.IsFeatureDDisabledAsync()).ShouldBeFalse(); + } + + private async Task ConfigDisabledFeaturesAsync(string disableFeatureNames) + { + var chain = await _blockchainService.GetChainAsync(); + await _blockchainService.SetIrreversibleBlockAsync(chain, chain.BestChainHeight, chain.BestChainHash); + var proposalId = (await ParliamentContractStub.CreateProposal.SendAsync(new CreateProposalInput + { + ContractMethodName = "SetConfiguration", + ExpiredTime = TimestampHelper.GetUtcNow().AddDays(1), + Params = new SetConfigurationInput + { + Key = FeatureManagementConstants.FeatureDisableConfigurationName, + Value = new StringValue { Value = disableFeatureNames }.ToByteString() + }.ToByteString(), + ToAddress = ConfigurationContractAddress, + OrganizationAddress = await ParliamentContractStub.GetDefaultOrganizationAddress.CallAsync(new Empty()) + })).Output; + await ParliamentContractStub.Approve.SendAsync(proposalId); + await ParliamentContractStub.Release.SendAsync(proposalId); + } } \ No newline at end of file diff --git a/test/AElf.Kernel.FeatureManager.Tests/FeatureManagerTestModule.cs b/test/AElf.Kernel.FeatureManagement.Tests/FeatureManagementTestModule.cs similarity index 84% rename from test/AElf.Kernel.FeatureManager.Tests/FeatureManagerTestModule.cs rename to test/AElf.Kernel.FeatureManagement.Tests/FeatureManagementTestModule.cs index b4c2548c34..c109b08ef7 100644 --- a/test/AElf.Kernel.FeatureManager.Tests/FeatureManagerTestModule.cs +++ b/test/AElf.Kernel.FeatureManagement.Tests/FeatureManagementTestModule.cs @@ -5,12 +5,12 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.Modularity; -namespace AElf.Kernel.FeatureManager.Tests; +namespace AElf.Kernel.FeatureManagement.Tests; [DependsOn(typeof(ContractTestModule), - typeof(FeatureManagerAElfModule), + typeof(FeatureManagementAElfModule), typeof(KernelAElfModule))] -public class FeatureManagerTestModule : ContractTestModule +public class FeatureManagementTestModule : ContractTestModule { public override void ConfigureServices(ServiceConfigurationContext context) { diff --git a/test/AElf.Kernel.FeatureManagement.Tests/IMockService.cs b/test/AElf.Kernel.FeatureManagement.Tests/IMockService.cs new file mode 100644 index 0000000000..240ec6177a --- /dev/null +++ b/test/AElf.Kernel.FeatureManagement.Tests/IMockService.cs @@ -0,0 +1,60 @@ +using System.Threading.Tasks; +using AElf.Kernel.FeatureManagement.Core; +using Volo.Abp.DependencyInjection; + +namespace AElf.Kernel.FeatureManagement.Tests; + +public interface IMockService +{ + Task GetCurrentFeatureNameAsync(); + + Task IsFeatureADisabledAsync(); + Task IsFeatureBDisabledAsync(); + Task IsFeatureCDisabledAsync(); + Task IsFeatureDDisabledAsync(); +} + +public class MockService : IMockService, ITransientDependency +{ + private const string Version1 = nameof(Version1); + private const string Version2 = nameof(Version2); + private const string Version3 = nameof(Version3); + private readonly IFeatureManagementService _featureManagementService; + + public MockService(IFeatureManagementService featureManagementService) + { + _featureManagementService = featureManagementService; + } + + public async Task GetCurrentFeatureNameAsync() + { + if (await _featureManagementService.IsFeatureActive(Version3)) return Version3; + + if (await _featureManagementService.IsFeatureActive(Version2)) return Version2; + + return Version1; + } + + + public Task IsFeatureADisabledAsync() + { + return _featureManagementService.IsFeatureDisabledAsync("FeatureA"); + } + + public Task IsFeatureBDisabledAsync() + { + return _featureManagementService.IsFeatureDisabledAsync("FeatureB", "FeatureBAndC"); + + } + + public Task IsFeatureCDisabledAsync() + { + return _featureManagementService.IsFeatureDisabledAsync("FeatureC", "FeatureBAndC"); + + } + + public Task IsFeatureDDisabledAsync() + { + return _featureManagementService.IsFeatureDisabledAsync("FeatureD"); + } +} \ No newline at end of file diff --git a/test/AElf.Kernel.FeatureManager.Tests/KernelFeatureManagerTestBase.cs b/test/AElf.Kernel.FeatureManagement.Tests/KernelFeatureManagementTestBase.cs similarity index 95% rename from test/AElf.Kernel.FeatureManager.Tests/KernelFeatureManagerTestBase.cs rename to test/AElf.Kernel.FeatureManagement.Tests/KernelFeatureManagementTestBase.cs index 277fde204e..d52477ce5c 100644 --- a/test/AElf.Kernel.FeatureManager.Tests/KernelFeatureManagerTestBase.cs +++ b/test/AElf.Kernel.FeatureManagement.Tests/KernelFeatureManagementTestBase.cs @@ -12,9 +12,9 @@ using AElf.Types; using Google.Protobuf; -namespace AElf.Kernel.FeatureManager.Tests; +namespace AElf.Kernel.FeatureManagement.Tests; -public class KernelFeatureManagerTestBase : ContractTestBase +public class KernelFeatureManagementTestBase : ContractTestBase { internal ConfigurationContainer.ConfigurationStub ConfigurationStub; internal ParliamentContractImplContainer.ParliamentContractImplStub ParliamentContractStub; diff --git a/test/AElf.Kernel.FeatureDisable.Tests/MinerList.cs b/test/AElf.Kernel.FeatureManagement.Tests/MinerList.cs similarity index 100% rename from test/AElf.Kernel.FeatureDisable.Tests/MinerList.cs rename to test/AElf.Kernel.FeatureManagement.Tests/MinerList.cs diff --git a/test/AElf.Kernel.FeatureManager.Tests/OptionalLogEventProcessingService.cs b/test/AElf.Kernel.FeatureManagement.Tests/OptionalLogEventProcessingService.cs similarity index 93% rename from test/AElf.Kernel.FeatureManager.Tests/OptionalLogEventProcessingService.cs rename to test/AElf.Kernel.FeatureManagement.Tests/OptionalLogEventProcessingService.cs index 4e6f52f26a..d658e2a689 100644 --- a/test/AElf.Kernel.FeatureManager.Tests/OptionalLogEventProcessingService.cs +++ b/test/AElf.Kernel.FeatureManagement.Tests/OptionalLogEventProcessingService.cs @@ -3,7 +3,7 @@ using AElf.Kernel.Blockchain; using AElf.Kernel.SmartContract.Application; -namespace AElf.Kernel.FeatureManager.Tests; +namespace AElf.Kernel.FeatureManagement.Tests; public class OptionalLogEventProcessingService : ILogEventProcessingService where T : ILogEventProcessor { diff --git a/test/AElf.Kernel.FeatureManager.Tests/IMockService.cs b/test/AElf.Kernel.FeatureManager.Tests/IMockService.cs deleted file mode 100644 index 56c8a6330f..0000000000 --- a/test/AElf.Kernel.FeatureManager.Tests/IMockService.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Threading.Tasks; -using Volo.Abp.DependencyInjection; - -namespace AElf.Kernel.FeatureManager.Tests; - -public interface IMockService -{ - Task GetCurrentFeatureNameAsync(); -} - -public class MockService : IMockService, ITransientDependency -{ - private const string Version1 = nameof(Version1); - private const string Version2 = nameof(Version2); - private const string Version3 = nameof(Version3); - private readonly IFeatureActiveService _featureActiveService; - - public MockService(IFeatureActiveService featureActiveService) - { - _featureActiveService = featureActiveService; - } - - public async Task GetCurrentFeatureNameAsync() - { - if (await _featureActiveService.IsFeatureActive(Version3)) return Version3; - - if (await _featureActiveService.IsFeatureActive(Version2)) return Version2; - - return Version1; - } -} \ No newline at end of file diff --git a/test/AElf.Kernel.FeatureManager.Tests/MinerList.cs b/test/AElf.Kernel.FeatureManager.Tests/MinerList.cs deleted file mode 100644 index 0ef019af8c..0000000000 --- a/test/AElf.Kernel.FeatureManager.Tests/MinerList.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Linq; -using AElf.CSharp.Core.Extension; -using AElf.Types; -using Google.Protobuf; -using Google.Protobuf.WellKnownTypes; - -namespace AElf.Contracts.Consensus.AEDPoS; - -internal partial class MinerList -{ - public Round GenerateFirstRoundOfNewTerm(int miningInterval, - Timestamp currentBlockTime, long currentRoundNumber = 0, long currentTermNumber = 0) - { - var sortedMiners = - (from obj in Pubkeys - .ToDictionary(miner => miner.ToHex(), miner => miner[0]) - orderby obj.Value descending - select obj.Key).ToList(); - - var round = new Round(); - - for (var i = 0; i < sortedMiners.Count; i++) - { - var minerInRound = new MinerInRound(); - - // The first miner will be the extra block producer of first round of each term. - if (i == 0) minerInRound.IsExtraBlockProducer = true; - - minerInRound.Pubkey = sortedMiners[i]; - minerInRound.Order = i + 1; - minerInRound.ExpectedMiningTime = currentBlockTime.AddMilliseconds(i * miningInterval + miningInterval); - // Should be careful during validation. - minerInRound.PreviousInValue = Hash.Empty; - - round.RealTimeMinersInformation.Add(sortedMiners[i], minerInRound); - } - - round.RoundNumber = currentRoundNumber + 1; - round.TermNumber = currentTermNumber + 1; - round.IsMinerListJustChanged = true; - - return round; - } - - public Hash GetMinersHash() - { - var orderedMiners = Pubkeys.OrderBy(p => p); - return HashHelper.ComputeFrom(orderedMiners.Aggregate("", (current, publicKey) => current + publicKey)); - } -} \ No newline at end of file diff --git a/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs b/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs index f43cef0e42..690d3e03dc 100644 --- a/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs +++ b/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using AElf.Kernel.FeatureDisable.Core; +using AElf.Kernel.FeatureManagement.Core; using AElf.Kernel.SmartContract.Application; using AElf.Kernel.SmartContract.Domain; using AElf.Kernel.SmartContract.Infrastructure; @@ -21,8 +21,8 @@ public class PlainTransactionExecutingAsPluginService : PlainTransactionExecutin public PlainTransactionExecutingAsPluginService (ISmartContractExecutiveService smartContractExecutiveService, IEnumerable postPlugins, IEnumerable prePlugins, - ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) : base( - smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService) + ITransactionContextFactory transactionContextFactory, IFeatureManagementService featureManagementService) : base( + smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureManagementService) { _smartContractExecutiveService = smartContractExecutiveService; }