Commit be13ebf8 authored by Dan Gershony's avatar Dan Gershony

NodeLifetime in Breeze

parent 6af1ba3b
......@@ -57,7 +57,7 @@ namespace Breeze.Api
return Task.CompletedTask;
},
this.fullNode.GlobalCancellation.Cancellation.Token,
this.fullNode.NodeLifetime.ApplicationStopping,
repeatEvery: this.apiFeatureOptions.KeepaliveMonitor?.KeepaliveInterval,
startAfter: TimeSpans.Minute);
}
......
......@@ -13,6 +13,7 @@ using Stratis.Bitcoin.Consensus.Deployments;
using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Controllers;
using Stratis.Bitcoin.Common.Hosting;
namespace Breeze.Wallet
{
......@@ -24,10 +25,10 @@ namespace Breeze.Wallet
private readonly ConcurrentChain chain;
private readonly NodeDeployments nodeDeployments;
private readonly IAsyncLoopFactory asyncLoopFactory;
private readonly FullNode.CancellationProvider cancellationProvider;
private readonly INodeLifetime nodeLifetime;
public LightWalletFeature(IWalletSyncManager walletSyncManager, IWalletManager walletManager, IConnectionManager connectionManager,
ConcurrentChain chain, NodeDeployments nodeDeployments, IAsyncLoopFactory asyncLoopFactory, FullNode.CancellationProvider cancellationProvider)
ConcurrentChain chain, NodeDeployments nodeDeployments, IAsyncLoopFactory asyncLoopFactory, INodeLifetime nodeLifetime)
{
this.walletSyncManager = walletSyncManager;
this.walletManager = walletManager;
......@@ -35,7 +36,7 @@ namespace Breeze.Wallet
this.chain = chain;
this.nodeDeployments = nodeDeployments;
this.asyncLoopFactory = asyncLoopFactory;
this.cancellationProvider = cancellationProvider;
this.nodeLifetime = nodeLifetime;
}
public override void Start()
......@@ -50,7 +51,7 @@ namespace Breeze.Wallet
public void StartDeploymentsChecksLoop()
{
var loopToken = CancellationTokenSource.CreateLinkedTokenSource(this.cancellationProvider.Cancellation.Token);
var loopToken = CancellationTokenSource.CreateLinkedTokenSource(this.nodeLifetime.ApplicationStopping);
this.asyncLoopFactory.Run("LightWalletFeature.CheckDeployments", token =>
{
if(!this.chain.IsDownloaded())
......
......@@ -10,6 +10,7 @@ using Stratis.Bitcoin.Notifications;
using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Notifications;
using Stratis.Bitcoin.Common.Hosting;
namespace Breeze.Wallet
{
......@@ -21,13 +22,13 @@ namespace Breeze.Wallet
private readonly CoinType coinType;
private readonly ILogger logger;
private readonly Signals signals;
private readonly FullNode.CancellationProvider cancellationProvider;
private ChainedBlock walletTip;
private readonly INodeLifetime nodeLifetime;
public ChainedBlock WalletTip => this.walletTip;
public LightWalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network,
BlockNotification blockNotification, Signals signals, FullNode.CancellationProvider cancellationProvider)
BlockNotification blockNotification, Signals signals, INodeLifetime nodeLifetime)
{
this.walletManager = walletManager as WalletManager;
this.chain = chain;
......@@ -35,7 +36,7 @@ namespace Breeze.Wallet
this.blockNotification = blockNotification;
this.coinType = (CoinType)network.Consensus.CoinType;
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
this.cancellationProvider = cancellationProvider;
this.nodeLifetime = nodeLifetime;
}
/// <inheritdoc />
......@@ -147,7 +148,7 @@ namespace Breeze.Wallet
// if the chain is already past the date we want to sync from, we don't wait, even though the chain might not be fully downloaded.
if (this.chain.Tip.Header.BlockTime.LocalDateTime < date)
{
AsyncLoop.RunUntil("WalletFeature.DownloadChain", this.cancellationProvider.Cancellation.Token,
AsyncLoop.RunUntil("WalletFeature.DownloadChain", this.nodeLifetime.ApplicationStopping,
() => this.chain.Tip.Header.BlockTime.LocalDateTime >= date,
() => this.StartSync(this.chain.GetHeightAtTime(date)),
(ex) =>
......@@ -173,7 +174,7 @@ namespace Breeze.Wallet
// if the chain is already past the height we want to sync from, we don't wait, even though the chain might not be fully downloaded.
if (this.chain.Tip.Height < height)
{
AsyncLoop.RunUntil("WalletFeature.DownloadChain", this.cancellationProvider.Cancellation.Token,
AsyncLoop.RunUntil("WalletFeature.DownloadChain", this.nodeLifetime.ApplicationStopping,
() => this.chain.Tip.Height >= height,
() => this.StartSync(height),
(ex) =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment