From dcc054a3b33e117422db0713cf423317422da196 Mon Sep 17 00:00:00 2001 From: eanzhao Date: Thu, 8 Aug 2024 15:37:46 +0800 Subject: [PATCH 1/2] Move feature disable service related code to feature manager module. --- AElf.All.sln | 26 ++---- .../FeatureDisableConstants.cs | 6 -- .../AElf.Kernel.FeatureDisable.csproj | 15 ---- .../FeatureDisableAElfModule.cs | 15 ---- .../AElf.Kernel.FeatureManager.Core.csproj} | 4 +- .../FeatureDisableCoreAElfModule.cs | 4 +- .../FeatureManagerConstants.cs | 1 + .../IFeatureActiveService.cs | 0 .../IFeatureDisableService.cs | 3 +- .../AElf.Kernel.FeatureManager.csproj | 1 + .../DisableFeatureOptions.cs | 4 +- .../FeatureDisableConfigurationProcessor.cs | 6 +- .../FeatureDisableService.cs | 5 +- .../FeatureManagerAElfModule.cs | 2 + .../IDisabledFeatureListProvider.cs | 4 +- .../AElf.Kernel.SmartContract.csproj | 2 +- .../PlainTransactionExecutingService.cs | 2 +- .../SmartContractAElfModule.cs | 4 +- src/AElf.Kernel/AElf.Kernel.csproj | 2 +- src/AElf.Kernel/KernelAElfModule.cs | 4 +- .../AElf.Kernel.FeatureDisable.Tests.csproj | 85 ------------------- .../FeatureDisableTestModule.cs | 25 ------ .../IMockService.cs | 44 ---------- .../KernelFeatureManagerTestBase.cs | 60 ------------- .../MinerList.cs | 50 ----------- .../OptionalLogEventProcessingService.cs | 21 ----- .../FeatureDisableServiceTest.cs} | 11 ++- .../IMockService.cs | 32 ++++++- 28 files changed, 71 insertions(+), 367 deletions(-) delete mode 100644 src/AElf.Kernel.FeatureDisable.Core/FeatureDisableConstants.cs delete mode 100644 src/AElf.Kernel.FeatureDisable/AElf.Kernel.FeatureDisable.csproj delete mode 100644 src/AElf.Kernel.FeatureDisable/FeatureDisableAElfModule.cs rename src/{AElf.Kernel.FeatureDisable.Core/AElf.Kernel.FeatureDisable.Core.csproj => AElf.Kernel.FeatureManager.Core/AElf.Kernel.FeatureManager.Core.csproj} (67%) rename src/{AElf.Kernel.FeatureDisable.Core => AElf.Kernel.FeatureManager.Core}/FeatureDisableCoreAElfModule.cs (60%) rename src/{AElf.Kernel.FeatureManager => AElf.Kernel.FeatureManager.Core}/FeatureManagerConstants.cs (64%) rename src/{AElf.Kernel.FeatureManager => AElf.Kernel.FeatureManager.Core}/IFeatureActiveService.cs (100%) rename src/{AElf.Kernel.FeatureDisable.Core => AElf.Kernel.FeatureManager.Core}/IFeatureDisableService.cs (84%) rename src/{AElf.Kernel.FeatureDisable => AElf.Kernel.FeatureManager}/DisableFeatureOptions.cs (56%) rename src/{AElf.Kernel.FeatureDisable => AElf.Kernel.FeatureManager}/FeatureDisableConfigurationProcessor.cs (85%) rename src/{AElf.Kernel.FeatureDisable => AElf.Kernel.FeatureManager}/FeatureDisableService.cs (93%) rename src/{AElf.Kernel.FeatureDisable => AElf.Kernel.FeatureManager}/IDisabledFeatureListProvider.cs (95%) delete mode 100644 test/AElf.Kernel.FeatureDisable.Tests/AElf.Kernel.FeatureDisable.Tests.csproj delete mode 100644 test/AElf.Kernel.FeatureDisable.Tests/FeatureDisableTestModule.cs delete mode 100644 test/AElf.Kernel.FeatureDisable.Tests/IMockService.cs delete mode 100644 test/AElf.Kernel.FeatureDisable.Tests/KernelFeatureManagerTestBase.cs delete mode 100644 test/AElf.Kernel.FeatureDisable.Tests/MinerList.cs delete mode 100644 test/AElf.Kernel.FeatureDisable.Tests/OptionalLogEventProcessingService.cs rename test/{AElf.Kernel.FeatureDisable.Tests/FeatureDisableTest.cs => AElf.Kernel.FeatureManager.Tests/FeatureDisableServiceTest.cs} (88%) diff --git a/AElf.All.sln b/AElf.All.sln index 34ad27a9ac..31fcb1a499 100644 --- a/AElf.All.sln +++ b/AElf.All.sln @@ -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.FeatureManager.Core", "src\AElf.Kernel.FeatureManager.Core\AElf.Kernel.FeatureManager.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/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/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/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.Core/AElf.Kernel.FeatureDisable.Core.csproj b/src/AElf.Kernel.FeatureManager.Core/AElf.Kernel.FeatureManager.Core.csproj similarity index 67% rename from src/AElf.Kernel.FeatureDisable.Core/AElf.Kernel.FeatureDisable.Core.csproj rename to src/AElf.Kernel.FeatureManager.Core/AElf.Kernel.FeatureManager.Core.csproj index 7b39f518d5..8ae10ac224 100644 --- a/src/AElf.Kernel.FeatureDisable.Core/AElf.Kernel.FeatureDisable.Core.csproj +++ b/src/AElf.Kernel.FeatureManager.Core/AElf.Kernel.FeatureManager.Core.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -7,7 +7,7 @@ - + diff --git a/src/AElf.Kernel.FeatureDisable.Core/FeatureDisableCoreAElfModule.cs b/src/AElf.Kernel.FeatureManager.Core/FeatureDisableCoreAElfModule.cs similarity index 60% rename from src/AElf.Kernel.FeatureDisable.Core/FeatureDisableCoreAElfModule.cs rename to src/AElf.Kernel.FeatureManager.Core/FeatureDisableCoreAElfModule.cs index c9e524ec01..67d22d61a8 100644 --- a/src/AElf.Kernel.FeatureDisable.Core/FeatureDisableCoreAElfModule.cs +++ b/src/AElf.Kernel.FeatureManager.Core/FeatureDisableCoreAElfModule.cs @@ -1,9 +1,9 @@ using AElf.Modularity; using Volo.Abp.Modularity; -namespace AElf.Kernel.FeatureDisable.Core; +namespace AElf.Kernel.FeatureManager.Core; -public class FeatureDisableCoreAElfModule : AElfModule +public class FeatureManagerCoreAElfModule : AElfModule { public override void ConfigureServices(ServiceConfigurationContext context) { diff --git a/src/AElf.Kernel.FeatureManager/FeatureManagerConstants.cs b/src/AElf.Kernel.FeatureManager.Core/FeatureManagerConstants.cs similarity index 64% rename from src/AElf.Kernel.FeatureManager/FeatureManagerConstants.cs rename to src/AElf.Kernel.FeatureManager.Core/FeatureManagerConstants.cs index b433ec58bf..e26642babc 100644 --- a/src/AElf.Kernel.FeatureManager/FeatureManagerConstants.cs +++ b/src/AElf.Kernel.FeatureManager.Core/FeatureManagerConstants.cs @@ -3,4 +3,5 @@ namespace AElf.Kernel.FeatureManager; public class FeatureManagerConstants { public const string FeatureConfigurationNamePrefix = "AElfFeature_"; + public const string FeatureDisableConfigurationName = "DisableFeatureNameList"; } \ No newline at end of file diff --git a/src/AElf.Kernel.FeatureManager/IFeatureActiveService.cs b/src/AElf.Kernel.FeatureManager.Core/IFeatureActiveService.cs similarity index 100% rename from src/AElf.Kernel.FeatureManager/IFeatureActiveService.cs rename to src/AElf.Kernel.FeatureManager.Core/IFeatureActiveService.cs diff --git a/src/AElf.Kernel.FeatureDisable.Core/IFeatureDisableService.cs b/src/AElf.Kernel.FeatureManager.Core/IFeatureDisableService.cs similarity index 84% rename from src/AElf.Kernel.FeatureDisable.Core/IFeatureDisableService.cs rename to src/AElf.Kernel.FeatureManager.Core/IFeatureDisableService.cs index 0131adc57b..cc41651140 100644 --- a/src/AElf.Kernel.FeatureDisable.Core/IFeatureDisableService.cs +++ b/src/AElf.Kernel.FeatureManager.Core/IFeatureDisableService.cs @@ -1,6 +1,7 @@ +using System.Threading.Tasks; using Volo.Abp.DependencyInjection; -namespace AElf.Kernel.FeatureDisable.Core; +namespace AElf.Kernel.FeatureManager; public interface IFeatureDisableService { diff --git a/src/AElf.Kernel.FeatureManager/AElf.Kernel.FeatureManager.csproj b/src/AElf.Kernel.FeatureManager/AElf.Kernel.FeatureManager.csproj index 20260d21b7..2474e34642 100644 --- a/src/AElf.Kernel.FeatureManager/AElf.Kernel.FeatureManager.csproj +++ b/src/AElf.Kernel.FeatureManager/AElf.Kernel.FeatureManager.csproj @@ -10,6 +10,7 @@ + diff --git a/src/AElf.Kernel.FeatureDisable/DisableFeatureOptions.cs b/src/AElf.Kernel.FeatureManager/DisableFeatureOptions.cs similarity index 56% rename from src/AElf.Kernel.FeatureDisable/DisableFeatureOptions.cs rename to src/AElf.Kernel.FeatureManager/DisableFeatureOptions.cs index f5968ba95a..53678031a8 100644 --- a/src/AElf.Kernel.FeatureDisable/DisableFeatureOptions.cs +++ b/src/AElf.Kernel.FeatureManager/DisableFeatureOptions.cs @@ -1,4 +1,6 @@ -namespace AElf.Kernel.FeatureDisable; +using System.Collections.Generic; + +namespace AElf.Kernel.FeatureManager; public class DisableFeatureOptions { diff --git a/src/AElf.Kernel.FeatureDisable/FeatureDisableConfigurationProcessor.cs b/src/AElf.Kernel.FeatureManager/FeatureDisableConfigurationProcessor.cs similarity index 85% rename from src/AElf.Kernel.FeatureDisable/FeatureDisableConfigurationProcessor.cs rename to src/AElf.Kernel.FeatureManager/FeatureDisableConfigurationProcessor.cs index 1adb8c45a9..b5824c94d8 100644 --- a/src/AElf.Kernel.FeatureDisable/FeatureDisableConfigurationProcessor.cs +++ b/src/AElf.Kernel.FeatureManager/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.FeatureManager; public class FeatureDisableConfigurationProcessor : IConfigurationProcessor, ITransientDependency { @@ -15,7 +15,7 @@ public FeatureDisableConfigurationProcessor(IDisabledFeatureListProvider disable _disabledFeatureListProvider = disabledFeatureListProvider; } - public string ConfigurationName => FeatureDisableConstants.FeatureDisableConfigurationName; + public string ConfigurationName => FeatureManagerConstants.FeatureDisableConfigurationName; public async Task ProcessConfigurationAsync(ByteString byteString, BlockIndex blockIndex) { diff --git a/src/AElf.Kernel.FeatureDisable/FeatureDisableService.cs b/src/AElf.Kernel.FeatureManager/FeatureDisableService.cs similarity index 93% rename from src/AElf.Kernel.FeatureDisable/FeatureDisableService.cs rename to src/AElf.Kernel.FeatureManager/FeatureDisableService.cs index 2ac30dbe73..cb915cb6a1 100644 --- a/src/AElf.Kernel.FeatureDisable/FeatureDisableService.cs +++ b/src/AElf.Kernel.FeatureManager/FeatureDisableService.cs @@ -1,8 +1,9 @@ +using System.Linq; +using System.Threading.Tasks; using AElf.Kernel.Blockchain.Application; -using AElf.Kernel.FeatureDisable.Core; using Volo.Abp.DependencyInjection; -namespace AElf.Kernel.FeatureDisable; +namespace AElf.Kernel.FeatureManager; public class FeatureDisableService : IFeatureDisableService, ITransientDependency { diff --git a/src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs b/src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs index ce74c7f47e..0966ff90d7 100644 --- a/src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs +++ b/src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs @@ -1,10 +1,12 @@ using AElf.Kernel.Configuration; +using AElf.Kernel.FeatureManager.Core; using AElf.Modularity; using Volo.Abp.Modularity; namespace AElf.Kernel.FeatureManager; [DependsOn( + typeof(FeatureManagerCoreAElfModule), typeof(ConfigurationAElfModule) )] public class FeatureManagerAElfModule : AElfModule diff --git a/src/AElf.Kernel.FeatureDisable/IDisabledFeatureListProvider.cs b/src/AElf.Kernel.FeatureManager/IDisabledFeatureListProvider.cs similarity index 95% rename from src/AElf.Kernel.FeatureDisable/IDisabledFeatureListProvider.cs rename to src/AElf.Kernel.FeatureManager/IDisabledFeatureListProvider.cs index 36b05ecad1..ae34c3b333 100644 --- a/src/AElf.Kernel.FeatureDisable/IDisabledFeatureListProvider.cs +++ b/src/AElf.Kernel.FeatureManager/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.FeatureManager; public interface IDisabledFeatureListProvider { diff --git a/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj b/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj index ab2cf443cf..31ac67de62 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..341a23c9fb 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.FeatureManager; using AElf.Kernel.SmartContract.Domain; using AElf.Kernel.SmartContract.Infrastructure; using AElf.Types; diff --git a/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs b/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs index 670ee60cdb..805ab907f8 100644 --- a/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs +++ b/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs @@ -1,4 +1,4 @@ -using AElf.Kernel.FeatureDisable.Core; +using AElf.Kernel.FeatureManager.Core; using AElf.Kernel.SmartContract.Application; using AElf.Kernel.SmartContract.Infrastructure; using AElf.Modularity; @@ -8,7 +8,7 @@ namespace AElf.Kernel.SmartContract; [DependsOn(typeof(CoreKernelAElfModule), - typeof(FeatureDisableCoreAElfModule))] + typeof(FeatureManagerCoreAElfModule))] 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..19b35a277f 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..589d2ddf81 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.FeatureManager; 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(FeatureManagerAElfModule), 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/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/MinerList.cs b/test/AElf.Kernel.FeatureDisable.Tests/MinerList.cs deleted file mode 100644 index 0ef019af8c..0000000000 --- a/test/AElf.Kernel.FeatureDisable.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.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.FeatureDisable.Tests/FeatureDisableTest.cs b/test/AElf.Kernel.FeatureManager.Tests/FeatureDisableServiceTest.cs similarity index 88% rename from test/AElf.Kernel.FeatureDisable.Tests/FeatureDisableTest.cs rename to test/AElf.Kernel.FeatureManager.Tests/FeatureDisableServiceTest.cs index 2343599aeb..80d9825866 100644 --- a/test/AElf.Kernel.FeatureDisable.Tests/FeatureDisableTest.cs +++ b/test/AElf.Kernel.FeatureManager.Tests/FeatureDisableServiceTest.cs @@ -1,22 +1,21 @@ +using System.Threading.Tasks; 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; +namespace AElf.Kernel.FeatureManager.Tests; -public class FeatureDisableTest : KernelFeatureDisableTestBase +public class FeatureDisableServiceTest : KernelFeatureManagerTestBase { private readonly IMockService _mockService; private readonly IBlockchainService _blockchainService; - public FeatureDisableTest() + public FeatureDisableServiceTest() { _mockService = GetRequiredService(); _blockchainService = GetRequiredService(); @@ -43,7 +42,7 @@ private async Task ConfigDisabledFeaturesAsync(string disableFeatureNames) ExpiredTime = TimestampHelper.GetUtcNow().AddDays(1), Params = new SetConfigurationInput { - Key = FeatureDisableConstants.FeatureDisableConfigurationName, + Key = FeatureManagerConstants.FeatureDisableConfigurationName, Value = new StringValue { Value = disableFeatureNames }.ToByteString() }.ToByteString(), ToAddress = ConfigurationContractAddress, diff --git a/test/AElf.Kernel.FeatureManager.Tests/IMockService.cs b/test/AElf.Kernel.FeatureManager.Tests/IMockService.cs index 56c8a6330f..a907c9ee0c 100644 --- a/test/AElf.Kernel.FeatureManager.Tests/IMockService.cs +++ b/test/AElf.Kernel.FeatureManager.Tests/IMockService.cs @@ -6,6 +6,11 @@ namespace AElf.Kernel.FeatureManager.Tests; public interface IMockService { Task GetCurrentFeatureNameAsync(); + + Task IsFeatureADisabledAsync(); + Task IsFeatureBDisabledAsync(); + Task IsFeatureCDisabledAsync(); + Task IsFeatureDDisabledAsync(); } public class MockService : IMockService, ITransientDependency @@ -14,10 +19,12 @@ public class MockService : IMockService, ITransientDependency private const string Version2 = nameof(Version2); private const string Version3 = nameof(Version3); private readonly IFeatureActiveService _featureActiveService; + private readonly IFeatureDisableService _featureDisableService; - public MockService(IFeatureActiveService featureActiveService) + public MockService(IFeatureActiveService featureActiveService, IFeatureDisableService featureDisableService) { _featureActiveService = featureActiveService; + _featureDisableService = featureDisableService; } public async Task GetCurrentFeatureNameAsync() @@ -28,4 +35,27 @@ public async Task GetCurrentFeatureNameAsync() return Version1; } + + + 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 From 3570b8ed819d6c93dcc0f6c5ed5dabb44d3e22c5 Mon Sep 17 00:00:00 2001 From: eanzhao Date: Thu, 8 Aug 2024 19:06:32 +0800 Subject: [PATCH 2/2] Combine IFeatureActiveService & IFeatureDisableService to IFeatureManagementService --- AElf.All.sln | 6 +- AElf.sln | 4 +- ...nitTestPlainTransactionExecutingService.cs | 6 +- ...AElf.Kernel.FeatureManagement.Core.csproj} | 0 .../FeatureManagementConstants.cs} | 4 +- .../FeatureManagementCoreAElfModule.cs} | 4 +- .../IFeatureManagementService.cs | 22 ++++++ .../AElf.Kernel.FeatureManagement.csproj} | 4 +- .../FeatureDisableConfigurationProcessor.cs | 4 +- .../FeatureManagementAElfModule.cs | 14 ++++ .../FeatureManagementOptions.cs | 8 +++ .../FeatureManagementService.cs | 70 +++++++++++++++++++ .../IDisabledFeatureListProvider.cs | 2 +- .../IFeatureActiveService.cs | 8 --- .../IFeatureDisableService.cs | 17 ----- .../DisableFeatureOptions.cs | 8 --- .../FeatureActiveService.cs | 42 ----------- .../FeatureDisableService.cs | 42 ----------- .../FeatureManagerAElfModule.cs | 14 ---- .../AElf.Kernel.SmartContract.csproj | 2 +- .../PlainTransactionExecutingService.cs | 12 ++-- .../SmartContractAElfModule.cs | 5 +- src/AElf.Kernel/AElf.Kernel.csproj | 2 +- src/AElf.Kernel/KernelAElfModule.cs | 4 +- ...Elf.Kernel.FeatureManagement.Tests.csproj} | 3 +- .../FeatureManagementServiceTest.cs} | 39 +++++++++-- .../FeatureManagementTestModule.cs} | 6 +- .../IMockService.cs | 25 ++++--- .../KernelFeatureManagementTestBase.cs} | 4 +- .../MinerList.cs | 0 .../OptionalLogEventProcessingService.cs | 2 +- .../FeatureDisableServiceTest.cs | 54 -------------- ...lainTransactionExecutingAsPluginService.cs | 6 +- 33 files changed, 201 insertions(+), 242 deletions(-) rename src/{AElf.Kernel.FeatureManager.Core/AElf.Kernel.FeatureManager.Core.csproj => AElf.Kernel.FeatureManagement.Core/AElf.Kernel.FeatureManagement.Core.csproj} (100%) rename src/{AElf.Kernel.FeatureManager.Core/FeatureManagerConstants.cs => AElf.Kernel.FeatureManagement.Core/FeatureManagementConstants.cs} (66%) rename src/{AElf.Kernel.FeatureManager.Core/FeatureDisableCoreAElfModule.cs => AElf.Kernel.FeatureManagement.Core/FeatureManagementCoreAElfModule.cs} (59%) create mode 100644 src/AElf.Kernel.FeatureManagement.Core/IFeatureManagementService.cs rename src/{AElf.Kernel.FeatureManager/AElf.Kernel.FeatureManager.csproj => AElf.Kernel.FeatureManagement/AElf.Kernel.FeatureManagement.csproj} (72%) rename src/{AElf.Kernel.FeatureManager => AElf.Kernel.FeatureManagement}/FeatureDisableConfigurationProcessor.cs (85%) create mode 100644 src/AElf.Kernel.FeatureManagement/FeatureManagementAElfModule.cs create mode 100644 src/AElf.Kernel.FeatureManagement/FeatureManagementOptions.cs create mode 100644 src/AElf.Kernel.FeatureManagement/FeatureManagementService.cs rename src/{AElf.Kernel.FeatureManager => AElf.Kernel.FeatureManagement}/IDisabledFeatureListProvider.cs (97%) delete mode 100644 src/AElf.Kernel.FeatureManager.Core/IFeatureActiveService.cs delete mode 100644 src/AElf.Kernel.FeatureManager.Core/IFeatureDisableService.cs delete mode 100644 src/AElf.Kernel.FeatureManager/DisableFeatureOptions.cs delete mode 100644 src/AElf.Kernel.FeatureManager/FeatureActiveService.cs delete mode 100644 src/AElf.Kernel.FeatureManager/FeatureDisableService.cs delete mode 100644 src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs rename test/{AElf.Kernel.FeatureManager.Tests/AElf.Kernel.FeatureManager.Tests.csproj => AElf.Kernel.FeatureManagement.Tests/AElf.Kernel.FeatureManagement.Tests.csproj} (98%) rename test/{AElf.Kernel.FeatureManager.Tests/FeatureActiveServiceTest.cs => AElf.Kernel.FeatureManagement.Tests/FeatureManagementServiceTest.cs} (64%) rename test/{AElf.Kernel.FeatureManager.Tests/FeatureManagerTestModule.cs => AElf.Kernel.FeatureManagement.Tests/FeatureManagementTestModule.cs} (84%) rename test/{AElf.Kernel.FeatureManager.Tests => AElf.Kernel.FeatureManagement.Tests}/IMockService.cs (50%) rename test/{AElf.Kernel.FeatureManager.Tests/KernelFeatureManagerTestBase.cs => AElf.Kernel.FeatureManagement.Tests/KernelFeatureManagementTestBase.cs} (95%) rename test/{AElf.Kernel.FeatureManager.Tests => AElf.Kernel.FeatureManagement.Tests}/MinerList.cs (100%) rename test/{AElf.Kernel.FeatureManager.Tests => AElf.Kernel.FeatureManagement.Tests}/OptionalLogEventProcessingService.cs (93%) delete mode 100644 test/AElf.Kernel.FeatureManager.Tests/FeatureDisableServiceTest.cs diff --git a/AElf.All.sln b/AElf.All.sln index 31fcb1a499..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,7 +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.FeatureManager.Core", "src\AElf.Kernel.FeatureManager.Core\AElf.Kernel.FeatureManager.Core.csproj", "{EB2EE653-B268-481B-9C5A-096E939E07E1}" +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 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.FeatureManager.Core/AElf.Kernel.FeatureManager.Core.csproj b/src/AElf.Kernel.FeatureManagement.Core/AElf.Kernel.FeatureManagement.Core.csproj similarity index 100% rename from src/AElf.Kernel.FeatureManager.Core/AElf.Kernel.FeatureManager.Core.csproj rename to src/AElf.Kernel.FeatureManagement.Core/AElf.Kernel.FeatureManagement.Core.csproj diff --git a/src/AElf.Kernel.FeatureManager.Core/FeatureManagerConstants.cs b/src/AElf.Kernel.FeatureManagement.Core/FeatureManagementConstants.cs similarity index 66% rename from src/AElf.Kernel.FeatureManager.Core/FeatureManagerConstants.cs rename to src/AElf.Kernel.FeatureManagement.Core/FeatureManagementConstants.cs index e26642babc..1abb74cc4a 100644 --- a/src/AElf.Kernel.FeatureManager.Core/FeatureManagerConstants.cs +++ b/src/AElf.Kernel.FeatureManagement.Core/FeatureManagementConstants.cs @@ -1,6 +1,6 @@ -namespace AElf.Kernel.FeatureManager; +namespace AElf.Kernel.FeatureManagement; -public class FeatureManagerConstants +public class FeatureManagementConstants { public const string FeatureConfigurationNamePrefix = "AElfFeature_"; public const string FeatureDisableConfigurationName = "DisableFeatureNameList"; diff --git a/src/AElf.Kernel.FeatureManager.Core/FeatureDisableCoreAElfModule.cs b/src/AElf.Kernel.FeatureManagement.Core/FeatureManagementCoreAElfModule.cs similarity index 59% rename from src/AElf.Kernel.FeatureManager.Core/FeatureDisableCoreAElfModule.cs rename to src/AElf.Kernel.FeatureManagement.Core/FeatureManagementCoreAElfModule.cs index 67d22d61a8..a3669e0415 100644 --- a/src/AElf.Kernel.FeatureManager.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.FeatureManager.Core; +namespace AElf.Kernel.FeatureManagement.Core; -public class FeatureManagerCoreAElfModule : 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 2474e34642..a8774c8deb 100644 --- a/src/AElf.Kernel.FeatureManager/AElf.Kernel.FeatureManager.csproj +++ b/src/AElf.Kernel.FeatureManagement/AElf.Kernel.FeatureManagement.csproj @@ -3,14 +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.FeatureManager/FeatureDisableConfigurationProcessor.cs b/src/AElf.Kernel.FeatureManagement/FeatureDisableConfigurationProcessor.cs similarity index 85% rename from src/AElf.Kernel.FeatureManager/FeatureDisableConfigurationProcessor.cs rename to src/AElf.Kernel.FeatureManagement/FeatureDisableConfigurationProcessor.cs index b5824c94d8..79cefeb915 100644 --- a/src/AElf.Kernel.FeatureManager/FeatureDisableConfigurationProcessor.cs +++ b/src/AElf.Kernel.FeatureManagement/FeatureDisableConfigurationProcessor.cs @@ -4,7 +4,7 @@ using Google.Protobuf.WellKnownTypes; using Volo.Abp.DependencyInjection; -namespace AElf.Kernel.FeatureManager; +namespace AElf.Kernel.FeatureManagement; public class FeatureDisableConfigurationProcessor : IConfigurationProcessor, ITransientDependency { @@ -15,7 +15,7 @@ public FeatureDisableConfigurationProcessor(IDisabledFeatureListProvider disable _disabledFeatureListProvider = disabledFeatureListProvider; } - public string ConfigurationName => FeatureManagerConstants.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.FeatureManager/IDisabledFeatureListProvider.cs b/src/AElf.Kernel.FeatureManagement/IDisabledFeatureListProvider.cs similarity index 97% rename from src/AElf.Kernel.FeatureManager/IDisabledFeatureListProvider.cs rename to src/AElf.Kernel.FeatureManagement/IDisabledFeatureListProvider.cs index ae34c3b333..960c8881cb 100644 --- a/src/AElf.Kernel.FeatureManager/IDisabledFeatureListProvider.cs +++ b/src/AElf.Kernel.FeatureManagement/IDisabledFeatureListProvider.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.DependencyInjection; -namespace AElf.Kernel.FeatureManager; +namespace AElf.Kernel.FeatureManagement; public interface IDisabledFeatureListProvider { diff --git a/src/AElf.Kernel.FeatureManager.Core/IFeatureActiveService.cs b/src/AElf.Kernel.FeatureManager.Core/IFeatureActiveService.cs deleted file mode 100644 index c2f6c2febb..0000000000 --- a/src/AElf.Kernel.FeatureManager.Core/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.FeatureManager.Core/IFeatureDisableService.cs b/src/AElf.Kernel.FeatureManager.Core/IFeatureDisableService.cs deleted file mode 100644 index cc41651140..0000000000 --- a/src/AElf.Kernel.FeatureManager.Core/IFeatureDisableService.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Threading.Tasks; -using Volo.Abp.DependencyInjection; - -namespace AElf.Kernel.FeatureManager; - -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.FeatureManager/DisableFeatureOptions.cs b/src/AElf.Kernel.FeatureManager/DisableFeatureOptions.cs deleted file mode 100644 index 53678031a8..0000000000 --- a/src/AElf.Kernel.FeatureManager/DisableFeatureOptions.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections.Generic; - -namespace AElf.Kernel.FeatureManager; - -public class DisableFeatureOptions -{ - public List FeatureNameList { get; set; } -} \ No newline at end of file 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/FeatureDisableService.cs b/src/AElf.Kernel.FeatureManager/FeatureDisableService.cs deleted file mode 100644 index cb915cb6a1..0000000000 --- a/src/AElf.Kernel.FeatureManager/FeatureDisableService.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using AElf.Kernel.Blockchain.Application; -using Volo.Abp.DependencyInjection; - -namespace AElf.Kernel.FeatureManager; - -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.FeatureManager/FeatureManagerAElfModule.cs b/src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs deleted file mode 100644 index 0966ff90d7..0000000000 --- a/src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs +++ /dev/null @@ -1,14 +0,0 @@ -using AElf.Kernel.Configuration; -using AElf.Kernel.FeatureManager.Core; -using AElf.Modularity; -using Volo.Abp.Modularity; - -namespace AElf.Kernel.FeatureManager; - -[DependsOn( - typeof(FeatureManagerCoreAElfModule), - typeof(ConfigurationAElfModule) -)] -public class FeatureManagerAElfModule : AElfModule -{ -} \ 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 31ac67de62..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 341a23c9fb..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.FeatureManager; +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 805ab907f8..609500e02e 100644 --- a/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs +++ b/src/AElf.Kernel.SmartContract/SmartContractAElfModule.cs @@ -1,4 +1,5 @@ -using AElf.Kernel.FeatureManager.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(FeatureManagerCoreAElfModule))] + 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 19b35a277f..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 589d2ddf81..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.FeatureManager; +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(FeatureManagerAElfModule), + typeof(FeatureManagementAElfModule), typeof(NodeAElfModule), typeof(SmartContractExecutionAElfModule), typeof(TransactionPoolAElfModule), 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.FeatureManager.Tests/IMockService.cs b/test/AElf.Kernel.FeatureManagement.Tests/IMockService.cs similarity index 50% rename from test/AElf.Kernel.FeatureManager.Tests/IMockService.cs rename to test/AElf.Kernel.FeatureManagement.Tests/IMockService.cs index a907c9ee0c..240ec6177a 100644 --- a/test/AElf.Kernel.FeatureManager.Tests/IMockService.cs +++ b/test/AElf.Kernel.FeatureManagement.Tests/IMockService.cs @@ -1,12 +1,13 @@ using System.Threading.Tasks; +using AElf.Kernel.FeatureManagement.Core; using Volo.Abp.DependencyInjection; -namespace AElf.Kernel.FeatureManager.Tests; +namespace AElf.Kernel.FeatureManagement.Tests; public interface IMockService { Task GetCurrentFeatureNameAsync(); - + Task IsFeatureADisabledAsync(); Task IsFeatureBDisabledAsync(); Task IsFeatureCDisabledAsync(); @@ -18,20 +19,18 @@ 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; - private readonly IFeatureDisableService _featureDisableService; + private readonly IFeatureManagementService _featureManagementService; - public MockService(IFeatureActiveService featureActiveService, IFeatureDisableService featureDisableService) + public MockService(IFeatureManagementService featureManagementService) { - _featureActiveService = featureActiveService; - _featureDisableService = featureDisableService; + _featureManagementService = featureManagementService; } public async Task GetCurrentFeatureNameAsync() { - if (await _featureActiveService.IsFeatureActive(Version3)) return Version3; + if (await _featureManagementService.IsFeatureActive(Version3)) return Version3; - if (await _featureActiveService.IsFeatureActive(Version2)) return Version2; + if (await _featureManagementService.IsFeatureActive(Version2)) return Version2; return Version1; } @@ -39,23 +38,23 @@ public async Task GetCurrentFeatureNameAsync() public Task IsFeatureADisabledAsync() { - return _featureDisableService.IsFeatureDisabledAsync("FeatureA"); + return _featureManagementService.IsFeatureDisabledAsync("FeatureA"); } public Task IsFeatureBDisabledAsync() { - return _featureDisableService.IsFeatureDisabledAsync("FeatureB", "FeatureBAndC"); + return _featureManagementService.IsFeatureDisabledAsync("FeatureB", "FeatureBAndC"); } public Task IsFeatureCDisabledAsync() { - return _featureDisableService.IsFeatureDisabledAsync("FeatureC", "FeatureBAndC"); + return _featureManagementService.IsFeatureDisabledAsync("FeatureC", "FeatureBAndC"); } public Task IsFeatureDDisabledAsync() { - return _featureDisableService.IsFeatureDisabledAsync("FeatureD"); + 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.FeatureManager.Tests/MinerList.cs b/test/AElf.Kernel.FeatureManagement.Tests/MinerList.cs similarity index 100% rename from test/AElf.Kernel.FeatureManager.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/FeatureDisableServiceTest.cs b/test/AElf.Kernel.FeatureManager.Tests/FeatureDisableServiceTest.cs deleted file mode 100644 index 80d9825866..0000000000 --- a/test/AElf.Kernel.FeatureManager.Tests/FeatureDisableServiceTest.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Threading.Tasks; -using AElf.Contracts.Configuration; -using AElf.CSharp.Core.Extension; -using AElf.Kernel.Blockchain.Application; -using AElf.Standards.ACS3; -using Google.Protobuf; -using Google.Protobuf.WellKnownTypes; -using Shouldly; -using Xunit; - -namespace AElf.Kernel.FeatureManager.Tests; - -public class FeatureDisableServiceTest : KernelFeatureManagerTestBase -{ - private readonly IMockService _mockService; - private readonly IBlockchainService _blockchainService; - - public FeatureDisableServiceTest() - { - _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 = FeatureManagerConstants.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.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; }