-
Notifications
You must be signed in to change notification settings - Fork 1k
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] ApplicationLogs from Plugin System #3619
Closed
cschuchardt88
wants to merge
7
commits into
neo-project:master
from
cschuchardt88:remove/plugin-applicationlogs
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ef57781
[Remove] ApplicationLogs from Plugin System
cschuchardt88 4761349
Fixed test
cschuchardt88 b4d79cd
Merge branch 'master' into remove/plugin-applicationlogs
Jim8y c18d756
Merge branch 'master' into remove/plugin-applicationlogs
Jim8y 700986a
Update src/Neo.CLI/Neo.CLI.csproj
shargon 46f1be8
Merge branch 'master' into remove/plugin-applicationlogs
Jim8y 8fc8d9f
Apply suggestions from code review
shargon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 3 additions & 6 deletions
9
...gins/ApplicationLogs/ApplicationLogs.json → src/Neo.CLI/configs/ApplicationLogs.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
{ | ||
"PluginConfiguration": { | ||
"ApplicationLogs": { | ||
"AutoStart": false, | ||
"Path": "ApplicationLogs_{0}", | ||
"Network": 860833102, | ||
"MaxStackSize": 65535, | ||
"Debug": false, | ||
"UnhandledExceptionPolicy": "StopPlugin" | ||
}, | ||
"Dependency": [ | ||
"RpcServer" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// LogReader.cs file belongs to the neo project and is free | ||
// ApplicationLogsPlugin.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
|
@@ -9,6 +9,7 @@ | |
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using Neo.ConsoleService; | ||
using Neo.Extensions; | ||
using Neo.IEventHandlers; | ||
|
@@ -26,63 +27,61 @@ | |
|
||
namespace Neo.Plugins.ApplicationLogs | ||
{ | ||
public class LogReader : Plugin, ICommittingHandler, ICommittedHandler, ILogHandler | ||
public class ApplicationLogsPlugin : IDisposable, ICommittingHandler, ICommittedHandler, ILogHandler | ||
{ | ||
#region Globals | ||
|
||
internal NeoStore _neostore; | ||
private NeoSystem _neosystem; | ||
internal readonly NeoStore NeoStore; | ||
private readonly NeoSystem _neoSystem; | ||
private readonly List<LogEventArgs> _logEvents; | ||
|
||
#endregion | ||
|
||
public override string Name => "ApplicationLogs"; | ||
public override string Description => "Synchronizes smart contract VM executions and notifications (NotifyLog) on blockchain."; | ||
protected override UnhandledExceptionPolicy ExceptionPolicy => Settings.Default.ExceptionPolicy; | ||
public UnhandledExceptionPolicy ExceptionPolicy => Settings.Current.ExceptionPolicy; | ||
|
||
#region Ctor | ||
|
||
public LogReader() | ||
public ApplicationLogsPlugin(string configDirectory, NeoSystem neoSystem) | ||
{ | ||
_logEvents = new(); | ||
Blockchain.Committing += ((ICommittingHandler)this).Blockchain_Committing_Handler; | ||
Blockchain.Committed += ((ICommittedHandler)this).Blockchain_Committed_Handler; | ||
|
||
var configuration = new ConfigurationBuilder() | ||
.AddJsonFile(Combine(configDirectory, "ApplicationLogs.json"), optional: true) | ||
.Build() | ||
.GetSection("ApplicationLogs"); | ||
|
||
Settings.Load(configuration); | ||
|
||
if (Settings.Current.AutoStart) | ||
{ | ||
var path = string.Format(Settings.Current.Path, neoSystem.Settings.Network.ToString("X8")); | ||
var store = neoSystem.LoadStore(GetFullPath(path)); | ||
NeoStore = new NeoStore(store); | ||
_neoSystem = neoSystem; | ||
RpcServerPlugin.RegisterMethods(this, neoSystem.Settings.Network); | ||
|
||
if (Settings.Current.Debug) | ||
ApplicationEngine.Log += ((ILogHandler)this).ApplicationEngine_Log_Handler; | ||
} | ||
|
||
(configuration as IDisposable)?.Dispose(); | ||
} | ||
|
||
#endregion | ||
|
||
#region Override Methods | ||
|
||
public override string ConfigFile => Combine(RootPath, "ApplicationLogs.json"); | ||
|
||
public override void Dispose() | ||
public void Dispose() | ||
{ | ||
Blockchain.Committing -= ((ICommittingHandler)this).Blockchain_Committing_Handler; | ||
Blockchain.Committed -= ((ICommittedHandler)this).Blockchain_Committed_Handler; | ||
if (Settings.Default.Debug) | ||
if (Settings.Current.Debug) | ||
ApplicationEngine.Log -= ((ILogHandler)this).ApplicationEngine_Log_Handler; | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected override void Configure() | ||
{ | ||
Settings.Load(GetConfiguration()); | ||
} | ||
|
||
protected override void OnSystemLoaded(NeoSystem system) | ||
{ | ||
if (system.Settings.Network != Settings.Default.Network) | ||
return; | ||
string path = string.Format(Settings.Default.Path, Settings.Default.Network.ToString("X8")); | ||
var store = system.LoadStore(GetFullPath(path)); | ||
_neostore = new NeoStore(store); | ||
_neosystem = system; | ||
RpcServerPlugin.RegisterMethods(this, Settings.Default.Network); | ||
|
||
if (Settings.Default.Debug) | ||
ApplicationEngine.Log += ((ILogHandler)this).ApplicationEngine_Log_Handler; | ||
} | ||
|
||
#endregion | ||
|
||
#region JSON RPC Methods | ||
|
@@ -128,7 +127,7 @@ internal void OnGetBlockCommand(string blockHashOrIndex, string eventName = null | |
UInt256 blockhash; | ||
if (uint.TryParse(blockHashOrIndex, out var blockIndex)) | ||
{ | ||
blockhash = NativeContract.Ledger.GetBlockHash(_neosystem.StoreView, blockIndex); | ||
blockhash = NativeContract.Ledger.GetBlockHash(_neoSystem.StoreView, blockIndex); | ||
} | ||
else if (UInt256.TryParse(blockHashOrIndex, out blockhash) == false) | ||
{ | ||
|
@@ -137,11 +136,11 @@ internal void OnGetBlockCommand(string blockHashOrIndex, string eventName = null | |
} | ||
|
||
var blockOnPersist = string.IsNullOrEmpty(eventName) ? | ||
_neostore.GetBlockLog(blockhash, TriggerType.OnPersist) : | ||
_neostore.GetBlockLog(blockhash, TriggerType.OnPersist, eventName); | ||
NeoStore.GetBlockLog(blockhash, TriggerType.OnPersist) : | ||
NeoStore.GetBlockLog(blockhash, TriggerType.OnPersist, eventName); | ||
var blockPostPersist = string.IsNullOrEmpty(eventName) ? | ||
_neostore.GetBlockLog(blockhash, TriggerType.PostPersist) : | ||
_neostore.GetBlockLog(blockhash, TriggerType.PostPersist, eventName); | ||
NeoStore.GetBlockLog(blockhash, TriggerType.PostPersist) : | ||
NeoStore.GetBlockLog(blockhash, TriggerType.PostPersist, eventName); | ||
|
||
if (blockOnPersist == null) | ||
ConsoleHelper.Error($"No logs."); | ||
|
@@ -157,8 +156,8 @@ internal void OnGetBlockCommand(string blockHashOrIndex, string eventName = null | |
internal void OnGetTransactionCommand(UInt256 txhash, string eventName = null) | ||
{ | ||
var txApplication = string.IsNullOrEmpty(eventName) ? | ||
_neostore.GetTransactionLog(txhash) : | ||
_neostore.GetTransactionLog(txhash, eventName); | ||
NeoStore.GetTransactionLog(txhash) : | ||
NeoStore.GetTransactionLog(txhash, eventName); | ||
|
||
if (txApplication == null) | ||
ConsoleHelper.Error($"No logs."); | ||
|
@@ -182,8 +181,8 @@ internal void OnGetContractCommand(UInt160 scripthash, uint page = 1, uint pageS | |
} | ||
|
||
var txContract = string.IsNullOrEmpty(eventName) ? | ||
_neostore.GetContractLog(scripthash, TriggerType.Application, page, pageSize) : | ||
_neostore.GetContractLog(scripthash, TriggerType.Application, eventName, page, pageSize); | ||
NeoStore.GetContractLog(scripthash, TriggerType.Application, page, pageSize) : | ||
NeoStore.GetContractLog(scripthash, TriggerType.Application, eventName, page, pageSize); | ||
|
||
if (txContract.Count == 0) | ||
ConsoleHelper.Error($"No logs."); | ||
|
@@ -198,40 +197,40 @@ internal void OnGetContractCommand(UInt160 scripthash, uint page = 1, uint pageS | |
|
||
void ICommittingHandler.Blockchain_Committing_Handler(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList) | ||
{ | ||
if (system.Settings.Network != Settings.Default.Network) | ||
if (!Settings.Current.AutoStart) | ||
return; | ||
|
||
if (_neostore is null) | ||
if (NeoStore is null) | ||
return; | ||
_neostore.StartBlockLogBatch(); | ||
_neostore.PutBlockLog(block, applicationExecutedList); | ||
if (Settings.Default.Debug) | ||
NeoStore.StartBlockLogBatch(); | ||
NeoStore.PutBlockLog(block, applicationExecutedList); | ||
if (Settings.Current.Debug) | ||
{ | ||
foreach (var appEng in applicationExecutedList.Where(w => w.Transaction != null)) | ||
{ | ||
var logs = _logEvents.Where(w => w.ScriptContainer.Hash == appEng.Transaction.Hash).ToList(); | ||
if (logs.Any()) | ||
_neostore.PutTransactionEngineLogState(appEng.Transaction.Hash, logs); | ||
NeoStore.PutTransactionEngineLogState(appEng.Transaction.Hash, logs); | ||
} | ||
_logEvents.Clear(); | ||
} | ||
} | ||
|
||
void ICommittedHandler.Blockchain_Committed_Handler(NeoSystem system, Block block) | ||
{ | ||
if (system.Settings.Network != Settings.Default.Network) | ||
if (!Settings.Current.AutoStart) | ||
return; | ||
if (_neostore is null) | ||
if (NeoStore is null) | ||
return; | ||
_neostore.CommitBlockLog(); | ||
NeoStore.CommitBlockLog(); | ||
} | ||
|
||
void ILogHandler.ApplicationEngine_Log_Handler(object sender, LogEventArgs e) | ||
{ | ||
if (Settings.Default.Debug == false) | ||
if (Settings.Current.AutoStart == false) | ||
return; | ||
|
||
if (_neosystem.Settings.Network != Settings.Default.Network) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We remove the network settings, unexpected change for this PR |
||
if (!Settings.Current.Debug) | ||
return; | ||
|
||
if (e.ScriptContainer == null) | ||
|
@@ -277,7 +276,7 @@ private void PrintExecutionToConsole(BlockchainExecutionModel model) | |
ConsoleHelper.Info($" {GetMethodParameterName(notifyItem.ScriptHash, notifyItem.EventName, ncount, i)}: ", $"{notifyItem.State[i].ToJson()}"); | ||
} | ||
} | ||
if (Settings.Default.Debug) | ||
if (Settings.Current.Debug) | ||
{ | ||
if (model.Logs.Length == 0) | ||
ConsoleHelper.Info("Logs: ", "[]"); | ||
|
@@ -311,7 +310,7 @@ private void PrintEventModelToConsole(IReadOnlyCollection<(BlockchainEventModel | |
|
||
private string GetMethodParameterName(UInt160 scriptHash, string methodName, uint ncount, int parameterIndex) | ||
{ | ||
var contract = NativeContract.ContractManagement.GetContract(_neosystem.StoreView, scriptHash); | ||
var contract = NativeContract.ContractManagement.GetContract(_neoSystem.StoreView, scriptHash); | ||
if (contract == null) | ||
return $"{parameterIndex}"; | ||
var contractEvent = contract.Manifest.Abi.Events.SingleOrDefault(s => s.Name == methodName && (uint)s.Parameters.Length == ncount); | ||
|
@@ -331,7 +330,7 @@ private JObject EventModelToJObject(BlockchainEventModel model) | |
|
||
private JObject TransactionToJObject(UInt256 txHash) | ||
{ | ||
var appLog = _neostore.GetTransactionLog(txHash); | ||
var appLog = NeoStore.GetTransactionLog(txHash); | ||
if (appLog == null) | ||
return null; | ||
|
||
|
@@ -346,7 +345,7 @@ private JObject TransactionToJObject(UInt256 txHash) | |
|
||
try | ||
{ | ||
trigger["stack"] = appLog.Stack.Select(s => s.ToJson(Settings.Default.MaxStackSize)).ToArray(); | ||
trigger["stack"] = appLog.Stack.Select(s => s.ToJson(Settings.Current.MaxStackSize)).ToArray(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
@@ -375,7 +374,7 @@ private JObject TransactionToJObject(UInt256 txHash) | |
return notification; | ||
}).ToArray(); | ||
|
||
if (Settings.Default.Debug) | ||
if (Settings.Current.Debug) | ||
{ | ||
trigger["logs"] = appLog.Logs.Select(s => | ||
{ | ||
|
@@ -392,8 +391,8 @@ private JObject TransactionToJObject(UInt256 txHash) | |
|
||
private JObject BlockToJObject(UInt256 blockHash) | ||
{ | ||
var blockOnPersist = _neostore.GetBlockLog(blockHash, TriggerType.OnPersist); | ||
var blockPostPersist = _neostore.GetBlockLog(blockHash, TriggerType.PostPersist); | ||
var blockOnPersist = NeoStore.GetBlockLog(blockHash, TriggerType.OnPersist); | ||
var blockPostPersist = NeoStore.GetBlockLog(blockHash, TriggerType.PostPersist); | ||
|
||
if (blockOnPersist == null && blockPostPersist == null) | ||
return null; | ||
|
@@ -419,7 +418,7 @@ private JObject BlockItemToJObject(BlockchainExecutionModel blockExecutionModel) | |
trigger["gasconsumed"] = blockExecutionModel.GasConsumed.ToString(); | ||
try | ||
{ | ||
trigger["stack"] = blockExecutionModel.Stack.Select(q => q.ToJson(Settings.Default.MaxStackSize)).ToArray(); | ||
trigger["stack"] = blockExecutionModel.Stack.Select(q => q.ToJson(Settings.Current.MaxStackSize)).ToArray(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
@@ -445,7 +444,7 @@ private JObject BlockItemToJObject(BlockchainExecutionModel blockExecutionModel) | |
return notification; | ||
}).ToArray(); | ||
|
||
if (Settings.Default.Debug) | ||
if (Settings.Current.Debug) | ||
{ | ||
trigger["logs"] = blockExecutionModel.Logs.Select(s => | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this affect the function in CLI.Plugin? like when we list the plugins, can we still get the ApplicationLogs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you will not see
ApplicationLogs
in the plugins. Future we will not have plugins. It will be features.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't list the plugin by RPC