public TxHubTests()
 {
     _txHub             = GetRequiredService <ITxHub>();
     _blockchainService = GetRequiredService <IBlockchainService>();
     _kernelTestHelper  = GetRequiredService <KernelTestHelper>();
     _eventBus          = GetRequiredService <ILocalEventBus>();
 }
Exemple #2
0
        public OSTestHelper(IOsBlockchainNodeContextService osBlockchainNodeContextService,
                            IAccountService accountService,
                            IMinerService minerService,
                            IBlockchainService blockchainService,
                            ITxHub txHub,
                            ISmartContractAddressService smartContractAddressService,
                            IBlockAttachService blockAttachService,
                            IStaticChainInformationProvider staticChainInformationProvider,
                            ITransactionResultService transactionResultService,
                            IOptionsSnapshot <ChainOptions> chainOptions)
        {
            _chainOptions = chainOptions.Value;
            _osBlockchainNodeContextService = osBlockchainNodeContextService;
            _accountService              = accountService;
            _minerService                = minerService;
            _blockchainService           = blockchainService;
            _smartContractAddressService = smartContractAddressService;
            _blockAttachService          = blockAttachService;
            _txHub = txHub;
            _staticChainInformationProvider = staticChainInformationProvider;
            _transactionResultService       = transactionResultService;

            BestBranchBlockList     = new List <Block>();
            ForkBranchBlockList     = new List <Block>();
            UnlinkedBranchBlockList = new List <Block>();
        }
Exemple #3
0
        public PoTC(IMiner miner, ITxHub txHub)
        {
            _miner = miner;
            _txHub = txHub;

            _logger = LogManager.GetLogger(nameof(PoTC));
        }
Exemple #4
0
        public MinerService(IMiningService miningService, ITxHub txHub)
        {
            _miningService = miningService;
            _txHub         = txHub;

            EventBus = NullLocalEventBus.Instance;
        }
Exemple #5
0
        public async Task GlobalSetup()
        {
            _chains = GetRequiredService <IBlockchainStore <Chain> >();
            _chainStateInfoCollection = GetRequiredService <IStateStore <ChainStateInfo> >();
            _blockchainStateManager   = GetRequiredService <IBlockchainStateManager>();
            _blockchainStateService   = GetRequiredService <IBlockchainStateService>();
            _blockchainService        = GetRequiredService <IBlockchainService>();
            _osTestHelper             = GetRequiredService <OSTestHelper>();
            _chainManager             = GetRequiredService <IChainManager>();
            _blockManager             = GetRequiredService <IBlockManager>();
            _transactionManager       = GetRequiredService <ITransactionManager>();
            _transactionResultManager = GetRequiredService <ITransactionResultManager>();
            _txHub = GetRequiredService <ITxHub>();

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

            _chain = await _blockchainService.GetChainAsync();

            var blockHash = _chain.BestChainHash;

            while (true)
            {
                var blockState = await _blockchainStateManager.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 _blockchainStateManager.GetBlockStateSetAsync(block.GetHash());

                _blockStateSets.Add(blockState);
            }

            var chain = await _blockchainService.GetChainAsync();

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

            _chainStateInfo = await _chainStateInfoCollection.GetAsync(chain.Id.ToStorageKey());
        }
Exemple #6
0
        internal IMiner GetMiner(IMinerConfig config, ITxHub hub, ClientManager clientManager = null)
        {
            var miner = new AElf.Miner.Miner.Miner(config, hub, _chainService, _concurrencyExecutingService,
                                                   _transactionResultManager, _logger, clientManager, _binaryMerkleTreeManager, null,
                                                   MockBlockValidationService().Object, _chainContextService, _chainManagerBasic, _stateStore);

            return(miner);
        }
Exemple #7
0
        public async Task GlobalSetup()
        {
            _blockchainService  = GetRequiredService <IBlockchainService>();
            _osTestHelper       = GetRequiredService <OSTestHelper>();
            _transactionManager = GetRequiredService <ITransactionManager>();
            _txHub = GetRequiredService <ITxHub>();

            _chain = await _blockchainService.GetChainAsync();
        }
Exemple #8
0
        public MinerService(IMiningService miningService, ITxHub txHub,
                            IBlockTransactionLimitProvider blockTransactionLimitProvider)
        {
            _miningService = miningService;
            _txHub         = txHub;
            _blockTransactionLimitProvider = blockTransactionLimitProvider;

            Logger = NullLogger <MinerService> .Instance;
        }
Exemple #9
0
        public BlockChainAppService(IBlockchainService blockchainService,
                                    ITxHub txHub, IBlockStateSetManger blockStateSetManger)
        {
            _blockchainService   = blockchainService;
            _txHub               = txHub;
            _blockStateSetManger = blockStateSetManger;

            Logger        = NullLogger <BlockChainAppService> .Instance;
            LocalEventBus = NullLocalEventBus.Instance;
        }
Exemple #10
0
 public BlockChainAppServiceTest(ITestOutputHelper outputHelper) : base(outputHelper)
 {
     _blockchainService           = GetRequiredService <IBlockchainService>();
     _smartContractAddressService = GetRequiredService <ISmartContractAddressService>();
     _txHub = GetRequiredService <ITxHub>();
     _blockchainStateMergingService = GetRequiredService <IBlockchainStateMergingService>();
     _blockchainStateManager        = GetRequiredService <IBlockchainStateManager>();
     _osTestHelper   = GetRequiredService <OSTestHelper>();
     _accountService = GetRequiredService <IAccountService>();
 }
Exemple #11
0
 public MainchainNodeService(IStateStore stateStore, ITxHub hub, IChainCreationService chainCreationService,
                             IBlockSynchronizer blockSynchronizer, IChainService chainService, IMiner miner, ILogger logger)
 {
     _stateStore           = stateStore;
     _chainCreationService = chainCreationService;
     _chainService         = chainService;
     _txHub             = hub;
     _logger            = logger;
     _miner             = miner;
     _blockSynchronizer = blockSynchronizer;
 }
Exemple #12
0
        public MinerService(IMiningService miningService, ITxHub txHub,
                            IBlockTransactionLimitProvider blockTransactionLimitProvider,
                            IOptionsMonitor <TransactionPackingOptions> transactionPackingOptions)
        {
            _miningService = miningService;
            _txHub         = txHub;
            _blockTransactionLimitProvider = blockTransactionLimitProvider;
            _transactionPackingOptions     = transactionPackingOptions.CurrentValue;

            Logger = NullLogger <MinerService> .Instance;
        }
Exemple #13
0
        public ChainControllerRpcServiceServerTest(ITestOutputHelper outputHelper) : base(outputHelper)
        {
            Logger = GetService <ILogger <ChainControllerRpcServiceServerTest> >() ??
                     NullLogger <ChainControllerRpcServiceServerTest> .Instance;

            _blockchainService           = GetRequiredService <IBlockchainService>();
            _txHub                       = GetRequiredService <ITxHub>();
            _accountService              = GetRequiredService <IAccountService>();
            _smartContractAddressService = GetRequiredService <ISmartContractAddressService>();
            _osTestHelper                = GetRequiredService <OSTestHelper>();
        }
Exemple #14
0
        public BlockExecutor(IChainService chainService, IExecutingService executingService,
                             ITransactionResultManager transactionResultManager, ClientManager clientManager,
                             IBinaryMerkleTreeManager binaryMerkleTreeManager, ITxHub txHub, IChainManagerBasic chainManagerBasic, IStateStore stateStore)
        {
            _chainService             = chainService;
            _executingService         = executingService;
            _transactionResultManager = transactionResultManager;
            _clientManager            = clientManager;
            _binaryMerkleTreeManager  = binaryMerkleTreeManager;
            _txHub             = txHub;
            _chainManagerBasic = chainManagerBasic;
            _stateStore        = stateStore;
            _dpoSInfoProvider  = new DPoSInfoProvider(_stateStore);

            _logger = LogManager.GetLogger(nameof(BlockExecutor));

            MessageHub.Instance.Subscribe <DPoSStateChanged>(inState => _isMining = inState.IsMining);

            _executing         = false;
            _prepareTerminated = false;
            _terminated        = false;

            MessageHub.Instance.Subscribe <TerminationSignal>(signal =>
            {
                if (signal.Module == TerminatedModuleEnum.BlockExecutor)
                {
                    if (!_executing)
                    {
                        _terminated = true;
                        MessageHub.Instance.Publish(new TerminatedModule(TerminatedModuleEnum.BlockExecutor));
                    }
                    else
                    {
                        _prepareTerminated = true;
                    }
                }
            });

            MessageHub.Instance.Subscribe <StateEvent>(inState =>
            {
                if (inState == StateEvent.RollbackFinished)
                {
                    _isLimitExecutionTime = false;
                }

                if (inState == StateEvent.MiningStart)
                {
                    _isLimitExecutionTime = true;
                }

                _logger?.Trace($"Current Event: {inState.ToString()} ,IsLimitExecutionTime: {_isLimitExecutionTime}");
            });
        }
 public BlockchainNodeContextService(
     IBlockchainService blockchainService, IChainCreationService chainCreationService, ITxHub txHub,
     ISmartContractAddressUpdateService smartContractAddressUpdateService,
     IDefaultContractZeroCodeProvider defaultContractZeroCodeProvider, IConsensusService consensusService)
 {
     _blockchainService    = blockchainService;
     _chainCreationService = chainCreationService;
     _txHub = txHub;
     _smartContractAddressUpdateService = smartContractAddressUpdateService;
     _defaultContractZeroCodeProvider   = defaultContractZeroCodeProvider;
     _consensusService = consensusService;
 }
        public void Setup(BenchmarkContext context)
        {
            _osTestHelper = GetRequiredService <OSTestHelper>();
            _txHub        = GetRequiredService <ITxHub>();

            _counter = context.GetCounter("TestCounter");

            AsyncHelper.RunSync(async() =>
            {
                _transactions = await _osTestHelper.GenerateTransferTransactions(1000);
            });
        }
Exemple #17
0
 public ParallelTests()
 {
     _blockchainService        = GetRequiredService <IBlockchainService>();
     _blockExecutingService    = GetRequiredService <IBlockExecutingService>();
     _minerService             = GetRequiredService <IMinerService>();
     _transactionResultManager = GetRequiredService <ITransactionResultManager>();
     _grouper            = GetRequiredService <ITransactionGrouper>();
     _codeRemarksManager = GetRequiredService <ICodeRemarksManager>();
     _txHub = GetRequiredService <ITxHub>();
     _blockAttachService = GetRequiredService <IBlockAttachService>();
     _accountService     = GetRequiredService <IAccountService>();
     _parallelTestHelper = GetRequiredService <ParallelTestHelper>();
 }
Exemple #18
0
 public ParallelTests()
 {
     _blockchainService        = GetRequiredService <IBlockchainService>();
     _blockExecutingService    = GetRequiredService <IBlockExecutingService>();
     _transactionResultManager = GetRequiredService <ITransactionResultManager>();
     _grouper = GetRequiredService <ITransactionGrouper>();
     _contractRemarksService = GetRequiredService <IContractRemarksService>();
     _txHub = GetRequiredService <ITxHub>();
     _blockAttachService          = GetRequiredService <IBlockAttachService>();
     _accountService              = GetRequiredService <IAccountService>();
     _parallelTestHelper          = GetRequiredService <ParallelTestHelper>();
     _smartContractAddressService = GetRequiredService <ISmartContractAddressService>();
 }
Exemple #19
0
        public async Task GlobalSetup()
        {
            _blockchainService        = GetRequiredService <IBlockchainService>();
            _osTestHelper             = GetRequiredService <OSTestHelper>();
            _minerService             = GetRequiredService <IMinerService>();
            _transactionResultManager = GetRequiredService <ITransactionResultManager>();
            _blockStateSets           = GetRequiredService <INotModifiedCachedStateStore <BlockStateSet> >();
            _transactionManager       = GetRequiredService <ITransactionManager>();
            _txHub = GetRequiredService <ITxHub>();

            _transactions = new List <Transaction>();
            _chain        = await _blockchainService.GetChainAsync();
        }
Exemple #20
0
        public TransactionResultTest(ITxPoolConfig txPoolConfig, IChainService chainService,
                                     ITxSignatureVerifier signatureVerifier, ITxRefBlockValidator refBlockValidator,
                                     ITransactionResultManager transactionResultManager, ITxHub txHub)
        {
            ChainConfig.Instance.ChainId    = Hash.Generate().DumpHex();
            NodeConfig.Instance.NodeAccount = Address.Generate().DumpHex();
            _transactionResultManager       = transactionResultManager;
            _signatureVerifier = signatureVerifier;
            _refBlockValidator = refBlockValidator;
            _txHub             = txHub;
//            _transactionResultService = new TransactionResultService(
//                new TxPool(logger,
//                    new NewTxHub(transactionManager, chainService, signatureVerifier, refBlockValidator)), transactionResultManager);
            _transactionResultService = new TransactionResultService(_txHub, _transactionResultManager);
        }
Exemple #21
0
 public ParallelTestHelper(IOsBlockchainNodeContextService osBlockchainNodeContextService,
                           IAccountService accountService,
                           IMinerService minerService,
                           IBlockchainService blockchainService,
                           ITxHub txHub,
                           ISmartContractAddressService smartContractAddressService,
                           IBlockAttachService blockAttachService,
                           IStaticChainInformationProvider staticChainInformationProvider,
                           ITransactionResultService transactionResultService,
                           IOptionsSnapshot <ChainOptions> chainOptions) : base(osBlockchainNodeContextService, accountService,
                                                                                minerService, blockchainService, txHub, smartContractAddressService, blockAttachService,
                                                                                staticChainInformationProvider, transactionResultService, chainOptions)
 {
     _accountService = accountService;
     _staticChainInformationProvider = staticChainInformationProvider;
 }
Exemple #22
0
        public void Setup(BenchmarkContext context)
        {
            _blockchainService  = GetRequiredService <IBlockchainService>();
            _osTestHelper       = GetRequiredService <OSTestHelper>();
            _minerService       = GetRequiredService <IMinerService>();
            _txHub              = GetRequiredService <ITxHub>();
            _blockAttachService = GetRequiredService <IBlockAttachService>();

            _counter = context.GetCounter("TestCounter");

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

                await _osTestHelper.BroadcastTransactions(transactions);
            });
        }
Exemple #23
0
 public ParallelTests()
 {
     _blockchainService        = GetRequiredService <IBlockchainService>();
     _blockExecutingService    = GetRequiredService <IBlockExecutingService>();
     _transactionResultManager = GetRequiredService <ITransactionResultManager>();
     _grouper = GetRequiredService <ITransactionGrouper>();
     _blockchainStateService = GetRequiredService <IBlockchainStateService>();
     _txHub = GetRequiredService <ITxHub>();
     _blockAttachService              = GetRequiredService <IBlockAttachService>();
     _accountService                  = GetRequiredService <IAccountService>();
     _parallelTestHelper              = GetRequiredService <ParallelTestHelper>();
     _smartContractAddressService     = GetRequiredService <ISmartContractAddressService>();
     _blockchainStateManager          = GetRequiredService <IBlockchainStateManager>();
     _versionedStates                 = GetRequiredService <IStateStore <VersionedState> >();
     _nonparallelContractCodeProvider = GetRequiredService <INonparallelContractCodeProvider>();
     _blockStateSetManger             = GetRequiredService <IBlockStateSetManger>();
 }
Exemple #24
0
        public MockSetup(IDataStore dataStore, IStateStore stateStore, ITxHub txHub)
        {
            _dataStore  = dataStore;
            _stateStore = stateStore;

            _smartContractManager        = new SmartContractManager(_dataStore);
            _transactionManager          = new TransactionManager(_dataStore);
            _transactionTraceManager     = new TransactionTraceManager(_dataStore);
            _transactionResultManager    = new TransactionResultManager(_dataStore);
            _smartContractRunnerFactory  = new SmartContractRunnerFactory();
            _concurrencyExecutingService = new SimpleExecutingService(
                new SmartContractService(_smartContractManager, _smartContractRunnerFactory, _stateStore,
                                         _functionMetadataService), _transactionTraceManager, _stateStore,
                new ChainContextService(GetChainService()));
            _txHub             = txHub;
            _chainManagerBasic = new ChainManagerBasic(dataStore);
        }
        public void Setup(BenchmarkContext context)
        {
            _osTestHelper      = GetRequiredService <OSTestHelper>();
            _txHub             = GetRequiredService <ITxHub>();
            _blockchainService = GetRequiredService <IBlockchainService>();

            _counter = context.GetCounter("TestCounter");

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

                await _txHub.HandleTransactionsReceivedAsync(new TransactionsReceivedEvent
                {
                    Transactions = transactions
                });

                await _osTestHelper.MinedOneBlock();
            });
        }
        public BlockChainAppService(IBlockchainService blockchainService,
                                    ISmartContractAddressService smartContractAddressService,
                                    ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                    ITransactionManager transactionManager,
                                    ITransactionResultQueryService transactionResultQueryService,
                                    ITxHub txHub,
                                    IBlockchainStateManager blockchainStateManager
                                    )
        {
            _blockchainService                   = blockchainService;
            _smartContractAddressService         = smartContractAddressService;
            _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
            _transactionManager                  = transactionManager;
            _transactionResultQueryService       = transactionResultQueryService;
            _txHub = txHub;
            _blockchainStateManager = blockchainStateManager;

            Logger        = NullLogger <BlockChainAppService> .Instance;
            LocalEventBus = NullLocalEventBus.Instance;
        }
Exemple #27
0
        public Miner(IMinerConfig config, ITxHub txHub, IChainService chainService,
                     IExecutingService executingService, ITransactionResultManager transactionResultManager,
                     ILogger logger, ClientManager clientManager,
                     IBinaryMerkleTreeManager binaryMerkleTreeManager, ServerManager serverManager,
                     IBlockValidationService blockValidationService, IChainContextService chainContextService, IChainManagerBasic chainManagerBasic, IStateStore stateStore)
        {
            Config                    = config;
            _txHub                    = txHub;
            _chainService             = chainService;
            _executingService         = executingService;
            _transactionResultManager = transactionResultManager;
            _logger                   = logger;
            _clientManager            = clientManager;
            _binaryMerkleTreeManager  = binaryMerkleTreeManager;
            _serverManager            = serverManager;
            _blockValidationService   = blockValidationService;
            _chainContextService      = chainContextService;
            _chainManagerBasic        = chainManagerBasic;
            _txFilter                 = new TransactionFilter();
            _dpoSInfoProvider         = new DPoSInfoProvider(stateStore);

            _maxMineTime = ConsensusConfig.Instance.DPoSMiningInterval * NodeConfig.Instance.RatioMine;
        }
 public TransactionResultService(ITxHub txHub, ITransactionResultManager transactionResultManager)
 {
     _txHub = txHub;
     _transactionResultManager = transactionResultManager;
 }
 public TxPoolInterestedEventsHandler(ITxHub txHub)
 {
     _txHub = txHub;
 }
Exemple #30
0
        public DPoS(IStateStore stateStore, ITxHub txHub, IMiner miner, IChainService chainService)
        {
            _txHub             = txHub;
            _miner             = miner;
            _chainService      = chainService;
            _prepareTerminated = false;
            _terminated        = false;

            _logger = LogManager.GetLogger(nameof(DPoS));

            Helper = new AElfDPoSHelper(Hash.LoadHex(ChainConfig.Instance.ChainId), Miners,
                                        ContractAddress, stateStore);

            Provider = new DPoSInfoProvider(stateStore);

            var count = MinersConfig.Instance.Producers.Count;

            GlobalConfig.BlockProducerNumber    = count;
            GlobalConfig.BlockNumberOfEachRound = count + 1;

            _logger?.Info("Block Producer nodes count:" + GlobalConfig.BlockProducerNumber);
            _logger?.Info("Blocks of one round:" + GlobalConfig.BlockNumberOfEachRound);

            if (GlobalConfig.BlockProducerNumber == 1 && NodeConfig.Instance.IsMiner)
            {
                AElfDPoSObserver.RecoverMining();
            }

            MessageHub.Instance.Subscribe <UpdateConsensus>(async option =>
            {
                if (option == UpdateConsensus.Update)
                {
                    _logger?.Trace("UpdateConsensus - Update");
                    await Update();
                }

                if (option == UpdateConsensus.Dispose)
                {
                    _logger?.Trace("UpdateConsensus - Dispose");
                    Stop();
                }
            });

            MessageHub.Instance.Subscribe <LockMining>(async inState =>
            {
                if (inState.Lock)
                {
                    IncrementLockNumber();
                }
                else
                {
                    await Start();
                }
            });

            MessageHub.Instance.Subscribe <TerminationSignal>(signal =>
            {
                if (signal.Module == TerminatedModuleEnum.Mining)
                {
                    _prepareTerminated = true;
                }
            });

            MessageHub.Instance.Subscribe <FSMStateChanged>(inState => { CurrentState = inState.CurrentState; });
        }