@@ -49,7 +49,7 @@ import (
49
49
// CompressedBody = { type: [0x04, 0x00], data: snappyFramed(rlp(body)) }
50
50
// CompressedReceipts = { type: [0x05, 0x00], data: snappyFramed(rlp(receipts)) }
51
51
// TotalDifficulty = { type: [0x06, 0x00], data: uint256(header.total_difficulty) }
52
- // Accumulator = { type: [0x07, 0x00], data: accumulator-root }
52
+ // AccumulatorRoot = { type: [0x07, 0x00], data: accumulator-root }
53
53
// BlockIndex = { type: [0x32, 0x66], data: block-index }
54
54
//
55
55
// Accumulator is computed by constructing an SSZ list of header-records of length at most
@@ -64,8 +64,8 @@ import (
64
64
// block-index := starting-number | index | index | index ... | count
65
65
//
66
66
// starting-number is the first block number in the archive. Every index is a
67
- // defined relative to index's location in the file . The total number of block
68
- // entries in the file is recorded in count.
67
+ // defined relative to beginning of the record . The total number of block
68
+ // entries in the file is recorded with count.
69
69
//
70
70
// Due to the accumulator size limit of 8192, the maximum number of blocks in
71
71
// an Era1 batch is also 8192.
@@ -115,12 +115,14 @@ func (b *Builder) Add(block *types.Block, receipts types.Receipts, td *big.Int)
115
115
func (b * Builder ) AddRLP (header , body , receipts []byte , number uint64 , hash common.Hash , td , difficulty * big.Int ) error {
116
116
// Write Era1 version entry before first block.
117
117
if b .startNum == nil {
118
- if err := writeVersion (b .w ); err != nil {
118
+ n , err := b .w .Write (TypeVersion , nil )
119
+ if err != nil {
119
120
return err
120
121
}
121
- n := number
122
- b .startNum = & n
122
+ startNum := number
123
+ b .startNum = & startNum
123
124
b .startTd = new (big.Int ).Sub (td , difficulty )
125
+ b .written += n
124
126
}
125
127
if len (b .indexes ) >= MaxEra1Size {
126
128
return fmt .Errorf ("exceeds maximum batch size of %d" , MaxEra1Size )
@@ -169,7 +171,7 @@ func (b *Builder) Finalize() (common.Hash, error) {
169
171
return common.Hash {}, fmt .Errorf ("error writing accumulator: %w" , err )
170
172
}
171
173
// Get beginning of index entry to calculate block relative offset.
172
- base := int64 (b .written + ( 3 * 8 )) // skip e2store header (type, length) and start block
174
+ base := int64 (b .written )
173
175
174
176
// Construct block index. Detailed format described in Builder
175
177
// documentation, but it is essentially encoded as:
@@ -186,7 +188,7 @@ func (b *Builder) Finalize() (common.Hash, error) {
186
188
// relative offset, the corresponding block can be quickly read by
187
189
// performing a seek relative to the current position.
188
190
for i , offset := range b .indexes {
189
- relative := int64 (offset ) - ( base + int64 ( i ) * 8 )
191
+ relative := int64 (offset ) - base
190
192
binary .LittleEndian .PutUint64 (index [8 + i * 8 :], uint64 (relative ))
191
193
}
192
194
binary .LittleEndian .PutUint64 (index [8 + count * 8 :], uint64 (count ))
@@ -220,9 +222,3 @@ func (b *Builder) snappyWrite(typ uint16, in []byte) error {
220
222
}
221
223
return nil
222
224
}
223
-
224
- // writeVersion writes a version entry to e2store.
225
- func writeVersion (w * e2store.Writer ) error {
226
- _ , err := w .Write (TypeVersion , nil )
227
- return err
228
- }
0 commit comments