예제 #1
0
        public void MakeReady(CommandDispatcher dispatcher)
        {
            var nodeMode = Settings.Node.Mode;

            Logger.Success($"Node is now running in {nodeMode.ToString().ToLower()} mode!");
            _nodeReady = true;
        }
예제 #2
0
        private Node SetupNode()
        {
            if (Settings.Node.Mode == NodeMode.Proxy)
            {
                Logger.Warning("No nexus will be setup locally due to proxy mode being enabled");
                return(null);
            }

            Node node = null;

            if (this._mempool != null)
            {
                this._mempool.SetKeys(_nodeKeys);
            }

            if (!Settings.Node.IsValidator && Settings.Node.Seeds.Count == 0 && _peerCaps.HasFlag(PeerCaps.Sync))
            {
                throw new Exception("A non-validator node with sync enabled must specificy a non-empty list of seed endpoints");
            }

            node = new Node("Spook v" + Version
                            , _nexus
                            , _mempool
                            , _nodeKeys
                            , Settings.Node.NodeHost
                            , _availablePorts
                            , _peerCaps
                            , Settings.Node.Seeds
                            , Logger);

            var missingNexus = !_nexus.HasGenesis;

            if (missingNexus)
            {
                if (Settings.Node.IsValidator)
                {
                    var nexusName = Settings.Node.NexusName;
                    if (Settings.Node.NexusBootstrap)
                    {
                        if (!ValidationUtils.IsValidIdentifier(nexusName))
                        {
                            Logger.Error("Invalid nexus name: " + nexusName);
                            this.Terminate();
                        }

                        Logger.Message($"Boostraping {nexusName} nexus using {_nodeKeys.Address}...");

                        var genesisTimestamp = Settings.Node.GenesisTimestamp;

                        if (!_nexus.CreateGenesisBlock(_nodeKeys, genesisTimestamp, DomainSettings.LatestKnownProtocol))
                        {
                            throw new ChainException("Genesis block failure");
                        }

                        Logger.Success("Genesis block created: " + _nexus.GetGenesisHash(_nexus.RootStorage));

                        missingNexus = false;
                    }
                }
                else
                {
                    if (_mempool != null)
                    {
                        _mempool.SubmissionCallback = (tx, chain) =>
                        {
                            Logger.Message($"Relaying tx {tx.Hash} to other node");
                        };
                    }
                }

                if (missingNexus && !_peerCaps.HasFlag(PeerCaps.Sync))
                {
                    Logger.Error("No Nexus found.");
                    this.Terminate();
                }
            }
            else
            {
                var genesisAddress = _nexus.GetGenesisAddress(_nexus.RootStorage);
                if (Settings.Node.IsValidator && !Settings.Node.Readonly)
                {
                    if (!_nexus.IsKnownValidator(_nodeKeys.Address))
                    {
                        throw new Exception("Specified node key does not match a known validator address");
                    }
                    else
                    if (_nodeKeys.Address != genesisAddress)
                    {
                        Logger.Warning("Specified node key does not match genesis address " + genesisAddress.Text);
                    }
                }

                var chainHeight = _nexus.RootChain.Height;
                var genesisHash = _nexus.GetGenesisHash(_nexus.RootStorage);
                Logger.Success($"Loaded {Nexus.Name} Nexus with genesis {genesisHash } with {chainHeight} blocks");
            }

            return(node);
        }