Ejemplo n.º 1
0
        public async Task SetIrreversibleBlockAsync(Chain chain, long irreversibleBlockHeight,
                                                    Hash irreversibleBlockHash)
        {
            // Create before IChainManager.SetIrreversibleBlockAsync so that we can correctly get the previous LIB info
            var eventDataToPublish = new NewIrreversibleBlockFoundEvent()
            {
                PreviousIrreversibleBlockHash   = chain.LastIrreversibleBlockHash,
                PreviousIrreversibleBlockHeight = chain.LastIrreversibleBlockHeight,
                BlockHash   = irreversibleBlockHash,
                BlockHeight = irreversibleBlockHeight
            };

            var success = await _chainManager.SetIrreversibleBlockAsync(chain, irreversibleBlockHash);

            if (!success)
            {
                return;
            }
            // TODO: move to background job, it will slow down our system
            // Clean last branches and not linked
            var toCleanBlocks = await _chainManager.CleanBranchesAsync(chain, eventDataToPublish.PreviousIrreversibleBlockHash,
                                                                       eventDataToPublish.PreviousIrreversibleBlockHeight);

            await RemoveBlocksAsync(toCleanBlocks);

            await LocalEventBus.PublishAsync(eventDataToPublish);
        }
        public async Task GlobalSetup()
        {
            _chains = GetRequiredService <IBlockchainStore <Chain> >();
            _chainStateInfoCollection = GetRequiredService <IStateStore <ChainStateInfo> >();
            _blockchainStateService   = GetRequiredService <IBlockchainStateService>();
            _blockStateSetManger      = GetRequiredService <IBlockStateSetManger>();
            _blockchainService        = GetRequiredService <IBlockchainService>();
            _osTestHelper             = GetRequiredService <OSTestHelper>();
            _chainManager             = GetRequiredService <IChainManager>();
            _blockManager             = GetRequiredService <IBlockManager>();
            _transactionManager       = GetRequiredService <ITransactionManager>();
            _transactionPoolService   = GetRequiredService <ITransactionPoolService>();


            _blockStateSets = new List <BlockStateSet>();
            _blocks         = new List <Block>();

            _chain = await _blockchainService.GetChainAsync();

            var blockHash = _chain.BestChainHash;

            while (true)
            {
                var blockState = await _blockStateSetManger.GetBlockStateSetAsync(blockHash);

                _blockStateSets.Add(blockState);

                var blockHeader = await _blockchainService.GetBlockHeaderByHashAsync(blockHash);

                blockHash = blockHeader.PreviousBlockHash;
                if (blockHash == _chain.LastIrreversibleBlockHash)
                {
                    break;
                }
            }

            await _blockchainStateService.MergeBlockStateAsync(_chain.BestChainHeight, _chain.BestChainHash);

            for (var i = 0; i < BlockCount; i++)
            {
                var transactions = await _osTestHelper.GenerateTransferTransactions(TransactionCount);

                await _osTestHelper.BroadcastTransactions(transactions);

                var block = await _osTestHelper.MinedOneBlock();

                _blocks.Add(block);

                var blockState = await _blockStateSetManger.GetBlockStateSetAsync(block.GetHash());

                _blockStateSets.Add(blockState);
            }

            var chain = await _blockchainService.GetChainAsync();

            await _chainManager.SetIrreversibleBlockAsync(chain, chain.BestChainHash);

            _chainStateInfo = await _chainStateInfoCollection.GetAsync(chain.Id.ToStorageKey());
        }
Ejemplo n.º 3
0
        public void Setup(BenchmarkContext context)
        {
            _blockchainStateService = GetRequiredService <IBlockchainStateService>();
            _blockchainService      = GetRequiredService <IBlockchainService>();
            _osTestHelper           = GetRequiredService <OSTestHelper>();
            _chainManager           = GetRequiredService <IChainManager>();

            _counter = context.GetCounter("TestCounter");

            AsyncHelper.RunSync(async() =>
            {
                var transactions = await _osTestHelper.GenerateTransferTransactions(1000);
                await _osTestHelper.BroadcastTransactions(transactions);
                await _osTestHelper.MinedOneBlock();

                var chain = await _blockchainService.GetChainAsync();
                await _chainManager.SetIrreversibleBlockAsync(chain, chain.BestChainHash);
            });
        }
Ejemplo n.º 4
0
        public async Task SetIrreversibleBlockAsync(Chain chain, long irreversibleBlockHeight,
                                                    Hash irreversibleBlockHash)
        {
            // Create before IChainManager.SetIrreversibleBlockAsync so that we can correctly get the previous LIB info
            var eventDataToPublish = new NewIrreversibleBlockFoundEvent()
            {
                PreviousIrreversibleBlockHash   = chain.LastIrreversibleBlockHash,
                PreviousIrreversibleBlockHeight = chain.LastIrreversibleBlockHeight,
                BlockHash   = irreversibleBlockHash,
                BlockHeight = irreversibleBlockHeight
            };

            var success = await _chainManager.SetIrreversibleBlockAsync(chain, irreversibleBlockHash);

            if (!success)
            {
                return;
            }

            await LocalEventBus.PublishAsync(eventDataToPublish);
        }