Пример #1
0
        private async Task <List <TransactionTrace> > ExecuteTransactions(List <Transaction> txs, bool noTimeout = false)
        {
            using (var cts = new CancellationTokenSource())
            {
                if (!noTimeout)
                {
                    var distance = await _dpoSInfoProvider.GetDistanceToTimeSlotEnd();

                    var distanceRation = distance * (NodeConfig.Instance.RatioSynchronize + NodeConfig.Instance.RatioMine);
                    var timeout        = Math.Min(distanceRation, _maxMineTime);
                    cts.CancelAfter(TimeSpan.FromMilliseconds(timeout));
                    _logger?.Trace($"Execution limit time: {timeout}ms");
                }

                if (cts.IsCancellationRequested)
                {
                    return(null);
                }
                var disambiguationHash =
                    HashHelpers.GetDisambiguationHash(await GetNewBlockIndexAsync(), _producerAddress);

                var traces = txs.Count == 0
                    ? new List <TransactionTrace>()
                    : await _executingService.ExecuteAsync(txs, Config.ChainId, cts.Token, disambiguationHash);

                return(traces);
            }
        }
Пример #2
0
        public void GetDisambiguationHashTest()
        {
            var blockHeight = 10;
            var keyPair     = CryptoHelpers.GenerateKeyPair();
            var pubKeyHash  = Hash.FromRawBytes(keyPair.PublicKey);
            var hash        = HashHelpers.GetDisambiguationHash(blockHeight, pubKeyHash);

            hash.ShouldNotBeNull();
            hash.ShouldNotBe(Hash.FromMessage(new Int64Value()
            {
                Value = blockHeight
            }));
            hash.ShouldNotBe(pubKeyHash);
        }