Skip to content

Commit 0cd2d31

Browse files
committed
fix: remove IRenderers from BlockPolicySource
1 parent 5e77a05 commit 0cd2d31

File tree

7 files changed

+25
-49
lines changed

7 files changed

+25
-49
lines changed

.Lib9c.Benchmarks/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void Main(string[] args)
6060

6161
Log.Logger = new LoggerConfiguration().MinimumLevel.Verbose().WriteTo.Console().CreateLogger();
6262
Libplanet.Crypto.CryptoConfig.CryptoBackend = new Secp256K1CryptoBackend<SHA256>();
63-
var policySource = new BlockPolicySource(Log.Logger, LogEventLevel.Verbose);
63+
var policySource = new BlockPolicySource();
6464
IBlockPolicy policy =
6565
policySource.GetPolicy(
6666
maxTransactionsBytesPolicy: null,

.Lib9c.Tests/Action/RewardGoldTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ namespace Lib9c.Tests.Action
88
using System.Threading.Tasks;
99
using Bencodex;
1010
using Bencodex.Types;
11+
using Lib9c.Renderers;
1112
using Libplanet.Action;
1213
using Libplanet.Action.State;
1314
using Libplanet.Blockchain;
1415
using Libplanet.Blockchain.Policies;
16+
using Libplanet.Blockchain.Renderers;
1517
using Libplanet.Crypto;
1618
using Libplanet.Store;
1719
using Libplanet.Store.Trie;
@@ -479,7 +481,7 @@ void AssertMinerReward(int blockIndex, string expected)
479481
[InlineData(false)]
480482
public async Task Genesis_StateRootHash(bool mainnet)
481483
{
482-
BlockPolicySource blockPolicySource = new BlockPolicySource(Logger.None);
484+
BlockPolicySource blockPolicySource = new BlockPolicySource();
483485
NCStagePolicy stagePolicy = new NCStagePolicy(default, 2);
484486
IBlockPolicy policy = blockPolicySource.GetPolicy();
485487
Block genesis;
@@ -553,7 +555,7 @@ public async Task Genesis_StateRootHash(bool mainnet)
553555
blockChainStates: new BlockChainStates(store, stateStore),
554556
actionTypeLoader: new NCActionLoader()
555557
),
556-
renderers: blockPolicySource.GetRenderers()
558+
renderers: new IRenderer[] { new ActionRenderer(), new BlockRenderer() }
557559
);
558560
Assert.Equal(genesis.StateRootHash, blockChain.Genesis.StateRootHash);
559561
}

.Lib9c.Tests/Policy/BlockPolicyTest.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Lib9c.Tests
66
using System.Linq;
77
using System.Numerics;
88
using Bencodex.Types;
9+
using Lib9c.Renderers;
910
using Libplanet.Action;
1011
using Libplanet.Blockchain;
1112
using Libplanet.Blockchain.Policies;
@@ -45,7 +46,7 @@ public void ValidateNextBlockTx()
4546
var adminPrivateKey = new PrivateKey();
4647
var adminAddress = adminPrivateKey.ToAddress();
4748

48-
var blockPolicySource = new BlockPolicySource(Logger.None);
49+
var blockPolicySource = new BlockPolicySource();
4950
IBlockPolicy policy = blockPolicySource.GetPolicy(null, null, null, null);
5051
IStagePolicy stagePolicy = new VolatileStagePolicy();
5152
Block genesis = MakeGenesisBlock(
@@ -67,7 +68,7 @@ public void ValidateNextBlockTx()
6768
blockChainStates: new BlockChainStates(store, stateStore),
6869
actionTypeLoader: new NCActionLoader()
6970
),
70-
renderers: new[] { blockPolicySource.BlockRenderer }
71+
renderers: new[] { new BlockRenderer() }
7172
);
7273
Transaction txByStranger =
7374
Transaction.Create(
@@ -136,7 +137,7 @@ public void ValidateNextBlockTx_Mead()
136137
{
137138
var adminPrivateKey = new PrivateKey();
138139
var adminAddress = adminPrivateKey.ToAddress();
139-
var blockPolicySource = new BlockPolicySource(Logger.None);
140+
var blockPolicySource = new BlockPolicySource();
140141
var actionTypeLoader = new NCActionLoader();
141142
IBlockPolicy policy = blockPolicySource.GetPolicy(null, null, null, null);
142143
IStagePolicy stagePolicy = new VolatileStagePolicy();
@@ -177,7 +178,7 @@ public void ValidateNextBlockTx_Mead()
177178
blockChainStates: new BlockChainStates(store, stateStore),
178179
actionTypeLoader: new NCActionLoader()
179180
),
180-
renderers: new[] { blockPolicySource.BlockRenderer }
181+
renderers: new[] { new BlockRenderer() }
181182
);
182183
Assert.Equal(1 * Currencies.Mead, blockChain.GetBalance(adminAddress, Currencies.Mead));
183184
Assert.Equal(1 * Currencies.Mead, blockChain.GetBalance(MeadConfig.PatronAddress, Currencies.Mead));
@@ -243,7 +244,7 @@ public void BlockCommitFromNonValidator()
243244
var adminAddress = adminPrivateKey.ToAddress();
244245
var nonValidator = new PrivateKey();
245246

246-
var blockPolicySource = new BlockPolicySource(Logger.None);
247+
var blockPolicySource = new BlockPolicySource();
247248
IBlockPolicy policy = blockPolicySource.GetPolicy(null, null, null, null);
248249
IStagePolicy stagePolicy = new VolatileStagePolicy();
249250
Block genesis = MakeGenesisBlock(
@@ -265,7 +266,7 @@ public void BlockCommitFromNonValidator()
265266
blockChainStates: new BlockChainStates(store, stateStore),
266267
actionTypeLoader: new NCActionLoader()
267268
),
268-
renderers: new[] { blockPolicySource.BlockRenderer }
269+
renderers: new[] { new BlockRenderer() }
269270
);
270271
blockChain.MakeTransaction(
271272
adminPrivateKey,
@@ -288,7 +289,7 @@ public void MustNotIncludeBlockActionAtTransaction()
288289
new byte[] { 0x00, 0x01 }
289290
);
290291

291-
var blockPolicySource = new BlockPolicySource(Logger.None);
292+
var blockPolicySource = new BlockPolicySource();
292293
IBlockPolicy policy = blockPolicySource.GetPolicy(
293294
maxTransactionsBytesPolicy: null,
294295
minTransactionsPerBlockPolicy: null,
@@ -319,7 +320,7 @@ public void MustNotIncludeBlockActionAtTransaction()
319320
blockChainStates: new BlockChainStates(store, stateStore),
320321
actionTypeLoader: actionLoader
321322
),
322-
renderers: new[] { blockPolicySource.BlockRenderer }
323+
renderers: new[] { new BlockRenderer() }
323324
);
324325

325326
var unloadableAction = blockChain.MakeTransaction(
@@ -340,7 +341,7 @@ public void EarnMiningGoldWhenSuccessMining()
340341
new byte[] { 0x00, 0x01 }
341342
);
342343

343-
var blockPolicySource = new BlockPolicySource(Logger.None);
344+
var blockPolicySource = new BlockPolicySource();
344345
IBlockPolicy policy = blockPolicySource.GetPolicy(
345346
maxTransactionsBytesPolicy: null,
346347
minTransactionsPerBlockPolicy: null,
@@ -372,7 +373,7 @@ public void EarnMiningGoldWhenSuccessMining()
372373
blockChainStates: new BlockChainStates(store, stateStore),
373374
actionTypeLoader: new NCActionLoader()
374375
),
375-
renderers: new[] { blockPolicySource.BlockRenderer }
376+
renderers: new[] { new BlockRenderer() }
376377
);
377378

378379
blockChain.MakeTransaction(
@@ -392,7 +393,7 @@ public void ValidateNextBlockWithManyTransactions()
392393
{
393394
var adminPrivateKey = new PrivateKey();
394395
var adminPublicKey = adminPrivateKey.PublicKey;
395-
var blockPolicySource = new BlockPolicySource(Logger.None);
396+
var blockPolicySource = new BlockPolicySource();
396397
IBlockPolicy policy = blockPolicySource.GetPolicy(
397398
maxTransactionsBytesPolicy: null,
398399
minTransactionsPerBlockPolicy: null,
@@ -491,7 +492,7 @@ public void ValidateNextBlockWithManyTransactionsPerSigner()
491492
{
492493
var adminPrivateKey = new PrivateKey();
493494
var adminPublicKey = adminPrivateKey.PublicKey;
494-
var blockPolicySource = new BlockPolicySource(Logger.None);
495+
var blockPolicySource = new BlockPolicySource();
495496
IBlockPolicy policy = blockPolicySource.GetPolicy(
496497
maxTransactionsBytesPolicy: null,
497498
minTransactionsPerBlockPolicy: null,

.Lib9c.Tests/StagePolicyTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Lib9c.Tests
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Threading.Tasks;
7+
using Lib9c.Renderers;
78
using Lib9c.Tests.TestHelper;
89
using Libplanet.Action;
910
using Libplanet.Blockchain;
@@ -243,11 +244,11 @@ private void AssertTxs(BlockChain blockChain, NCStagePolicy policy, params Trans
243244

244245
private BlockChain MakeChainWithStagePolicy(NCStagePolicy stagePolicy)
245246
{
246-
BlockPolicySource blockPolicySource = new BlockPolicySource(Logger.None);
247+
BlockPolicySource blockPolicySource = new BlockPolicySource();
247248
IBlockPolicy policy = blockPolicySource.GetPolicy();
248249
BlockChain chain =
249250
BlockChainHelper.MakeBlockChain(
250-
blockRenderers: new[] { blockPolicySource.BlockRenderer },
251+
blockRenderers: new[] { new BlockRenderer() },
251252
policy: policy,
252253
stagePolicy: stagePolicy);
253254
return chain;

Lib9c.DevExtensions/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ IStateStore StateStore
4949
IKeyValueStore stateKeyValueStore = null
5050
)
5151
{
52-
var policySource = new BlockPolicySource(logger);
52+
var policySource = new BlockPolicySource();
5353
IBlockPolicy policy = policySource.GetPolicy();
5454
IStagePolicy stagePolicy = new VolatileStagePolicy();
5555
IStore store = new RocksDBStore(storePath);

Lib9c.Policy/Policy/BlockPolicySource.cs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Collections.Immutable;
43
using System.Linq;
54
using Bencodex.Types;
65
using Lib9c.Abstractions;
7-
using Lib9c.Renderers;
86
using Libplanet.Action;
97
using Libplanet.Action.Loader;
108
using Libplanet.Blockchain;
119
using Libplanet.Blockchain.Policies;
12-
using Libplanet.Blockchain.Renderers;
1310
using Nekoyume.Action;
1411
using Nekoyume.Action.Loader;
1512
using Nekoyume.Model;
1613
using Nekoyume.Model.State;
17-
using Serilog;
18-
using Serilog.Events;
1914
using Lib9c;
2015
using Libplanet.Crypto;
2116
using Libplanet.Types.Blocks;
@@ -41,30 +36,10 @@ public partial class BlockPolicySource
4136

4237
private readonly IActionLoader _actionLoader;
4338

44-
// FIXME: Why does BlockPolicySource have renderers?
45-
public readonly ActionRenderer ActionRenderer = new ActionRenderer();
46-
47-
// FIXME: Why does BlockPolicySource have renderers?
48-
public readonly BlockRenderer BlockRenderer = new BlockRenderer();
49-
50-
// FIXME: Why does BlockPolicySource have renderers?
51-
public readonly LoggedActionRenderer LoggedActionRenderer;
52-
53-
// FIXME: Why does BlockPolicySource have renderers?
54-
public readonly LoggedRenderer LoggedBlockRenderer;
55-
5639
public BlockPolicySource(
57-
ILogger logger,
58-
LogEventLevel logEventLevel = LogEventLevel.Verbose,
59-
IActionLoader actionLoader = null)
40+
IActionLoader? actionLoader = null)
6041
{
61-
_actionLoader ??= new NCActionLoader();
62-
63-
LoggedActionRenderer =
64-
new LoggedActionRenderer(ActionRenderer, logger, logEventLevel);
65-
66-
LoggedBlockRenderer =
67-
new LoggedRenderer(BlockRenderer, logger, logEventLevel);
42+
_actionLoader = actionLoader ?? new NCActionLoader();
6843
}
6944

7045
/// <summary>
@@ -175,9 +150,6 @@ internal IBlockPolicy GetPolicy(
175150
#endif
176151
}
177152

178-
public IEnumerable<IRenderer> GetRenderers() =>
179-
new IRenderer[] { BlockRenderer, LoggedActionRenderer };
180-
181153
internal static TxPolicyViolationException ValidateNextBlockTxRaw(
182154
BlockChain blockChain,
183155
IActionLoader actionLoader,

Lib9c.Utils/BlockHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static Block ProposeGenesisBlock(
9696
{
9797
actions.AddRange(actionBases);
9898
}
99-
var blockAction = new BlockPolicySource(Log.Logger).GetPolicy().BlockAction;
99+
var blockAction = new BlockPolicySource().GetPolicy().BlockAction;
100100
var actionLoader = new NCActionLoader();
101101
var actionEvaluator = new ActionEvaluator(
102102
_ => blockAction,

0 commit comments

Comments
 (0)