Пример #1
0
        public bool AddAuthResult(AuthorizedMsg msg)
        {
            // check repeated message
            if (OutputMsgs.ToList().Any(a => a.From == msg.From))
            {
                return(false);
            }

            // only when success there is AuthSign
            if (msg.Result == APIResultCodes.Success && msg.AuthSign != null)
            {
                if (msg.From != msg.AuthSign.Key)
                {
                    return(false);
                }

                // verify signature
                if (!Signatures.VerifyAccountSignature(InputMsg.Block.Hash, msg.AuthSign.Key, msg.AuthSign.Signature))
                {
                    _log.LogError($"AuthorizedMsg from {msg.From.Shorten()} for block {InputMsg.Block.Hash.Shorten()} verification failed.");
                    return(false);
                }
            }

            // check for valid validators
            if (!CheckSenderValid(msg.From))
            {
                return(false);
            }

            OutputMsgs.Add(msg);
            return(true);
        }
Пример #2
0
        public bool AddAuthResult(AuthorizedMsg msg)
        {
            // check repeated message
            if (OutputMsgs.ToList().Any(a => a.From == msg.From))
            {
                return(false);
            }

            OutputMsgs.Add(msg);
            return(true);
        }
Пример #3
0
        public APIResultCodes GetMajorErrorCode()
        {
            var q = OutputMsgs.GroupBy(a => a.Result)
                    .Select(g => new { g.Key, Count = g.Count() })
                    .OrderByDescending(x => x.Count);

            if (q.Any())
            {
                return(q.First().Key);
            }
            else
            {
                return(APIResultCodes.UnknownError);
            }
        }
Пример #4
0
        private ConsensusResult CheckAuthorizedResults()
        {
            var AuthMsgList = OutputMsgs.ToList();
            var ok          = AuthMsgList.Count(a => a.IsSuccess);

            if (ok >= WinNumber)
            {
                return(ConsensusResult.Yay);
            }

            var notok = AuthMsgList.Count(a => !a.IsSuccess);

            if (notok >= WinNumber)
            {
                return(ConsensusResult.Nay);
            }

            return(ConsensusResult.Uncertain);
        }
Пример #5
0
        private ConsensusResult CheckAuthorizedResults()
        {
            var AuthMsgList = OutputMsgs.ToList();
            var ok          = AuthMsgList.Count(a => a.IsSuccess);

            if (ok >= WinNumber)
            {
                return(ConsensusResult.Yea);
            }

            var notok = AuthMsgList.Count(a => !a.IsSuccess);

            if (notok >= WinNumber)
            {
                return(ConsensusResult.Nay);
            }

            _log.LogInformation($"msg count: {AuthMsgList.Count} Win Number: {WinNumber}");
            return(ConsensusResult.Uncertain);
        }
Пример #6
0
 public void Reset()
 {
     _localResult = null;
     OutputMsgs.Clear();
     CommitMsgs.Clear();
 }
Пример #7
0
 public void AddAuthResult(AuthorizedMsg msg)
 {
     OutputMsgs.Add(msg);
 }