Commit 8036646f authored by Dan Gershony's avatar Dan Gershony

Light wallet sync manager

parent 8e6ab15d
......@@ -297,3 +297,4 @@ Thumbs.db
project.lock.json
/Breeze/src/Breeze.Daemon/Wallets
/Breeze/src/Breeze.Daemon/Logs
/Breeze.UI/.vscode/.BROWSE.VC.DB-wal
......@@ -27,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stratis.Bitcoin", "..\..\St
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stratis.Bitcoin.Common", "..\..\StratisBitcoinFullNode\Stratis.Bitcoin.Common\Stratis.Bitcoin.Common.csproj", "{4F9F7CF7-326C-4FC0-9EFB-209536A42030}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Breeze.Daemon", "src\Breeze.Daemon\Breeze.Daemon.csproj", "{3F0937A2-3182-42D9-866F-3DEDEE28EC5A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Breeze.Daemon", "src\Breeze.Daemon\Breeze.Daemon.csproj", "{AAF6163B-1BE2-48CE-9F9F-577C6D7AAB8D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -63,10 +63,10 @@ Global
{4F9F7CF7-326C-4FC0-9EFB-209536A42030}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F9F7CF7-326C-4FC0-9EFB-209536A42030}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F9F7CF7-326C-4FC0-9EFB-209536A42030}.Release|Any CPU.Build.0 = Release|Any CPU
{3F0937A2-3182-42D9-866F-3DEDEE28EC5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F0937A2-3182-42D9-866F-3DEDEE28EC5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F0937A2-3182-42D9-866F-3DEDEE28EC5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F0937A2-3182-42D9-866F-3DEDEE28EC5A}.Release|Any CPU.Build.0 = Release|Any CPU
{AAF6163B-1BE2-48CE-9F9F-577C6D7AAB8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAF6163B-1BE2-48CE-9F9F-577C6D7AAB8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAF6163B-1BE2-48CE-9F9F-577C6D7AAB8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAF6163B-1BE2-48CE-9F9F-577C6D7AAB8D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -77,6 +77,5 @@ Global
{D16CD478-9D1E-4C69-91AD-43539E94A215} = {807563C4-7259-434D-B604-A14C3DCF8E30}
{2490DD1A-6C14-47F2-A9C6-56761A52E2D9} = {807563C4-7259-434D-B604-A14C3DCF8E30}
{29E411B1-5687-43EE-A71B-6CCEC2289129} = {1B724678-2B73-483E-B981-3A6733C2194E}
{3F0937A2-3182-42D9-866F-3DEDEE28EC5A} = {807563C4-7259-434D-B604-A14C3DCF8E30}
EndGlobalSection
EndGlobal
......@@ -33,7 +33,7 @@ namespace Breeze.Api
body = string.Join(Environment.NewLine, arguments.Values);
}
this.logger.LogInformation($"Received {request.Method} {request.GetDisplayUrl()}. Body: '{body}'");
this.logger.LogDebug($"Received {request.Method} {request.GetDisplayUrl()}. Body: '{body}'");
await next();
}
}
......
......@@ -9,25 +9,79 @@ using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Configuration;
using Stratis.Bitcoin.Logging;
using Breeze.Wallet;
using NBitcoin;
using NBitcoin.Protocol;
using Stratis.Bitcoin.BlockStore;
using Stratis.Bitcoin.Consensus;
using Stratis.Bitcoin.MemoryPool;
using Stratis.Bitcoin.Miner;
using Stratis.Bitcoin.Notifications;
using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Wallet;
namespace Breeze.Daemon
{
public class Program
{
public static void Main(string[] args)
{
IFullNodeBuilder fullNodeBuilder = null;
if (args.Contains("stratis"))
{
// configure Full Node
Logs.Configure(Logs.GetLoggerFactory(args));
if (NodeSettings.PrintHelp(args, Network.StratisMain))
return;
var network = args.Contains("-testnet") ? InitStratisTest() : Network.StratisMain;
var nodeSettings = NodeSettings.FromArguments(args, "stratis", network, ProtocolVersion.ALT_PROTOCOL_VERSION);
if (args.Contains("light"))
{
fullNodeBuilder = new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
.UseLightWallet()
.UseBlockNotification()
.UseTransactionNotification()
.UseApi();
}
else
{
fullNodeBuilder = new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
.UseStratisConsensus()
.UseBlockStore()
.UseMempool()
.UseWallet()
.AddPowPosMining()
.UseApi();
}
}
else
{
NodeSettings nodeSettings = NodeSettings.FromArguments(args);
var fullNodeBuilder = new FullNodeBuilder()
if (args.Contains("light"))
{
fullNodeBuilder = new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
.UseLightWallet()
.UseBlockNotification()
.UseTransactionNotification()
.UseApi();
}
else
{
fullNodeBuilder = new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
.UseConsensus()
.UseBlockStore()
.UseMempool()
.UseWallet()
.UseApi();
}
}
// add the tumbler's settings
var tumblerAddress = args.SingleOrDefault(arg => arg.StartsWith("-tumbler-uri="));
......@@ -39,8 +93,57 @@ namespace Breeze.Daemon
var node = fullNodeBuilder.Build();
// start Full Node - this will also start the API
//start Full Node - this will also start the API
node.Run();
}
private static Network InitStratisTest()
{
Block.BlockSignature = true;
Transaction.TimeStamp = true;
var consensus = Network.StratisMain.Consensus.Clone();
consensus.PowLimit = new Target(uint256.Parse("0000ffff00000000000000000000000000000000000000000000000000000000"));
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
var pchMessageStart = new byte[4];
pchMessageStart[0] = 0x71;
pchMessageStart[1] = 0x31;
pchMessageStart[2] = 0x21;
pchMessageStart[3] = 0x11;
var magic = BitConverter.ToUInt32(pchMessageStart, 0); //0x5223570;
var genesis = Network.StratisMain.GetGenesis().Clone();
genesis.Header.Time = 1493909211;
genesis.Header.Nonce = 2433759;
genesis.Header.Bits = consensus.PowLimit;
consensus.HashGenesisBlock = genesis.GetHash();
Guard.Assert(consensus.HashGenesisBlock == uint256.Parse("0x00000e246d7b73b88c9ab55f2e5e94d9e22d471def3df5ea448f5576b1d156b9"));
var builder = new NetworkBuilder()
.SetName("StratisTest")
.SetConsensus(consensus)
.SetMagic(magic)
.SetGenesis(genesis)
.SetPort(26178)
.SetRPCPort(26174)
.SetBase58Bytes(Base58Type.PUBKEY_ADDRESS, new byte[] { (65) })
.SetBase58Bytes(Base58Type.SCRIPT_ADDRESS, new byte[] { (196) })
.SetBase58Bytes(Base58Type.SECRET_KEY, new byte[] { (65 + 128) })
.SetBase58Bytes(Base58Type.ENCRYPTED_SECRET_KEY_NO_EC, new byte[] { 0x01, 0x42 })
.SetBase58Bytes(Base58Type.ENCRYPTED_SECRET_KEY_EC, new byte[] { 0x01, 0x43 })
.SetBase58Bytes(Base58Type.EXT_PUBLIC_KEY, new byte[] { (0x04), (0x88), (0xB2), (0x1E) })
.SetBase58Bytes(Base58Type.EXT_SECRET_KEY, new byte[] { (0x04), (0x88), (0xAD), (0xE4) })
.AddDNSSeeds(new[]
{
new DNSSeedData("stratisplatform.com", "testnode1.stratisplatform.com"),
});
return builder.BuildAndRegister();
}
}
}
......@@ -5,21 +5,22 @@ using Stratis.Bitcoin.Logging;
using Microsoft.Extensions.Logging;
using Serilog;
using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Controllers;
namespace Breeze.Wallet
{
public class LightWalletFeature : FullNodeFeature
{
private readonly TrackNotifier trackNotifier;
private readonly LightWalletSyncManager lightWalletSyncManager;
public LightWalletFeature(TrackNotifier trackNotifier)
public LightWalletFeature(LightWalletSyncManager lightWalletSyncManager)
{
this.trackNotifier = trackNotifier;
this.lightWalletSyncManager = lightWalletSyncManager;
}
public override void Start()
{
this.trackNotifier.Initialize().GetAwaiter().GetResult();
this.lightWalletSyncManager.Initialize();
}
public override void Stop()
......@@ -28,20 +29,20 @@ namespace Breeze.Wallet
}
}
public static class WalletFeatureExtension
public static class LightWalletFeatureExtension
{
public static IFullNodeBuilder UseLightWallet(this IFullNodeBuilder fullNodeBuilder)
{
// use the wallet and on top of that start to notifier
fullNodeBuilder.UseWallet();
fullNodeBuilder.ConfigureFeature(features =>
{
features
.AddFeature<LightWalletFeature>()
.FeatureServices(services =>
{
services.AddSingleton<TrackNotifier>();
services.AddSingleton<IWalletSyncManager, LightWalletSyncManager>();
services.AddSingleton<IWalletManager, WalletManager>();
services.AddSingleton<WalletController>();
});
});
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
......@@ -12,11 +8,10 @@ using Stratis.Bitcoin;
using Stratis.Bitcoin.Notifications;
using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Notifications;
namespace Breeze.Wallet
{
public class TrackNotifier
public class LightWalletSyncManager : WalletSyncManager
{
private readonly WalletManager walletManager;
private readonly ConcurrentChain chain;
......@@ -24,26 +19,21 @@ namespace Breeze.Wallet
private readonly CoinType coinType;
private readonly ILogger logger;
public TrackNotifier(ILoggerFactory loggerFactory, IWalletManager walletManager,
ConcurrentChain chain, BlockNotification blockNotification, Network network)
public LightWalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network,
BlockNotification blockNotification):base(loggerFactory, walletManager, chain, network)
{
this.walletManager = walletManager as WalletManager;
this.chain = chain;
this.blockNotification = blockNotification;
this.coinType = (CoinType)network.Consensus.CoinType;
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
}
/// <inheritdoc />
public Task Initialize()
public override void Initialize()
{
// get the chain headers. This needs to be up-to-date before we really do anything
//await this.WaitForChainDownloadAsync();
this.WaitForChainDownloadAsync().GetAwaiter().GetResult();
// start syncing blocks
var bestHeightForSyncing = this.FindBestHeightForSyncing();
this.SyncFrom(bestHeightForSyncing);
return Task.CompletedTask;
}
private int FindBestHeightForSyncing()
......@@ -85,7 +75,7 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public void SyncFrom(DateTime date)
public override void SyncFrom(DateTime date)
{
int blockSyncStart = this.chain.GetHeightAtTime(date);
......@@ -94,7 +84,7 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public void SyncFrom(int height)
public override void SyncFrom(int height)
{
this.blockNotification.SyncFrom(this.chain.GetBlock(height).HashBlock);
}
......
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