internal PeerWorker(WorkerConfig workerConfig, LocalClient localClient, CoreDaemon coreDaemon, HeadersRequestWorker headersRequestWorker) : base("PeerWorker", workerConfig.initialNotify, workerConfig.minIdleTime, workerConfig.maxIdleTime) { this.localClient = localClient; this.coreDaemon = coreDaemon; this.headersRequestWorker = headersRequestWorker; }
public WalletMonitor(CoreDaemon coreDaemon, bool keepEntries = true) : base("WalletMonitor", initialNotify: true, minIdleTime: TimeSpan.FromMilliseconds(0), maxIdleTime: TimeSpan.MaxValue) { this.coreDaemon = coreDaemon; this.addressesByOutputScriptHash = new Dictionary<UInt256, List<MonitoredWalletAddress>>(); this.matcherAddresses = new List<MonitoredWalletAddress>(); this.keepEntries = keepEntries; this.entries = ImmutableList.CreateBuilder<WalletEntry>(); this.bitBalance = 0; this.coreDaemon.OnChainStateChanged += HandleChainStateChanged; }
public HeadersRequestWorker(WorkerConfig workerConfig, LocalClient localClient, CoreDaemon coreDaemon) : base("HeadersRequestWorker", workerConfig.initialNotify, workerConfig.minIdleTime, workerConfig.maxIdleTime) { this.localClient = localClient; this.coreDaemon = coreDaemon; this.coreStorage = coreDaemon.CoreStorage; this.headersRequestsByPeer = new ConcurrentDictionary<Peer, DateTimeOffset>(); this.localClient.OnBlockHeaders += HandleBlockHeaders; this.coreDaemon.OnTargetChainChanged += HandleTargetChainChanged; this.flushWorker = new WorkerMethod("HeadersRequestWorker.FlushWorker", FlushWorkerMethod, initialNotify: true, minIdleTime: TimeSpan.Zero, maxIdleTime: TimeSpan.MaxValue); this.flushQueue = new ConcurrentQueue<FlushHeaders>(); }
private CoreDaemon CreateExampleDaemon(out BlockProvider embeddedBlocks, out IStorageManager storageManager, int? maxHeight = null) { // retrieve first 10,000 testnet3 blocks embeddedBlocks = new BlockProvider("BitSharp.Examples.Blocks.TestNet3.zip"); // initialize in-memory storage storageManager = new MemoryStorageManager(); // intialize testnet3 rules (ignore script errors, script engine is not and is not intended to be complete) var rules = new Testnet3Rules { IgnoreScriptErrors = true }; // initialize & start core daemon var coreDaemon = new CoreDaemon(rules, storageManager) { MaxHeight = maxHeight, IsStarted = true }; // add embedded blocks coreDaemon.CoreStorage.AddBlocks(embeddedBlocks.ReadBlocks()); // wait for core daemon to finish processing any available data coreDaemon.WaitForUpdate(); return coreDaemon; }
public MainWindow() { try { //TODO //************************************************************** var useTestNet = false; var connectToPeers = true; var ignoreScripts = false; var pruningMode = PruningMode.TxIndex | PruningMode.BlockSpentIndex | PruningMode.BlockTxesDelete; var enableDummyWallet = true; var useLevelDb = false; var runInMemory = false; var cleanData = false; var cleanChainState = false; var cleanBlockTxes = false // clean block txes if the chain state is being cleaned and block txes have been pruned, the new chain state will require intact blocks to validate || (cleanChainState && (pruningMode.HasFlag(PruningMode.BlockTxesPreserveMerkle) || pruningMode.HasFlag(PruningMode.BlockTxesDestroyMerkle))); //NOTE: Running with a cleaned chained state against a pruned blockchain does not work. // It will see the data is missing, but won't redownload the blocks. //************************************************************** long? cacheSizeMaxBytes = 512.MEBIBYTE(); // directories var baseDirectory = Config.LocalStoragePath; //if (Debugger.IsAttached) // baseDirectory = Path.Combine(baseDirectory, "Debugger"); var chainType = useTestNet ? ChainType.TestNet3 : ChainType.MainNet; string[] blockTxesStorageLocations = null; // detect local dev machine - TODO proper configuration var isAzureVM = (Environment.MachineName == "BITSHARP"); var isLocalDev = (Environment.MachineName == "SKIPPY"); if (isAzureVM) { cacheSizeMaxBytes = null; BlockRequestWorker.SecondaryBlockFolder = @"E:\BitSharp.Blocks\RawBlocks"; PeerWorker.ConnectedMax = 15; blockTxesStorageLocations = new[] { @"E:\Blocks1", @"E:\Blocks2", @"E:\Blocks3", @"E:\Blocks4", }; } else if (isLocalDev) { //Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; cacheSizeMaxBytes = (int)2.GIBIBYTE(); // location to store a copy of raw blocks to avoid redownload BlockRequestWorker.SecondaryBlockFolder = Path.Combine(baseDirectory, "RawBlocks"); // split block txes storage across 2 dedicated SSDs, keep chain state on main SSD //blockTxesStorageLocations = new[] //{ // @"Y:\BitSharp", // @"Z:\BitSharp", //}; } //TODO if (cleanData) { try { Directory.Delete(Path.Combine(baseDirectory, "Data", chainType.ToString()), recursive: true); } catch (IOException) { } } if (cleanChainState) { try { Directory.Delete(Path.Combine(baseDirectory, "Data", chainType.ToString(), "ChainState"), recursive: true); } catch (IOException) { } } if (cleanBlockTxes) { try { Directory.Delete(Path.Combine(baseDirectory, "Data", chainType.ToString(), "BlockTxes"), recursive: true); } catch (IOException) { } } // initialize kernel this.kernel = new StandardKernel(); // add logging module this.kernel.Load(new LoggingModule(baseDirectory, LogLevel.Info)); // log startup this.logger = LogManager.GetCurrentClassLogger(); this.logger.Info($"Starting up: {DateTime.Now}"); var modules = new List<INinjectModule>(); // add storage module if (useLevelDb) { ulong? blocksCacheSize = null; ulong? blocksWriteCacheSize = null; ulong? blockTxesCacheSize = null; ulong? blockTxesWriteCacheSize = null; ulong? chainStateCacheSize = null; ulong? chainStateWriteCacheSize = null; modules.Add(new LevelDbStorageModule(baseDirectory, chainType, blocksCacheSize, blocksWriteCacheSize, blockTxesCacheSize, blockTxesWriteCacheSize, chainStateCacheSize, chainStateWriteCacheSize)); long? writeCacheSizeMaxBytes = 128.MEBIBYTE(); } else if (runInMemory) { modules.Add(new MemoryStorageModule()); modules.Add(new NodeMemoryStorageModule()); } else { modules.Add(new EsentStorageModule(baseDirectory, chainType, cacheSizeMaxBytes: cacheSizeMaxBytes, blockTxesStorageLocations: blockTxesStorageLocations)); } // add rules module modules.Add(new RulesModule(chainType)); // load modules this.kernel.Load(modules.ToArray()); // initialize rules var rules = this.kernel.Get<ICoreRules>(); rules.IgnoreScripts = ignoreScripts; // initialize the blockchain daemon this.coreDaemon = this.kernel.Get<CoreDaemon>(); this.coreDaemon.PruningMode = pruningMode; this.kernel.Bind<CoreDaemon>().ToConstant(this.coreDaemon).InTransientScope(); // initialize dummy wallet monitor this.dummyMonitor = new DummyMonitor(this.coreDaemon); if (enableDummyWallet) { Task.Run(() => this.dummyMonitor.Start()); } else { // allow pruning to any height when not using the wallet this.coreDaemon.PrunableHeight = int.MaxValue; } // initialize p2p client this.localClient = this.kernel.Get<LocalClient>(); this.kernel.Bind<LocalClient>().ToConstant(this.localClient).InTransientScope(); // setup view model this.viewModel = new MainWindowViewModel(this.kernel, this.dummyMonitor); InitializeComponent(); // start the blockchain daemon Task.Run(() => this.coreDaemon.Start()); // start p2p client Task.Run(() => this.localClient.Start(connectToPeers)); this.DataContext = this.viewModel; } catch (Exception ex) { if (this.logger != null) { this.logger.Fatal(ex, "Application failed"); LogManager.Flush(); } else { Console.WriteLine(ex); } Environment.Exit(-1); } }
public DummyMonitor(CoreDaemon coreDaemon) : base(coreDaemon, keepEntries: false) { this.AddAddress(new First10000Address()); this.AddAddress(new Top10000Address()); }
public NodeRpcServer(CoreDaemon coreDaemon, int port) : base(coreDaemon, port) { this.coreDaemon = coreDaemon; }
public PeerWorker(WorkerConfig workerConfig, LocalClient localClient, CoreDaemon coreDaemon) : base("PeerWorker", workerConfig.initialNotify, workerConfig.minIdleTime, workerConfig.maxIdleTime) { this.localClient = localClient; this.coreDaemon = coreDaemon; }