Beispiel #1
0
        private void RequestChangeView()
        {
            if (!context.State.HasFlag(ConsensusState.ViewChanging))
            {
                context.State |= ConsensusState.ViewChanging;
                context.ExpectedView[context.MyIndex]++;
            }
            else
            {
                // 判断本地的ViewNumber是否掉队了
                if (IsMyExpectedViewNumberOutdated())
                {
                    Log($"my expected view number is outdated: height={context.BlockIndex} view={context.ViewNumber} nv={context.ExpectedView[context.MyIndex]} state={context.State}");

                    // 同步本地的ViewNumber
                    context.ExpectedView[context.MyIndex]++;
                }
            }

            Log($"request change view: height={context.BlockIndex} view={context.ViewNumber} nv={context.ExpectedView[context.MyIndex]} state={context.State}");
            SetNextTimer(context.ExpectedView[context.MyIndex]);
            localNode.Tell(new LocalNode.SendDirectly {
                Inventory = context.MakeChangeView()
            });
            CheckExpectedView(context.ExpectedView[context.MyIndex]);
        }
Beispiel #2
0
 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)
         {
             localNode.Tell(new LocalNode.SendDirectly {
                 Inventory = context.MakeChangeView(viewNumber)
             });
         }
         InitializeConsensus(viewNumber);
     }
 }
Beispiel #3
0
 private void RequestChangeView()
 {
     context.State |= ConsensusState.ViewChanging;
     context.ExpectedView[context.MyIndex]++;
     Log($"request change view: height={context.BlockIndex} view={context.ViewNumber} nv={context.ExpectedView[context.MyIndex]} state={context.State}");
     ChangeTimer(TimeSpan.FromSeconds(Blockchain.SecondsPerBlock << (context.ExpectedView[context.MyIndex] + 1)));
     localNode.Tell(new LocalNode.SendDirectly {
         Inventory = context.MakeChangeView()
     });
     CheckExpectedView(context.ExpectedView[context.MyIndex]);
 }
 private void CheckExpectedView(byte viewNumber)
 {
     if (context.ViewNumber >= viewNumber)
     {
         return;
     }
     // if there are `M` change view payloads with NewViewNumber greater than viewNumber, then, it is safe to move
     if (context.ChangeViewPayloads.Count(p => p != null && p.GetDeserializedMessage <ChangeView>().NewViewNumber >= viewNumber) >= context.M())
     {
         if (!context.WatchOnly())
         {
             ChangeView message = context.ChangeViewPayloads[context.MyIndex]?.GetDeserializedMessage <ChangeView>();
             // Communicate the network about my agreement to move to `viewNumber`
             // if my last change view payload, `message`, has NewViewNumber lower than current view to change
             if (message is null || message.NewViewNumber < viewNumber)
             {
                 localNode.Tell(new LocalNode.SendDirectly {
                     Inventory = context.MakeChangeView()
                 });
             }
         }
         InitializeConsensus(viewNumber);
     }
 }