This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.go
212 lines (162 loc) · 5.91 KB
/
types.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package eth2node
import (
verkle "github.com/protolambda/go-verkle"
"github.com/protolambda/zrnt/eth2/beacon"
"github.com/protolambda/ztyp/codec"
"github.com/protolambda/ztyp/tree"
)
type VerticalIndex uint64
// Aliases for ease of use
type ValidatorIndex = beacon.ValidatorIndex
type Root = beacon.Root
type Shard = beacon.Shard
type Slot = beacon.Slot
type Epoch = beacon.Epoch
type BLSSignature = beacon.BLSSignature
type PointIndex uint64
type Point = verkle.Big
type ShardBlock struct {
ShardParentRoot Root
BeaconParentRoot Root
Slot Slot
Shard Shard
ProposerIndex ValidatorIndex
Body ShardBlockData
}
func (d *ShardBlock) Deserialize(dr *codec.DecodingReader) error {
return dr.Container(&d.ShardParentRoot, &d.BeaconParentRoot, &d.Slot, &d.Shard, &d.ProposerIndex, &d.Body)
}
func (d *ShardBlock) Serialize(w *codec.EncodingWriter) error {
return w.Container(&d.ShardParentRoot, &d.BeaconParentRoot, &d.Slot, &d.Shard, &d.ProposerIndex, &d.Body)
}
func (d *ShardBlock) ByteLength() uint64 {
return codec.ContainerLength(&d.ShardParentRoot, &d.BeaconParentRoot, &d.Slot, &d.Shard, &d.ProposerIndex, &d.Body)
}
func (d *ShardBlock) FixedLength() uint64 {
return 0
}
func (d *ShardBlock) HashTreeRoot(hFn tree.HashFn) Root {
return hFn.HashTreeRoot(&d.ShardParentRoot, &d.BeaconParentRoot, &d.Slot, &d.Shard, &d.ProposerIndex, &d.Body)
}
type SignedShardBlock struct {
Message ShardBlock
Signature BLSSignature
}
func (d *SignedShardBlock) Deserialize(dr *codec.DecodingReader) error {
return dr.Container(&d.Message, &d.Signature)
}
func (d *SignedShardBlock) Serialize(w *codec.EncodingWriter) error {
return w.Container(&d.Message, &d.Signature)
}
func (d *SignedShardBlock) ByteLength() uint64 {
return codec.ContainerLength(&d.Message, &d.Signature)
}
func (d *SignedShardBlock) FixedLength() uint64 {
return 0
}
func (d *SignedShardBlock) HashTreeRoot(hFn tree.HashFn) Root {
return hFn.HashTreeRoot(&d.Message, &d.Signature)
}
type ShardBlockHeader struct {
ShardParentRoot Root
BeaconParentRoot Root
Slot Slot
Shard Shard
ProposerIndex ValidatorIndex
BodyRoot Root
}
func (d *ShardBlockHeader) Deserialize(dr *codec.DecodingReader) error {
return dr.FixedLenContainer(&d.ShardParentRoot, &d.BeaconParentRoot, &d.Slot, &d.Shard, &d.ProposerIndex, &d.BodyRoot)
}
func (d *ShardBlockHeader) Serialize(w *codec.EncodingWriter) error {
return w.FixedLenContainer(&d.ShardParentRoot, &d.BeaconParentRoot, &d.Slot, &d.Shard, &d.ProposerIndex, &d.BodyRoot)
}
func (d *ShardBlockHeader) ByteLength() uint64 {
return codec.ContainerLength(&d.ShardParentRoot, &d.BeaconParentRoot, &d.Slot, &d.Shard, &d.ProposerIndex, &d.BodyRoot)
}
func (d *ShardBlockHeader) FixedLength() uint64 {
return codec.ContainerLength(&d.ShardParentRoot, &d.BeaconParentRoot, &d.Slot, &d.Shard, &d.ProposerIndex, &d.BodyRoot)
}
func (d *ShardBlockHeader) HashTreeRoot(hFn tree.HashFn) Root {
return hFn.HashTreeRoot(&d.ShardParentRoot, &d.BeaconParentRoot, &d.Slot, &d.Shard, &d.ProposerIndex, &d.BodyRoot)
}
type SignedShardBlockHeader struct {
Message ShardBlockHeader
Signature BLSSignature
}
func (d *SignedShardBlockHeader) Deserialize(dr *codec.DecodingReader) error {
return dr.FixedLenContainer(&d.Message, &d.Signature)
}
func (d *SignedShardBlockHeader) Serialize(w *codec.EncodingWriter) error {
return w.FixedLenContainer(&d.Message, &d.Signature)
}
func (d *SignedShardBlockHeader) ByteLength() uint64 {
return codec.ContainerLength(&d.Message, &d.Signature)
}
func (d *SignedShardBlockHeader) FixedLength() uint64 {
return codec.ContainerLength(&d.Message, &d.Signature)
}
func (d *SignedShardBlockHeader) HashTreeRoot(hFn tree.HashFn) Root {
return hFn.HashTreeRoot(&d.Message, &d.Signature)
}
// TODO: normally would put this in spec config, but that's not up to date with prototype config options
const blockDataLimit = 1 << 20
type ShardBlockData []byte
func (d *ShardBlockData) Deserialize(dr *codec.DecodingReader) error {
return dr.ByteList((*[]byte)(d), blockDataLimit)
}
func (d *ShardBlockData) Serialize(w *codec.EncodingWriter) error {
return w.Write(*d)
}
func (d *ShardBlockData) ByteLength() uint64 {
return uint64(len(*d))
}
func (d *ShardBlockData) FixedLength() uint64 {
return 0
}
func (d *ShardBlockData) HashTreeRoot(hFn tree.HashFn) Root {
return hFn.ByteListHTR(*d, blockDataLimit)
}
// TODO
const sampleByteLength = 1 << 20
// TODO naming
type ShardBlockDataChunk []byte
func (d *ShardBlockDataChunk) Deserialize(dr *codec.DecodingReader) error {
return dr.ByteVector((*[]byte)(d), sampleByteLength)
}
func (d *ShardBlockDataChunk) Serialize(w *codec.EncodingWriter) error {
return w.Write(*d)
}
func (d *ShardBlockDataChunk) ByteLength() uint64 {
return uint64(len(*d))
}
func (d *ShardBlockDataChunk) FixedLength() uint64 {
return uint64(len(*d))
}
func (d *ShardBlockDataChunk) HashTreeRoot(hFn tree.HashFn) Root {
return hFn.ByteVectorHTR(*d)
}
type DASMessage struct {
Slot Slot
Chunk ShardBlockDataChunk
Index VerticalIndex
// TODO: does this need a ref to the shard block root, so it can be matched with the header easily?
ShardHeaderRoot Root
// Proof to show that the chunk is part of the vector commitment in the header.
KateProof beacon.BLSPubkey
}
func (d *DASMessage) Deserialize(dr *codec.DecodingReader) error {
return dr.FixedLenContainer(&d.Slot, &d.Chunk, &d.ShardHeaderRoot, &d.KateProof)
}
func (d *DASMessage) Serialize(w *codec.EncodingWriter) error {
return w.FixedLenContainer(&d.Slot, &d.Chunk, &d.ShardHeaderRoot, &d.KateProof)
}
func (d *DASMessage) ByteLength() uint64 {
return codec.ContainerLength(&d.Slot, &d.Chunk, &d.ShardHeaderRoot, &d.KateProof)
}
func (d *DASMessage) FixedLength() uint64 {
return codec.ContainerLength(&d.Slot, &d.Chunk, &d.ShardHeaderRoot, &d.KateProof)
}
func (d *DASMessage) HashTreeRoot(hFn tree.HashFn) Root {
return hFn.HashTreeRoot(&d.Slot, &d.Chunk, &d.ShardHeaderRoot, &d.KateProof)
}