Commit b48c9e77 authored by Dan Gershony's avatar Dan Gershony Committed by GitHub

Merge pull request #115 from dangershony/light-wallet-drop-nodes-behind

Checking for segwit activation and adding the behavior to drop nodes …
parents 9efbd476 9f4c4190
using Stratis.Bitcoin.Builder.Feature;
using Microsoft.Extensions.DependencyInjection;
using NBitcoin;
using NBitcoin.Protocol;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Connection;
using Stratis.Bitcoin.Consensus;
using Stratis.Bitcoin.Consensus.Deployments;
using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Controllers;
......@@ -10,17 +15,30 @@ namespace Breeze.Wallet
{
private readonly IWalletSyncManager walletSyncManager;
private readonly IWalletManager walletManager;
private readonly IConnectionManager connectionManager;
private readonly ConcurrentChain chain;
private readonly NodeDeployments nodeDeployments;
public LightWalletFeature(IWalletSyncManager walletSyncManager, IWalletManager walletManager)
public LightWalletFeature(IWalletSyncManager walletSyncManager, IWalletManager walletManager, IConnectionManager connectionManager,
ConcurrentChain chain, NodeDeployments nodeDeployments)
{
this.walletSyncManager = walletSyncManager;
this.walletManager = walletManager;
this.connectionManager = connectionManager;
this.chain = chain;
this.nodeDeployments = nodeDeployments;
}
public override void Start()
{
this.connectionManager.Parameters.TemplateBehaviors.Add(new DropNodesBehaviour(this.chain, this.connectionManager));
this.walletManager.Initialize();
this.walletSyncManager.Initialize();
var flags = this.nodeDeployments.GetFlags(this.walletSyncManager.WalletTip);
if (flags.ScriptFlags.HasFlag(ScriptVerify.Witness))
this.connectionManager.AddDiscoveredNodesRequirement(NodeServices.NODE_WITNESS);
}
public override void Stop()
......
......@@ -23,6 +23,8 @@ namespace Breeze.Wallet
private ChainedBlock walletTip;
public ChainedBlock WalletTip => this.walletTip;
public LightWalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network,
BlockNotification blockNotification, Signals signals)
{
......@@ -61,6 +63,7 @@ namespace Breeze.Wallet
this.walletManager.RemoveBlocks(fork);
this.walletManager.WalletTipHash = fork.HashBlock;
this.walletTip = fork;
this.logger.LogWarning($"Wallet tip was out of sync, wallet tip reverted back to Height = {this.walletTip.Height} hash = {this.walletTip.HashBlock}.");
}
}
......@@ -139,6 +142,7 @@ namespace Breeze.Wallet
Guard.Assert(fork.HashBlock == block.Header.HashPrevBlock);
this.walletManager.RemoveBlocks(fork);
this.logger.LogWarning($"Reorg detected, wallet tip reverted back to Height = {fork.Height} hash = {fork.HashBlock}.");
}
else
{
......
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