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

Initialize Consensus at the correct view #779

Merged
merged 8 commits into from
Mar 12, 2024
Merged

Conversation

vncoelho
Copy link
Member

close #778

@vncoelho
Copy link
Member Author

@superboyiii, can you test?
@shargon, can you review.

@vncoelho
Copy link
Member Author

@dotnet-policy-service agree

@vncoelho
Copy link
Member Author

@vncoelho please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

@Jim8y
Copy link
Contributor

Jim8y commented Aug 30, 2023

@vncoelho is this one ready for review?

@vncoelho
Copy link
Member Author

Yes

@Jim8y Jim8y added waiting for review Need Active Pr will be closed after one week if no new activity. labels Feb 12, 2024
@Jim8y
Copy link
Contributor

Jim8y commented Feb 16, 2024

@shargon how do you think about this pr? @roman-khimov can you please also take a look?

@Jim8y Jim8y removed the Need Active Pr will be closed after one week if no new activity. label Feb 16, 2024
Co-authored-by: Shargon <shargon@gmail.com>
Copy link
Member Author

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

I committed @shargon suggestion, it makes it simpler.

@@ -157,7 +157,7 @@ private void OnStart()
return;
}
}
InitializeConsensus(0);
InitializeConsensus(context.ViewNumber);

Choose a reason for hiding this comment

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

It's good that you've simplified the code by removing the unnecessary if condition. However, it would be better to add a null check for context before using context.ViewNumber to avoid potential NullReferenceException.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks bot, I thought about that in previous discussions here. That why I did not applied the change before.
Perhaps we need to check if its null and then set to 0 for such case.
Can you apply that?

Copy link
Contributor

Choose a reason for hiding this comment

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

This bot is so polite.

Copy link
Member

@cschuchardt88 cschuchardt88 Feb 16, 2024

Choose a reason for hiding this comment

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

Thanks bot, I thought about that in previous discussions here. That why I did not applied the change before. Perhaps we need to check if its null and then set to 0 for such case. Can you apply that?

@vncoelho

InitializeConsensus(context?.ViewNumber ?? 0);

This bot is so polite.

Well the difference is I have the solution

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's null then highly likely we're dead already at the line 145, so I don't think it's a problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Cris, can you suggest the change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Line 145 @roman-khimov is
https://github.com/neo-project/neo-modules/blob/a57e51fa85c03f3f8823bdb7701a95aa0478df5c/src/DBFTPlugin/Consensus/ConsensusService.cs#L145C1-L145C68

I do not see where context.ViewNumber was initialized in a normal use case, without recovery.
Maybe 0 is the default of the C# creation of the context class, but I am not sure.

@@ -157,7 +157,7 @@ private void OnStart()
return;
}
}
InitializeConsensus(0);
InitializeConsensus(context.ViewNumber);
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's null then highly likely we're dead already at the line 145, so I don't think it's a problem.

@vncoelho
Copy link
Member Author

I am going to test, but last time (1 year ago), I thought that @cschuchardt88 suggestion InitializeConsensus(context?.ViewNumber ?? 0); could be needed.

@vncoelho
Copy link
Member Author

If we are going to proceed, let's just make sure that ViewNumber could not assume something different here and lead to a crash. I did not yet check it completely.

My comment from Dec,2022

@vncoelho
Copy link
Member Author

@shargon

I cannot test against current master, there is some another error in my setup

neo> FATAL [23:55:59.600] 	System.Collections.Generic.KeyNotFoundException
The given key 'Store' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Neo.Persistence.StoreFactory.GetStore(String storageEngine, String path) in /opt/neoLib/src/Neo/Persistence/StoreFactory.cs:line 48
   at Neo.NeoSystem.LoadStore(String path) in /opt/neoLib/src/Neo/NeoSystem.cs:line 228
   at Neo.Plugins.TokensTracker.OnSystemLoaded(NeoSystem system)
   at Neo.NeoSystem..ctor(ProtocolSettings settings, IStore storage) in /opt/neoLib/src/Neo/NeoSystem.cs:line 137
   at Neo.NeoSystem..ctor(ProtocolSettings settings, String storageEngine, String storagePath) in /opt/neoLib/src/Neo/NeoSystem.cs:line 118
   at Neo.CLI.MainService.Start(CommandLineOptions options) in /opt/neoLib/src/Neo.CLI/CLI/MainService.cs:line 380
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key 'Store' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Neo.Persistence.StoreFactory.GetStore(String storageEngine, String path) in /opt/neoLib/src/Neo/Persistence/StoreFactory.cs:line 48
   at Neo.NeoSystem.LoadStore(String path) in /opt/neoLib/src/Neo/NeoSystem.cs:line 228
   at Neo.Plugins.TokensTracker.OnSystemLoaded(NeoSystem system)
   at Neo.NeoSystem..ctor(ProtocolSettings settings, IStore storage) in /opt/neoLib/src/Neo/NeoSystem.cs:line 137
   at Neo.NeoSystem..ctor(ProtocolSettings settings, String storageEngine, String storagePath) in /opt/neoLib/src/Neo/NeoSystem.cs:line 118
   at Neo.CLI.MainService.Start(CommandLineOptions options) in /opt/neoLib/src/Neo.CLI/CLI/MainService.cs:line 380
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
/opt/start_node.sh: line 2:   128 Aborted                 (core dumped) dotnet neo-cli.dll

@vncoelho
Copy link
Member Author

@neo-project/core please wait until I can test the PR against current master branch, or, at least, add @cschuchardt88 suggestion.

@Jim8y Jim8y added the blocked label Feb 17, 2024
@cschuchardt88
Copy link
Member

cschuchardt88 commented Feb 17, 2024

I am going to test, but last time (1 year ago), I thought that @cschuchardt88 suggestion InitializeConsensus(context?.ViewNumber ?? 0); could be needed.

Yes it is needed because of line 145 dbftSettings.IgnoreRecoveryLogs that it could be true.

@cschuchardt88
Copy link
Member

cschuchardt88 commented Feb 17, 2024

@shargon

I cannot test against current master, there is some another error in my setup

neo> FATAL [23:55:59.600] 	System.Collections.Generic.KeyNotFoundException
The given key 'Store' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Neo.Persistence.StoreFactory.GetStore(String storageEngine, String path) in /opt/neoLib/src/Neo/Persistence/StoreFactory.cs:line 48
   at Neo.NeoSystem.LoadStore(String path) in /opt/neoLib/src/Neo/NeoSystem.cs:line 228
   at Neo.Plugins.TokensTracker.OnSystemLoaded(NeoSystem system)
   at Neo.NeoSystem..ctor(ProtocolSettings settings, IStore storage) in /opt/neoLib/src/Neo/NeoSystem.cs:line 137
   at Neo.NeoSystem..ctor(ProtocolSettings settings, String storageEngine, String storagePath) in /opt/neoLib/src/Neo/NeoSystem.cs:line 118
   at Neo.CLI.MainService.Start(CommandLineOptions options) in /opt/neoLib/src/Neo.CLI/CLI/MainService.cs:line 380
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key 'Store' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Neo.Persistence.StoreFactory.GetStore(String storageEngine, String path) in /opt/neoLib/src/Neo/Persistence/StoreFactory.cs:line 48
   at Neo.NeoSystem.LoadStore(String path) in /opt/neoLib/src/Neo/NeoSystem.cs:line 228
   at Neo.Plugins.TokensTracker.OnSystemLoaded(NeoSystem system)
   at Neo.NeoSystem..ctor(ProtocolSettings settings, IStore storage) in /opt/neoLib/src/Neo/NeoSystem.cs:line 137
   at Neo.NeoSystem..ctor(ProtocolSettings settings, String storageEngine, String storagePath) in /opt/neoLib/src/Neo/NeoSystem.cs:line 118
   at Neo.CLI.MainService.Start(CommandLineOptions options) in /opt/neoLib/src/Neo.CLI/CLI/MainService.cs:line 380
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
/opt/start_node.sh: line 2:   128 Aborted                 (core dumped) dotnet neo-cli.dll

You do not have the store library for whatever store is in your config.json

@vncoelho vncoelho merged commit 58fa510 into master Mar 12, 2024
3 of 4 checks passed
@vncoelho vncoelho deleted the recoverCrashAtCorrectView branch March 12, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not InitializeConsensus(0) if crashed and recovered
5 participants