/// <summary>
 /// Constructs an instance of a MempoolSignaled object.
 /// Starts the block notification loop to memory pool behaviors for connected nodes.
 /// </summary>
 /// <param name="manager">Memory pool manager injected dependency.</param>
 /// <param name="chainIndexer">Concurrent chain injected dependency.</param>
 /// <param name="connection">Connection manager injected dependency.</param>
 /// <param name="nodeLifetime">Node lifetime injected dependency.</param>
 /// <param name="asyncProvider">Asynchronous loop factory injected dependency.</param>
 /// <param name="mempoolLock">The mempool lock.</param>
 /// <param name="memPool">the mempool.</param>
 /// <param name="validator">The mempool validator.</param>
 /// <param name="mempoolOrphans">The mempool orphan list.</param>
 public MempoolSignaled(
     MempoolManager manager,
     ChainIndexer chainIndexer,
     IConnectionManager connection,
     INodeLifetime nodeLifetime,
     IAsyncProvider asyncProvider,
     MempoolSchedulerLock mempoolLock,
     ITxMempool memPool,
     IMempoolValidator validator,
     MempoolOrphans mempoolOrphans,
     ISignals signals,
     IInitialBlockDownloadState initialBlockDownloadState)
 {
     this.manager                   = manager;
     this.chainIndexer              = chainIndexer;
     this.connection                = connection;
     this.nodeLifetime              = nodeLifetime;
     this.asyncProvider             = asyncProvider;
     this.mempoolLock               = mempoolLock;
     this.memPool                   = memPool;
     this.validator                 = validator;
     this.mempoolOrphans            = mempoolOrphans;
     this.signals                   = signals;
     this.initialBlockDownloadState = initialBlockDownloadState;
 }
Exemplo n.º 2
0
        public WalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ChainIndexer chainIndexer,
                                 Network network, IBlockStore blockStore, StoreSettings storeSettings, ISignals signals,
                                 IAsyncProvider asyncProvider)
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(walletManager, nameof(walletManager));
            Guard.NotNull(chainIndexer, nameof(chainIndexer));
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(blockStore, nameof(blockStore));
            Guard.NotNull(storeSettings, nameof(storeSettings));
            Guard.NotNull(signals, nameof(signals));
            Guard.NotNull(asyncProvider, nameof(asyncProvider));

            this.walletManager = walletManager;
            this.chainIndexer  = chainIndexer;
            this.blockStore    = blockStore;
            this.storeSettings = storeSettings;
            this.signals       = signals;
            this.asyncProvider = asyncProvider;
            this.logger        = loggerFactory.CreateLogger(GetType().FullName);
            this.blocksQueue   =
                this.asyncProvider.CreateAndRunAsyncDelegateDequeuer <Block>(
                    $"{nameof(WalletSyncManager)}-{nameof(this.blocksQueue)}", OnProcessBlockAsync);

            this.blocksQueueSize = 0;
        }
Exemplo n.º 3
0
 public PruneBlockStoreServiceTests() : base(new StraxMain())
 {
     this.asyncProvider   = new Mock <IAsyncProvider>().Object;
     this.blockRepository = new Mock <IBlockRepository>().Object;
     this.chainState      = new Mock <IChainState>();
     this.nodeLifetime    = new NodeLifetime();
 }
Exemplo n.º 4
0
        public BlockStoreSignaled(
            IBlockStoreQueue blockStoreQueue,
            StoreSettings storeSettings,
            IChainState chainState,
            IConnectionManager connection,
            INodeLifetime nodeLifetime,
            ILoggerFactory loggerFactory,
            IInitialBlockDownloadState initialBlockDownloadState,
            ISignals signals,
            IAsyncProvider asyncProvider)
        {
            this.blockStoreQueue           = blockStoreQueue;
            this.chainState                = chainState;
            this.connection                = connection;
            this.nodeLifetime              = nodeLifetime;
            this.logger                    = loggerFactory.CreateLogger(this.GetType().FullName);
            this.storeSettings             = storeSettings;
            this.initialBlockDownloadState = initialBlockDownloadState;
            this.signals                   = signals;
            this.asyncProvider             = asyncProvider;

            this.blocksToAnnounce = asyncProvider.CreateAsyncQueue <ChainedHeader>();
            this.dequeueLoopTask  = this.DequeueContinuouslyAsync();

            this.asyncProvider.RegisterTask($"{nameof(BlockStoreSignaled)}.{nameof(this.dequeueLoopTask)}", this.dequeueLoopTask);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the factory.
        /// </summary>
        /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
        /// <param name="dateTimeProvider">Provider of time functions.</param>
        /// <param name="loggerFactory">Factory for creating loggers.</param>
        /// <param name="payloadProvider">A provider of network payload messages.</param>
        /// <param name="selfEndpointTracker">Tracker for endpoints known to be self.</param>
        /// <param name="initialBlockDownloadState">Provider of IBD state.</param>
        /// <param name="connectionManagerSettings">Configuration related to incoming and outgoing connections.</param>
        public NetworkPeerFactory(Network network,
                                  IDateTimeProvider dateTimeProvider,
                                  ILoggerFactory loggerFactory,
                                  PayloadProvider payloadProvider,
                                  ISelfEndpointTracker selfEndpointTracker,
                                  IInitialBlockDownloadState initialBlockDownloadState,
                                  ConnectionManagerSettings connectionManagerSettings,
                                  IAsyncProvider asyncProvider,
                                  IPeerAddressManager peerAddressManager)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));

            this.network                   = network;
            this.dateTimeProvider          = dateTimeProvider;
            this.loggerFactory             = loggerFactory;
            this.payloadProvider           = payloadProvider;
            this.selfEndpointTracker       = selfEndpointTracker;
            this.lastClientId              = 0;
            this.initialBlockDownloadState = initialBlockDownloadState;
            this.connectionManagerSettings = connectionManagerSettings;
            this.asyncProvider             = Guard.NotNull(asyncProvider, nameof(asyncProvider));
            this.peerAddressManager        = peerAddressManager;
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Initializes an instance of the object.
        /// </summary>
        /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
        /// <param name="peer">Network peer the node is connected to, or will connect to.</param>
        /// <param name="client">Initialized TCP client, which may or may not be already connected.</param>
        /// <param name="clientId">Unique identifier of the connection.</param>
        /// <param name="processMessageAsync">Callback to be called when a new message arrives from the peer.</param>
        /// <param name="dateTimeProvider">Provider of time functions.</param>
        /// <param name="loggerFactory">Factory for creating loggers.</param>
        /// <param name="payloadProvider">A provider of network payload messages.</param>
        public NetworkPeerConnection(Network network, INetworkPeer peer, TcpClient client, int clientId,
                                     ProcessMessageAsync <IncomingMessage> processMessageAsync, IDateTimeProvider dateTimeProvider,
                                     ILoggerFactory loggerFactory, PayloadProvider payloadProvider, IAsyncProvider asyncProvider)
        {
            this.loggerFactory   = loggerFactory;
            this.payloadProvider = payloadProvider;
            this.asyncProvider   = Guard.NotNull(asyncProvider, nameof(asyncProvider));
            this.logger          = this.loggerFactory.CreateLogger(GetType().FullName, $"[{clientId}-{peer.PeerEndPoint}] ");

            this.network          = network;
            this.dateTimeProvider = dateTimeProvider;

            this.peer      = peer;
            this.tcpClient = client;
            this.Id        = clientId;

            this.stream = this.tcpClient.Connected ? this.tcpClient.GetStream() : null;

            this.writeLock = new AsyncLock();

            this.CancellationSource = new CancellationTokenSource();

            this.MessageProducer = new MessageProducer <IncomingMessage>();
            this.messageListener =
                new CallbackMessageListener <IncomingMessage>(asyncProvider, processMessageAsync, peer);
            this.messageProducerRegistration = this.MessageProducer.AddMessageListener(this.messageListener);
        }
        public LightWalletSyncManager(
            ILoggerFactory loggerFactory,
            IWalletManager walletManager,
            ChainIndexer chainIndexer,
            Network network,
            IBlockNotification blockNotification,
            ISignals signals,
            INodeLifetime nodeLifetime,
            IAsyncProvider asyncProvider,
            IConsensusManager consensusManager)
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(walletManager, nameof(walletManager));
            Guard.NotNull(chainIndexer, nameof(chainIndexer));
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(blockNotification, nameof(blockNotification));
            Guard.NotNull(signals, nameof(signals));
            Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            Guard.NotNull(asyncProvider, nameof(asyncProvider));
            Guard.NotNull(consensusManager, nameof(consensusManager));

            this.walletManager     = walletManager;
            this.chainIndexer      = chainIndexer;
            this.signals           = signals;
            this.blockNotification = blockNotification;
            this.logger            = loggerFactory.CreateLogger(this.GetType().FullName);
            this.nodeLifetime      = nodeLifetime;
            this.asyncProvider     = asyncProvider;
            this.consensusManager  = consensusManager;
        }
Exemplo n.º 8
0
        public TestPoAMiner(
            IConsensusManager consensusManager,
            IDateTimeProvider dateTimeProvider,
            Network network,
            INodeLifetime nodeLifetime,
            ILoggerFactory loggerFactory,
            IInitialBlockDownloadState ibdState,
            BlockDefinition blockDefinition,
            ISlotsManager slotsManager,
            IConnectionManager connectionManager,
            PoABlockHeaderValidator poaHeaderValidator,
            IFederationManager federationManager,
            IIntegrityValidator integrityValidator,
            IWalletManager walletManager,
            INodeStats nodeStats,
            VotingManager votingManager,
            PoASettings poAMinerSettings,
            IAsyncProvider asyncProvider,
            IIdleFederationMembersKicker idleFederationMembersKicker,
            NodeSettings nodeSettings)
            : base(consensusManager, dateTimeProvider, network, nodeLifetime, loggerFactory, ibdState, blockDefinition, slotsManager,
                   connectionManager, poaHeaderValidator, federationManager, integrityValidator, walletManager, nodeStats, votingManager, poAMinerSettings, asyncProvider, idleFederationMembersKicker, nodeSettings)
        {
            this.timeProvider = dateTimeProvider as EditableTimeProvider;

            this.cancellation = new CancellationTokenSource();
            this.slotsManager = slotsManager;
        }
 public FederationGatewayController(
     IAsyncProvider asyncProvider,
     ChainIndexer chainIndexer,
     IConnectionManager connectionManager,
     ICrossChainTransferStore crossChainTransferStore,
     IMaturedBlocksProvider maturedBlocksProvider,
     Network network,
     IFederatedPegSettings federatedPegSettings,
     IFederationWalletManager federationWalletManager,
     IFullNode fullNode,
     IPeerBanning peerBanning,
     IFederationManager federationManager = null)
 {
     this.asyncProvider           = asyncProvider;
     this.chainIndexer            = chainIndexer;
     this.connectionManager       = connectionManager;
     this.crossChainTransferStore = crossChainTransferStore;
     this.federatedPegSettings    = federatedPegSettings;
     this.federationWalletManager = federationWalletManager;
     this.federationManager       = federationManager;
     this.fullNode = fullNode;
     this.logger   = LogManager.GetCurrentClassLogger();
     this.maturedBlocksProvider = maturedBlocksProvider;
     this.network     = network;
     this.peerBanning = peerBanning;
 }
Exemplo n.º 10
0
        public SignedMultisigTransactionBroadcaster(
            IAsyncProvider asyncProvider,
            ILoggerFactory loggerFactory,
            ICrossChainTransferStore store,
            INodeLifetime nodeLifetime,
            MempoolManager mempoolManager,
            IBroadcasterManager broadcasterManager,
            IInitialBlockDownloadState ibdState,
            IFederationWalletManager federationWalletManager)
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(store, nameof(store));
            Guard.NotNull(mempoolManager, nameof(mempoolManager));
            Guard.NotNull(broadcasterManager, nameof(broadcasterManager));


            this.asyncProvider      = asyncProvider;
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
            this.store              = store;
            this.nodeLifetime       = nodeLifetime;
            this.mempoolManager     = mempoolManager;
            this.broadcasterManager = broadcasterManager;

            this.ibdState = ibdState;
            this.federationWalletManager = federationWalletManager;
        }
Exemplo n.º 11
0
        public InteropPoller(NodeSettings nodeSettings,
                             InteropSettings interopSettings,
                             IEthereumClientBase ethereumClientBase,
                             IAsyncProvider asyncProvider,
                             INodeLifetime nodeLifetime,
                             ChainIndexer chainIndexer,
                             IInitialBlockDownloadState initialBlockDownloadState,
                             IFederationManager federationManager,
                             IFederationHistory federationHistory,
                             IFederatedPegBroadcaster federatedPegBroadcaster,
                             IConversionRequestRepository conversionRequestRepository,
                             IInteropTransactionManager interopTransactionManager,
                             CounterChainNetworkWrapper counterChainNetworkWrapper)
        {
            this.interopSettings             = interopSettings;
            this.ethereumClientBase          = ethereumClientBase;
            this.network                     = nodeSettings.Network;
            this.asyncProvider               = asyncProvider;
            this.nodeLifetime                = nodeLifetime;
            this.chainIndexer                = chainIndexer;
            this.initialBlockDownloadState   = initialBlockDownloadState;
            this.federationManager           = federationManager;
            this.federationHistory           = federationHistory;
            this.federatedPegBroadcaster     = federatedPegBroadcaster;
            this.conversionRequestRepository = conversionRequestRepository;
            this.interopTransactionManager   = interopTransactionManager;
            this.counterChainNetwork         = counterChainNetworkWrapper.CounterChainNetwork;
            this.logger = nodeSettings.LoggerFactory.CreateLogger(this.GetType().FullName);

            this.firstPoll = true;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="xServerFeature"/> class with the xServers.
        /// </summary>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="dataFolders">The data folders of the system.</param>
        /// <param name="asyncProvider">The async loop factory.</param>
        /// <param name="nodeLifetime">The managment of the node process.</param>
        /// <param name="network">The network managment.</param>
        public xServerManager(
            ILoggerFactory loggerFactory,
            DataFolder dataFolders,
            IAsyncProvider asyncProvider,
            INodeLifetime nodeLifetime,
            xServerSettings xServerSettings,
            Network network)
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(dataFolders, nameof(dataFolders));
            Guard.NotNull(asyncProvider, nameof(asyncProvider));
            Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            Guard.NotNull(xServerSettings, nameof(xServerSettings));

            this.logger          = loggerFactory.CreateLogger(this.GetType().FullName);
            this.dataFolders     = dataFolders;
            this.asyncProvider   = asyncProvider;
            this.nodeLifetime    = nodeLifetime;
            this.xServerSettings = xServerSettings;
            this.network         = network;

            string path = Path.Combine(this.dataFolders.xServerAppsPath, xServerPeersFileName);

            this.xServerPeerList = new xServerPeers(path);

            this.xServerPeersLock = new object();
        }
Exemplo n.º 13
0
 /// <summary>
 /// Creates a new <see cref="IAsyncEnumerable{T}"/> which will use the given callback as implementation for <see cref="IAsyncEnumerable{T}.GetAsyncEnumerator"/> method.
 /// </summary>
 /// <typeparam name="T">The type of items being iterated.</typeparam>
 /// <param name="getEnumerator">The callback for <see cref="IAsyncEnumerable{T}.GetAsyncEnumerator"/> implementation.</param>
 /// <param name="asyncProvider">The <see cref="IAsyncProvider"/> to use.</param>
 /// <returns>A new instance of <see cref="IAsyncEnumerable{T}"/> with given parameters.</returns>
 /// <exception cref="ArgumentNullException">If either of <paramref name="getEnumerator"/> or <paramref name="asyncProvider"/> is <c>null</c>.</exception>
 public static IAsyncEnumerable <T> FromGeneratorCallback <T>(
     Func <IAsyncEnumerator <T> > getEnumerator,
     IAsyncProvider asyncProvider
     )
 {
     return(new AsyncEnumerableFunctionalWrapper <T>(asyncProvider, getEnumerator));
 }
Exemplo n.º 14
0
 /// <summary>
 /// This creates a <see cref="IAsyncEnumerable{T}"/> that will behave like the given set of delegates.
 /// Each enumeration is assumed to be stateless, meaning that the same set of delegates is shared by all instances returned by <see cref="IAsyncEnumerable{T}.GetAsyncEnumerator"/>.
 /// </summary>
 /// <typeparam name="T">The type of items being enumerated.</typeparam>
 /// <param name="startInfo">The <see cref="WrappingEnumerationStartInfo{T}"/> containing delegates that capture all signatures of all methods of <see cref="IAsyncEnumerator{T}"/> interface.</param>
 /// <returns>A new <see cref="IAsyncEnumerable{T}"/>, which will share the given delegates by all instances returned by <see cref="IAsyncEnumerable{T}.GetAsyncEnumerator"/>.</returns>
 /// <param name="asyncProvider">The <see cref="IAsyncProvider"/> for the returned <see cref="IAsyncEnumerable{T}"/>.</param>
 /// <exception cref="ArgumentNullException">If either of <see cref="WrappingEnumerationStartInfo{T}.WaitForNext"/> or <see cref="WrappingEnumerationStartInfo{T}.TryGetNext"/> delegates of <paramref name="startInfo"/> are <c>null</c>.</exception>
 /// <seealso cref="WrappingEnumerationStartInfo{T}"/>
 /// <seealso cref="CreateWrappingStartInfo"/>
 public static IAsyncEnumerable <T> CreateStatelessWrappingEnumerable <T>(
     WrappingEnumerationStartInfo <T> startInfo,
     IAsyncProvider asyncProvider
     )
 {
     return(new StatelessAsyncEnumerableWrapper <T>(startInfo, asyncProvider));
 }
Exemplo n.º 15
0
        public PartialTransactionRequester(
            ILoggerFactory loggerFactory,
            ICrossChainTransferStore crossChainTransferStore,
            IAsyncProvider asyncProvider,
            INodeLifetime nodeLifetime,
            IConnectionManager connectionManager,
            IFederatedPegSettings federatedPegSettings,
            IInitialBlockDownloadState ibdState,
            IFederationWalletManager federationWalletManager)
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(crossChainTransferStore, nameof(crossChainTransferStore));
            Guard.NotNull(asyncProvider, nameof(asyncProvider));
            Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            Guard.NotNull(federatedPegSettings, nameof(federatedPegSettings));

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
            this.crossChainTransferStore = crossChainTransferStore;
            this.asyncProvider           = asyncProvider;
            this.nodeLifetime            = nodeLifetime;
            this.connectionManager       = connectionManager;
            this.federatedPegSettings    = federatedPegSettings;
            this.ibdState = ibdState;
            this.federationWalletManager = federationWalletManager;
        }
        protected ConsensusRuleUnitTestBase(Network network)
        {
            this.network = network;

            this.logger        = new Mock <ILogger>();
            this.loggerFactory = new Mock <ILoggerFactory>();
            this.loggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(new Mock <ILogger>().Object);
            this.dateTimeProvider = new Mock <IDateTimeProvider>();

            this.chainState        = new Mock <IChainState>();
            this.checkpoints       = new Mock <ICheckpoints>();
            this.ChainIndexer      = new ChainIndexer(this.network);
            this.consensusSettings = new ConsensusSettings(NodeSettings.Default(this.network));
            this.nodeDeployments   = new NodeDeployments(this.network, this.ChainIndexer);

            this.rules            = new List <IConsensusRuleBase>();
            this.ruleRegistration = new Mock <IRuleRegistration>();

            if (network.Consensus.IsProofOfStake)
            {
                this.ruleContext = new PosRuleContext(new ValidationContext(), this.dateTimeProvider.Object.GetTimeOffset());
            }
            else
            {
                this.ruleContext = new PowRuleContext(new ValidationContext(), this.dateTimeProvider.Object.GetTimeOffset());
            }

            this.asyncProvider = new AsyncProvider(this.loggerFactory.Object, new Mock <ISignals>().Object, new NodeLifetime());
        }
Exemplo n.º 17
0
        public BaseFeature(NodeSettings nodeSettings,
                           DataFolder dataFolder,
                           INodeLifetime nodeLifetime,
                           ChainIndexer chainIndexer,
                           IChainState chainState,
                           IConnectionManager connectionManager,
                           IChainRepository chainRepository,
                           IFinalizedBlockInfoRepository finalizedBlockInfo,
                           IDateTimeProvider dateTimeProvider,
                           IAsyncProvider asyncProvider,
                           ITimeSyncBehaviorState timeSyncBehaviorState,
                           ILoggerFactory loggerFactory,
                           IInitialBlockDownloadState initialBlockDownloadState,
                           IPeerBanning peerBanning,
                           IPeerAddressManager peerAddressManager,
                           IConsensusManager consensusManager,
                           IConsensusRuleEngine consensusRules,
                           IPartialValidator partialValidator,
                           IBlockPuller blockPuller,
                           IBlockStore blockStore,
                           Network network,
                           ITipsManager tipsManager,
                           NodeDeployments nodeDeployments,
                           IKeyValueRepository keyValueRepo,
                           INodeStats nodeStats,
                           IBroadcasterManager broadcasterManager,
                           IProvenBlockHeaderStore provenBlockHeaderStore = null)
        {
            this.chainState      = Guard.NotNull(chainState, nameof(chainState));
            this.chainRepository = Guard.NotNull(chainRepository, nameof(chainRepository));
            this.finalizedBlockInfoRepository = Guard.NotNull(finalizedBlockInfo, nameof(finalizedBlockInfo));
            this.nodeSettings           = Guard.NotNull(nodeSettings, nameof(nodeSettings));
            this.dataFolder             = Guard.NotNull(dataFolder, nameof(dataFolder));
            this.nodeLifetime           = Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            this.chainIndexer           = Guard.NotNull(chainIndexer, nameof(chainIndexer));
            this.connectionManager      = Guard.NotNull(connectionManager, nameof(connectionManager));
            this.consensusManager       = consensusManager;
            this.consensusRules         = consensusRules;
            this.blockPuller            = blockPuller;
            this.blockStore             = blockStore;
            this.network                = network;
            this.nodeStats              = nodeStats;
            this.broadcasterManager     = broadcasterManager;
            this.provenBlockHeaderStore = provenBlockHeaderStore;
            this.partialValidator       = partialValidator;
            this.peerBanning            = Guard.NotNull(peerBanning, nameof(peerBanning));
            this.tipsManager            = Guard.NotNull(tipsManager, nameof(tipsManager));
            this.keyValueRepo           = Guard.NotNull(keyValueRepo, nameof(keyValueRepo));
            this.nodeDeployments        = nodeDeployments;

            this.peerAddressManager = Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            this.peerAddressManager.PeerFilePath = this.dataFolder;

            this.initialBlockDownloadState = initialBlockDownloadState;
            this.dateTimeProvider          = dateTimeProvider;
            this.asyncProvider             = asyncProvider;
            this.timeSyncBehaviorState     = timeSyncBehaviorState;
            this.loggerFactory             = loggerFactory;
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
        }
        public WalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ChainIndexer chainIndexer,
                                 Network network, IBlockStore blockStore, StoreSettings storeSettings, ISignals signals, IAsyncProvider asyncProvider, INodeLifetime nodeLifetime,
                                 MempoolManager mempoolManager = null)
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(walletManager, nameof(walletManager));
            Guard.NotNull(chainIndexer, nameof(chainIndexer));
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(blockStore, nameof(blockStore));
            Guard.NotNull(storeSettings, nameof(storeSettings));
            Guard.NotNull(signals, nameof(signals));
            Guard.NotNull(asyncProvider, nameof(asyncProvider));
            Guard.NotNull(nodeLifetime, nameof(nodeLifetime));

            this.mempoolManager        = mempoolManager;
            this.walletManager         = walletManager;
            this.chainIndexer          = chainIndexer;
            this.blockStore            = blockStore;
            this.storeSettings         = storeSettings;
            this.signals               = signals;
            this.asyncProvider         = asyncProvider;
            this.logger                = loggerFactory.CreateLogger(this.GetType().FullName);
            this.nodeLifetime          = nodeLifetime;
            this.syncCancellationToken = CancellationTokenSource.CreateLinkedTokenSource(this.nodeLifetime.ApplicationStopping);
            this.lockObject            = new object();
        }
Exemplo n.º 19
0
        /// <summary>Constructor for dependency injection.</summary>
        protected PeerConnector(
            IAsyncProvider asyncProvider,
            IDateTimeProvider dateTimeProvider,
            ILoggerFactory loggerFactory,
            Network network,
            INetworkPeerFactory networkPeerFactory,
            INodeLifetime nodeLifetime,
            NodeSettings nodeSettings,
            ConnectionManagerSettings connectionSettings,
            IPeerAddressManager peerAddressManager,
            ISelfEndpointTracker selfEndpointTracker)
        {
            this.asyncProvider       = asyncProvider;
            this.ConnectorPeers      = new NetworkPeerCollection();
            this.dateTimeProvider    = dateTimeProvider;
            this.loggerFactory       = loggerFactory;
            this.logger              = loggerFactory.CreateLogger(this.GetType().FullName);
            this.network             = network;
            this.networkPeerFactory  = networkPeerFactory;
            this.NodeLifetime        = nodeLifetime;
            this.ConnectionSettings  = connectionSettings;
            this.PeerAddressManager  = peerAddressManager;
            this.networkPeerDisposer = new NetworkPeerDisposer(this.loggerFactory, this.asyncProvider, this.OnPeerDisposed);
            this.selfEndpointTracker = selfEndpointTracker;
            this.Requirements        = new NetworkPeerRequirement {
                MinVersion = nodeSettings.MinProtocolVersion ?? nodeSettings.ProtocolVersion
            };

            this.connectionInterval = this.CalculateConnectionInterval();
        }
Exemplo n.º 20
0
        public MaturedBlocksSyncManager(
            IAsyncProvider asyncProvider,
            ICrossChainTransferStore crossChainTransferStore,
            IFederationGatewayClient federationGatewayClient,
            IFederationWalletManager federationWalletManager,
            IInitialBlockDownloadState initialBlockDownloadState,
            INodeLifetime nodeLifetime,
            IConversionRequestRepository conversionRequestRepository,
            ChainIndexer chainIndexer,
            Network network,
            IFederatedPegSettings federatedPegSettings,
            IFederationManager federationManager = null,
            IExternalApiPoller externalApiPoller = null,
            IConversionRequestFeeService conversionRequestFeeService = null)
        {
            this.asyncProvider = asyncProvider;
            this.chainIndexer  = chainIndexer;
            this.conversionRequestRepository = conversionRequestRepository;
            this.crossChainTransferStore     = crossChainTransferStore;
            this.federationGatewayClient     = federationGatewayClient;
            this.federatedPegSettings        = federatedPegSettings;
            this.federationWalletManager     = federationWalletManager;
            this.initialBlockDownloadState   = initialBlockDownloadState;
            this.nodeLifetime = nodeLifetime;
            this.conversionRequestRepository = conversionRequestRepository;
            this.chainIndexer                = chainIndexer;
            this.externalApiPoller           = externalApiPoller;
            this.conversionRequestFeeService = conversionRequestFeeService;
            this.network           = network;
            this.federationManager = federationManager;

            this.logger = LogManager.GetCurrentClassLogger();
        }
        public LightWalletFeature(
            IWalletSyncManager walletSyncManager,
            IWalletManager walletManager,
            IConnectionManager connectionManager,
            ChainIndexer chainIndexer,
            NodeDeployments nodeDeployments,
            IAsyncProvider asyncProvider,
            INodeLifetime nodeLifetime,
            IWalletFeePolicy walletFeePolicy,
            BroadcasterBehavior broadcasterBehavior,
            ILoggerFactory loggerFactory,
            StoreSettings storeSettings,
            WalletSettings walletSettings,
            INodeStats nodeStats,
            IPruneBlockStoreService lightWalletBlockStoreService)
        {
            this.walletSyncManager   = walletSyncManager;
            this.walletManager       = walletManager;
            this.connectionManager   = connectionManager;
            this.chainIndexer        = chainIndexer;
            this.nodeDeployments     = nodeDeployments;
            this.asyncProvider       = asyncProvider;
            this.nodeLifetime        = nodeLifetime;
            this.walletFeePolicy     = walletFeePolicy;
            this.broadcasterBehavior = broadcasterBehavior;
            this.logger         = loggerFactory.CreateLogger(this.GetType().FullName);
            this.loggerFactory  = loggerFactory;
            this.storeSettings  = storeSettings;
            this.walletSettings = walletSettings;

            this.lightWalletBlockStoreService = lightWalletBlockStoreService;

            nodeStats.RegisterStats(this.AddInlineStats, StatsType.Inline, this.GetType().Name);
            nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, this.GetType().Name);
        }
Exemplo n.º 22
0
        public AddressIndexer(StoreSettings storeSettings, DataFolder dataFolder, ILoggerFactory loggerFactory, Network network, INodeStats nodeStats,
                              IConsensusManager consensusManager, IAsyncProvider asyncProvider, ChainIndexer chainIndexer, IDateTimeProvider dateTimeProvider)
        {
            this.storeSettings       = storeSettings;
            this.network             = network;
            this.nodeStats           = nodeStats;
            this.dataFolder          = dataFolder;
            this.consensusManager    = consensusManager;
            this.asyncProvider       = asyncProvider;
            this.dateTimeProvider    = dateTimeProvider;
            this.loggerFactory       = loggerFactory;
            this.scriptAddressReader = new ScriptAddressReader();

            this.lockObject           = new object();
            this.flushChangesInterval = TimeSpan.FromMinutes(2);
            this.lastFlushTime        = this.dateTimeProvider.GetUtcNow();
            this.cancellation         = new CancellationTokenSource();
            this.chainIndexer         = chainIndexer;
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

            this.averageTimePerBlock = new AverageCalculator(200);
            int maxReorgLength = GetMaxReorgOrFallbackMaxReorg(this.network);

            this.compactionTriggerDistance = maxReorgLength * 2 + SyncBuffer + 1000;
        }
Exemplo n.º 23
0
        public InteropPoller(NodeSettings nodeSettings, InteropSettings interopSettings, IAsyncProvider asyncProvider, INodeLifetime nodeLifetime,
                             ChainIndexer chainIndexer, IInitialBlockDownloadState initialBlockDownloadState, IFederationManager federationManager, IFederationHistory federationHistory,
                             IFederatedPegBroadcaster federatedPegBroadcaster, IConversionRequestRepository conversionRequestRepository, IInteropTransactionManager interopTransactionManager,
                             CounterChainNetworkWrapper counterChainNetworkWrapper, IETHCompatibleClientProvider clientProvider)
        {
            this.interopSettings             = interopSettings;
            this.clientProvider              = clientProvider;
            this.network                     = nodeSettings.Network;
            this.asyncProvider               = asyncProvider;
            this.nodeLifetime                = nodeLifetime;
            this.chainIndexer                = chainIndexer;
            this.initialBlockDownloadState   = initialBlockDownloadState;
            this.federationManager           = federationManager;
            this.federationHistory           = federationHistory;
            this.federatedPegBroadcaster     = federatedPegBroadcaster;
            this.conversionRequestRepository = conversionRequestRepository;
            this.interopTransactionManager   = interopTransactionManager;
            this.counterChainNetwork         = counterChainNetworkWrapper.CounterChainNetwork;
            this.logger = nodeSettings.LoggerFactory.CreateLogger(this.GetType().FullName);

            this.eventFilterCreationRequired = new Dictionary <DestinationChain, bool>()
            {
                { DestinationChain.ETH, true }
            };
        }
Exemplo n.º 24
0
        /// <summary>
        /// Constructs the cold staking manager which is used by the cold staking controller.
        /// </summary>
        /// <param name="network">The network that the manager is running on.</param>
        /// <param name="chainIndexer">Thread safe class representing a chain of headers from genesis.</param>
        /// <param name="walletSettings">The wallet settings.</param>
        /// <param name="dataFolder">Contains path locations to folders and files on disk.</param>
        /// <param name="walletFeePolicy">The wallet fee policy.</param>
        /// <param name="asyncProvider">Factory for creating and also possibly starting application defined tasks inside async loop.</param>
        /// <param name="nodeLifeTime">Allows consumers to perform cleanup during a graceful shutdown.</param>
        /// <param name="scriptAddressReader">A reader for extracting an address from a <see cref="Script"/>.</param>
        /// <param name="loggerFactory">The logger factory to use to create the custom logger.</param>
        /// <param name="dateTimeProvider">Provider of time functions.</param>
        /// <param name="broadcasterManager">The broadcaster manager.</param>
        public ColdStakingManager(
            Network network,
            ChainIndexer chainIndexer,
            WalletSettings walletSettings,
            DataFolder dataFolder,
            IWalletFeePolicy walletFeePolicy,
            IAsyncProvider asyncProvider,
            INodeLifetime nodeLifeTime,
            IScriptAddressReader scriptAddressReader,
            ILoggerFactory loggerFactory,
            IDateTimeProvider dateTimeProvider,
            IWalletRepository walletRepository,
            IBroadcasterManager broadcasterManager = null) : base(
                loggerFactory,
                network,
                chainIndexer,
                walletSettings,
                dataFolder,
                walletFeePolicy,
                asyncProvider,
                nodeLifeTime,
                dateTimeProvider,
                scriptAddressReader,
                walletRepository,
                broadcasterManager
                )
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider));

            this.logger           = loggerFactory.CreateLogger(this.GetType().FullName);
            this.dateTimeProvider = dateTimeProvider;
        }
Exemplo n.º 25
0
 public PowMining(
     IAsyncProvider asyncProvider,
     IBlockProvider blockProvider,
     IConsensusManager consensusManager,
     ChainIndexer chainIndexer,
     IDateTimeProvider dateTimeProvider,
     ITxMempool mempool,
     MempoolSchedulerLock mempoolLock,
     Network network,
     INodeLifetime nodeLifetime,
     ILoggerFactory loggerFactory,
     IInitialBlockDownloadState initialBlockDownloadState)
 {
     this.asyncProvider             = asyncProvider;
     this.blockProvider             = blockProvider;
     this.chainIndexer              = chainIndexer;
     this.consensusManager          = consensusManager;
     this.dateTimeProvider          = dateTimeProvider;
     this.loggerFactory             = loggerFactory;
     this.initialBlockDownloadState = initialBlockDownloadState;
     this.logger       = loggerFactory.CreateLogger(this.GetType().FullName);
     this.mempool      = mempool;
     this.mempoolLock  = mempoolLock;
     this.network      = network;
     this.nodeLifetime = nodeLifetime;
     this.miningCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(new[] { this.nodeLifetime.ApplicationStopping });
 }
Exemplo n.º 26
0
 /// <summary>
 /// This creates a <see cref="IAsyncEnumerable{T}"/> that will behave like the given set of delegates.
 /// Each enumeration is assumed to have inner state, meaning that the call to create delegates is done on every call to <see cref="IAsyncEnumerable{T}.GetAsyncEnumerator"/>.
 /// </summary>
 /// <typeparam name="T">The type of items being enumerated.</typeparam>
 /// <param name="startInfoFactory">The callback creating a structure containing all the delegates that the calls to methods of <see cref="IAsyncEnumerator{T}"/> will be call-through to.</param>
 /// <param name="asyncProvider">The <see cref="IAsyncProvider"/> for the returned <see cref="IAsyncEnumerable{T}"/>.</param>
 /// <returns>A new <see cref="IAsyncEnumerable{T}"/>, which will call the given <paramref name="startInfoFactory"/> on each call to <see cref="IAsyncEnumerable{T}.GetAsyncEnumerator"/>, and the resulting <see cref="IAsyncEnumerator{T}"/> will pass each invocation of its methods the set of delegates returned by <paramref name="startInfoFactory"/>.</returns>
 /// <exception cref="ArgumentNullException">If <paramref name="startInfoFactory"/> is <c>null</c>.</exception>
 /// <seealso cref="WrappingEnumerationStartInfo{T}"/>
 /// <seealso cref="CreateWrappingStartInfo"/>
 public static IAsyncEnumerable <T> CreateStatefulWrappingEnumerable <T>(
     Func <WrappingEnumerationStartInfo <T> > startInfoFactory,
     IAsyncProvider asyncProvider
     )
 {
     return(new StatefulAsyncEnumerableWrapper <T>(startInfoFactory, asyncProvider));
 }
        /// <summary>
        /// Initializes the cross-chain transfer tests.
        /// </summary>
        /// <param name="network">The network to run the tests for.</param>
        public CrossChainTestBase(Network network = null, Network counterChainNetwork = null)
        {
            this.network             = network ?? FederatedPegNetwork.NetworksSelector.Regtest();
            this.counterChainNetwork = counterChainNetwork ?? Networks.Stratis.Regtest();
            this.federatedPegOptions = new FederatedPegOptions(counterChainNetwork);

            NetworkRegistration.Register(this.network);

            this.loggerFactory = Substitute.For <ILoggerFactory>();
            this.nodeLifetime  = new NodeLifetime();
            this.logger        = Substitute.For <ILogger>();
            this.signals       = Substitute.For <ISignals>();
            this.asyncProvider = new AsyncProvider(this.loggerFactory, this.signals, this.nodeLifetime);
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.dateTimeProvider                   = DateTimeProvider.Default;
            this.opReturnDataReader                 = new OpReturnDataReader(this.loggerFactory, this.federatedPegOptions);
            this.blockRepository                    = Substitute.For <IBlockRepository>();
            this.fullNode                           = Substitute.For <IFullNode>();
            this.withdrawalTransactionBuilder       = Substitute.For <IWithdrawalTransactionBuilder>();
            this.federationWalletManager            = Substitute.For <IFederationWalletManager>();
            this.federationWalletSyncManager        = Substitute.For <IFederationWalletSyncManager>();
            this.FederationWalletTransactionHandler = Substitute.For <IFederationWalletTransactionHandler>();
            this.walletFeePolicy                    = Substitute.For <IWalletFeePolicy>();
            this.connectionManager                  = Substitute.For <IConnectionManager>();
            this.dBreezeSerializer                  = new DBreezeSerializer(this.network.Consensus.ConsensusFactory);
            this.ibdState                           = Substitute.For <IInitialBlockDownloadState>();
            this.wallet = null;
            this.federationGatewaySettings = Substitute.For <IFederationGatewaySettings>();
            this.ChainIndexer = new ChainIndexer(this.network);

            this.federationGatewaySettings.TransactionFee.Returns(new Money(0.01m, MoneyUnit.BTC));

            // Generate the keys used by the federation members for our tests.
            this.federationKeys = new[]
            {
                "ensure feel swift crucial bridge charge cloud tell hobby twenty people mandate",
                "quiz sunset vote alley draw turkey hill scrap lumber game differ fiction",
                "exchange rent bronze pole post hurry oppose drama eternal voice client state"
            }.Select(m => HdOperations.GetExtendedKey(m)).ToArray();

            SetExtendedKey(0);

            this.fundingTransactions = new List <Transaction>();

            this.blockDict = new Dictionary <uint256, Block>();
            this.blockDict[this.network.GenesisHash] = this.network.GetGenesis();

            this.blockRepository.GetBlocks(Arg.Any <List <uint256> >()).ReturnsForAnyArgs((x) =>
            {
                var hashes = x.ArgAt <List <uint256> >(0);
                var blocks = new List <Block>();
                for (int i = 0; i < hashes.Count; i++)
                {
                    blocks.Add(this.blockDict.TryGetValue(hashes[i], out Block block) ? block : null);
                }

                return(blocks);
            });
        }
        /// <summary>
        ///     Initializes the instance of the object.
        /// </summary>
        /// <param name="processMessageAsync">
        ///     User defined callback routine to be executed when a new message arrives to the
        ///     listener.
        /// </param>
        public CallbackMessageListener(IAsyncProvider asyncProvider, ProcessMessageAsync <T> processMessageAsync,
                                       INetworkPeer peer)
        {
            var queuerName = $"{nameof(CallbackMessageListener<T>)}-{typeof(T).Name}-{peer.PeerEndPoint}";

            this.asyncQueue = asyncProvider.CreateAndRunAsyncDelegateDequeuer(queuerName,
                                                                              new Func <T, CancellationToken, Task>(processMessageAsync));
        }
Exemplo n.º 29
0
        public PartialValidator(IAsyncProvider asyncProvider, IConsensusRuleEngine consensusRules, ILoggerFactory loggerFactory)
        {
            this.asyncProvider  = Guard.NotNull(asyncProvider, nameof(asyncProvider));
            this.consensusRules = consensusRules;
            this.logger         = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode");

            this.asyncQueue = asyncProvider.CreateAndRunAsyncDelegateDequeuer <PartialValidationItem>(this.GetType().Name, this.OnEnqueueAsync);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Initializes the instance of the object and subscribes to the peer's message producer.
        /// </summary>
        /// <param name="peer">Connected network peer that we receive messages from.</param>
        public NetworkPeerListener(INetworkPeer peer, IAsyncProvider asyncProvider)
        {
            this.peer          = peer;
            this.asyncProvider = asyncProvider;
            this.asyncIncomingMessagesQueue = asyncProvider.CreateAsyncQueue <IncomingMessage>();

            this.messageProducerRegistration = peer.MessageProducer.AddMessageListener(this);
        }