Beispiel #1
0
        private void Initialize()
        {
            _transactionManager        = new TransactionManager(_dataStore, _logger);
            _transactionReceiptManager = new TransactionReceiptManager(_database);
            _smartContractManager      = new SmartContractManager(_dataStore);
            _transactionResultManager  = new TransactionResultManager(_dataStore);
            _transactionTraceManager   = new TransactionTraceManager(_dataStore);
            _functionMetadataService   = new FunctionMetadataService(_dataStore, _logger);
            _chainManagerBasic         = new ChainManagerBasic(_dataStore);
            _chainService = new ChainService(_chainManagerBasic, new BlockManagerBasic(_dataStore),
                                             _transactionManager, _transactionTraceManager, _dataStore, StateStore);
            _smartContractRunnerFactory = new SmartContractRunnerFactory();

            /*var runner = new SmartContractRunner("../../../../AElf.SDK.CSharp/bin/Debug/netstandard2.0/");
             * _smartContractRunnerFactory.AddRunner(0, runner);*/
            var runner = new SmartContractRunner(ContractCodes.TestContractFolder);

            _smartContractRunnerFactory.AddRunner(0, runner);
            _concurrencyExecutingService = new SimpleExecutingService(
                new SmartContractService(_smartContractManager, _smartContractRunnerFactory, StateStore,
                                         _functionMetadataService), _transactionTraceManager, StateStore,
                new ChainContextService(_chainService));

            _chainCreationService = new ChainCreationService(_chainService,
                                                             new SmartContractService(new SmartContractManager(_dataStore), _smartContractRunnerFactory,
                                                                                      StateStore, _functionMetadataService), _logger);

            _binaryMerkleTreeManager = new BinaryMerkleTreeManager(_dataStore);
            _chainContextService     = new ChainContextService(_chainService);
            _stateStore = new StateStore(_database);
        }
Beispiel #2
0
        public Benchmarks(IStateStore stateStore, IChainCreationService chainCreationService,
                          IChainContextService chainContextService, ISmartContractService smartContractService,
                          ILogger logger, IFunctionMetadataService functionMetadataService, BenchmarkOptions options, IExecutingService executingService)
        {
            ChainId               = Hash.Generate();
            _stateStore           = stateStore;
            _chainCreationService = chainCreationService;
            _smartContractService = smartContractService;
            _logger               = logger;
            _options              = options;
            _executingService     = executingService;


            _servicePack = new ServicePack
            {
                ChainContextService      = chainContextService,
                SmartContractService     = _smartContractService,
                ResourceDetectionService = new ResourceUsageDetectionService(functionMetadataService),
                StateStore = _stateStore
            };

            _dataGenerater = new TransactionDataGenerator(options);
            byte[] code;
            using (FileStream file = File.OpenRead(Path.GetFullPath(options.DllDir + "/" + options.ContractDll)))
            {
                code = file.ReadFully();
            }
            _contractHash = Prepare(code).Result;
        }
Beispiel #3
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}");
            });
        }
Beispiel #4
0
        public BlockExecutionService(IExecutingService executingService, ITxPoolService txPoolService,
                                     IChainService chainService, ITransactionManager transactionManager,
                                     ITransactionResultManager transactionResultManager, IStateDictator stateDictator,
                                     IBinaryMerkleTreeManager binaryMerkleTreeManager)
        {
            _executingService         = executingService;
            _txPoolService            = txPoolService;
            _chainService             = chainService;
            _transactionManager       = transactionManager;
            _transactionResultManager = transactionResultManager;
            _stateDictator            = stateDictator;
            _binaryMerkleTreeManager  = binaryMerkleTreeManager;

            _logger = LogManager.GetLogger(nameof(BlockExecutionService));
        }
Beispiel #5
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);
        }
Beispiel #6
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;
        }
Beispiel #7
0
        protected override void OnReceive(object message)
        {
            switch (message)
            {
            case LocalSerivcePack res:
                if (_state == State.PendingSetSericePack)
                {
                    _servicePack           = res.ServicePack;
                    _proxyExecutingService = new SimpleExecutingService(_servicePack.SmartContractService, _servicePack.TransactionTraceManager, _servicePack.StateStore, _servicePack.ChainContextService);
                    _state = State.Idle;
                }

                break;

            case JobExecutionRequest req:
                if (_state == State.Idle)
                {
                    _cancellationTokenSource?.Dispose();
                    _cancellationTokenSource = new CancellationTokenSource();

                    var self = Self;
                    Task.Run(() =>
                    {
                        RunJob(req)
                        .ContinueWith(
                            task => task.Result,
                            TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously
                            ).PipeTo(self);
                    });

/*
 * Temporarily disabled.
 * TODO: https://github.com/AElfProject/AElf/issues/338
 *                      Sender.Tell(new JobExecutionStatus(req.RequestId, JobExecutionStatus.RequestStatus.Running));
 */
                }

/*
 * Temporarily disabled.
 * TODO: https://github.com/AElfProject/AElf/issues/338
 *                  else if (_state == State.PendingSetSericePack)
 *                  {
 *                      Sender.Tell(new JobExecutionStatus(req.RequestId,
 *                          JobExecutionStatus.RequestStatus.FailedDueToWorkerNotReady));
 *                  }
 *                  else
 *                  {
 *                      Sender.Tell(new JobExecutionStatus(req.RequestId, JobExecutionStatus.RequestStatus.Rejected));
 *                  }
 */
                break;

            case JobExecutionCancelMessage c:
                _cancellationTokenSource?.Cancel();
                Sender.Tell(JobExecutionCancelAckMessage.Instance);
                break;

/*
 * Temporarily disabled.
 * TODO: https://github.com/AElfProject/AElf/issues/338
 *              case JobExecutionStatusQuery query:
 *                  if (query.RequestId != _servingRequestId)
 *                  {
 *                      Sender.Tell(new JobExecutionStatus(query.RequestId,
 *                          JobExecutionStatus.RequestStatus.InvalidRequestId));
 *                  }
 *                  else
 *                  {
 *                      Sender.Tell(new JobExecutionStatus(query.RequestId, JobExecutionStatus.RequestStatus.Running));
 *                  }
 *                  break;
 */
            }
        }
Beispiel #8
0
 public BlockChainTests(BlockChainTests_MockSetup mock, SimpleExecutingService executingService)
 {
     _mock             = mock;
     _executingService = executingService;
 }
 public ParallelTransactionExecutingService(IActorEnvironment actorEnvironment, IGrouper grouper, ServicePack servicePack)
 {
     _actorEnvironment      = actorEnvironment;
     _grouper               = grouper;
     _singlExecutingService = new SimpleExecutingService(servicePack.SmartContractService, servicePack.TransactionTraceManager, servicePack.StateStore, servicePack.ChainContextService);
 }