From a25c7233ce943f9251816018955ad2c698e33d19 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 7 Jun 2024 10:38:47 +0800 Subject: [PATCH 1/6] fix 3296 --- src/Plugins/ApplicationLogs/Store/LogStorageStore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs index 249c5d3bd1..147a80034b 100644 --- a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs +++ b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs @@ -159,7 +159,7 @@ public Guid PutStackItemState(StackItem stackItem) { _snapshot.Put(key, BinarySerializer.Serialize(stackItem, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } - catch (NotSupportedException) + catch { _snapshot.Put(key, BinarySerializer.Serialize(StackItem.Null, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } From c183732fc0bce449707b0124a2b185b20cd3a26b Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 7 Jun 2024 10:42:12 +0800 Subject: [PATCH 2/6] Update src/Plugins/ApplicationLogs/Store/LogStorageStore.cs --- src/Plugins/ApplicationLogs/Store/LogStorageStore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs index 147a80034b..b8f817238c 100644 --- a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs +++ b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs @@ -159,7 +159,7 @@ public Guid PutStackItemState(StackItem stackItem) { _snapshot.Put(key, BinarySerializer.Serialize(stackItem, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } - catch + catch // Ref. https://github.com/neo-project/neo/issues/3296 { _snapshot.Put(key, BinarySerializer.Serialize(StackItem.Null, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } From 1378d24feeb09abe0c5b61a026aa30979b83af94 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 7 Jun 2024 10:59:54 +0800 Subject: [PATCH 3/6] add exception message to the incorrect storeitem --- .../ApplicationLogs/Store/LogStorageStore.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs index b8f817238c..105da2c786 100644 --- a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs +++ b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs @@ -15,6 +15,7 @@ using Neo.SmartContract; using Neo.VM; using Neo.VM.Types; +using System.Text; namespace Neo.Plugins.ApplicationLogs.Store { @@ -159,9 +160,20 @@ public Guid PutStackItemState(StackItem stackItem) { _snapshot.Put(key, BinarySerializer.Serialize(stackItem, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } - catch // Ref. https://github.com/neo-project/neo/issues/3296 + catch (NotSupportedException ex) // Ref. https://github.com/neo-project/neo/issues/3296 { - _snapshot.Put(key, BinarySerializer.Serialize(StackItem.Null, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); + var message = ex.Message.Length > 1024 ? string.Concat(ex.Message.AsSpan(0, 1021), "...") : ex.Message; + _snapshot.Put(key, Encoding.UTF8.GetBytes("Not Supported Exception: " + message)); + } + catch (FormatException ex) + { + var message = ex.Message.Length > 1024 ? string.Concat(ex.Message.AsSpan(0, 1021), "...") : ex.Message; + _snapshot.Put(key, Encoding.UTF8.GetBytes("Format Exception: " + message)); + } + catch (Exception ex) + { + var message = ex.Message.Length > 1024 ? string.Concat(ex.Message.AsSpan(0, 1021), "...") : ex.Message; + _snapshot.Put(key, Encoding.UTF8.GetBytes("Exception: " + message)); } return id; } From dc0b57444c25b36bb9aaf6ebcfbc26f86e379ed3 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 7 Jun 2024 11:10:38 +0800 Subject: [PATCH 4/6] optimize the code to apply Hecate suggestion --- .../ApplicationLogs/Store/LogStorageStore.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs index 105da2c786..4371f36e9b 100644 --- a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs +++ b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs @@ -160,20 +160,13 @@ public Guid PutStackItemState(StackItem stackItem) { _snapshot.Put(key, BinarySerializer.Serialize(stackItem, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } - catch (NotSupportedException ex) // Ref. https://github.com/neo-project/neo/issues/3296 - { - var message = ex.Message.Length > 1024 ? string.Concat(ex.Message.AsSpan(0, 1021), "...") : ex.Message; - _snapshot.Put(key, Encoding.UTF8.GetBytes("Not Supported Exception: " + message)); - } - catch (FormatException ex) - { - var message = ex.Message.Length > 1024 ? string.Concat(ex.Message.AsSpan(0, 1021), "...") : ex.Message; - _snapshot.Put(key, Encoding.UTF8.GetBytes("Format Exception: " + message)); - } catch (Exception ex) { - var message = ex.Message.Length > 1024 ? string.Concat(ex.Message.AsSpan(0, 1021), "...") : ex.Message; - _snapshot.Put(key, Encoding.UTF8.GetBytes("Exception: " + message)); + var detailedException = ex.Message; + if (detailedException.Length > 1024) + detailedException = string.Concat(detailedException.AsSpan(0, 1021), "..."); + ByteString exceptionRecord = new(Encoding.UTF8.GetBytes(detailedException)); + _snapshot.Put(key, BinarySerializer.Serialize(exceptionRecord, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } return id; } From 512d738ba00d05ce1b3be4c758126cdbe0c22b9a Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 7 Jun 2024 22:27:48 +0800 Subject: [PATCH 5/6] revert change to the exception info --- src/Plugins/ApplicationLogs/Store/LogStorageStore.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs index 4371f36e9b..fcfb8cc95e 100644 --- a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs +++ b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs @@ -160,13 +160,9 @@ public Guid PutStackItemState(StackItem stackItem) { _snapshot.Put(key, BinarySerializer.Serialize(stackItem, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } - catch (Exception ex) + catch { - var detailedException = ex.Message; - if (detailedException.Length > 1024) - detailedException = string.Concat(detailedException.AsSpan(0, 1021), "..."); - ByteString exceptionRecord = new(Encoding.UTF8.GetBytes(detailedException)); - _snapshot.Put(key, BinarySerializer.Serialize(exceptionRecord, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); + _snapshot.Put(key, BinarySerializer.Serialize(StackItem.Null, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } return id; } From ae9466708440f7d02009778b49b0e9e49d8e2780 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 7 Jun 2024 22:28:08 +0800 Subject: [PATCH 6/6] clean using --- src/Plugins/ApplicationLogs/Store/LogStorageStore.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs index fcfb8cc95e..147a80034b 100644 --- a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs +++ b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs @@ -15,7 +15,6 @@ using Neo.SmartContract; using Neo.VM; using Neo.VM.Types; -using System.Text; namespace Neo.Plugins.ApplicationLogs.Store {