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

StatesDumper: fix bug with missing states dumps #568

Merged
merged 3 commits into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/StatesDumper/StatesDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void IPersistencePlugin.OnPersist(NeoSystem system, Block block, DataCache snaps

private void OnPersistStorage(uint network, DataCache snapshot)
{
if (!bs_cache.TryGetValue(network, out JArray cache)) return;
uint blockIndex = NativeContract.Ledger.CurrentIndex(snapshot);
if (blockIndex >= Settings.Default.HeightToBegin)
{
Expand Down Expand Up @@ -90,7 +89,12 @@ private void OnPersistStorage(uint network, DataCache snapshot)
bs_item["block"] = blockIndex;
bs_item["size"] = array.Count;
bs_item["storage"] = array;
if (!bs_cache.TryGetValue(network, out JArray cache))
Copy link
Member

Choose a reason for hiding this comment

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

I think it's here which cause #736 since cache will be cleared when node exit.

{
cache = new JArray();
}
cache.Add(bs_item);
bs_cache[network] = cache;
}
}

Expand All @@ -108,7 +112,6 @@ void OnCommitStorage(uint network, DataCache snapshot)
if ((blockIndex % Settings.Default.BlockCacheSize == 0) || (Settings.Default.HeightToStartRealTimeSyncing != -1 && blockIndex >= Settings.Default.HeightToStartRealTimeSyncing))
{
string path = HandlePaths(network, blockIndex);
Directory.CreateDirectory(path);
path = $"{path}/dump-block-{blockIndex}.json";
File.WriteAllText(path, cache.ToString());
cache.Clear();
Expand Down