Beispiel #1
0
        public void Write(TxoPack txos, SectorIndex sectorIndex, Hash256 sectorHash)
        {
            if (_config.ImplicitSectors)
            {
                throw new InvalidOperationException();
            }

            var partition = PartitionByExplicitSector(sectorIndex, sectorHash, txos.GetForwardIterator());

            Write(partition, txos);
        }
Beispiel #2
0
        /// <summary>
        /// Reading layers with explicit outpoint ranges.
        /// </summary>
        /// <param name="txoIn">txopack providing outpoints requesting a read</param>
        /// <param name="sectorIndex">Identifies the first sector to be read.</param>
        /// <param name="sectorHash">Identifies the hash range of the sector.</param>
        /// <param name="txoOut">output txoPack to collect read results</param>
        private void Read(TxoPack txoIn, SectorIndex sectorIndex, Hash256 sectorHash, TxoPack txoOut)
        {
            if (_config.ImplicitSectors)
            {
                throw new InvalidOperationException();
            }

            var partition = PartitionByExplicitSector(sectorIndex, sectorHash, txoIn.GetForwardIterator());

            Read(partition, txoOut);
        }
Beispiel #3
0
        public void Write(TxoPack txos)
        {
            if (!_config.ImplicitSectors)
            {
                throw new InvalidOperationException();
            }

            var partition = PartitionByImplicitSector(txos.GetForwardIterator());

            Write(partition, txos);
        }
Beispiel #4
0
        public void Read(TxoPack txoIn, TxoPack txoOut)
        {
            if (!_config.ImplicitSectors)
            {
                throw new InvalidOperationException();
            }

            txoOut.Clear();
            var partition = PartitionByImplicitSector(txoIn.GetForwardIterator());

            Read(partition, txoOut);
        }
Beispiel #5
0
        private void Write(IEnumerable <SectorRange> partition, TxoPack txos)
        {
            // 'partition' is expected to be aligned with local sectors
            foreach (var range in partition)
            {
                var childSectorIndex = SectorIndex.Unknown;
                if (_store.TryRead(range.Index, out var sector))
                {
                    sector.Deserialize(_deserialized, out childSectorIndex);
                }
                else
                {
                    _deserialized.Clear(); // make empty TxoPack
                }

                _deserialized.AddOrMerge(txos.GetForwardIterator(), _merged, _lineage);

                // extra TXOs fit locally
                if (_merged.IsOverflowing(sector.Length))
                {
                    if (_subTable == null)
                    {
                        // Normally everything should have been set up during initialization
                        throw new SozuTableOverflowException();
                    }

                    // TODO: [tandabany] WIP for the overflowing part
                    _merged.Split((int)(sector.Length * .5), _kept, _flowDown);

                    if (childSectorIndex.IsUnknown())
                    {
                        var deltaBitDepth = _subTable._config.SectorBitDepth - _config.SectorBitDepth;
                        childSectorIndex = _subTable._store.AllocateSectors(1 << deltaBitDepth);
                    }

                    sector.Serialize(_kept, childSectorIndex);
                    _store.Write(range.Index, sector);

                    _subTable.Write(_flowDown, childSectorIndex, range.LeftTxid);
                }
                else
                {
                    sector.Serialize(_merged, childSectorIndex);
                    _store.Write(range.Index, sector);
                }
            }
        }