From 9aabae1302d14588b671ad7e096e5680e6b4b999 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Mon, 25 Sep 2023 20:47:18 +0900 Subject: [PATCH] Revert renderer --- Lib9c | 2 +- .../Commands/AccountCommandTest.cs | 2 +- .../Commands/ChainCommandTest.cs | 8 ++++---- .../Commands/ChainCommand.cs | 2 +- .../Commands/ReplayCommand.cs | 4 ++-- .../NineChroniclesNodeService.cs | 17 +++++++++-------- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Lib9c b/Lib9c index ccd74ec1d..04ec16ebb 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit ccd74ec1d303d1c07c3ecff7d64d98c346e122ce +Subproject commit 04ec16ebbe79f4d9547c1fc1d55b0d81185095c9 diff --git a/NineChronicles.Headless.Executable.Tests/Commands/AccountCommandTest.cs b/NineChronicles.Headless.Executable.Tests/Commands/AccountCommandTest.cs index 08d7a2759..7bb3fa3e0 100644 --- a/NineChronicles.Headless.Executable.Tests/Commands/AccountCommandTest.cs +++ b/NineChronicles.Headless.Executable.Tests/Commands/AccountCommandTest.cs @@ -46,7 +46,7 @@ public void Balance(StoreType storeType) var stateKeyValueStore = new RocksDBKeyValueStore(statesPath); var stateStore = new TrieStateStore(stateKeyValueStore); IStagePolicy stagePolicy = new VolatileStagePolicy(); - IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy(); + IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetPolicy(); ActionEvaluator actionEvaluator = new ActionEvaluator( _ => blockPolicy.BlockAction, new BlockChainStates(store, stateStore), diff --git a/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs b/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs index dc21068eb..17f04ca9a 100644 --- a/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs +++ b/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs @@ -90,7 +90,7 @@ public void Inspect(StoreType storeType) IStore store = storeType.CreateStore(_storePath); IStateStore stateStore = new TrieStateStore(new RocksDBKeyValueStore(Path.Combine(_storePath, "states"))); IStagePolicy stagePolicy = new VolatileStagePolicy(); - IBlockPolicy blockPolicy = new BlockPolicySource().GetTestPolicy(); + IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetTestPolicy(); ActionEvaluator actionEvaluator = new ActionEvaluator( _ => blockPolicy.BlockAction, new BlockChainStates(store, stateStore), @@ -151,7 +151,7 @@ public void Truncate(StoreType storeType) IStore store = storeType.CreateStore(_storePath); IStateStore stateStore = new TrieStateStore(new RocksDBKeyValueStore(Path.Combine(_storePath, "states"))); IStagePolicy stagePolicy = new VolatileStagePolicy(); - IBlockPolicy blockPolicy = new BlockPolicySource().GetTestPolicy(); + IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetTestPolicy(); ActionEvaluator actionEvaluator = new ActionEvaluator( _ => blockPolicy.BlockAction, new BlockChainStates(store, stateStore), @@ -230,7 +230,7 @@ public void PruneState(StoreType storeType) var stateKeyValueStore = new RocksDBKeyValueStore(statesPath); var stateStore = new TrieStateStore(stateKeyValueStore); IStagePolicy stagePolicy = new VolatileStagePolicy(); - IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy(); + IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetPolicy(); ActionEvaluator actionEvaluator = new ActionEvaluator( _ => blockPolicy.BlockAction, new BlockChainStates(store, stateStore), @@ -272,7 +272,7 @@ public void Snapshot(StoreType storeType) var stateKeyValueStore = new RocksDBKeyValueStore(statesPath); var stateStore = new TrieStateStore(stateKeyValueStore); IStagePolicy stagePolicy = new VolatileStagePolicy(); - IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy(); + IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetPolicy(); ActionEvaluator actionEvaluator = new ActionEvaluator( _ => blockPolicy.BlockAction, new BlockChainStates(store, stateStore), diff --git a/NineChronicles.Headless.Executable/Commands/ChainCommand.cs b/NineChronicles.Headless.Executable/Commands/ChainCommand.cs index 22ebe8425..817fc859e 100644 --- a/NineChronicles.Headless.Executable/Commands/ChainCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/ChainCommand.cs @@ -114,7 +114,7 @@ public void Inspect( } IStagePolicy stagePolicy = new VolatileStagePolicy(); - IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy(); + IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetPolicy(); IStore store = storeType.CreateStore(storePath); var stateStore = new TrieStateStore(new DefaultKeyValueStore(null)); if (!(store.GetCanonicalChainId() is { } chainId)) diff --git a/NineChronicles.Headless.Executable/Commands/ReplayCommand.cs b/NineChronicles.Headless.Executable/Commands/ReplayCommand.cs index 9fb831a5a..19ebea278 100644 --- a/NineChronicles.Headless.Executable/Commands/ReplayCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/ReplayCommand.cs @@ -475,7 +475,7 @@ private static (FileStream? fs, StreamWriter? sw) GetOutputFileStream( var genesisBlock = store.GetBlock(genesisBlockHash); // Make BlockChain and blocks. - var policy = new BlockPolicySource().GetPolicy(); + var policy = new BlockPolicySource(Logger.None).GetPolicy(); var stagePolicy = new VolatileStagePolicy(); var stateKeyValueStore = new RocksDBKeyValueStore(Path.Combine(storePath, "states")); var stateStore = new TrieStateStore(stateKeyValueStore); @@ -525,7 +525,7 @@ private Transaction LoadTx(string txPath) private ActionEvaluator GetActionEvaluator(BlockChain blockChain) { - var policy = new BlockPolicySource().GetPolicy(); + var policy = new BlockPolicySource(Logger.None).GetPolicy(); IActionLoader actionLoader = new NCActionLoader(); return new ActionEvaluator( _ => policy.BlockAction, diff --git a/NineChronicles.Headless/NineChroniclesNodeService.cs b/NineChronicles.Headless/NineChroniclesNodeService.cs index 9e075af5b..155068c0e 100644 --- a/NineChronicles.Headless/NineChroniclesNodeService.cs +++ b/NineChronicles.Headless/NineChroniclesNodeService.cs @@ -84,10 +84,11 @@ public NineChroniclesNodeService( Properties = properties; LogEventLevel logLevel = LogEventLevel.Debug; + var blockPolicySource = new BlockPolicySource(Log.Logger, logLevel); IStagePolicy stagePolicy = new NCStagePolicy(txLifeTime, txQuotaPerSigner); - BlockRenderer = new BlockRenderer(); - ActionRenderer = new ActionRenderer(); + BlockRenderer = blockPolicySource.BlockRenderer; + ActionRenderer = blockPolicySource.ActionRenderer; ExceptionRenderer = new ExceptionRenderer(); NodeStatusRenderer = new NodeStatusRenderer(); var renderers = new List(); @@ -100,12 +101,12 @@ public NineChroniclesNodeService( if (Properties.Render) { - renderers.Add(BlockRenderer); - renderers.Add(new LoggedActionRenderer(ActionRenderer, Log.Logger, logLevel)); + renderers.Add(blockPolicySource.BlockRenderer); + renderers.Add(blockPolicySource.LoggedActionRenderer); } else if (Properties.LogActionRenders) { - renderers.Add(BlockRenderer); + renderers.Add(blockPolicySource.BlockRenderer); // The following "nullRenderer" does nothing. It's just for filling // the LoggedActionRenderer() constructor's parameter: IActionRenderer nullRenderer = new AnonymousActionRenderer(); @@ -119,7 +120,7 @@ public NineChroniclesNodeService( } else { - renderers.Add(new LoggedRenderer(BlockRenderer, Log.Logger, logLevel)); + renderers.Add(blockPolicySource.LoggedBlockRenderer); } if (strictRendering) @@ -241,7 +242,7 @@ StandaloneContext context internal static IBlockPolicy GetBlockPolicy(NetworkType networkType, IActionLoader actionLoader) { - var source = new BlockPolicySource(actionLoader); + var source = new BlockPolicySource(Log.Logger, LogEventLevel.Debug, actionLoader); return networkType switch { NetworkType.Main => source.GetPolicy(), @@ -254,7 +255,7 @@ internal static IBlockPolicy GetBlockPolicy(NetworkType networkType, IActionLoad } internal static IBlockPolicy GetTestBlockPolicy() => - new BlockPolicySource().GetTestPolicy(); + new BlockPolicySource(Log.Logger, LogEventLevel.Debug).GetTestPolicy(); public Task CheckPeer(string addr) => NodeService?.CheckPeer(addr) ?? throw new InvalidOperationException();