Esempio n. 1
0
        public void RestoreCheckpoint(string checkPointArchive, bool force)
        {
            if (chain.ConsensusNodes.Count != 1)
            {
                throw new ArgumentException("Checkpoint restore is only supported on single node express instances", nameof(chain));
            }

            checkPointArchive = ResolveCheckpointFileName(checkPointArchive);
            if (!fileSystem.File.Exists(checkPointArchive))
            {
                throw new Exception($"Checkpoint {checkPointArchive} couldn't be found");
            }

            var node = chain.ConsensusNodes[0];

            if (IsRunning(node))
            {
                var scriptHash = node.Wallet.DefaultAccount?.ScriptHash ?? "<unknown>";
                throw new InvalidOperationException($"node {scriptHash} currently running");
            }

            var checkpointTempPath = fileSystem.GetTempFolder();

            using var folderCleanup = AnonymousDisposable.Create(() =>
            {
                if (fileSystem.Directory.Exists(checkpointTempPath))
                {
                    fileSystem.Directory.Delete(checkpointTempPath, true);
                }
            });

            var nodePath = fileSystem.GetNodePath(node);

            if (fileSystem.Directory.Exists(nodePath))
            {
                if (!force)
                {
                    throw new Exception("You must specify force to restore a checkpoint to an existing blockchain.");
                }

                fileSystem.Directory.Delete(nodePath, true);
            }

            var wallet          = DevWallet.FromExpressWallet(ProtocolSettings, node.Wallet);
            var multiSigAccount = wallet.GetMultiSigAccounts().Single();

            RocksDbStorageProvider.RestoreCheckpoint(checkPointArchive, checkpointTempPath, ProtocolSettings, multiSigAccount.ScriptHash);
            fileSystem.Directory.Move(checkpointTempPath, nodePath);
        }
Esempio n. 2
0
        public OfflineNode(ProtocolSettings settings, RocksDbStorageProvider rocksDbStorageProvider, Wallet nodeWallet, ExpressChain chain, bool enableTrace)
        {
            this.nodeWallet             = nodeWallet;
            this.chain                  = chain;
            this.rocksDbStorageProvider = rocksDbStorageProvider;
            applicationEngineProvider   = enableTrace ? new ApplicationEngineProvider() : null;
            consensusNodesKeys          = new Lazy <KeyPair[]>(() => chain.GetConsensusNodeKeys());

            var storageProviderPlugin = new StorageProviderPlugin(rocksDbStorageProvider);

            _         = new PersistencePlugin(rocksDbStorageProvider);
            neoSystem = new NeoSystem(settings, storageProviderPlugin.Name);

            ApplicationEngine.Log += OnLog !;
        }
Esempio n. 3
0
        public OfflineNode(ProtocolSettings settings, RocksDbStorageProvider rocksDbStorageProvider, Wallet nodeWallet, ExpressChain chain, bool enableTrace)
        {
            this.nodeWallet             = nodeWallet;
            this.chain                  = chain;
            this.rocksDbStorageProvider = rocksDbStorageProvider;
            applicationEngineProvider   = enableTrace ? new ExpressApplicationEngineProvider() : null;
            consensusNodesKeys          = new Lazy <KeyPair[]>(() => chain.ConsensusNodes
                                                               .Select(n => n.Wallet.DefaultAccount ?? throw new Exception())
                                                               .Select(a => new KeyPair(a.PrivateKey.HexToBytes()))
                                                               .ToArray());

            var storageProviderPlugin = new StorageProviderPlugin(rocksDbStorageProvider);

            _         = new ExpressAppLogsPlugin(rocksDbStorageProvider);
            neoSystem = new NeoSystem(settings, storageProviderPlugin.Name);

            ApplicationEngine.Log += OnLog !;
        }
Esempio n. 4
0
 public OfflineNode(ProtocolSettings settings, RocksDbStorageProvider rocksDbStorageProvider, ExpressWallet nodeWallet, ExpressChain chain, bool enableTrace)
     : this(settings, rocksDbStorageProvider, DevWallet.FromExpressWallet(settings, nodeWallet), chain, enableTrace)
 {
 }