1
- import { CachedBeaconStateAllForks , computeEpochAtSlot , DataAvailableStatus } from "@lodestar/state-transition" ;
2
- import { MaybeValidExecutionStatus } from "@lodestar/fork-choice" ;
1
+ import { CachedBeaconStateAllForks , computeEpochAtSlot } from "@lodestar/state-transition" ;
2
+ import { MaybeValidExecutionStatus , DataAvailabilityStatus } from "@lodestar/fork-choice" ;
3
3
import { allForks , deneb , Slot , RootHex } from "@lodestar/types" ;
4
- import { ForkSeq } from "@lodestar/params" ;
4
+ import { ForkSeq , ForkName } from "@lodestar/params" ;
5
5
import { ChainForkConfig } from "@lodestar/config" ;
6
6
7
7
export enum BlockInputType {
8
- preDeneb = "preDeneb" ,
9
- postDeneb = "postDeneb" ,
10
- blobsPromise = "blobsPromise" ,
8
+ // preData is preDeneb
9
+ preData = "preData" ,
10
+ // data is out of available window, can be used to sync forward and keep adding to forkchoice
11
+ outOfRangeData = "outOfRangeData" ,
12
+ availableData = "availableData" ,
13
+ dataPromise = "dataPromise" ,
11
14
}
12
15
13
16
/** Enum to represent where blocks come from */
@@ -31,21 +34,28 @@ export enum GossipedInputType {
31
34
blob = "blob" ,
32
35
}
33
36
34
- export type BlobsCache = Map < number , { blobSidecar : deneb . BlobSidecar ; blobBytes : Uint8Array | null } > ;
37
+ type BlobsCacheMap = Map < number , { blobSidecar : deneb . BlobSidecar ; blobBytes : Uint8Array | null } > ;
38
+
39
+ type ForkBlobsInfo = { fork : ForkName . deneb } ;
40
+ type BlobsData = { blobs : deneb . BlobSidecars ; blobsBytes : ( Uint8Array | null ) [ ] ; blobsSource : BlobsSource } ;
41
+ export type BlockInputDataBlobs = ForkBlobsInfo & BlobsData ;
42
+ export type BlockInputData = BlockInputDataBlobs ;
43
+
35
44
export type BlockInputBlobs = { blobs : deneb . BlobSidecars ; blobsBytes : ( Uint8Array | null ) [ ] ; blobsSource : BlobsSource } ;
36
- type CachedBlobs = {
37
- blobsCache : BlobsCache ;
38
- availabilityPromise : Promise < BlockInputBlobs > ;
39
- resolveAvailability : ( blobs : BlockInputBlobs ) => void ;
40
- } ;
45
+ type Availability < T > = { availabilityPromise : Promise < T > ; resolveAvailability : ( data : T ) => void } ;
46
+
47
+ type CachedBlobs = { blobsCache : BlobsCacheMap } & Availability < BlockInputDataBlobs > ;
48
+ export type CachedData = ForkBlobsInfo & CachedBlobs ;
41
49
42
50
export type BlockInput = { block : allForks . SignedBeaconBlock ; source : BlockSource ; blockBytes : Uint8Array | null } & (
43
- | { type : BlockInputType . preDeneb }
44
- | ( { type : BlockInputType . postDeneb } & BlockInputBlobs )
51
+ | { type : BlockInputType . preData | BlockInputType . outOfRangeData }
52
+ | ( { type : BlockInputType . availableData } & { blockData : BlockInputData } )
45
53
// the blobsSource here is added to BlockInputBlobs when availability is resolved
46
- | ( { type : BlockInputType . blobsPromise } & CachedBlobs )
54
+ | ( { type : BlockInputType . dataPromise } & { cachedData : CachedData } )
47
55
) ;
48
- export type NullBlockInput = { block : null ; blockRootHex : RootHex ; blockInputPromise : Promise < BlockInput > } & CachedBlobs ;
56
+ export type NullBlockInput = { block : null ; blockRootHex : RootHex ; blockInputPromise : Promise < BlockInput > } & {
57
+ cachedData : CachedData ;
58
+ } ;
49
59
50
60
export function blockRequiresBlobs ( config : ChainForkConfig , blockSlot : Slot , clockSlot : Slot ) : boolean {
51
61
return (
@@ -56,7 +66,7 @@ export function blockRequiresBlobs(config: ChainForkConfig, blockSlot: Slot, clo
56
66
}
57
67
58
68
export const getBlockInput = {
59
- preDeneb (
69
+ preData (
60
70
config : ChainForkConfig ,
61
71
block : allForks . SignedBeaconBlock ,
62
72
source : BlockSource ,
@@ -66,61 +76,76 @@ export const getBlockInput = {
66
76
throw Error ( `Post Deneb block slot ${ block . message . slot } ` ) ;
67
77
}
68
78
return {
69
- type : BlockInputType . preDeneb ,
79
+ type : BlockInputType . preData ,
80
+ block,
81
+ source,
82
+ blockBytes,
83
+ } ;
84
+ } ,
85
+
86
+ // This isn't used right now but we might enable importing blobs into forkchoice from a point
87
+ // where data is not guaranteed to be available to hopefully reach a point where we have
88
+ // available data. Hence the validator duties can't be performed on outOfRangeData
89
+ //
90
+ // This can help with some of the requests of syncing without data for some use cases for e.g.
91
+ // building states or where importing data isn't important if valid child exists like ILs
92
+ outOfRangeData (
93
+ config : ChainForkConfig ,
94
+ block : allForks . SignedBeaconBlock ,
95
+ source : BlockSource ,
96
+ blockBytes : Uint8Array | null
97
+ ) : BlockInput {
98
+ if ( config . getForkSeq ( block . message . slot ) < ForkSeq . deneb ) {
99
+ throw Error ( `Pre Deneb block slot ${ block . message . slot } ` ) ;
100
+ }
101
+ return {
102
+ type : BlockInputType . outOfRangeData ,
70
103
block,
71
104
source,
72
105
blockBytes,
73
106
} ;
74
107
} ,
75
108
76
- postDeneb (
109
+ availableData (
77
110
config : ChainForkConfig ,
78
111
block : allForks . SignedBeaconBlock ,
79
112
source : BlockSource ,
80
- blobs : deneb . BlobSidecars ,
81
- blobsSource : BlobsSource ,
82
113
blockBytes : Uint8Array | null ,
83
- blobsBytes : ( Uint8Array | null ) [ ]
114
+ blockData : BlockInputData
84
115
) : BlockInput {
85
116
if ( config . getForkSeq ( block . message . slot ) < ForkSeq . deneb ) {
86
117
throw Error ( `Pre Deneb block slot ${ block . message . slot } ` ) ;
87
118
}
88
119
return {
89
- type : BlockInputType . postDeneb ,
120
+ type : BlockInputType . availableData ,
90
121
block,
91
122
source,
92
- blobs,
93
- blobsSource,
94
123
blockBytes,
95
- blobsBytes ,
124
+ blockData ,
96
125
} ;
97
126
} ,
98
127
99
- blobsPromise (
128
+ dataPromise (
100
129
config : ChainForkConfig ,
101
130
block : allForks . SignedBeaconBlock ,
102
131
source : BlockSource ,
103
- blobsCache : BlobsCache ,
104
132
blockBytes : Uint8Array | null ,
105
- availabilityPromise : Promise < BlockInputBlobs > ,
106
- resolveAvailability : ( blobs : BlockInputBlobs ) => void
133
+ cachedData : CachedData
107
134
) : BlockInput {
108
135
if ( config . getForkSeq ( block . message . slot ) < ForkSeq . deneb ) {
109
136
throw Error ( `Pre Deneb block slot ${ block . message . slot } ` ) ;
110
137
}
111
138
return {
112
- type : BlockInputType . blobsPromise ,
139
+ type : BlockInputType . dataPromise ,
113
140
block,
114
141
source,
115
- blobsCache,
116
142
blockBytes,
117
- availabilityPromise,
118
- resolveAvailability,
143
+ cachedData,
119
144
} ;
120
145
} ,
121
146
} ;
122
147
123
- export function getBlockInputBlobs ( blobsCache : BlobsCache ) : Omit < BlockInputBlobs , "blobsSource" > {
148
+ export function getBlockInputBlobs ( blobsCache : BlobsCacheMap ) : Omit < BlobsData , "blobsSource" > {
124
149
const blobs = [ ] ;
125
150
const blobsBytes = [ ] ;
126
151
@@ -206,7 +231,7 @@ export type FullyVerifiedBlock = {
206
231
* used in optimistic sync or for merge block
207
232
*/
208
233
executionStatus : MaybeValidExecutionStatus ;
209
- dataAvailableStatus : DataAvailableStatus ;
234
+ dataAvailabilityStatus : DataAvailabilityStatus ;
210
235
/** Seen timestamp seconds */
211
236
seenTimestampSec : number ;
212
237
} ;
0 commit comments