Ejemplo n.º 1
0
 private void OnTimer(Timer timer)
 {
     if (context.State.HasFlag(ConsensusState.BlockSent))
     {
         return;
     }
     if (timer.Height != context.BlockIndex || timer.ViewNumber != context.ViewNumber)
     {
         return;
     }
     Log($"timeout: height={timer.Height} view={timer.ViewNumber} state={context.State}");
     if (context.State.HasFlag(ConsensusState.Primary) && !context.State.HasFlag(ConsensusState.RequestSent))
     {
         Log($"send prepare request: height={timer.Height} view={timer.ViewNumber}");
         context.State |= ConsensusState.RequestSent;
         if (!context.State.HasFlag(ConsensusState.SignatureSent))
         {
             context.Fill();
             context.SignHeader();
         }
         system.LocalNode.Tell(new LocalNode.SendDirectly {
             Inventory = context.MakePrepareRequest()
         });
         if (context.TransactionHashes.Length > 1)
         {
             foreach (InvPayload payload in InvPayload.CreateGroup(InventoryType.TX, context.TransactionHashes.Skip(1).ToArray()))
             {
                 system.LocalNode.Tell(Message.Create("inv", payload));
             }
         }
         ChangeTimer(TimeSpan.FromSeconds(Blockchain.SecondsPerBlock << (timer.ViewNumber + 1)));
     }
     else if ((context.State.HasFlag(ConsensusState.Primary) && context.State.HasFlag(ConsensusState.RequestSent)) || context.State.HasFlag(ConsensusState.Backup))
     {
         RequestChangeView();
     }
 }
Ejemplo n.º 2
0
 private void OnTimer(Timer timer)
 {
     if (context.State.HasFlag(ConsensusState.BlockSent))
     {
         return;
     }
     if (timer.Height != context.BlockIndex || timer.ViewNumber != context.ViewNumber)
     {
         return;
     }
     Log($"timeout: height={timer.Height} view={timer.ViewNumber} state={context.State}");
     if (context.State.HasFlag(ConsensusState.Primary) && !context.State.HasFlag(ConsensusState.RequestSent))
     {
         Log($"send prepare request: height={timer.Height} view={timer.ViewNumber}");
         context.State |= ConsensusState.RequestSent;
         if (!context.State.HasFlag(ConsensusState.SignatureSent))
         {
             context.Fill(wallet);
             context.Timestamp = Math.Max(DateTime.UtcNow.ToTimestamp(), context.Snapshot.GetHeader(context.PrevHash).Timestamp + 1);
             context.Signatures[context.MyIndex] = context.MakeHeader().Sign(context.KeyPair);
         }
         SignAndRelay(context.MakePrepareRequest());
         if (context.TransactionHashes.Length > 1)
         {
             foreach (InvPayload payload in InvPayload.CreateGroup(InventoryType.TX, context.TransactionHashes.Skip(1).ToArray()))
             {
                 system.LocalNode.Tell(Message.Create("inv", payload));
             }
         }
         ChangeTimer(TimeSpan.FromSeconds(Blockchain.SecondsPerBlock << (timer.ViewNumber + 1)));
     }
     else if ((context.State.HasFlag(ConsensusState.Primary) && context.State.HasFlag(ConsensusState.RequestSent)) || context.State.HasFlag(ConsensusState.Backup))
     {
         RequestChangeView();
     }
 }