@@ -3,7 +3,11 @@ import {ChainForkConfig} from "@lodestar/config";
3
3
import { Db , Repository , KeyValue , FilterOptions } from "@lodestar/db" ;
4
4
import { Slot , Root , allForks , ssz } from "@lodestar/types" ;
5
5
import { bytesToInt } from "@lodestar/utils" ;
6
- import { getSignedBlockTypeFromBytes } from "../../util/multifork.js" ;
6
+ import { blindedOrFullBlockHashTreeRoot } from "@lodestar/state-transition" ;
7
+ import {
8
+ deserializeFullOrBlindedSignedBeaconBlock ,
9
+ serializeFullOrBlindedSignedBeaconBlock ,
10
+ } from "../../util/fullOrBlindedBlock.js" ;
7
11
import { Bucket , getBucketNameByValue } from "../buckets.js" ;
8
12
import { getRootIndexKey , getParentRootIndexKey } from "./blockArchiveIndex.js" ;
9
13
import { deleteParentRootIndex , deleteRootIndex , storeParentRootIndex , storeRootIndex } from "./blockArchiveIndex.js" ;
@@ -21,7 +25,7 @@ export type BlockArchiveBatchPutBinaryItem = KeyValue<Slot, Uint8Array> & {
21
25
/**
22
26
* Stores finalized blocks. Block slot is identifier.
23
27
*/
24
- export class BlockArchiveRepository extends Repository < Slot , allForks . SignedBeaconBlock > {
28
+ export class BlockArchiveRepository extends Repository < Slot , allForks . FullOrBlindedSignedBeaconBlock > {
25
29
constructor ( config : ChainForkConfig , db : Db ) {
26
30
const bucket = Bucket . allForks_blockArchive ;
27
31
const type = ssz . phase0 . SignedBeaconBlock ; // Pick some type but won't be used
@@ -30,17 +34,17 @@ export class BlockArchiveRepository extends Repository<Slot, allForks.SignedBeac
30
34
31
35
// Overrides for multi-fork
32
36
33
- encodeValue ( value : allForks . SignedBeaconBlock ) : Uint8Array {
34
- return this . config . getForkTypes ( value . message . slot ) . SignedBeaconBlock . serialize ( value ) ;
37
+ encodeValue ( value : allForks . FullOrBlindedSignedBeaconBlock ) : Uint8Array {
38
+ return serializeFullOrBlindedSignedBeaconBlock ( this . config , value ) ;
35
39
}
36
40
37
- decodeValue ( data : Uint8Array ) : allForks . SignedBeaconBlock {
38
- return getSignedBlockTypeFromBytes ( this . config , data ) . deserialize ( data ) ;
41
+ decodeValue ( data : Uint8Array ) : allForks . FullOrBlindedSignedBeaconBlock {
42
+ return deserializeFullOrBlindedSignedBeaconBlock ( this . config , data ) ;
39
43
}
40
44
41
45
// Handle key as slot
42
46
43
- getId ( value : allForks . SignedBeaconBlock ) : Slot {
47
+ getId ( value : allForks . FullOrBlindedSignedBeaconBlock ) : Slot {
44
48
return value . message . slot ;
45
49
}
46
50
@@ -50,8 +54,8 @@ export class BlockArchiveRepository extends Repository<Slot, allForks.SignedBeac
50
54
51
55
// Overrides to index
52
56
53
- async put ( key : Slot , value : allForks . SignedBeaconBlock ) : Promise < void > {
54
- const blockRoot = this . config . getForkTypes ( value . message . slot ) . BeaconBlock . hashTreeRoot ( value . message ) ;
57
+ async put ( key : Slot , value : allForks . FullOrBlindedSignedBeaconBlock ) : Promise < void > {
58
+ const blockRoot = blindedOrFullBlockHashTreeRoot ( this . config , value . message ) ;
55
59
const slot = value . message . slot ;
56
60
await Promise . all ( [
57
61
super . put ( key , value ) ,
@@ -60,12 +64,12 @@ export class BlockArchiveRepository extends Repository<Slot, allForks.SignedBeac
60
64
] ) ;
61
65
}
62
66
63
- async batchPut ( items : KeyValue < Slot , allForks . SignedBeaconBlock > [ ] ) : Promise < void > {
67
+ async batchPut ( items : KeyValue < Slot , allForks . FullOrBlindedSignedBeaconBlock > [ ] ) : Promise < void > {
64
68
await Promise . all ( [
65
69
super . batchPut ( items ) ,
66
70
Array . from ( items ) . map ( ( item ) => {
67
71
const slot = item . value . message . slot ;
68
- const blockRoot = this . config . getForkTypes ( slot ) . BeaconBlock . hashTreeRoot ( item . value . message ) ;
72
+ const blockRoot = blindedOrFullBlockHashTreeRoot ( this . config , item . value . message ) ;
69
73
return storeRootIndex ( this . db , slot , blockRoot ) ;
70
74
} ) ,
71
75
Array . from ( items ) . map ( ( item ) => {
@@ -84,25 +88,25 @@ export class BlockArchiveRepository extends Repository<Slot, allForks.SignedBeac
84
88
] ) ;
85
89
}
86
90
87
- async remove ( value : allForks . SignedBeaconBlock ) : Promise < void > {
91
+ async remove ( value : allForks . FullOrBlindedSignedBeaconBlock ) : Promise < void > {
88
92
await Promise . all ( [
89
93
super . remove ( value ) ,
90
- deleteRootIndex ( this . db , this . config . getForkTypes ( value . message . slot ) . SignedBeaconBlock , value ) ,
94
+ deleteRootIndex ( this . db , this . config . getForkTypes ( value . message . slot ) . BeaconBlock , value ) ,
91
95
deleteParentRootIndex ( this . db , value ) ,
92
96
] ) ;
93
97
}
94
98
95
- async batchRemove ( values : allForks . SignedBeaconBlock [ ] ) : Promise < void > {
99
+ async batchRemove ( values : allForks . FullOrBlindedSignedBeaconBlock [ ] ) : Promise < void > {
96
100
await Promise . all ( [
97
101
super . batchRemove ( values ) ,
98
102
Array . from ( values ) . map ( ( value ) =>
99
- deleteRootIndex ( this . db , this . config . getForkTypes ( value . message . slot ) . SignedBeaconBlock , value )
103
+ deleteRootIndex ( this . db , this . config . getForkTypes ( value . message . slot ) . BeaconBlock , value )
100
104
) ,
101
105
Array . from ( values ) . map ( ( value ) => deleteParentRootIndex ( this . db , value ) ) ,
102
106
] ) ;
103
107
}
104
108
105
- async * valuesStream ( opts ?: BlockFilterOptions ) : AsyncIterable < allForks . SignedBeaconBlock > {
109
+ async * valuesStream ( opts ?: BlockFilterOptions ) : AsyncIterable < allForks . FullOrBlindedSignedBeaconBlock > {
106
110
const firstSlot = this . getFirstSlot ( opts ) ;
107
111
const valuesStream = super . valuesStream ( opts ) ;
108
112
const step = ( opts && opts . step ) ?? 1 ;
@@ -114,13 +118,13 @@ export class BlockArchiveRepository extends Repository<Slot, allForks.SignedBeac
114
118
}
115
119
}
116
120
117
- async values ( opts ?: BlockFilterOptions ) : Promise < allForks . SignedBeaconBlock [ ] > {
121
+ async values ( opts ?: BlockFilterOptions ) : Promise < allForks . FullOrBlindedSignedBeaconBlock [ ] > {
118
122
return all ( this . valuesStream ( opts ) ) ;
119
123
}
120
124
121
125
// INDEX
122
126
123
- async getByRoot ( root : Root ) : Promise < allForks . SignedBeaconBlock | null > {
127
+ async getByRoot ( root : Root ) : Promise < allForks . FullOrBlindedSignedBeaconBlock | null > {
124
128
const slot = await this . getSlotByRoot ( root ) ;
125
129
return slot !== null ? this . get ( slot ) : null ;
126
130
}
@@ -130,7 +134,7 @@ export class BlockArchiveRepository extends Repository<Slot, allForks.SignedBeac
130
134
return slot !== null ? ( { key : slot , value : await this . getBinary ( slot ) } as KeyValue < Slot , Buffer > ) : null ;
131
135
}
132
136
133
- async getByParentRoot ( root : Root ) : Promise < allForks . SignedBeaconBlock | null > {
137
+ async getByParentRoot ( root : Root ) : Promise < allForks . FullOrBlindedSignedBeaconBlock | null > {
134
138
const slot = await this . getSlotByParentRoot ( root ) ;
135
139
return slot !== null ? this . get ( slot ) : null ;
136
140
}
0 commit comments