Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
Moved the dependency on the FullNode out of the MemPool Feature
Browse files Browse the repository at this point in the history
(MempoolFeature fix args) in the GitHub project
  • Loading branch information
bokobza committed Mar 15, 2017
1 parent 5439af2 commit 93b8fa9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
13 changes: 11 additions & 2 deletions Stratis.Bitcoin/Builder/FullNodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public FullNodeBuilder()
public NodeArgs NodeArgs { get; set; }
public Network Network { get; set; }

/// <summary>
/// Adds services to the builder.
/// </summary>
/// <param name="configureServices">A method that adds services to the builder</param>
/// <returns>An IFullNodebuilder</returns>
public IFullNodeBuilder ConfigureServices(Action<IServiceCollection> configureServices)
{
Guard.NotNull(configureServices, nameof(configureServices));
Expand All @@ -70,15 +75,19 @@ public IFullNodeBuilder ConfigureServices(Action<IServiceCollection> configureSe
return this;
}

/// <summary>
/// Adds features to the builder.
/// </summary>
/// <param name="configureFeatures">A method that adds features to the collection</param>
/// <returns>An IFullNodebuilder</returns>
public IFullNodeBuilder ConfigureFeature(Action<FeatureCollection> configureFeatures)
{
Guard.NotNull(configureFeatures, nameof(configureFeatures));

featuresRegistrationDelegates.Add(configureFeatures);
return this;
}



public IFullNodeBuilder Configure(Action<IServiceProvider> configure)
{
if (configure == null)
Expand Down
1 change: 1 addition & 0 deletions Stratis.Bitcoin/Builder/FullNodeBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static IFullNodeBuilder AddRequired(this IFullNodeBuilder builder)
service.AddSingleton(consensusValidator);
service.AddSingleton<DBreezeCoinView>(coinviewdb);
service.AddSingleton<CoinView>(coinView);
service.AddSingleton<Signals>();

// TODO: move to ConnectionManagerFeature
var connectionManager = new ConnectionManager(nodeBuilder.Network, new NodeConnectionParameters(),
Expand Down
10 changes: 5 additions & 5 deletions Stratis.Bitcoin/FullNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public FullNode Initialize(FullNodeServiceProvider serviceProvider)
this.CoinView = this.Services.ServiceProvider.GetService<CoinView>();
this.Chain = this.Services.ServiceProvider.GetService<ConcurrentChain>();
this.GlobalCancellation = this.Services.ServiceProvider.GetService<CancellationProvider>();

this.MempoolManager = this.Services.ServiceProvider.GetService<MempoolManager>();
this.Signals = this.Services.ServiceProvider.GetService<Signals>();
return this;
}

Expand Down Expand Up @@ -145,9 +146,7 @@ public void Start()
_Resources.Add(RPCHost);
Logs.RPC.LogInformation("RPC Server listening on: " + Environment.NewLine + String.Join(Environment.NewLine, _Args.RPC.GetUrls()));
}

this.Signals = new Signals();


if(AddressManager.Count == 0)
Logs.FullNode.LogInformation("AddressManager is empty, discovering peers...");

Expand All @@ -161,7 +160,7 @@ public void Start()
var blockPuller = new NodesBlockPuller(Chain, ConnectionManager.ConnectedNodes);
connectionParameters.TemplateBehaviors.Add(new NodesBlockPuller.NodesBlockPullerBehavior(blockPuller));

// === BlockSgtore ===
// === BlockStore ===
var blockRepository = new BlockRepository(this.Network, DataFolder.BlockPath);
var blockStoreCache = new BlockStoreCache(blockRepository);
_Resources.Add(blockStoreCache);
Expand Down Expand Up @@ -189,6 +188,7 @@ public void Start()
// add disposables (TODO: move this to the consensus feature)
this.Resources.Add(this.Services.ServiceProvider.GetService<DBreezeCoinView>());

// start all the features defined
this.StartFeatures();

_ChainBehaviorState.HighestValidatedPoW = ConsensusLoop.Tip;
Expand Down
23 changes: 12 additions & 11 deletions Stratis.Bitcoin/MemoryPool/MempoolFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
using NBitcoin;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Builder.Feature;
using Stratis.Bitcoin.Connection;

namespace Stratis.Bitcoin.MemoryPool
{
public class MempoolFeature : FullNodeFeature
{
private readonly FullNode fullNode;
private readonly MempoolManager manager;
private readonly Signals signals;
private readonly ConnectionManager connectionManager;
private readonly MempoolSignaled mempoolSignaled;
private readonly MempoolBehavior mempoolBehavior;

public MempoolFeature(FullNode fullNode, MempoolManager manager)
public MempoolFeature(ConnectionManager connectionManager, Signals signals, MempoolSignaled mempoolSignaled, MempoolBehavior mempoolBehavior)
{
this.fullNode = fullNode;
this.manager = manager;
this.signals = signals;
this.connectionManager = connectionManager;
this.mempoolSignaled = mempoolSignaled;
this.mempoolBehavior = mempoolBehavior;
}

public override void Start()
{
// TODO: move service resolver types to the constructor
this.fullNode.ConnectionManager.Parameters.TemplateBehaviors.Add(this.fullNode.Services.ServiceProvider.GetService<MempoolBehavior>());
this.fullNode.Signals.Blocks.Subscribe(this.fullNode.Services.ServiceProvider.GetService<MempoolSignaled>());

this.fullNode.MempoolManager = this.manager;
this.connectionManager.Parameters.TemplateBehaviors.Add(this.mempoolBehavior);
this.signals.Blocks.Subscribe(this.mempoolSignaled);
}
}

Expand All @@ -44,7 +46,6 @@ public static IFullNodeBuilder UseMempool(this IFullNodeBuilder fullNodeBuilder)
services.AddSingleton<MempoolManager>();
services.AddSingleton<MempoolBehavior>();
services.AddSingleton<MempoolSignaled>();

});
});

Expand Down
12 changes: 6 additions & 6 deletions Stratis.Bitcoin/MemoryPool/MempoolSignaled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Stratis.Bitcoin.MemoryPool
{
public class MempoolSignaled : SignalObserver<Block>
public class MempoolSignaled : SignalObserver<Block>
{
private readonly MempoolManager manager;
private readonly ConcurrentChain chain;
Expand All @@ -35,7 +35,7 @@ protected override void OnNextCore(Block value)

private void RelayWorker(CancellationToken cancellationToken)
{
AsyncLoop.Run("MemoryPool.RelayWorker", async token =>
AsyncLoop.Run("MemoryPool.RelayWorker", async token =>
{
var nodes = this.connection.ConnectedNodes;
if (!nodes.Any())
Expand All @@ -45,10 +45,10 @@ private void RelayWorker(CancellationToken cancellationToken)
var behaviours = nodes.Select(s => s.Behavior<MempoolBehavior>());
foreach (var behaviour in behaviours)
await behaviour.SendTrickle().ConfigureAwait(false);
},
cancellationToken,
repeatEvery: TimeSpans.TenSeconds,
startAfter: TimeSpans.TenSeconds);
},
cancellationToken,
repeatEvery: TimeSpans.TenSeconds,
startAfter: TimeSpans.TenSeconds);
}
}
}

0 comments on commit 93b8fa9

Please sign in to comment.