Skip to content

Commit

Permalink
Combine IFeatureActiveService & IFeatureDisableService to IFeatureMan…
Browse files Browse the repository at this point in the history
…agementService
  • Loading branch information
eanzhao committed Aug 8, 2024
1 parent dcc054a commit 3570b8e
Show file tree
Hide file tree
Showing 33 changed files with 201 additions and 242 deletions.
6 changes: 3 additions & 3 deletions AElf.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions AElf.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,8 +13,8 @@ public class UnitTestPlainTransactionExecutingService : PlainTransactionExecutin
{
public UnitTestPlainTransactionExecutingService(ISmartContractExecutiveService smartContractExecutiveService,
IEnumerable<IPostExecutionPlugin> postPlugins, IEnumerable<IPreExecutionPlugin> prePlugins,
ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) : base(
smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService)
ITransactionContextFactory transactionContextFactory, IFeatureManagementService featureManagementService) : base(
smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureManagementService)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Volo.Abp.DependencyInjection;

namespace AElf.Kernel.FeatureManagement.Core;

public interface IFeatureManagementService
{
Task<bool> IsFeatureActive(string featureName);
Task<bool> IsFeatureDisabledAsync(params string[] featureNames);
}

public class DefaultFeatureManagementService : IFeatureManagementService, ITransientDependency
{
public Task<bool> IsFeatureActive(string featureName)
{
return Task.FromResult(false);
}

Check warning on line 16 in src/AElf.Kernel.FeatureManagement.Core/IFeatureManagementService.cs

View check run for this annotation

Codecov / codecov/patch

src/AElf.Kernel.FeatureManagement.Core/IFeatureManagementService.cs#L14-L16

Added lines #L14 - L16 were not covered by tests

public Task<bool> IsFeatureDisabledAsync(params string[] featureNames)
{
return Task.FromResult(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<PackageId>AElf.Kernel.FeatureManager</PackageId>
<PackageId>AElf.Kernel.FeatureManagement</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>Module that contains code to enable or disable new features of AElf.</Description>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AElf.Kernel.Configuration\AElf.Kernel.Configuration.csproj" />
<ProjectReference Include="..\AElf.Kernel.FeatureManager.Core\AElf.Kernel.FeatureManager.Core.csproj" />
<ProjectReference Include="..\AElf.Kernel.FeatureManagement.Core\AElf.Kernel.FeatureManagement.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
{
Expand Down
14 changes: 14 additions & 0 deletions src/AElf.Kernel.FeatureManagement/FeatureManagementAElfModule.cs
Original file line number Diff line number Diff line change
@@ -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
{
}
8 changes: 8 additions & 0 deletions src/AElf.Kernel.FeatureManagement/FeatureManagementOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;

namespace AElf.Kernel.FeatureManagement;

public class FeatureManagementOptions
{
public List<string> DisableFeatureNameList { get; set; }
}
70 changes: 70 additions & 0 deletions src/AElf.Kernel.FeatureManagement/FeatureManagementService.cs
Original file line number Diff line number Diff line change
@@ -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<bool> 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<bool> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.DependencyInjection;

namespace AElf.Kernel.FeatureManager;
namespace AElf.Kernel.FeatureManagement;

public interface IDisabledFeatureListProvider
{
Expand Down
8 changes: 0 additions & 8 deletions src/AElf.Kernel.FeatureManager.Core/IFeatureActiveService.cs

This file was deleted.

17 changes: 0 additions & 17 deletions src/AElf.Kernel.FeatureManager.Core/IFeatureDisableService.cs

This file was deleted.

8 changes: 0 additions & 8 deletions src/AElf.Kernel.FeatureManager/DisableFeatureOptions.cs

This file was deleted.

42 changes: 0 additions & 42 deletions src/AElf.Kernel.FeatureManager/FeatureActiveService.cs

This file was deleted.

42 changes: 0 additions & 42 deletions src/AElf.Kernel.FeatureManager/FeatureDisableService.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/AElf.Kernel.FeatureManager/FeatureManagerAElfModule.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ProjectReference Include="..\AElf.CSharp.Core\AElf.CSharp.Core.csproj"/>
<ProjectReference Include="..\AElf.Kernel.Core\AElf.Kernel.Core.csproj"/>
<ProjectReference Include="..\AElf.Kernel.SmartContract.Shared\AElf.Kernel.SmartContract.Shared.csproj"/>
<ProjectReference Include="..\AElf.Kernel.FeatureManager.Core\AElf.Kernel.FeatureManager.Core.csproj" />
<ProjectReference Include="..\AElf.Kernel.FeatureManagement.Core\AElf.Kernel.FeatureManagement.Core.csproj" />
</ItemGroup>
<ItemGroup>
<ContractStub Include="..\..\protobuf\acs0.proto">
Expand Down
Loading

0 comments on commit 3570b8e

Please sign in to comment.