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

add logs to execution #737

Closed
wants to merge 32 commits into from
Closed

add logs to execution #737

wants to merge 32 commits into from

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Jun 25, 2022

No description provided.

@Jim8y
Copy link
Contributor Author

Jim8y commented Jun 25, 2022

will update utest later

Copy link
Member

@shargon shargon left a 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

@Jim8y
Copy link
Contributor Author

Jim8y commented Jun 28, 2022

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 =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect.

Copy link
Contributor Author

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.

}
list.Add(e);
}
ApplicationEngine.Log += Ev;
Copy link
Member

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.

Copy link
Contributor Author

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.

@Jim8y
Copy link
Contributor Author

Jim8y commented Jul 3, 2022

@nicolegys May you please help me test this?

}
_logs.Enqueue(e);
}
ApplicationEngine.Log += Ev;
Copy link
Member

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.

@devhawk
Copy link
Contributor

devhawk commented Jul 8, 2022

Why are we doing this?

@@ -25,7 +25,7 @@ namespace Neo.Plugins
{
public class LogReader : Plugin
{
private DB db;
private DB _db;
Copy link
Contributor

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.

// 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)
Copy link
Contributor

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();
}


Copy link
Contributor

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

devhawk
devhawk previously requested changes Jul 8, 2022
Copy link
Contributor

@devhawk devhawk left a 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

@Jim8y
Copy link
Contributor Author

Jim8y commented Jul 11, 2022

@devhawk done as you suggested

@@ -56,6 +52,13 @@ protected override void OnSystemLoaded(NeoSystem system)
servers.TryAdd(s.Network, server);
}

public override void Dispose()
Copy link
Contributor

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

/// <summary>
/// Maximum number of events to be logged per contract
/// </summary>
private const int MaxLogEvents = 50;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be configurable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 @Liaojinghui

Copy link
Member

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();
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

// 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)
Copy link
Contributor

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

@devhawk devhawk dismissed their stale review July 11, 2022 16:46

fixed

Put(appExec.Transaction.Hash.ToArray(), Neo.Utility.StrictUTF8.GetBytes(txJson.ToString()));
}
RpcServer.LogEvents.Clear();
Copy link
Member

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.

Copy link
Contributor Author

@Jim8y Jim8y Jul 13, 2022

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.

@nicolegys
Copy link
Contributor

nicolegys commented Sep 5, 2022

Test pass

1662373813763

@Jim8y
Copy link
Contributor Author

Jim8y commented Sep 13, 2022

@shargon May you please review this pr?

@superboyiii
Copy link
Member

@shargon @erikzhang Could you review it?

@Jim8y Jim8y closed this by deleting the head repository Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants