Exemple #1
0
        /// <summary>
        /// Mock a chain with a best branch, and some fork branches
        /// </summary>
        /// <returns>
        ///       Mock Chain
        ///    BestChainHeight: 11
        /// LongestChainHeight: 13
        ///         LIB height: 5
        ///
        ///             Height: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 -> 11 -> 12 -> 13 -> 14 -> 15 -> 16 -> 17 -> 18 -> 19
        ///        Best Branch: a -> b -> c -> d -> e -> f -> g -> h -> i -> j  -> k
        ///     Longest Branch:                                   (h)-> l -> m  -> n  -> o  ->  p ->  q ->  r ->  s ->  t ->  u ->  v
        ///        Fork Branch:                    (e)-> q -> r -> s -> t -> u
        ///    Unlinked Branch:                                              v  -> w  -> x  -> y  -> z
        /// </returns>
        public async Task <Chain> MockChainAsync()
        {
            var chain = await CreateChain();

            var genesisBlock = await _blockchainService.GetBlockByHashAsync(chain.GenesisBlockHash);

            BestBranchBlockList.Add(genesisBlock);

            BestBranchBlockList.AddRange(await AddBestBranch());

            LongestBranchBlockList =
                await AddForkBranch(BestBranchBlockList[7].Height, BestBranchBlockList[7].GetHash(), 11);

            foreach (var block in LongestBranchBlockList)
            {
                var chainBlockLink = await _chainManager.GetChainBlockLinkAsync(block.GetHash());

                await _chainManager.SetChainBlockLinkExecutionStatusAsync(chainBlockLink,
                                                                          ChainBlockLinkExecutionStatus.ExecutionFailed);
            }

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

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

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

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

            return(chain);
        }
Exemple #2
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
            });
        }
        /// <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);

                NotLinkedBlockList = await AddForkBranch(HashHelper.ComputeFrom("UnlinkBlock"), 9);

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

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

            await _transactionPoolService.UpdateTransactionPoolByBestChainAsync(chain.BestChainHash,
                                                                                chain.BestChainHeight);
        }