-
Notifications
You must be signed in to change notification settings - Fork 2
/
codec.go
35 lines (28 loc) · 868 Bytes
/
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
// Copyright (C) 2019-2023, Lux Partners Limited. All rights reserved.
// See the file LICENSE for licensing terms.
package block
import (
"math"
"github.com/luxdefi/node/codec"
"github.com/luxdefi/node/codec/linearcodec"
"github.com/luxdefi/node/utils"
)
const codecVersion = 0
// The maximum block size is enforced by the p2p message size limit.
// See: [constants.DefaultMaxMessageSize]
//
// Invariant: This codec must never be used to unmarshal a slice unless it is a
// `[]byte`. Otherwise a malicious payload could cause an OOM.
var c codec.Manager
func init() {
linearCodec := linearcodec.NewCustomMaxLength(math.MaxUint32)
c = codec.NewManager(math.MaxInt)
err := utils.Err(
linearCodec.RegisterType(&statelessBlock{}),
linearCodec.RegisterType(&option{}),
c.RegisterCodec(codecVersion, linearCodec),
)
if err != nil {
panic(err)
}
}