-
Notifications
You must be signed in to change notification settings - Fork 100
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
add logs to execution #737
Conversation
will update utest 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.
Could you do it without the neo changes? Attach an event before and remove later, like in neo UT
@shargon working on that |
@@ -83,6 +83,14 @@ private JObject GetInvokeResult(byte[] script, Signer[] signers = null, Witness[ | |||
obj["state"] = ToJson(n.State, session); | |||
return obj; | |||
})); | |||
json["logs"] = new JArray(session.Engine.Notifications.Select(n => |
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 is incorrect.
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 logic was when i try to add the log in the core, checking and removing useless code.
src/ApplicationLogs/LogReader.cs
Outdated
} | ||
list.Add(e); | ||
} | ||
ApplicationEngine.Log += Ev; |
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.
Should we add a setting in config.json to control whether logs are saved or not? I think maybe not all nodes want to do this.
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.
The term log
and notify
is abusively miss used, I don't think the user could tell which is log and which is notify.
@nicolegys May you please help me test this? |
src/RpcServer/RpcServerPlugin.cs
Outdated
} | ||
_logs.Enqueue(e); | ||
} | ||
ApplicationEngine.Log += Ev; |
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 method will be called multiple times.
Why are we doing this? |
src/ApplicationLogs/LogReader.cs
Outdated
@@ -25,7 +25,7 @@ namespace Neo.Plugins | |||
{ | |||
public class LogReader : Plugin | |||
{ | |||
private DB db; | |||
private DB _db; |
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.
Changes like this make it much harder to review PRs. Reviewers need to check each change to see if it is substantive or name change.
src/RpcServer/RpcServerPlugin.cs
Outdated
// It is potentially possible to have dos attack by sending a lot of transactions and logs. | ||
// To prevent this, we limit the number of logs to be logged per contract. | ||
// If the number of logs is greater than MAX_LOG_EVENTS, we remove the oldest log. | ||
private static void Ev(object _, LogEventArgs e) |
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.
All of this log tracking logic should be in RpcServer not RpcServerPlugin.
The separation of RpcServerPlugin and RpcServer is to enable NeoExpress to host RpcServer directly. So any changes to behavior of this plugin must be in RpcServer class so that NeoExpress can use it
@@ -49,6 +48,7 @@ public RpcServer(NeoSystem system, RpcServerSettings settings) | |||
Initialize_SmartContract(); | |||
} | |||
|
|||
|
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.
Like the variable name change in LogReader.cs, these kind of changes make it harder to review PRs. We should do changes like this in a dedicated PR like neo-project/neo#2785
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.
Log tracking logic needs to be moved into RpcServer
@devhawk done as you suggested |
src/RpcServer/RpcServerPlugin.cs
Outdated
@@ -56,6 +52,13 @@ protected override void OnSystemLoaded(NeoSystem system) | |||
servers.TryAdd(s.Network, server); | |||
} | |||
|
|||
public override void Dispose() |
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.
It looks like we could revert all the changes to this file in this PR
src/RpcServer/RpcServer.cs
Outdated
/// <summary> | ||
/// Maximum number of events to be logged per contract | ||
/// </summary> | ||
private const int MaxLogEvents = 50; |
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.
Should this be configurable?
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.
+1 @Liaojinghui
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.
Agree with @devhawk
|
||
private void OnCommitted(NeoSystem system, Block block) | ||
{ | ||
LogEvents.Clear(); |
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.
Should we be clearing all the events or just the ones for the transactions in block
?
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.
I think we should clear all log events, otherwise some logs will be there forever, which will be a memory leak.
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.
If you clear them in OnCommitting
, other plugins that depend on this data may not work. I think it should be cleaned up in OnCommitted
by a certain plugin.
src/RpcServer/RpcServer.cs
Outdated
// It is potentially possible to have dos attack by sending a lot of transactions and logs. | ||
// To prevent this, we limit the number of logs to be logged per contract. | ||
// If the number of logs is greater than MAX_LOG_EVENTS, we remove the oldest log. | ||
private static void Ev(object _, LogEventArgs e) |
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.
Can we change Ev
to something more descriptive like OnLog
Put(appExec.Transaction.Hash.ToArray(), Neo.Utility.StrictUTF8.GetBytes(txJson.ToString())); | ||
} | ||
RpcServer.LogEvents.Clear(); |
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.
Clear()
has been called in RpcServer.
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 is to make sure logs being removed from the memory as soon as possible. Add nother one in the server to ensure logs being removed even if there is no log plugin.
… into log-in-execution * 'log-in-execution' of github.com:Liaojinghui/neo-modules: Fix nep11 tracker (#741)
@shargon May you please review this pr? |
@shargon @erikzhang Could you review it? |
No description provided.