Beispiel #1
0
        public void Initialize()
        {
            var utxoHash = _utxoSet.GetBlockHashAsync().GetAwaiter().GetResult();

            while (true)
            {
                _Tip = Chain.GetBlock(utxoHash);
                if (_Tip != null)
                {
                    break;
                }
                utxoHash = _utxoSet.Rewind().GetAwaiter().GetResult();
            }
            Puller.SetLocation(Tip);
            bip9 = new ThresholdConditionCache(_Validator.ConsensusParams);
        }
Beispiel #2
0
        public BlockResult ExecuteNextBlock(CancellationToken cancellationToken)
        {
            BlockResult result = new BlockResult();

            try
            {
                using (watch.Start(o => Validator.PerformanceCounter.AddBlockFetchingTime(o)))
                {
                    while (true)
                    {
                        result.Block = Puller.NextBlock(cancellationToken);
                        if (result.Block != null)
                        {
                            break;
                        }
                        else
                        {
                            while (true)
                            {
                                var hash     = UTXOSet.Rewind().GetAwaiter().GetResult();
                                var rewinded = Chain.GetBlock(hash);
                                if (rewinded == null)
                                {
                                    continue;
                                }
                                _Tip = rewinded;
                                Puller.SetLocation(rewinded);
                                break;
                            }
                        }
                    }
                }

                this.AcceptBlock(result);
            }
            catch (ConsensusErrorException ex)
            {
                result.Error = ex.ConsensusError;
            }
            return(result);
        }