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

Fix and optimize view changing #590

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion neo/Consensus/ConsensusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ private void CheckExpectedView(byte viewNumber)
{
if (context.ViewNumber == viewNumber) return;
if (context.ChangeViewPayloads.Count(p => p != null && p.GetDeserializedMessage<ChangeView>().NewViewNumber == viewNumber) >= context.M)
{
ChangeView message = context.ChangeViewPayloads[context.MyIndex]?.GetDeserializedMessage<ChangeView>();
if (message is null || message.NewViewNumber < viewNumber)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this can happen from the path of receiving ChangeView if we receive M messages without having sent yet, right?
Nice fix.

localNode.Tell(new LocalNode.SendDirectly { Inventory = context.MakeChangeView(viewNumber) });
InitializeConsensus(viewNumber);
}
}

private void CheckPreparations()
Expand Down Expand Up @@ -499,7 +504,8 @@ public static Props Props(IActorRef localNode, IActorRef taskManager, Store stor
private void RequestChangeView()
{
context.State |= ConsensusState.ViewChanging;
byte expectedView = GetLastExpectedView(context.MyIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably remove the GetLastExpectedView method in this PR now since we always send ChangeView messages in recovery.

byte expectedView = context.ChangeViewPayloads[context.MyIndex]?.GetDeserializedMessage<ChangeView>().NewViewNumber ?? 0;
if (expectedView < context.ViewNumber) expectedView = context.ViewNumber;
expectedView++;
Log($"request change view: height={context.BlockIndex} view={context.ViewNumber} nv={expectedView} state={context.State}");
ChangeTimer(TimeSpan.FromSeconds(Blockchain.SecondsPerBlock << (expectedView + 1)));
Expand Down