• cody-wang-cb's avatar
    Fjord: Add Brotli channel compression support (#10358) · 4b8f6f4f
    cody-wang-cb authored
    * wip
    
    * wip
    
    * fix
    
    * fix
    
    * fix
    
    * fix
    
    * address some of the bots comments
    
    * use version bit of 1
    
    * fix lint
    
    * adding compression type
    
    * update batch reader
    
    * abstract span channel compressor
    
    * test and singular batch compressor
    
    * fix
    
    * lint
    
    * move channel compressor as interface
    
    * add base class
    
    * fix go mod
    
    * test fixes
    
    * address comments
    
    * fix
    
    * fix
    
    * revert channel builder test
    
    * revert ratio compressor test
    
    * add checks to accept brotli only post fjord
    
    * revemo unnecessary in test
    
    * fix forge-std
    
    * gofmt
    
    * address comments
    
    * remove methods in compressor
    
    * fix error msg
    
    * add compression algo flag to optional flags
    
    * add Clone() function
    
    ---------
    Co-authored-by: default avatarRoberto Bayardo <roberto.bayardo@coinbase.com>
    4b8f6f4f
config.go 983 Bytes
package compressor

import (
	"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
)

type Config struct {
	// TargetOutputSize is the target size that the compressed data should reach.
	// The shadow compressor guarantees that the compressed data stays below
	// this bound. The ratio compressor might go over.
	TargetOutputSize uint64
	// ApproxComprRatio to assume (only ratio compressor). Should be slightly smaller
	// than average from experiments to avoid the chances of creating a small
	// additional leftover frame.
	ApproxComprRatio float64
	// Kind of compressor to use. Must be one of KindKeys. If unset, NewCompressor
	// will default to RatioKind.
	Kind string

	// Type of compression algorithm to use. Must be one of [zlib, brotli-(9|10|11)]
	CompressionAlgo derive.CompressionAlgo
}

func (c Config) NewCompressor() (derive.Compressor, error) {
	if k, ok := Kinds[c.Kind]; ok {
		return k(c)
	}
	// default to RatioCompressor
	return Kinds[RatioKind](c)
}