Inheritance: Neo.Consensus.ConsensusMessage
Esempio n. 1
0
        private void OnPrepareResponseReceived(ExtensiblePayload payload, PrepareResponse message)
        {
            if (message.ViewNumber != context.ViewNumber)
            {
                return;
            }
            if (context.PreparationPayloads[message.ValidatorIndex] != null || context.NotAcceptingPayloadsDueToViewChanging)
            {
                return;
            }
            if (context.PreparationPayloads[context.Block.PrimaryIndex] != null && !message.PreparationHash.Equals(context.PreparationPayloads[context.Block.PrimaryIndex].Hash))
            {
                return;
            }

            // Timeout extension: prepare response has been received with success
            // around 2*15/M=30.0/5 ~ 40% block time (for M=5)
            ExtendTimerByFactor(2);

            Log($"{nameof(OnPrepareResponseReceived)}: height={message.BlockIndex} view={message.ViewNumber} index={message.ValidatorIndex}");
            context.PreparationPayloads[message.ValidatorIndex] = payload;
            if (context.WatchOnly || context.CommitSent)
            {
                return;
            }
            if (context.RequestSentOrReceived)
            {
                CheckPreparations();
            }
        }
Esempio n. 2
0
 private void OnPrepareResponseReceived(ConsensusPayload payload, PrepareResponse message)
 {
     if (context.Signatures[payload.ValidatorIndex] != null)
     {
         return;
     }
     Log($"{nameof(OnPrepareResponseReceived)}: height={payload.BlockIndex} view={message.ViewNumber} index={payload.ValidatorIndex}");
     byte[] hashData = context.MakeHeader()?.GetHashData();
     if (hashData == null)
     {
         context.Signatures[payload.ValidatorIndex] = message.Signature;
     }
     else if (Crypto.Default.VerifySignature(hashData, message.Signature, context.Validators[payload.ValidatorIndex].EncodePoint(false)))
     {
         context.Signatures[payload.ValidatorIndex] = message.Signature;
         CheckSignatures();
     }
 }
Esempio n. 3
0
        private void OnPrepareResponseReceived(ConsensusPayload payload, PrepareResponse message)
        {
            Log($"{nameof(OnPrepareResponseReceived)}: height={payload.BlockIndex} view={message.ViewNumber} index={payload.ValidatorIndex}");
            if (context.State.HasFlag(ConsensusState.BlockSent))
            {
                return;
            }
            if (context.Signatures[payload.ValidatorIndex] != null)
            {
                return;
            }
            Block header = context.MakeHeader();

            if (header == null || !Crypto.Default.VerifySignature(header.GetHashData(), message.Signature, context.Validators[payload.ValidatorIndex].EncodePoint(false)))
            {
                return;
            }
            context.Signatures[payload.ValidatorIndex] = message.Signature;
            CheckSignatures();
        }
Esempio n. 4
0
 private void OnPrepareResponseReceived(ConsensusPayload payload, PrepareResponse message)
 {
     if (context.PreparationPayloads[payload.ValidatorIndex] != null)
     {
         return;
     }
     if (context.PreparationPayloads[context.PrimaryIndex] != null && !message.PreparationHash.Equals(context.PreparationPayloads[context.PrimaryIndex].Hash))
     {
         return;
     }
     Log($"{nameof(OnPrepareResponseReceived)}: height={payload.BlockIndex} view={message.ViewNumber} index={payload.ValidatorIndex}");
     context.PreparationPayloads[payload.ValidatorIndex] = payload;
     if (context.CommitSent())
     {
         return;
     }
     if (context.RequestSentOrReceived())
     {
         CheckPreparations();
     }
 }