Ejemplo n.º 1
0
        public StateManager(IStorageManager storageManager, IRocksDbContext dbContext)
        {
            _balanceManager =
                new SnapshotManager <IBalanceSnapshot, BalanceSnapshot>(storageManager,
                                                                        (uint)RepositoryType.BalanceRepository);
            _contractManager =
                new SnapshotManager <IContractSnapshot, ContractSnapshot>(storageManager,
                                                                          (uint)RepositoryType.ContractRepository);
            _storageManager =
                new SnapshotManager <IStorageSnapshot, StorageSnapshot>(storageManager,
                                                                        (uint)RepositoryType.StorageRepository);
            _transactionManager =
                new SnapshotManager <ITransactionSnapshot, TransactionSnapshot>(storageManager,
                                                                                (uint)RepositoryType.TransactionRepository);
            _blockManager =
                new SnapshotManager <IBlockSnapshot, BlockSnapshot>(storageManager,
                                                                    (uint)RepositoryType.BlockRepository);
            _eventManager =
                new SnapshotManager <IEventSnapshot, EventSnapshot>(storageManager,
                                                                    (uint)RepositoryType.EventRepository);
            _validatorManager =
                new SnapshotManager <IValidatorSnapshot, ValidatorSnapshot>(storageManager,
                                                                            (uint)RepositoryType.ValidatorRepository);

            LastApprovedSnapshot = new BlockchainSnapshot(
                _balanceManager.LastApprovedSnapshot,
                _contractManager.LastApprovedSnapshot,
                _storageManager.LastApprovedSnapshot,
                _transactionManager.LastApprovedSnapshot,
                _blockManager.LastApprovedSnapshot,
                _eventManager.LastApprovedSnapshot,
                _validatorManager.LastApprovedSnapshot
                );
            _dbContext = dbContext;
        }
Ejemplo n.º 2
0
        public MetricsService(IRocksDbContext context, IConfigManager config)
        {
            _context = context;
            var rpcConfig = config.GetConfig <RpcConfig>("rpc") ?? RpcConfig.Default;

            _server = new MetricServer(hostname: "*", port: rpcConfig.MetricsPort);
        }
Ejemplo n.º 3
0
 public RocksDbRepository
 (
     IRocksDbContext rocksDbContext,
     IBinarySerializer binarySerializer
 )
 {
     _rocksDbContext   = rocksDbContext ?? throw new ArgumentNullException(nameof(rocksDbContext));
     _binarySerializer = binarySerializer ?? throw new ArgumentNullException(nameof(binarySerializer));
 }
Ejemplo n.º 4
0
        public StorageManager(IRocksDbContext rocksDbContext)
        {
            var versionIndexer = new VersionRepository(rocksDbContext);

            _versionFactory = new VersionFactory(versionIndexer.GetVersion(0));
            foreach (var repository in Enum.GetValues(typeof(RepositoryType)).Cast <RepositoryType>())
            {
                _repositoryManagers[(uint)repository] = new RepositoryManager(
                    (uint)repository, rocksDbContext, _versionFactory, versionIndexer
                    );
            }
        }
Ejemplo n.º 5
0
        public RepositoryManager(
            uint repositoryId,
            IRocksDbContext dbContext,
            VersionFactory versionFactory,
            VersionRepository versionRepository
            )
        {
            _repositoryId      = repositoryId;
            _dbContext         = dbContext;
            _versionFactory    = versionFactory;
            _versionRepository = versionRepository;
            var storageContext = new NodeRepository(dbContext);

            TrieMap       = new TrieHashMap(storageContext, versionFactory);
            LatestVersion = _versionRepository.GetVersion(_repositoryId);
        }
Ejemplo n.º 6
0
 public LocalTransactionRepository(IRocksDbContext rocksDbContext)
 {
     _rocksDbContext = rocksDbContext ?? throw new ArgumentNullException(nameof(rocksDbContext));
     _watchAddresses = new UInt160[] {};
 }
Ejemplo n.º 7
0
 public DbShrinkRepository(IRocksDbContext dbContext)
 {
     _dbContext = dbContext;
     UpdateBatch();
 }
Ejemplo n.º 8
0
 public HybridQueue(IRocksDbContext dbContext)
 {
     _dbContext = dbContext;
     CurBatch   = 0;
     TotalBatch = 0;
 }
Ejemplo n.º 9
0
 public VersionRepository(IRocksDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 10
0
 public NodeStorage(IRocksDbContext dbContext, VersionFactory versionFactory)
 {
     _dbContext      = dbContext;
     _versionFactory = versionFactory;
     nodeRetrieval   = new NodeRetrieval(_dbContext);
 }
Ejemplo n.º 11
0
 public PoolRepository(IRocksDbContext rocksDbContext)
 {
     _rocksDbContext = rocksDbContext ?? throw new ArgumentNullException(nameof(rocksDbContext));
 }
Ejemplo n.º 12
0
 public NodeRepository(IRocksDbContext rocksDbContext)
 {
     _rocksDbContext = rocksDbContext;
 }
Ejemplo n.º 13
0
 public SnapshotIndexRepository(IRocksDbContext dbContext, IStorageManager storageManager)
 {
     _dbContext      = dbContext;
     _storageManager = storageManager;
 }
 public ValidatorAttendanceRepository(IRocksDbContext rocksDbContext)
 {
     _rocksDbContext = rocksDbContext ?? throw new ArgumentNullException(nameof(rocksDbContext));
 }
Ejemplo n.º 15
0
 public RocksDbAtomicWrite(IRocksDbContext context)
 {
     _context    = context;
     _writeBatch = new WriteBatch();
 }
Ejemplo n.º 16
0
        public static void StartSync(IStateManager stateManager,
                                     IRocksDbContext dbContext,
                                     ISnapshotIndexRepository snapshotIndexRepository,
                                     VersionFactory versionFactory,
                                     ulong blockNumber)
        {
            dbContext.Save(EntryPrefix.NodesDownloadedTillNow.BuildPrefix(), UInt64Utils.ToBytes(0));
            List <string> devnetNodes = new List <string>
            {
                "http://157.245.160.201:7070",
                "http://95.217.6.171:7070",
                "http://88.99.190.191:7070",
                "http://94.130.78.183:7070",
                "http://94.130.24.163:7070",
                "http://94.130.110.127:7070",
                "http://94.130.110.95:7070",
                "http://94.130.58.63:7070",
                "http://88.99.86.166:7070",
                "http://88.198.78.106:7070",
                "http://88.198.78.141:7070",
                "http://88.99.126.144:7070",
                "http://88.99.87.58:7070",
                "http://95.217.6.234:7070"
            };
//            List <string> onlyonenode = new List<string>
            List <string> localnetNodes = new List <string>
            {
                "http://127.0.0.1:7070",
                "http://127.0.0.1:7071",
                "http://127.0.0.1:7072"
            };

            var snapshot = stateManager.NewSnapshot();

            ISnapshot[] snapshots = new ISnapshot[] { snapshot.Balances,
                                                      snapshot.Contracts,
                                                      snapshot.Storage,
                                                      snapshot.Transactions,
                                                      snapshot.Events,
                                                      snapshot.Validators, };

            List <string>  urls           = devnetNodes;
            HybridQueue    hybridQueue    = new HybridQueue(dbContext);
            PeerManager    peerManager    = new PeerManager(urls);
            NodeStorage    nodeStorage    = new NodeStorage(dbContext, versionFactory);
            RequestManager requestManager = new RequestManager(nodeStorage, hybridQueue);
            Downloader     downloader     = new Downloader(peerManager, requestManager, blockNumber);

            string[] trieNames = new string[]
            {
                "Balances", "Contracts", "Storage", "Transactions", "Events", "Validators"
            };


            downloader.DownloadBlocks(nodeStorage, snapshot.Blocks);

            for (int i = 0; i < trieNames.Length; i++)
            {
                Logger.LogWarning($"Starting trie {trieNames[i]}");
                string rootHash  = downloader.GetTrie(trieNames[i], nodeStorage);
                bool   foundRoot = nodeStorage.GetIdByHash(rootHash, out ulong curTrieRoot);
                snapshots[i].SetCurrentVersion(curTrieRoot);
                Logger.LogWarning($"Ending trie {trieNames[i]} : {curTrieRoot}");
                Logger.LogWarning($"Max Queue Size {requestManager.maxQueueSize}");
                Logger.LogWarning($"Total Nodes downloaded: {versionFactory.CurrentVersion}");
            }

            blockNumber = Convert.ToUInt64(downloader.GetBlockNumber(), 16);
            stateManager.Approve();
            stateManager.Commit();
            snapshotIndexRepository.SaveSnapshotForBlock(blockNumber, snapshot);
            Logger.LogWarning($"Set state to block {blockNumber} complete");
        }
Ejemplo n.º 17
0
 public NodeRetrieval(IRocksDbContext rocksDbContext)
 {
     _rocksDbContext = rocksDbContext;
 }