Пример #1
0
        public AuthState CreateAuthringState(AuthorizingMsg msg, bool sourceValid)
        {
            _log.LogInformation($"Consensus: CreateAuthringState Called: BlockIndex: {msg.Block.Height}");

            AuthState state;

            if (msg.Block is ServiceBlock sb)
            {
                _log.LogInformation($"AllVoters: {Board.AllVoters.Count}");
                state = new ServiceBlockAuthState(Worker_OnConsensusSuccessAsync, Board.AllVoters);
                msg.IsServiceBlock = true;
                state.SetView(Board.AllVoters);
            }
            else
            {
                state = new AuthState(Worker_OnConsensusSuccessAsync);
                msg.IsServiceBlock = false;
                state.SetView(Board.PrimaryAuthorizers);
            }
            state.InputMsg = msg;

            state.IsSourceValid = sourceValid;

            return(state);
        }
Пример #2
0
        private async Task <AuthState> PostToConsensusAsync(TransactionBlock block)
        {
            _log.LogInformation($"ApiService: PostToConsensusAsync Called: {block.BlockType}");

            //AuthorizingMsg msg = new AuthorizingMsg
            //{
            //    From = NodeService.Instance.PosWallet.AccountId,
            //    Block = block,
            //    MsgType = ChatMessageType.AuthorizerPrePrepare
            //};

            AuthorizingMsg msg = new AuthorizingMsg
            {
                From    = NodeService.Instance.PosWallet.AccountId,
                Block   = block,
                MsgType = ChatMessageType.AuthorizerPrePrepare
            };

            var state = new AuthState(true);

            state.SetView(await BlockChain.Singleton.GetLastServiceBlockAsync());
            state.InputMsg = msg;

            DagSystem.Singleton.Consensus.Tell(state);

            await state.Done.AsTask();

            state.Done.Close();
            state.Done = null;

            var ts1 = state.T1 == null ? "" : ((int)(DateTime.Now - state.T1).TotalMilliseconds).ToString();
            var ts2 = state.T2 == null ? "" : ((int)(DateTime.Now - state.T2).TotalMilliseconds).ToString();
            var ts3 = state.T3 == null ? "" : ((int)(DateTime.Now - state.T3).TotalMilliseconds).ToString();
            var ts4 = state.T4 == null ? "" : ((int)(DateTime.Now - state.T4).TotalMilliseconds).ToString();
            var ts5 = state.T5 == null ? "" : ((int)(DateTime.Now - state.T5).TotalMilliseconds).ToString();

            _log.LogInformation($"ApiService Timing:\n{ts1}\n{ts2}\n{ts3}\n{ts4}\n{ts5}\n");

            var resultMsg = state.OutputMsgs.Count > 0 ? state.OutputMsgs.First().Result.ToString() : "Unknown";

            _log.LogInformation($"ApiService: PostToConsensusAsync Exited: IsAuthoringSuccess: {state?.CommitConsensus == ConsensusResult.Yay} with {resultMsg}");

            if (state.CommitConsensus == ConsensusResult.Yay)
            {
                return(state);
            }
            else
            {
                return(null);
            }
        }