Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Remove IRenderers from BlockPolicySource #2255

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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(Logger.None).GetPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new BlockChainStates(store, stateStore),
Original file line number Diff line number Diff line change
@@ -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(Logger.None).GetTestPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().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(Logger.None).GetTestPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().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(Logger.None).GetPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().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(Logger.None).GetPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
new BlockChainStates(store, stateStore),
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ public void Inspect(
}

IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource(Logger.None).GetPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
IStore store = storeType.CreateStore(storePath);
var stateStore = new TrieStateStore(new DefaultKeyValueStore(null));
if (!(store.GetCanonicalChainId() is { } chainId))
4 changes: 2 additions & 2 deletions NineChronicles.Headless.Executable/Commands/ReplayCommand.cs
Original file line number Diff line number Diff line change
@@ -475,7 +475,7 @@ private static (FileStream? fs, StreamWriter? sw) GetOutputFileStream(
var genesisBlock = store.GetBlock(genesisBlockHash);

// Make BlockChain and blocks.
var policy = new BlockPolicySource(Logger.None).GetPolicy();
var policy = new BlockPolicySource().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(Logger.None).GetPolicy();
var policy = new BlockPolicySource().GetPolicy();
IActionLoader actionLoader = new NCActionLoader();
return new ActionEvaluator(
_ => policy.BlockAction,
17 changes: 8 additions & 9 deletions NineChronicles.Headless/NineChroniclesNodeService.cs
Original file line number Diff line number Diff line change
@@ -84,11 +84,10 @@ public NineChroniclesNodeService(
Properties = properties;

LogEventLevel logLevel = LogEventLevel.Debug;
var blockPolicySource = new BlockPolicySource(Log.Logger, logLevel);
IStagePolicy stagePolicy = new NCStagePolicy(txLifeTime, txQuotaPerSigner);

BlockRenderer = blockPolicySource.BlockRenderer;
ActionRenderer = blockPolicySource.ActionRenderer;
BlockRenderer = new BlockRenderer();
ActionRenderer = new ActionRenderer();
ExceptionRenderer = new ExceptionRenderer();
NodeStatusRenderer = new NodeStatusRenderer();
var renderers = new List<IRenderer>();
@@ -101,12 +100,12 @@ public NineChroniclesNodeService(

if (Properties.Render)
{
renderers.Add(blockPolicySource.BlockRenderer);
renderers.Add(blockPolicySource.LoggedActionRenderer);
renderers.Add(BlockRenderer);
renderers.Add(new LoggedActionRenderer(ActionRenderer, Log.Logger, logLevel));
}
else if (Properties.LogActionRenders)
{
renderers.Add(blockPolicySource.BlockRenderer);
renderers.Add(BlockRenderer);
// The following "nullRenderer" does nothing. It's just for filling
// the LoggedActionRenderer<T>() constructor's parameter:
IActionRenderer nullRenderer = new AnonymousActionRenderer();
@@ -120,7 +119,7 @@ public NineChroniclesNodeService(
}
else
{
renderers.Add(blockPolicySource.LoggedBlockRenderer);
renderers.Add(new LoggedRenderer(BlockRenderer, Log.Logger, logLevel));
}

if (strictRendering)
@@ -242,7 +241,7 @@ StandaloneContext context

internal static IBlockPolicy GetBlockPolicy(NetworkType networkType, IActionLoader actionLoader)
{
var source = new BlockPolicySource(Log.Logger, LogEventLevel.Debug, actionLoader);
var source = new BlockPolicySource(actionLoader);
return networkType switch
{
NetworkType.Main => source.GetPolicy(),
@@ -255,7 +254,7 @@ internal static IBlockPolicy GetBlockPolicy(NetworkType networkType, IActionLoad
}

internal static IBlockPolicy GetTestBlockPolicy() =>
new BlockPolicySource(Log.Logger, LogEventLevel.Debug).GetTestPolicy();
new BlockPolicySource().GetTestPolicy();

public Task<bool> CheckPeer(string addr) => NodeService?.CheckPeer(addr) ?? throw new InvalidOperationException();