github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/message/codec.go (about)

     1  // (c) 2019-2022, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package message
     5  
     6  import (
     7  	"github.com/MetalBlockchain/metalgo/codec"
     8  	"github.com/MetalBlockchain/metalgo/codec/linearcodec"
     9  	"github.com/MetalBlockchain/metalgo/utils/units"
    10  	"github.com/MetalBlockchain/metalgo/utils/wrappers"
    11  )
    12  
    13  const (
    14  	Version        = uint16(0)
    15  	maxMessageSize = 1 * units.MiB
    16  )
    17  
    18  var (
    19  	Codec           codec.Manager
    20  	CrossChainCodec codec.Manager
    21  )
    22  
    23  func init() {
    24  	Codec = codec.NewManager(maxMessageSize)
    25  	c := linearcodec.NewDefault()
    26  
    27  	errs := wrappers.Errs{}
    28  	errs.Add(
    29  		// Gossip types
    30  		c.RegisterType(TxsGossip{}),
    31  
    32  		// Types for state sync frontier consensus
    33  		c.RegisterType(SyncSummary{}),
    34  
    35  		// state sync types
    36  		c.RegisterType(BlockRequest{}),
    37  		c.RegisterType(BlockResponse{}),
    38  		c.RegisterType(LeafsRequest{}),
    39  		c.RegisterType(LeafsResponse{}),
    40  		c.RegisterType(CodeRequest{}),
    41  		c.RegisterType(CodeResponse{}),
    42  
    43  		// Warp request types
    44  		c.RegisterType(SignatureRequest{}),
    45  		c.RegisterType(SignatureResponse{}),
    46  
    47  		Codec.RegisterCodec(Version, c),
    48  	)
    49  
    50  	if errs.Errored() {
    51  		panic(errs.Err)
    52  	}
    53  
    54  	CrossChainCodec = codec.NewManager(maxMessageSize)
    55  	ccc := linearcodec.NewDefault()
    56  
    57  	errs = wrappers.Errs{}
    58  	errs.Add(
    59  		// CrossChainRequest Types
    60  		ccc.RegisterType(EthCallRequest{}),
    61  		ccc.RegisterType(EthCallResponse{}),
    62  
    63  		CrossChainCodec.RegisterCodec(Version, ccc),
    64  	)
    65  
    66  	if errs.Errored() {
    67  		panic(errs.Err)
    68  	}
    69  }