Exemple #1
0
 private void InitializeConsensus(ushort view_number)
 {
     if (view_number == 0)
     {
         context.Reset();
     }
     else
     {
         context.ChangeView(view_number);
     }
     if (context.MyIndex < 0)
     {
         return;
     }
     if (view_number > 0)
     {
         Log($"changeview: view={view_number} primary={context.Validators[context.GetPrimaryIndex((ushort)(view_number - 1u))]}", LogLevel.Warning);
     }
     Log($"initialize: height={context.BlockIndex} view={view_number} index={context.MyIndex} role={(context.MyIndex == context.PrimaryIndex ? ConsensusState.Primary : ConsensusState.Backup)}");
     if (context.MyIndex == context.PrimaryIndex)
     {
         context.State |= ConsensusState.Primary;
         TimeSpan span = TimeProvider.Current.UtcNow - block_received_time;
         if (span >= Blockchain.TimePerBlock)
         {
             ChangeTimer(TimeSpan.Zero);
         }
         else
         {
             ChangeTimer(Blockchain.TimePerBlock - span);
         }
     }
     else
     {
         context.State = ConsensusState.Backup;
         SetNextTimer(view_number + 1);
     }
     ProcessUnhandledPayload();
 }