Skip to content

Commit

Permalink
Remove StatesDumper - Minor Refactor on StorageDumper (#3281)
Browse files Browse the repository at this point in the history
* Remove StatesDumper - Minor Refactor on StorageDumper

* remove extra line

---------

Co-authored-by: Jimmy <[email protected]>
  • Loading branch information
vncoelho and Jim8y authored May 28, 2024
1 parent 7bb4900 commit df06791
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 291 deletions.
7 changes: 0 additions & 7 deletions neo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcServer", "src\Plugins\Rp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SQLiteWallet", "src\Plugins\SQLiteWallet\SQLiteWallet.csproj", "{F53D5FF0-5D3D-4E8B-A44F-C4C5D9B563B1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StatesDumper", "src\Plugins\StatesDumper\StatesDumper.csproj", "{90CCA7D4-C277-4112-A036-BBB90C3FE3BE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StateService", "src\Plugins\StateService\StateService.csproj", "{88975A8D-4797-45A4-BC3E-15962A425A54}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StorageDumper", "src\Plugins\StorageDumper\StorageDumper.csproj", "{FF76D8A4-356B-461A-8471-BC1B83E57BBC}"
Expand Down Expand Up @@ -202,10 +200,6 @@ Global
{F53D5FF0-5D3D-4E8B-A44F-C4C5D9B563B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F53D5FF0-5D3D-4E8B-A44F-C4C5D9B563B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F53D5FF0-5D3D-4E8B-A44F-C4C5D9B563B1}.Release|Any CPU.Build.0 = Release|Any CPU
{90CCA7D4-C277-4112-A036-BBB90C3FE3BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90CCA7D4-C277-4112-A036-BBB90C3FE3BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90CCA7D4-C277-4112-A036-BBB90C3FE3BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90CCA7D4-C277-4112-A036-BBB90C3FE3BE}.Release|Any CPU.Build.0 = Release|Any CPU
{88975A8D-4797-45A4-BC3E-15962A425A54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88975A8D-4797-45A4-BC3E-15962A425A54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88975A8D-4797-45A4-BC3E-15962A425A54}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -257,7 +251,6 @@ Global
{3DE59148-59D6-4CD3-8086-0BC74E3D4E0B} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{A3941551-E72C-42D7-8C4D-5122CB60D73D} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{F53D5FF0-5D3D-4E8B-A44F-C4C5D9B563B1} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{90CCA7D4-C277-4112-A036-BBB90C3FE3BE} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{88975A8D-4797-45A4-BC3E-15962A425A54} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{FF76D8A4-356B-461A-8471-BC1B83E57BBC} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{5E4947F3-05D3-4806-B0F3-30DAC71B5986} = {C2DC830A-327A-42A7-807D-295216D30DBB}
Expand Down
21 changes: 0 additions & 21 deletions src/Plugins/StatesDumper/PersistActions.cs

This file was deleted.

58 changes: 0 additions & 58 deletions src/Plugins/StatesDumper/Settings.cs

This file was deleted.

169 changes: 0 additions & 169 deletions src/Plugins/StatesDumper/StatesDumper.cs

This file was deleted.

18 changes: 0 additions & 18 deletions src/Plugins/StatesDumper/StatesDumper.csproj

This file was deleted.

9 changes: 0 additions & 9 deletions src/Plugins/StatesDumper/StatesDumper.json

This file was deleted.

6 changes: 5 additions & 1 deletion src/Plugins/StorageDumper/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ internal class Settings
/// Height to begin storage dump
/// </summary>
public uint HeightToBegin { get; }

/// <summary>
/// Default number of items per folder
/// </summary>
public uint StoragePerFolder { get; }
public IReadOnlyList<int> Exclude { get; }

public static Settings? Default { get; private set; }
Expand All @@ -34,6 +37,7 @@ private Settings(IConfigurationSection section)
/// Geting settings for storage changes state dumper
BlockCacheSize = section.GetValue("BlockCacheSize", 1000u);
HeightToBegin = section.GetValue("HeightToBegin", 0u);
StoragePerFolder = section.GetValue("StoragePerFolder", 100000u);
Exclude = section.GetSection("Exclude").Exists()
? section.GetSection("Exclude").GetChildren().Select(p => int.Parse(p.Value)).ToArray()

Check warning on line 42 in src/Plugins/StorageDumper/Settings.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.

Check warning on line 42 in src/Plugins/StorageDumper/Settings.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.
: new[] { NativeContract.Ledger.Id };
Expand Down
16 changes: 8 additions & 8 deletions src/Plugins/StorageDumper/StorageDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class StorageDumper : Plugin
private readonly Dictionary<uint, NeoSystem> systems = new Dictionary<uint, NeoSystem>();

private StreamWriter _writer;
/// <summary>
/// _currentBlock stores the last cached item
/// </summary>
private JObject _currentBlock;
private string _lastCreateDirectory;

Expand Down Expand Up @@ -93,7 +96,7 @@ private void OnPersistStorage(uint network, DataCache snapshot)
uint blockIndex = NativeContract.Ledger.CurrentIndex(snapshot);
if (blockIndex >= Settings.Default.HeightToBegin)

Check warning on line 97 in src/Plugins/StorageDumper/StorageDumper.cs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Dereference of a possibly null reference.

Check warning on line 97 in src/Plugins/StorageDumper/StorageDumper.cs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

Dereference of a possibly null reference.
{
JArray array = new JArray();
JArray stateChangeArray = new JArray();

foreach (var trackable in snapshot.GetChangeSet())
{
Expand All @@ -106,7 +109,6 @@ private void OnPersistStorage(uint network, DataCache snapshot)
state["state"] = "Added";
state["key"] = Convert.ToBase64String(trackable.Key.ToArray());
state["value"] = Convert.ToBase64String(trackable.Item.ToArray());
// Here we have a new trackable.Key and trackable.Item
break;
case TrackState.Changed:
state["state"] = "Changed";
Expand All @@ -118,13 +120,13 @@ private void OnPersistStorage(uint network, DataCache snapshot)
state["key"] = Convert.ToBase64String(trackable.Key.ToArray());
break;
}
array.Add(state);
stateChangeArray.Add(state);
}

JObject bs_item = new JObject();
bs_item["block"] = blockIndex;
bs_item["size"] = array.Count;
bs_item["storage"] = array;
bs_item["size"] = stateChangeArray.Count;
bs_item["storage"] = stateChangeArray;
_currentBlock = bs_item;
}
}
Expand Down Expand Up @@ -174,9 +176,7 @@ private string GetOrCreateDirectory(uint network, uint blockIndex)

private string GetDirectoryPath(uint network, uint blockIndex)
{
//Default Parameter
uint storagePerFolder = 100000;
uint folder = (blockIndex / storagePerFolder) * storagePerFolder;
uint folder = (blockIndex / Settings.Default.StoragePerFolder) * Settings.Default.StoragePerFolder;
return $"./StorageDumper_{network}/BlockStorage_{folder}";
}

Expand Down
1 change: 1 addition & 0 deletions src/Plugins/StorageDumper/StorageDumper.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"PluginConfiguration": {
"BlockCacheSize": 1000,
"HeightToBegin": 0,
"StoragePerFolder": 100000,
"Exclude": [ -4 ]
}
}

0 comments on commit df06791

Please sign in to comment.