@@ -9,6 +9,17 @@ import (
9
9
"github.com/gordian-engine/gordian/gturbine/erasure"
10
10
)
11
11
12
+ type ShredGroup struct {
13
+ DataShreds []* gturbine.Shred
14
+ RecoveryShreds []* gturbine.Shred
15
+ TotalDataShreds int
16
+ TotalRecoveryShreds int
17
+ GroupID string // Changed to string for UUID
18
+ BlockHash []byte
19
+ Height uint64 // Added to struct level
20
+ OriginalSize int
21
+ }
22
+
12
23
// FromBlock creates a new ShredGroup from a block of data
13
24
func NewShredGroup (block []byte , height uint64 , dataShreds , recoveryShreds int , chunkSize uint32 ) (* ShredGroup , error ) {
14
25
if len (block ) == 0 {
@@ -32,12 +43,14 @@ func NewShredGroup(block []byte, height uint64, dataShreds, recoveryShreds int,
32
43
33
44
// Create new shred group
34
45
group := & ShredGroup {
35
- DataShreds : make ([]* gturbine.Shred , dataShreds ),
36
- RecoveryShreds : make ([]* gturbine.Shred , recoveryShreds ),
37
- GroupID : uuid .New ().String (),
38
- BlockHash : blockHash [:],
39
- Height : height ,
40
- OriginalSize : len (block ),
46
+ DataShreds : make ([]* gturbine.Shred , dataShreds ),
47
+ RecoveryShreds : make ([]* gturbine.Shred , recoveryShreds ),
48
+ TotalDataShreds : dataShreds ,
49
+ TotalRecoveryShreds : recoveryShreds ,
50
+ GroupID : uuid .New ().String (),
51
+ BlockHash : blockHash [:],
52
+ Height : height ,
53
+ OriginalSize : len (block ),
41
54
}
42
55
43
56
// Create fixed-size data chunks
@@ -71,35 +84,37 @@ func NewShredGroup(block []byte, height uint64, dataShreds, recoveryShreds int,
71
84
// Create data shreds
72
85
for i := range dataBytes {
73
86
group .DataShreds [i ] = & gturbine.Shred {
74
- Index : uint32 (i ),
75
- Total : uint32 (dataShreds ),
76
- Data : dataBytes [i ],
77
- BlockHash : blockHash [:],
78
- GroupID : group .GroupID ,
79
- Height : height ,
80
- FullDataSize : group .OriginalSize ,
87
+ Index : i ,
88
+ TotalDataShreds : dataShreds ,
89
+ TotalRecoveryShreds : recoveryShreds ,
90
+ Data : dataBytes [i ],
91
+ BlockHash : blockHash [:],
92
+ GroupID : group .GroupID ,
93
+ Height : height ,
94
+ FullDataSize : group .OriginalSize ,
81
95
}
82
96
}
83
97
84
98
// Create recovery shreds
85
99
for i := range recoveryBytes {
86
100
group .RecoveryShreds [i ] = & gturbine.Shred {
87
- Index : uint32 (i ),
88
- Total : uint32 (len (recoveryBytes )),
89
- Data : recoveryBytes [i ],
90
- BlockHash : blockHash [:],
91
- GroupID : group .GroupID ,
92
- Height : height ,
93
- FullDataSize : group .OriginalSize ,
101
+ Index : i ,
102
+ TotalDataShreds : dataShreds ,
103
+ TotalRecoveryShreds : recoveryShreds ,
104
+ Data : recoveryBytes [i ],
105
+ BlockHash : blockHash [:],
106
+ GroupID : group .GroupID ,
107
+ Height : height ,
108
+ FullDataSize : group .OriginalSize ,
94
109
}
95
110
}
96
111
97
112
return group , nil
98
113
}
99
114
100
- // IsComplete checks if enough shreds are available for reconstruction
115
+ // IsFull checks if enough shreds are available for reconstruction
101
116
// NOTE: we'd like shredgroup to know the data threshold as a property on the shredgroup
102
- func (g * ShredGroup ) IsComplete (dataThreshold int ) bool {
117
+ func (g * ShredGroup ) IsFull (dataThreshold int ) bool {
103
118
104
119
// TODO: ensure that we've met the threshold by quorum of both data and recovery using the
105
120
valid := 0
@@ -191,7 +206,7 @@ func (g *ShredGroup) CollectDataShred(shred *gturbine.Shred) (bool, error) {
191
206
}
192
207
193
208
g .DataShreds [shred .Index ] = shred
194
- return g .IsComplete (len (g .DataShreds )), nil
209
+ return g .IsFull (len (g .DataShreds )), nil
195
210
}
196
211
197
212
// CollectRecoveryShred adds a recovery shred to the group
@@ -217,5 +232,5 @@ func (g *ShredGroup) CollectRecoveryShred(shred *gturbine.Shred) (bool, error) {
217
232
}
218
233
219
234
g .RecoveryShreds [shred .Index ] = shred
220
- return g .IsComplete (len (g .DataShreds )), nil
235
+ return g .IsFull (len (g .DataShreds )), nil
221
236
}
0 commit comments