Beispiel #1
0
 public async Task HandleBestChainFoundTest()
 {
     await _txHub.HandleBestChainFoundAsync(new BestChainFoundEventData
     {
         BlockHash   = _block.GetHash(),
         BlockHeight = _block.Height
     });
 }
Beispiel #2
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);
        }
Beispiel #3
0
        /// <summary>
        /// Mock a chain with a best branch, and some fork branches
        /// </summary>
        /// <returns>
        ///       Mock Chain
        ///    BestChainHeight: 11
        ///         LIB height: 5
        ///
        ///             Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14
        ///        Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j  -> k
        ///        Fork Branch:                    (e)-> q -> r -> s -> t -> u
        ///    Unlinked Branch:                                              v  -> w  -> x  -> y  -> z
        /// </returns>
        public async Task MockChainAsync()
        {
            await StartNodeAsync();

            var chain = await _blockchainService.GetChainAsync();

            if (chain.BestChainHeight == 1)
            {
                var genesisBlock = await _blockchainService.GetBlockByHashAsync(chain.GenesisBlockHash);

                BestBranchBlockList.Add(genesisBlock);

                BestBranchBlockList.AddRange(await AddBestBranch());

                ForkBranchBlockList =
                    await AddForkBranch(BestBranchBlockList[4].GetHash(), BestBranchBlockList[4].Height);

                UnlinkedBranchBlockList = await AddForkBranch(Hash.FromString("UnlinkBlock"), 9);

                // Set lib
                chain = await _blockchainService.GetChainAsync();

                await _blockchainService.SetIrreversibleBlockAsync(chain, BestBranchBlockList[4].Height,
                                                                   BestBranchBlockList[4].GetHash());
            }

            await _txHub.HandleBestChainFoundAsync(new BestChainFoundEventData
            {
                BlockHash   = chain.BestChainHash,
                BlockHeight = chain.BestChainHeight
            });
        }
Beispiel #4
0
        public async Task IterationCleanup()
        {
            await _txHub.CleanTransactionsAsync(_transactions.Select(t => t.GetHash()).ToList());

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

            await _transactionManager.RemoveTransactionsAsync(_transactions.Select(t => t.GetHash()).ToList());
        }
 public void HandleBestChainFoundTest()
 {
     AsyncHelper.RunSync(async() =>
     {
         var chain = await _blockchainService.GetChainAsync();
         await _txHub.HandleBestChainFoundAsync(new BestChainFoundEventData
         {
             BlockHash   = chain.BestChainHash,
             BlockHeight = chain.BestChainHeight
         });
     });
     _counter.Increment();
 }
Beispiel #6
0
 public void Cleanup()
 {
     AsyncHelper.RunSync(async() =>
     {
         await _blockAttachService.AttachBlockAsync(_block);
         var chain = await _blockchainService.GetChainAsync();
         await _txHub.HandleBestChainFoundAsync(new BestChainFoundEventData
         {
             BlockHash   = chain.BestChainHash,
             BlockHeight = chain.BestChainHeight
         });
     });
 }
        public async Task IterationCleanup()
        {
            await _txHub.HandleUnexecutableTransactionsFoundAsync(new UnexecutableTransactionsFoundEvent
                                                                  (null, _transactions.Select(t => t.GetHash()).ToList()));

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

            foreach (var transaction in _transactions)
            {
                _transactionManager.RemoveTransactionAsync(transaction.GetHash());
            }
        }
Beispiel #8
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
            });
        }
Beispiel #9
0
        public async Task IterationCleanup()
        {
            await _blockStateSets.RemoveAsync(_block.GetHash().ToStorageKey());

            foreach (var transaction in _transactions)
            {
                _transactionManager.RemoveTransaction(transaction.GetHash());
                _transactionResultManager.RemoveTransactionResultAsync(transaction.GetHash(), _block.GetHash());
                _transactionResultManager.RemoveTransactionResultAsync(transaction.GetHash(),
                                                                       _block.Header.GetPreMiningHash());
            }

            await _txHub.HandleUnexecutableTransactionsFoundAsync(new UnexecutableTransactionsFoundEvent
                                                                  (null, _transactions.Select(t => t.GetHash()).ToList()));

            await _txHub.HandleBestChainFoundAsync(new BestChainFoundEventData
            {
                BlockHash   = _chain.BestChainHash,
                BlockHeight = _chain.BestChainHeight
            });
        }
 public async Task HandleEventAsync(BestChainFoundEventData eventData)
 {
     await _txHub.HandleBestChainFoundAsync(eventData);
 }