Skip to content

Commit

Permalink
Merge pull request #3960 from riemannulus/imp/interfacing-policy-acti…
Browse files Browse the repository at this point in the history
…on-registy

🔧 refactor: interfacing policy action registy
  • Loading branch information
riemannulus authored Oct 8, 2024
2 parents cf42918 + fc702d0 commit 9bd2216
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ To be released.
to `IReadOnlyList<BlockHash>`. [[#3949]]
- (Libplanet.Net) Changed `ActionExecutionState` and `BlockVerificationState`
to be `Obsolete`. [[#3943]]
- (Libplanet.Action) Export `IPolicyActionsRegistry` interface
from `PolicyActionsRegistry`. [[#3960]]

### Backward-incompatible network protocol changes

Expand Down Expand Up @@ -66,6 +68,7 @@ To be released.
[#3948]: https://github.com/planetarium/libplanet/pull/3948
[#3949]: https://github.com/planetarium/libplanet/pull/3949
[#3950]: https://github.com/planetarium/libplanet/pull/3950
[#3960]: https://github.com/planetarium/libplanet/pull/3960


Version 5.2.2
Expand Down
4 changes: 2 additions & 2 deletions src/Libplanet.Action/ActionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Libplanet.Action
public class ActionEvaluator : IActionEvaluator
{
private readonly ILogger _logger;
private readonly PolicyActionsRegistry _policyActionsRegistry;
private readonly IPolicyActionsRegistry _policyActionsRegistry;
private readonly IStateStore _stateStore;
private readonly IActionLoader _actionLoader;

Expand All @@ -40,7 +40,7 @@ public class ActionEvaluator : IActionEvaluator
/// <param name="actionTypeLoader"> A <see cref="IActionLoader"/> implementation using
/// action type lookup.</param>
public ActionEvaluator(
PolicyActionsRegistry policyActionsRegistry,
IPolicyActionsRegistry policyActionsRegistry,
IStateStore stateStore,
IActionLoader actionTypeLoader)
{
Expand Down
36 changes: 36 additions & 0 deletions src/Libplanet.Action/IPolicyActionsRegistry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Immutable;

namespace Libplanet.Action
{
public interface IPolicyActionsRegistry
{
/// <summary>
/// An array of <see cref="IAction"/> to execute and be rendered at the beginning
/// for every block, if any.</summary>
ImmutableArray<IAction> BeginBlockActions
{
get;
}

Check warning on line 13 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Closing brace should be followed by blank line

Check warning on line 13 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Closing brace should be followed by blank line

Check warning on line 13 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (linux-8cores)

Closing brace should be followed by blank line

Check warning on line 13 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (windows-8cores)

Closing brace should be followed by blank line

Check warning on line 13 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Closing brace should be followed by blank line

Check warning on line 13 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (macOS, self-hosted, ARM64)

Closing brace should be followed by blank line
/// <summary>

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Elements should be separated by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Single-line comment should be preceded by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Elements should be separated by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Elements should be separated by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Single-line comment should be preceded by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Elements should be separated by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (linux-8cores)

Elements should be separated by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (linux-8cores)

Single-line comment should be preceded by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (windows-8cores)

Elements should be separated by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (windows-8cores)

Single-line comment should be preceded by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Elements should be separated by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Single-line comment should be preceded by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Elements should be separated by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (macOS, self-hosted, ARM64)

Elements should be separated by blank line

Check warning on line 14 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (macOS, self-hosted, ARM64)

Single-line comment should be preceded by blank line
/// An array of <see cref="IAction"/> to execute and be rendered at the end
/// for every block, if any.</summary>
ImmutableArray<IAction> EndBlockActions
{
get;
}

Check warning on line 20 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Closing brace should be followed by blank line

Check warning on line 20 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Closing brace should be followed by blank line

Check warning on line 20 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (linux-8cores)

Closing brace should be followed by blank line

Check warning on line 20 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (windows-8cores)

Closing brace should be followed by blank line

Check warning on line 20 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Closing brace should be followed by blank line

Check warning on line 20 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (macOS, self-hosted, ARM64)

Closing brace should be followed by blank line
/// <summary>

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Elements should be separated by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Single-line comment should be preceded by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Elements should be separated by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Single-line comment should be preceded by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (linux-8cores)

Elements should be separated by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (linux-8cores)

Single-line comment should be preceded by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (windows-8cores)

Elements should be separated by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (windows-8cores)

Single-line comment should be preceded by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Elements should be separated by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Single-line comment should be preceded by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (macOS, self-hosted, ARM64)

Elements should be separated by blank line

Check warning on line 21 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (macOS, self-hosted, ARM64)

Single-line comment should be preceded by blank line
/// An array of <see cref="IAction"/> to execute and be rendered at the beginning
/// for every transaction, if any.</summary>
ImmutableArray<IAction> BeginTxActions
{
get;
}

Check warning on line 27 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Closing brace should be followed by blank line

Check warning on line 27 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Closing brace should be followed by blank line

Check warning on line 27 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (linux-8cores)

Closing brace should be followed by blank line

Check warning on line 27 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (windows-8cores)

Closing brace should be followed by blank line

Check warning on line 27 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Closing brace should be followed by blank line

Check warning on line 27 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (macOS, self-hosted, ARM64)

Closing brace should be followed by blank line
/// <summary>

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Elements should be separated by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / check-build

Single-line comment should be preceded by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Elements should be separated by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / docs

Single-line comment should be preceded by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (linux-8cores)

Elements should be separated by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (linux-8cores)

Single-line comment should be preceded by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (windows-8cores)

Elements should be separated by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (windows-8cores)

Single-line comment should be preceded by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Elements should be separated by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / build

Single-line comment should be preceded by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (macOS, self-hosted, ARM64)

Elements should be separated by blank line

Check warning on line 28 in src/Libplanet.Action/IPolicyActionsRegistry.cs

View workflow job for this annotation

GitHub Actions / Run Benchmark.Net benchmarks (macOS, self-hosted, ARM64)

Single-line comment should be preceded by blank line
/// An array of <see cref="IAction"/> to execute and be rendered at the end
/// for every transaction, if any.</summary>
ImmutableArray<IAction> EndTxActions
{
get;
}
}
}
2 changes: 1 addition & 1 deletion src/Libplanet.Action/PolicyActionsRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Libplanet.Action
{
public class PolicyActionsRegistry
public class PolicyActionsRegistry : IPolicyActionsRegistry
{
/// <summary>
/// A class containing policy actions to evaluate at each situation.
Expand Down
6 changes: 3 additions & 3 deletions src/Libplanet/Blockchain/Policies/BlockPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BlockPolicy : IBlockPolicy
private readonly Func<BlockChain, Block, BlockPolicyViolationException?>
_validateNextBlock;

private readonly PolicyActionsRegistry _policyActionsRegistry;
private readonly IPolicyActionsRegistry _policyActionsRegistry;
private readonly Func<long, long> _getMaxTransactionsBytes;
private readonly Func<long, int> _getMinTransactionsPerBlock;
private readonly Func<long, int> _getMaxTransactionsPerBlock;
Expand Down Expand Up @@ -73,7 +73,7 @@ public class BlockPolicy : IBlockPolicy
/// Goes to <see cref="GetMaxEvidencePendingDuration"/>. Set to a constant function
/// of <c>10</c> by default.</param>
public BlockPolicy(
PolicyActionsRegistry? policyActionsRegistry = null,
IPolicyActionsRegistry? policyActionsRegistry = null,
TimeSpan? blockInterval = null,
Func<BlockChain, Transaction, TxPolicyViolationException?>?
validateNextBlockTx = null,
Expand Down Expand Up @@ -169,7 +169,7 @@ public BlockPolicy(
}
}

public PolicyActionsRegistry PolicyActionsRegistry => _policyActionsRegistry;
public IPolicyActionsRegistry PolicyActionsRegistry => _policyActionsRegistry;

/// <summary>
/// Targeted time interval between two consecutive <see cref="Block"/>s.
Expand Down
2 changes: 1 addition & 1 deletion src/Libplanet/Blockchain/Policies/IBlockPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IBlockPolicy
/// <summary>
/// A set of policy <see cref="IAction"/>s to evaluate at each situation.
/// </summary>
PolicyActionsRegistry PolicyActionsRegistry { get; }
IPolicyActionsRegistry PolicyActionsRegistry { get; }

/// <summary>
/// Checks if a <see cref="Transaction"/> can be included in a yet to be mined
Expand Down
2 changes: 1 addition & 1 deletion src/Libplanet/Blockchain/Policies/NullBlockPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public NullBlockPolicy(

public ISet<Address> BlockedMiners { get; } = new HashSet<Address>();

public PolicyActionsRegistry PolicyActionsRegistry => new PolicyActionsRegistry();
public IPolicyActionsRegistry PolicyActionsRegistry => new PolicyActionsRegistry();

public ImmutableArray<IAction> BeginBlockActions => ImmutableArray<IAction>.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public RocksDBStoreBlockChainTest(ITestOutputHelper output)
}

protected override StoreFixture GetStoreFixture(
PolicyActionsRegistry policyActionsRegistry = null)
IPolicyActionsRegistry policyActionsRegistry = null)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion test/Libplanet.RocksDBStore.Tests/RocksDBStoreFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Libplanet.RocksDBStore.Tests
public class RocksDBStoreFixture : StoreFixture
{
public RocksDBStoreFixture(
PolicyActionsRegistry policyActionsRegistry = null)
IPolicyActionsRegistry policyActionsRegistry = null)
: base(policyActionsRegistry)
{
Path = System.IO.Path.Combine(
Expand Down
2 changes: 1 addition & 1 deletion test/Libplanet.Tests/Blockchain/BlockChainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ void BuildIndex(Guid id, Block block)
/// <param name="policyActionsRegistry">The policy block actions to use.</param>
/// <returns>The store fixture that every test in this class depends on.</returns>
protected virtual StoreFixture GetStoreFixture(
PolicyActionsRegistry policyActionsRegistry = null)
IPolicyActionsRegistry policyActionsRegistry = null)
=> new MemoryStoreFixture(policyActionsRegistry);

private (Address[], Transaction[]) MakeFixturesForAppendTests(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public DefaultStoreBlockChainTest(ITestOutputHelper output)
}

protected override StoreFixture GetStoreFixture(
PolicyActionsRegistry policyActionsRegistry = null) =>
IPolicyActionsRegistry policyActionsRegistry = null) =>
new DefaultStoreFixture(policyActionsRegistry: policyActionsRegistry);
}
}
2 changes: 1 addition & 1 deletion test/Libplanet.Tests/Store/DefaultStoreFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DefaultStoreFixture : StoreFixture, IDisposable
{
public DefaultStoreFixture(
bool memory = true,
PolicyActionsRegistry policyActionsRegistry = null)
IPolicyActionsRegistry policyActionsRegistry = null)
: base(policyActionsRegistry)
{
if (memory)
Expand Down
2 changes: 1 addition & 1 deletion test/Libplanet.Tests/Store/MemoryStoreFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Libplanet.Tests.Store
public class MemoryStoreFixture : StoreFixture
{
public MemoryStoreFixture(
PolicyActionsRegistry policyActionsRegistry = null)
IPolicyActionsRegistry policyActionsRegistry = null)
: base(policyActionsRegistry)
{
Store = new MemoryStore();
Expand Down
2 changes: 1 addition & 1 deletion test/Libplanet.Tests/Store/StoreFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Libplanet.Tests.Store
{
public abstract class StoreFixture : IDisposable
{
protected StoreFixture(PolicyActionsRegistry policyActionsRegistry = null)
protected StoreFixture(IPolicyActionsRegistry policyActionsRegistry = null)
{
Path = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<ItemGroup>
<PackageReference Include="Cocona.Lite" Version="2.0.*" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="System.Text.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tools/Libplanet.Explorer.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public DumbBlockPolicy(BlockPolicy blockPolicy)
_impl = blockPolicy;
}

public PolicyActionsRegistry PolicyActionsRegistry => _impl.PolicyActionsRegistry;
public IPolicyActionsRegistry PolicyActionsRegistry => _impl.PolicyActionsRegistry;

public int GetMinTransactionsPerBlock(long index) =>
_impl.GetMinTransactionsPerBlock(index);
Expand Down

0 comments on commit 9bd2216

Please sign in to comment.