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

Limit result stack #696

Merged
merged 18 commits into from Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ApplicationLogs/ApplicationLogs/config.json
@@ -1,7 +1,8 @@
{
"PluginConfiguration": {
"Path": "ApplicationLogs_{0}",
"Network": 860833102
"Network": 860833102,
"MaxStackSize": 65535
},
"Dependency": [
"RpcServer"
Expand Down
12 changes: 6 additions & 6 deletions src/ApplicationLogs/LogReader.cs
Expand Up @@ -81,11 +81,11 @@ public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec)
trigger["gasconsumed"] = appExec.GasConsumed.ToString();
try
{
trigger["stack"] = appExec.Stack.Select(q => q.ToJson()).ToArray();
trigger["stack"] = appExec.Stack.Select(q => q.ToJson(Settings.Default.MaxStackSize)).ToArray();
}
catch (InvalidOperationException)
catch (Exception ex)
{
trigger["stack"] = "error: recursive reference";
trigger["exception"] = ex.Message;
}
trigger["notifications"] = appExec.Notifications.Select(q =>
{
Expand Down Expand Up @@ -124,11 +124,11 @@ public static JObject BlockLogToJson(Block block, IReadOnlyList<Blockchain.Appli
trigger["gasconsumed"] = appExec.GasConsumed.ToString();
try
{
trigger["stack"] = appExec.Stack.Select(q => q.ToJson()).ToArray();
trigger["stack"] = appExec.Stack.Select(q => q.ToJson(Settings.Default.MaxStackSize)).ToArray();
}
catch (InvalidOperationException)
catch (Exception ex)
{
trigger["stack"] = "error: recursive reference";
trigger["exception"] = ex.Message;
}
trigger["notifications"] = appExec.Notifications.Select(q =>
{
Expand Down
2 changes: 2 additions & 0 deletions src/ApplicationLogs/Settings.cs
Expand Up @@ -16,13 +16,15 @@ internal class Settings
{
public string Path { get; }
public uint Network { get; }
public int MaxStackSize { get; }

public static Settings Default { get; private set; }

private Settings(IConfigurationSection section)
{
this.Path = section.GetValue("Path", "ApplicationLogs_{0}");
this.Network = section.GetValue("Network", 5195086u);
this.MaxStackSize = section.GetValue("MaxStackSize", (int)ushort.MaxValue);
}

public static void Load(IConfigurationSection section)
Expand Down
6 changes: 3 additions & 3 deletions src/RpcServer/RpcServer.Wallet.cs
Expand Up @@ -389,11 +389,11 @@ private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] ar
json["exception"] = GetExceptionMessage(engine.FaultException);
try
{
json["stack"] = new JArray(engine.ResultStack.Select(p => p.ToJson()));
json["stack"] = new JArray(engine.ResultStack.Select(p => p.ToJson(settings.MaxStackSize)));
}
catch (InvalidOperationException)
catch (Exception ex)
{
json["stack"] = "error: recursive reference";
json["exception"] = ex.Message;
}
return json;
}
Expand Down
1 change: 1 addition & 0 deletions src/RpcServer/RpcServer/config.json
Expand Up @@ -14,6 +14,7 @@
"MaxFee": 0.1,
"MaxConcurrentConnections": 40,
"MaxIteratorResultItems": 100,
"MaxStackSize": 65535,
"DisabledMethods": [ "openwallet" ]
}
]
Expand Down
3 changes: 3 additions & 0 deletions src/RpcServer/Settings.cs
Expand Up @@ -41,6 +41,7 @@ public record RpcServerSettings
public long MaxGasInvoke { get; init; }
public long MaxFee { get; init; }
public int MaxIteratorResultItems { get; init; }
public int MaxStackSize { get; init; }
public string[] DisabledMethods { get; init; }

public static RpcServerSettings Default { get; } = new RpcServerSettings
Expand All @@ -53,6 +54,7 @@ public record RpcServerSettings
MaxFee = (long)new BigDecimal(0.1M, NativeContract.GAS.Decimals).Value,
TrustedAuthorities = Array.Empty<string>(),
MaxIteratorResultItems = 100,
MaxStackSize = ushort.MaxValue,
DisabledMethods = Array.Empty<string>(),
MaxConcurrentConnections = 40,
};
Expand All @@ -70,6 +72,7 @@ public static RpcServerSettings Load(IConfigurationSection section) => new()
MaxGasInvoke = (long)new BigDecimal(section.GetValue<decimal>("MaxGasInvoke", Default.MaxGasInvoke), NativeContract.GAS.Decimals).Value,
MaxFee = (long)new BigDecimal(section.GetValue<decimal>("MaxFee", Default.MaxFee), NativeContract.GAS.Decimals).Value,
MaxIteratorResultItems = section.GetValue("MaxIteratorResultItems", Default.MaxIteratorResultItems),
MaxStackSize = section.GetValue("MaxStackSize", Default.MaxStackSize),
DisabledMethods = section.GetSection("DisabledMethods").GetChildren().Select(p => p.Get<string>()).ToArray(),
MaxConcurrentConnections = section.GetValue("MaxConcurrentConnections", Default.MaxConcurrentConnections),
};
Expand Down