-
Notifications
You must be signed in to change notification settings - Fork 311
NodeBuilder: AddRPC() requires UseWallet() #285
Comments
Is this a dependency we require or should we load WalletRPCController conditionally depending upon whether UseWallet() was included? |
For now a quick fix is to allow wallet to be null however a better fix is to separate the controllers in to their features (like with api). |
This is the actual exception being thrown:
The exception is thrown when copying the node services to the RPC services in this line
|
If a node service is missing a dependency don't add it to RPC services. Fix for stratisproject#285
If node service is missing dependencies then skip adding that service to RPC. Fix for stratisproject#285
Unfortunately I cant seem to reproduce this bug.
|
If you startup the node like this you will encounter the error: var node = new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
.UseStratisConsensus()
.UseBlockStore()
.UseMempool()
.AddPowPosMining()
.AddRPC()
.Build(); Maybe I should create a unit test for it? |
As discussed the solution is to probably check feature dependencies at Feature level.
Then each feature can verify its dependencies (by feature) |
Execute() does both starting and stopping the service and the validation is only relevant to starting. Propose we do this instead:
public void Start()
{
try
{
IFeatureCollection featureCollection = this.FullNodeBuilder.Features;
this.Execute(service => service.ValidateDependencies(this.node.Services.ServiceProvider, featureCollection));
this.Execute(service => service.Start());
}
catch (Exception ex)
{
this.logger.LogError("An error occurred starting the application", ex);
throw;
}
}
public virtual void ValidateDependencies(IServiceProvider services, IFeatureCollection features)
{
Guard.NotNull<IFeatureCollection>(features, nameof(features));
var featureRegistration = features.FeatureRegistrations.FirstOrDefault(i => i.FeatureType == this.GetType());
DependencyEnumerator dependencyEnumerator = new DependencyEnumerator();
featureRegistration.ConfigureServicesDelegates.ForEach(i => i.Invoke(dependencyEnumerator));
foreach (var dependencyType in dependencyEnumerator.dependencies)
{
services.GetService(dependencyType);
}
} Thoughts? |
The above somewhat works but have one problem I haven't been able to figure out. IFullNodeBuilder is not registered in DI unless RPC is added. So I can't get to IFullNodeBuilder from FullNodeFeatureExecutor. Any ideas? |
I don't think we need to iterate over services, just let each feature validate its dependencies.
This could even be an extension
|
Yes I guess doing it via trying to resolve all the dependent services is probably a bit of overkill. Dependencies between features is likely more the exception than the rule. I'm sure in general the features are designed to be as standalone as possible. I will look at implementing your solution. |
I had problems getting access to the FullNodeBuilder.Features from within the FullNodeExecutor so instead I invoke the validation logic at the end of FullNodeBuilder.Build(). This seems to work but I have a couple of unit tests that now break. This test below breaks because not all the dependent services are available for the BlockStoreFeature (specifically NBitcoin.ConcurrentChain). Should this be refactored to take in mock feature instead of a real feature? Or is this purpose of the test testing that the default configuration can build a node with BlockStoreFeature? StratisBitcoinFullNode/Stratis.Bitcoin.Tests/Builder/FullNodeBuilderTest.cs Lines 137 to 164 in d136fb4
|
Doesn't this work?
|
Add a hook for a dependency check when running node feature executor. Throw exception if a feature's dependency is missing. Fix for stratisproject#285
Think I finally have a reasonable solution to this. I'll make a PR if you want to take a look. Thanks for all the help! |
PR has been merged into master |
* Differentiate between different node types and ensure premine can be received by integration tests * Tests much easier to work with * Minor amendments * Remove unused method * Add the correct nodes for a federation gateway
[Channels] Move Channel Start logic to Service
If you don't include UseWallet() then the Stratis node crashes on startup. Crash is due to a dependency on WalletManager (which isn't there if you don't include UseWallet())
The text was updated successfully, but these errors were encountered: