Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
496 additions
and
426 deletions.
There are no files selected for viewing
123 changes: 0 additions & 123 deletions
123
casper/src/main/scala/coop/rchain/casper/ReportMemStore.scala
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
casper/src/main/scala/coop/rchain/casper/ReportStore.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package coop.rchain.casper | ||
|
||
import cats.effect.Sync | ||
import com.google.protobuf.ByteString | ||
import coop.rchain.blockstorage.dag.codecs | ||
import coop.rchain.casper.protocol.BlockEventInfo | ||
import coop.rchain.shared.Compression | ||
import coop.rchain.shared.syntax._ | ||
import coop.rchain.store.{KeyValueStoreManager, KeyValueTypedStore} | ||
import net.jpountz.lz4.{LZ4CompressorWithLength, LZ4DecompressorWithLength} | ||
import scodec.SizeBound.unknown | ||
import scodec.{Attempt, Codec, DecodeResult, SizeBound} | ||
import scodec.bits.BitVector | ||
|
||
object ReportStore { | ||
|
||
val compressor = new LZ4CompressorWithLength(Compression.factory.fastCompressor()) | ||
// val compressor = new LZ4CompressorWithLength(factory.highCompressor(17)) // Max compression | ||
val decompressor = new LZ4DecompressorWithLength(Compression.factory.fastDecompressor()) | ||
|
||
def compressBytes(bytes: Array[Byte]): Array[Byte] = compressor.compress(bytes) | ||
|
||
type ReportStore[F[_]] = KeyValueTypedStore[F, ByteString, BlockEventInfo] | ||
|
||
val blockEventInfoCodec = new Codec[BlockEventInfo] { | ||
override def encode(value: BlockEventInfo): Attempt[BitVector] = | ||
Attempt.successful(BitVector(compressor.compress(value.toByteArray))) | ||
|
||
override def decode(bits: BitVector): Attempt[DecodeResult[BlockEventInfo]] = | ||
Attempt.successful( | ||
DecodeResult( | ||
BlockEventInfo.parseFrom(decompressor.decompress(bits.toByteArray)), | ||
BitVector.empty | ||
) | ||
) | ||
|
||
override def sizeBound: SizeBound = unknown | ||
} | ||
|
||
def store[F[_]: Sync](kvm: KeyValueStoreManager[F]): F[ReportStore[F]] = | ||
kvm.database("reporting-cache", codecs.codecByteString, blockEventInfoCodec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.