コード例 #1
0
        private List <Transaction> GetTransactionsToBeGrouped(List <Transaction> transactions, out GroupedTransactions groupedTransactions)
        {
            List <Transaction> toBeGrouped;

            groupedTransactions = new GroupedTransactions();
            if (transactions.Count > _options.MaxTransactions)
            {
                groupedTransactions.NonParallelizables.AddRange(
                    transactions.GetRange(_options.MaxTransactions, transactions.Count - _options.MaxTransactions));

                toBeGrouped = transactions.GetRange(0, _options.MaxTransactions);
            }
            else
            {
                toBeGrouped = transactions;
            }

            return(toBeGrouped);
        }
コード例 #2
0
        public async Task <GroupedTransactions> GroupAsync(IChainContext chainContext, List <Transaction> transactions)
        {
            Logger.LogTrace($"Entered GroupAsync");

            var groupedTransactions = new GroupedTransactions();

            List <Transaction> toBeGrouped;

            if (transactions.Count > _options.MaxTransactions)
            {
                groupedTransactions.NonParallelizables.AddRange(
                    transactions.GetRange(_options.MaxTransactions, transactions.Count - _options.MaxTransactions));

                toBeGrouped = transactions.GetRange(0, _options.MaxTransactions);
            }
            else
            {
                toBeGrouped = transactions;
            }

            using (var cts = new CancellationTokenSource(_options.GroupingTimeOut))
            {
                var parallelizables = new List <(Transaction, TransactionResourceInfo)>();

                Logger.LogTrace($"Extracting resources for transactions.");
                var txsWithResources = await _resourceExtractionService.GetResourcesAsync(chainContext, toBeGrouped, cts.Token);

                Logger.LogTrace($"Completed resource extraction.");

                foreach (var twr in txsWithResources)
                {
                    if (twr.Item2.ParallelType == ParallelType.InvalidContractAddress)
                    {
                        groupedTransactions.TransactionsWithoutContract.Add(twr.Item1);
                        continue;
                    }

                    // If timed out at this point, return all transactions as non-parallelizable
                    if (cts.IsCancellationRequested)
                    {
                        groupedTransactions.NonParallelizables.Add(twr.Item1);
                        continue;
                    }

                    if (twr.Item2.ParallelType == ParallelType.NonParallelizable)
                    {
                        groupedTransactions.NonParallelizables.Add(twr.Item1);
                        continue;
                    }

                    if (twr.Item2.Paths.Count == 0)
                    {
                        // groups.Add(new List<Transaction>() {twr.Item1}); // Run in their dedicated group
                        groupedTransactions.NonParallelizables.Add(twr.Item1);
                        continue;
                    }

                    parallelizables.Add(twr);
                }

                groupedTransactions.Parallelizables.AddRange(GroupParallelizables(parallelizables));

                Logger.LogTrace($"Completed transaction grouping.");
            }

            Logger.LogTrace($"From {transactions.Count} transactions, grouped into " +
                            $"{groupedTransactions.Parallelizables.Count} groups, left " +
                            $"{groupedTransactions.NonParallelizables.Count} as non-parallelizable transactions.");

            return(groupedTransactions);
        }