예제 #1
0
 public MinedBlockProducer(ITxSource txSource,
                           IBlockchainProcessor processor,
                           ISealer sealer,
                           IBlockTree blockTree,
                           IBlockProcessingQueue blockProcessingQueue,
                           IStateProvider stateProvider,
                           IGasLimitCalculator gasLimitCalculator,
                           ITimestamper timestamper,
                           ISpecProvider specProvider,
                           ILogManager logManager,
                           IDifficultyCalculator difficultyCalculator)
     : base(
         txSource,
         processor,
         sealer,
         blockTree,
         blockProcessingQueue,
         stateProvider,
         gasLimitCalculator,
         timestamper,
         specProvider,
         logManager)
 {
     _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator));
 }
예제 #2
0
 public HeaderValidator(IDifficultyCalculator difficultyCalculator, IBlockTree blockTree, ISealEngine sealEngine, ISpecProvider specProvider, ILogManager logManager)
 {
     _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator));
     _blockTree            = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
     _sealEngine           = sealEngine ?? throw new ArgumentNullException(nameof(sealEngine));
     _daoBlockNumber       = specProvider?.DaoBlockNumber;
 }
예제 #3
0
        public EthashSealValidator(ILogManager logManager, IDifficultyCalculator difficultyCalculator, ICryptoRandom cryptoRandom, IEthash ethash)
        {
            _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator));
            _cryptoRandom         = cryptoRandom ?? throw new ArgumentNullException(nameof(cryptoRandom));
            _ethash = ethash ?? throw new ArgumentNullException(nameof(ethash));
            _logger = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

            ResetValidationInterval();
        }
예제 #4
0
        public MessageHandler(INetworkManager manager, ConcurrentTransactionPool txPool, NetworkNodesPool nodePool, IDifficultyCalculator difficultyCalculator, IBlockValidator blockValidator, ILoggerFactory loggerFactory, IBlockchainRepository blockchainRepo, string netId)
            : base(manager, nodePool, loggerFactory)
        {
            _difficultyCalculator = difficultyCalculator;
            _blockValidator       = blockValidator;
            _blockchainRepo       = blockchainRepo;
            _netId  = netId;
            _txPool = txPool;

            _blockchain = _blockchainRepo.GetChainByNetId(_netId);
            _difficulty = _difficultyCalculator.CalculateCurrentDifficulty(_blockchain);
        }
예제 #5
0
 public MinedBlockProducer(
     IPendingTxSelector pendingTxSelector,
     IBlockchainProcessor processor,
     ISealer sealer,
     IBlockTree blockTree,
     IBlockProcessingQueue blockProcessingQueue,
     IStateProvider stateProvider,
     ITimestamper timestamper,
     ILogManager logManager,
     IDifficultyCalculator difficultyCalculator)
     : base(pendingTxSelector, processor, sealer, blockTree, blockProcessingQueue, stateProvider, timestamper, logManager)
 {
     _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator));
 }
예제 #6
0
 public BlockMiner(ITransactionKeyResolver transactionKeyResolver, IMerkleTreeBuilder merkleTreeBuilder, INetworkParameters networkParameters, IBlockbaseTransactionBuilder blockbaseBuilder, IPeerNetwork peerNetwork, IConsensusMethod consensusMethod, IUnconfirmedTransactionPool unconfirmedTransactionPool, IBlockRepository blockRepository, IReceiver blockReciever, IDifficultyCalculator difficultyCalculator, ILoggerFactory loggerFactory)
 {
     _networkParameters      = networkParameters;
     _peerNetwork            = peerNetwork;
     _blockbaseBuilder       = blockbaseBuilder;
     _blockReciever          = blockReciever;
     _consensusMethod        = consensusMethod;
     _difficultyCalculator   = difficultyCalculator;
     _transactionKeyResolver = transactionKeyResolver;
     _merkleTreeBuilder      = merkleTreeBuilder;
     _logger                              = loggerFactory.CreateLogger <BlockMiner>();
     _blockRepository                     = blockRepository;
     _unconfirmedTransactionPool          = unconfirmedTransactionPool;
     _unconfirmedTransactionPool.Changed += UnconfirmedTransactionPoolChanged;
 }
예제 #7
0
 public MinedBlockProducer(
     IDifficultyCalculator difficultyCalculator,
     ITxPool txPool,
     IBlockchainProcessor processor,
     ISealer sealer,
     IBlockTree blockTree,
     ITimestamp timestamp,
     ILogManager logManager)
 {
     _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator));
     _txPool    = txPool ?? throw new ArgumentNullException(nameof(txPool));
     _processor = processor ?? throw new ArgumentNullException(nameof(processor));
     _sealer    = sealer ?? throw new ArgumentNullException(nameof(sealer));
     _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
     _timestamp = timestamp;
     _logger    = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
 }
예제 #8
0
        public BlockchainNodeTests()
        {
            _receiver   = A.Fake <IReceiver>();
            _parameters = new StaticNetworkParameters()
            {
                BlockTime = TimeSpan.FromSeconds(1)
            };
            _loggerFactory              = A.Fake <ILoggerFactory>();
            _blockRepository            = A.Fake <IBlockRepository>();
            _blockVerifier              = A.Fake <IBlockVerifier>();
            _forkRebaser                = A.Fake <IForkRebaser>();
            _peerNetwork                = A.Fake <IPeerNetwork>();
            _unconfirmedTransactionPool = A.Fake <IUnconfirmedTransactionPool>();
            _difficultyCalculator       = A.Fake <IDifficultyCalculator>();

            _subject = new BlockchainNode(_blockRepository, _blockVerifier, _receiver, _loggerFactory, _forkRebaser, _parameters, _unconfirmedTransactionPool, _peerNetwork, _difficultyCalculator);
            _subject.PollTimer.Dispose();
        }
예제 #9
0
        public BlockchainNode(IBlockRepository blockRepository, IBlockVerifier blockVerifier, IReceiver receiver, ILoggerFactory loggerFactory, IForkRebaser forkRebaser, INetworkParameters parameters, IUnconfirmedTransactionPool unconfirmedTransactionPool, IPeerNetwork peerNetwork, IDifficultyCalculator difficultyCalculator)
        {
            _blockRepository            = blockRepository;
            _blockVerifier              = blockVerifier;
            _receiver                   = receiver;
            _parameters                 = parameters;
            _forkRebaser                = forkRebaser;
            _unconfirmedTransactionPool = unconfirmedTransactionPool;
            _peerNetwork                = peerNetwork;
            _difficultyCalculator       = difficultyCalculator;
            //_expectedBlockList = expectedBlockList;
            _logger = loggerFactory.CreateLogger <BlockchainNode>();

            _receiver.OnReceiveBlock       += RecieveBlock;
            _receiver.OnRecieveTransaction += RecieveTransaction;

            PollTimer = new Timer(GetMissingBlocks, null, TimeSpan.FromSeconds(5), _parameters.BlockTime);
        }
예제 #10
0
        public BlockchainProcessor(
            IBlockTree blockTree,
            ISealEngine sealEngine,
            ITransactionStore transactionStore,
            IDifficultyCalculator difficultyCalculator,
            IBlockProcessor blockProcessor,
            IEthereumSigner signer,
            ILogManager logManager)
        {
            _logger    = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
            _blockTree.NewBestSuggestedBlock += OnNewBestBlock;

            _transactionStore     = transactionStore ?? throw new ArgumentNullException(nameof(transactionStore));
            _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator));
            _sealEngine           = sealEngine ?? throw new ArgumentNullException(nameof(sealEngine));
            _blockProcessor       = blockProcessor ?? throw new ArgumentNullException(nameof(blockProcessor));
            _signer = signer ?? throw new ArgumentNullException(nameof(signer));
        }
예제 #11
0
파일: Miner.cs 프로젝트: SpenQ/Prototype
        public Miner(string netId, string minerWalletPubKey, string minerWalletPrivKey,
                     IBlockchainRepository blockchainRepo, ITransactionRepository transactionRepo,
                     ITransactionCreator transactionCreator, ITransactionValidator transactionValidator,
                     IDifficultyCalculator difficultyCalculator, IPowBlockCreator blockCreator,
                     IBlockValidator blockValidator, ConcurrentTransactionPool txPool, ILoggerFactory loggerFactory)
        {
            _logger               = loggerFactory.CreateLogger <Miner>();
            _walletPubKey         = minerWalletPubKey;
            _walletPrivKey        = minerWalletPrivKey;
            _blockchainRepo       = blockchainRepo;
            _networkIdentifier    = netId;
            _blockchain           = _blockchainRepo.GetChainByNetId(_networkIdentifier);
            _transactionRepo      = transactionRepo;
            _transactionCreator   = transactionCreator;
            _transactionValidator = transactionValidator;
            _difficultyCalculator = difficultyCalculator;
            _blockCreator         = blockCreator;
            _blockValidator       = blockValidator;
            _txPool               = txPool;

            EventPublisher.GetInstance().OnUnvalidatedTransactionReceived += OnUnvalidatedTransactionReceived;
            EventPublisher.GetInstance().OnUnvalidatedBlockCreated        += OnUnvalidatedBlockCreated;
            difficulty = _difficultyCalculator.CalculateCurrentDifficulty(_blockchain);
        }
예제 #12
0
 public EthashSealValidator(ILogManager logManager, IDifficultyCalculator difficultyCalculator, IEthash ethash)
 {
     _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator));
     _ethash = ethash ?? throw new ArgumentNullException(nameof(ethash));
     _logger = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
 }
예제 #13
0
        public NetworkManager(NetworkNodesPool nodePool, ILoggerFactory loggerFactory, IBlockValidator blockValidator, IDifficultyCalculator difficultyCalculator, IBlockchainRepository repo, string netId)
        {
            _logger   = loggerFactory.CreateLogger <NetworkManager>();
            _nodePool = nodePool;
            _repo     = repo;
            _netId    = netId;
            _relayedTransactionHashes = new List <string>();
            _relayedBlockHashes       = new List <string>();
            _messageHandler           = new MessageHandler(this, ConcurrentTransactionPool.GetInstance(), nodePool, difficultyCalculator, blockValidator, loggerFactory, repo, netId);
            _handshakeMessageHandler  = new HandshakeMessageHandler(this, nodePool, loggerFactory, repo, netId);
            _delays = new ConcurrentBag <int>();

            EventPublisher.GetInstance().OnValidatedBlockCreated    += OnValidatedBlockCreated;
            EventPublisher.GetInstance().OnValidTransactionReceived += OnValidTransactionReceived;
            // In the first phase, check every 10s if there is a node that has a longer chain than ours.
            // After the sync completed, exit the 'syncing' state and accept new blocks and transactions.
            StartSyncProcess(new CancellationTokenSource()); // todo cts
        }
예제 #14
0
 public EthashSealEngine(IEthash ethash, IDifficultyCalculator difficultyCalculator, ILogManager logManager)
 {
     _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator));
     _ethash = ethash ?? throw new ArgumentNullException(nameof(ethash));
 }
예제 #15
0
        public double GetDifficulty()
        {
            IDifficultyCalculator difficultyCalculator = DifficultyCalculatorFactory.GetCalculator(this.GetContainingBlockTypes());

            return(difficultyCalculator.CalculateDifficulty(this));
        }