Commit be13ebf8 authored by Dan Gershony's avatar Dan Gershony

NodeLifetime in Breeze

parent 6af1ba3b
...@@ -57,7 +57,7 @@ namespace Breeze.Api ...@@ -57,7 +57,7 @@ namespace Breeze.Api
return Task.CompletedTask; return Task.CompletedTask;
}, },
this.fullNode.GlobalCancellation.Cancellation.Token, this.fullNode.NodeLifetime.ApplicationStopping,
repeatEvery: this.apiFeatureOptions.KeepaliveMonitor?.KeepaliveInterval, repeatEvery: this.apiFeatureOptions.KeepaliveMonitor?.KeepaliveInterval,
startAfter: TimeSpans.Minute); startAfter: TimeSpans.Minute);
} }
......
...@@ -13,6 +13,7 @@ using Stratis.Bitcoin.Consensus.Deployments; ...@@ -13,6 +13,7 @@ using Stratis.Bitcoin.Consensus.Deployments;
using Stratis.Bitcoin.Utilities; using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Wallet; using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Controllers; using Stratis.Bitcoin.Wallet.Controllers;
using Stratis.Bitcoin.Common.Hosting;
namespace Breeze.Wallet namespace Breeze.Wallet
{ {
...@@ -24,10 +25,10 @@ namespace Breeze.Wallet ...@@ -24,10 +25,10 @@ namespace Breeze.Wallet
private readonly ConcurrentChain chain; private readonly ConcurrentChain chain;
private readonly NodeDeployments nodeDeployments; private readonly NodeDeployments nodeDeployments;
private readonly IAsyncLoopFactory asyncLoopFactory; private readonly IAsyncLoopFactory asyncLoopFactory;
private readonly FullNode.CancellationProvider cancellationProvider; private readonly INodeLifetime nodeLifetime;
public LightWalletFeature(IWalletSyncManager walletSyncManager, IWalletManager walletManager, IConnectionManager connectionManager, 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.walletSyncManager = walletSyncManager;
this.walletManager = walletManager; this.walletManager = walletManager;
...@@ -35,7 +36,7 @@ namespace Breeze.Wallet ...@@ -35,7 +36,7 @@ namespace Breeze.Wallet
this.chain = chain; this.chain = chain;
this.nodeDeployments = nodeDeployments; this.nodeDeployments = nodeDeployments;
this.asyncLoopFactory = asyncLoopFactory; this.asyncLoopFactory = asyncLoopFactory;
this.cancellationProvider = cancellationProvider; this.nodeLifetime = nodeLifetime;
} }
public override void Start() public override void Start()
...@@ -50,7 +51,7 @@ namespace Breeze.Wallet ...@@ -50,7 +51,7 @@ namespace Breeze.Wallet
public void StartDeploymentsChecksLoop() public void StartDeploymentsChecksLoop()
{ {
var loopToken = CancellationTokenSource.CreateLinkedTokenSource(this.cancellationProvider.Cancellation.Token); var loopToken = CancellationTokenSource.CreateLinkedTokenSource(this.nodeLifetime.ApplicationStopping);
this.asyncLoopFactory.Run("LightWalletFeature.CheckDeployments", token => this.asyncLoopFactory.Run("LightWalletFeature.CheckDeployments", token =>
{ {
if(!this.chain.IsDownloaded()) if(!this.chain.IsDownloaded())
......
...@@ -10,6 +10,7 @@ using Stratis.Bitcoin.Notifications; ...@@ -10,6 +10,7 @@ using Stratis.Bitcoin.Notifications;
using Stratis.Bitcoin.Utilities; using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Wallet; using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Notifications; using Stratis.Bitcoin.Wallet.Notifications;
using Stratis.Bitcoin.Common.Hosting;
namespace Breeze.Wallet namespace Breeze.Wallet
{ {
...@@ -21,13 +22,13 @@ namespace Breeze.Wallet ...@@ -21,13 +22,13 @@ namespace Breeze.Wallet
private readonly CoinType coinType; private readonly CoinType coinType;
private readonly ILogger logger; private readonly ILogger logger;
private readonly Signals signals; private readonly Signals signals;
private readonly FullNode.CancellationProvider cancellationProvider;
private ChainedBlock walletTip; private ChainedBlock walletTip;
private readonly INodeLifetime nodeLifetime;
public ChainedBlock WalletTip => this.walletTip; public ChainedBlock WalletTip => this.walletTip;
public LightWalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network, 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.walletManager = walletManager as WalletManager;
this.chain = chain; this.chain = chain;
...@@ -35,7 +36,7 @@ namespace Breeze.Wallet ...@@ -35,7 +36,7 @@ namespace Breeze.Wallet
this.blockNotification = blockNotification; this.blockNotification = blockNotification;
this.coinType = (CoinType)network.Consensus.CoinType; this.coinType = (CoinType)network.Consensus.CoinType;
this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
this.cancellationProvider = cancellationProvider; this.nodeLifetime = nodeLifetime;
} }
/// <inheritdoc /> /// <inheritdoc />
...@@ -147,7 +148,7 @@ namespace Breeze.Wallet ...@@ -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 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) 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.chain.Tip.Header.BlockTime.LocalDateTime >= date,
() => this.StartSync(this.chain.GetHeightAtTime(date)), () => this.StartSync(this.chain.GetHeightAtTime(date)),
(ex) => (ex) =>
...@@ -173,7 +174,7 @@ namespace Breeze.Wallet ...@@ -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 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) 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.chain.Tip.Height >= height,
() => this.StartSync(height), () => this.StartSync(height),
(ex) => (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