private void OnPrepare(AuthorizedMsg item)
        {
            _log.LogInformation($"Consensus: OnPrepare Called: Block Hash: {item.BlockHash}");

            if (_activeConsensus.ContainsKey(item.BlockHash))
            {
                var state = _activeConsensus[item.BlockHash];
                state.AddAuthResult(item);

                CheckAuthorizedAllOk(state);
            }
            else
            {
                // maybe outof ordered message
                List <SourceSignedMessage> msgs;
                if (_outOfOrderedMessages.ContainsKey(item.BlockHash))
                {
                    msgs = _outOfOrderedMessages[item.BlockHash];
                }
                else
                {
                    msgs = new List <SourceSignedMessage>();
                    msgs.Add(item);
                }

                msgs.Add(item);
            }
        }
        private AuthorizedMsg LocalAuthorizingAsync(AuthorizingMsg item)
        {
            var authorizer = _authorizers[item.Block.BlockType];

            var localAuthResult = authorizer.Authorize(item.Block);
            var result          = new AuthorizedMsg
            {
                From      = NodeService.Instance.PosWallet.AccountId,
                MsgType   = ChatMessageType.AuthorizerPrepare,
                BlockHash = item.Block.Hash,
                Result    = localAuthResult.Item1,
                AuthSign  = localAuthResult.Item2
            };

            if (item.Block.BlockType == BlockTypes.Consolidation)
            {
                // do nothing. the UIndex has already take cared of.
            }
            else
            {
                result.BlockUIndex = Mode == ConsensusWorkingMode.Normal ? _UIndexSeed++ : 0;     // if seed out of sync, then others know
            }

            return(result);
        }
        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);
        }
Exemple #4
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);
        }
 public void Reset()
 {
     _localResult = null;
     OutputMsgs.Clear();
     CommitMsgs.Clear();
 }
Exemple #6
0
 public void AddAuthResult(AuthorizedMsg msg)
 {
     OutputMsgs.Add(msg);
 }