Ejemplo n.º 1
0
        public async Task GlobalCleanup()
        {
            foreach (var block in _blocks)
            {
                await _txHub.HandleBlockAcceptedAsync(new BlockAcceptedEvent
                {
                    Block = block
                });

                await _transactionManager.RemoveTransactionsAsync(block.Body.TransactionIds);

                await _transactionResultManager.RemoveTransactionResultsAsync(block.Body.TransactionIds,
                                                                              block.GetHash());

                await _transactionResultManager.RemoveTransactionResultsAsync(block.Body.TransactionIds,
                                                                              block.Header.GetPreMiningHash());

                await _chainManager.RemoveChainBlockLinkAsync(block.GetHash());

                await _blockManager.RemoveBlockAsync(block.GetHash());
            }

            await _txHub.HandleBestChainFoundAsync(new BestChainFoundEventData
            {
                BlockHash   = _chain.BestChainHash,
                BlockHeight = _chain.BestChainHeight
            });

            await _chains.SetAsync(_chain.Id.ToStorageKey(), _chain);
        }
Ejemplo n.º 2
0
        public async Task IterationCleanup()
        {
            await _blockStateSets.RemoveAsync(_block.GetHash().ToStorageKey());

            var transactionIds = _systemTransactions.Concat(_cancellableTransactions).Select(t => t.GetHash()).ToList();
            await _transactionResultManager.RemoveTransactionResultsAsync(transactionIds, _block.GetHash());

            await _transactionResultManager.RemoveTransactionResultsAsync(transactionIds,
                                                                          _block.Header.GetPreMiningHash());
        }
Ejemplo n.º 3
0
        public async Task IterationCleanup()
        {
            await _blockStateSets.RemoveAsync(_block.GetHash().ToStorageKey());

            await _transactionManager.RemoveTransactionsAsync(_block.Body.TransactionIds);

            await _transactionResultManager.RemoveTransactionResultsAsync(_block.Body.TransactionIds, _block.GetHash());

            await _transactionResultManager.RemoveTransactionResultsAsync(_block.Body.TransactionIds,
                                                                          _block.Header.GetPreMiningHash());

            await _chainManager.RemoveChainBlockLinkAsync(_block.GetHash());

            await _blockManager.RemoveBlockAsync(_block.GetHash());

            await _chains.SetAsync(_chain.Id.ToStorageKey(), _chain);
        }
Ejemplo n.º 4
0
        public async Task IterationCleanup()
        {
            await _blockStateSets.RemoveAsync(_block.GetHash().ToStorageKey());

            var transactionIds = _transactions.Select(t => t.GetHash()).ToList();
            await _transactionManager.RemoveTransactionsAsync(transactionIds);

            await _transactionResultManager.RemoveTransactionResultsAsync(transactionIds, _block.GetHash());

            await _transactionResultManager.RemoveTransactionResultsAsync(transactionIds,
                                                                          _block.Header.GetPreMiningHash());

            await _txHub.CleanTransactionsAsync(_transactions.Select(t => t.GetHash()).ToList());

            await _txHub.HandleBestChainFoundAsync(new BestChainFoundEventData
            {
                BlockHash   = _chain.BestChainHash,
                BlockHeight = _chain.BestChainHeight
            });
        }
Ejemplo n.º 5
0
        public async Task ProcessTransactionResultAfterExecutionAsync(BlockHeader blockHeader,
                                                                      List <Hash> transactionIds)
        {
            var preMiningHash = blockHeader.GetPreMiningHash();
            var blockIndex    = new BlockIndex
            {
                BlockHash   = blockHeader.GetHash(),
                BlockHeight = blockHeader.Height
            };

            if (transactionIds.Count == 0)
            {
                // This will only happen during test environment
                return;
            }

            var firstTransaction = transactionIds.First();
            var withBlockHash    = await _transactionResultManager.HasTransactionResultAsync(
                firstTransaction, blockHeader.GetHash());

            var withPreMiningHash = await _transactionResultManager.HasTransactionResultAsync(
                firstTransaction, preMiningHash);

            if (!withBlockHash)
            {
                // TransactionResult is not saved with real BlockHash
                // Save results with real (post mining) Hash, so that it can be queried with TransactionBlockIndex
                var result = await _transactionResultManager.GetTransactionResultsAsync(transactionIds, preMiningHash);

                await _transactionResultManager.AddTransactionResultsAsync(result, blockIndex.BlockHash);
            }

            // Add TransactionBlockIndex
            if (withPreMiningHash)
            {
                await _transactionResultManager.RemoveTransactionResultsAsync(transactionIds, preMiningHash);
            }

            await _transactionBlockIndexService.AddBlockIndexAsync(transactionIds, blockIndex);
        }