예제 #1
0
        public void WriteNodeToBatch(ulong id, IHashTrieNode node, RocksDbAtomicWrite tx)
        {
            var prefix = EntryPrefix.PersistentHashMap.BuildPrefix(id);

            tx.Put(prefix, NodeSerializer.ToBytes(node));
            var hashPrefix = EntryPrefix.VersionByHash.BuildPrefix(node.Hash);

            tx.Put(hashPrefix, UInt64Utils.ToBytes(id));
        }
예제 #2
0
        public void CommitNodes()
        {
            RocksDbAtomicWrite tx = new RocksDbAtomicWrite(_dbContext);

            foreach (var item in _nodeCache)
            {
                tx.Put(EntryPrefix.PersistentHashMap.BuildPrefix(item.Key), NodeSerializer.ToBytes(item.Value));
                Console.WriteLine("Adding node to DB : " + item.Key);
            }
            ulong nodesCnt = UInt64Utils.FromBytes(_dbContext.Get(EntryPrefix.NodesDownloadedTillNow.BuildPrefix()));

            nodesCnt += (ulong)_nodeCache.Count;
            tx.Put(EntryPrefix.NodesDownloadedTillNow.BuildPrefix(), UInt64Utils.ToBytes(nodesCnt));
            tx.Commit();
            _nodeCache.Clear();
        }
예제 #3
0
        public void CommitIds()
        {
            RocksDbAtomicWrite tx = new RocksDbAtomicWrite(_dbContext);

            foreach (var item in _idCache)
            {
                tx.Put(EntryPrefix.VersionByHash.BuildPrefix(HexUtils.HexToBytes(item.Key)), UInt64Utils.ToBytes(item.Value));
            }
            tx.Commit();
            _idCache.Clear();
        }
예제 #4
0
        private void Save(byte[] key, byte[] content, bool tryCommit = true)
        {
            batch.Put(key, content);
            var keyHash = key.Keccak();

            _memDb[keyHash] = content;
            DbShrinkUtils.UpdateCounter();
            if (tryCommit && DbShrinkUtils.CycleEnded())
            {
                Commit();
            }
        }
예제 #5
0
        public void AddAndRemoveTransaction(TransactionReceipt txToAdd, TransactionReceipt txToRemove)
        {
            /* write transaction to storage */
            var batch    = new RocksDbAtomicWrite(_rocksDbContext);
            var prefixTx = EntryPrefix.TransactionByHash.BuildPrefix(txToRemove.Hash);

            batch.Delete(prefixTx);
            prefixTx = EntryPrefix.TransactionByHash.BuildPrefix(txToAdd.Hash);
            batch.Put(prefixTx, txToAdd.ToByteArray());
            /* add transaction to pool */
            var pool = GetTransactionPool();

            pool.Remove(txToRemove.Hash);
            if (!pool.Contains(txToAdd.Hash))
            {
                pool.Add(txToAdd.Hash);
            }
            prefixTx = EntryPrefix.TransactionPool.BuildPrefix();
            batch.Put(prefixTx, pool.TransactionHashListToByteArray());
            batch.Commit();
        }
예제 #6
0
 public void SetVersion(uint repository, ulong version, RocksDbAtomicWrite tx)
 {
     tx.Put(EntryPrefix.StorageVersionIndex.BuildPrefix(repository), version.ToBytes().ToArray());
 }