forked from ava-labs/subnet-evm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.go
70 lines (55 loc) · 1.58 KB
/
codec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// (c) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package message
import (
"github.com/MetalBlockchain/metalgo/codec"
"github.com/MetalBlockchain/metalgo/codec/linearcodec"
"github.com/MetalBlockchain/metalgo/utils/units"
"github.com/MetalBlockchain/metalgo/utils/wrappers"
)
const (
Version = uint16(0)
maxMessageSize = 2*units.MiB - 64*units.KiB // Subtract 64 KiB from p2p network cap to leave room for encoding overhead from AvalancheGo
)
var (
Codec codec.Manager
CrossChainCodec codec.Manager
)
func init() {
Codec = codec.NewManager(maxMessageSize)
c := linearcodec.NewDefault()
errs := wrappers.Errs{}
errs.Add(
// Gossip types
c.RegisterType(EthTxsGossip{}),
// Types for state sync frontier consensus
c.RegisterType(SyncSummary{}),
// state sync types
c.RegisterType(BlockRequest{}),
c.RegisterType(BlockResponse{}),
c.RegisterType(LeafsRequest{}),
c.RegisterType(LeafsResponse{}),
c.RegisterType(CodeRequest{}),
c.RegisterType(CodeResponse{}),
// Warp request types
c.RegisterType(MessageSignatureRequest{}),
c.RegisterType(BlockSignatureRequest{}),
c.RegisterType(SignatureResponse{}),
Codec.RegisterCodec(Version, c),
)
if errs.Errored() {
panic(errs.Err)
}
CrossChainCodec = codec.NewManager(maxMessageSize)
ccc := linearcodec.NewDefault()
errs = wrappers.Errs{}
errs.Add(
// CrossChainRequest Types
ccc.RegisterType(EthCallRequest{}),
ccc.RegisterType(EthCallResponse{}),
CrossChainCodec.RegisterCodec(Version, ccc),
)
if errs.Errored() {
panic(errs.Err)
}
}