github.com/ethereum-optimism/optimism@v1.7.2/op-node/rollup/derive/params.go (about) 1 package derive 2 3 import ( 4 "encoding/hex" 5 "errors" 6 "fmt" 7 8 plasma "github.com/ethereum-optimism/optimism/op-plasma" 9 ) 10 11 // count the tagging info as 200 in terms of buffer size. 12 const frameOverhead = 200 13 14 // frameSize calculates the size of the frame + overhead for 15 // storing the frame. The sum of the frame size of each frame in 16 // a channel determines the channel's size. The sum of the channel 17 // sizes is used for pruning & compared against `MaxChannelBankSize` 18 func frameSize(frame Frame) uint64 { 19 return uint64(len(frame.Data)) + frameOverhead 20 } 21 22 const DerivationVersion0 = 0 23 24 // DerivationVersion1 is reserved for batcher transactions containing plasma commitments. 25 const DerivationVersion1 = plasma.TxDataVersion1 26 27 // MaxSpanBatchSize is the maximum amount of bytes that will be needed 28 // to decode every span batch field. This value cannot be larger than 29 // MaxRLPBytesPerChannel because single batch cannot be larger than channel size. 30 const MaxSpanBatchSize = MaxRLPBytesPerChannel 31 32 // MaxChannelBankSize is the amount of memory space, in number of bytes, 33 // till the bank is pruned by removing channels, 34 // starting with the oldest channel. 35 const MaxChannelBankSize = 100_000_000 36 37 // MaxRLPBytesPerChannel is the maximum amount of bytes that will be read from 38 // a channel. This limit is set when decoding the RLP. 39 const MaxRLPBytesPerChannel = 10_000_000 40 41 // DuplicateErr is returned when a newly read frame is already known 42 var DuplicateErr = errors.New("duplicate frame") 43 44 // ChannelIDLength defines the length of the channel IDs 45 const ChannelIDLength = 16 46 47 // ChannelID is an opaque identifier for a channel. It is 128 bits to be globally unique. 48 type ChannelID [ChannelIDLength]byte 49 50 func (id ChannelID) String() string { 51 return fmt.Sprintf("%x", id[:]) 52 } 53 54 // TerminalString implements log.TerminalStringer, formatting a string for console output during logging. 55 func (id ChannelID) TerminalString() string { 56 return fmt.Sprintf("%x..%x", id[:3], id[13:]) 57 } 58 59 func (id ChannelID) MarshalText() ([]byte, error) { 60 return []byte(id.String()), nil 61 } 62 63 func (id *ChannelID) UnmarshalText(text []byte) error { 64 h, err := hex.DecodeString(string(text)) 65 if err != nil { 66 return err 67 } 68 if len(h) != ChannelIDLength { 69 return errors.New("invalid length") 70 } 71 copy(id[:], h) 72 return nil 73 }