@@ -9,24 +9,20 @@ import {AllocSource, BufferPool, BufferWithKey} from "../../util/bufferPool.js";
9
9
import { IClock } from "../../util/clock.js" ;
10
10
import { StateCloneOpts } from "../regen/interface.js" ;
11
11
import { serializeState } from "../serializeState.js" ;
12
- import { ShufflingCache } from "../shufflingCache.js" ;
13
12
import { CPStateDatastore , DatastoreKey , datastoreKeyToCheckpoint } from "./datastore/index.js" ;
14
13
import { MapTracker } from "./mapMetrics.js" ;
15
14
import { BlockStateCache , CacheItemType , CheckpointHex , CheckpointStateCache } from "./types.js" ;
16
15
17
16
export type PersistentCheckpointStateCacheOpts = {
18
17
/** Keep max n states in memory, persist the rest to disk */
19
18
maxCPStateEpochsInMemory ?: number ;
20
- /** for testing only */
21
- processLateBlock ?: boolean ;
22
19
} ;
23
20
24
21
type PersistentCheckpointStateCacheModules = {
25
22
metrics ?: Metrics | null ;
26
23
logger : Logger ;
27
24
clock ?: IClock | null ;
28
25
signal ?: AbortSignal ;
29
- shufflingCache : ShufflingCache ;
30
26
datastore : CPStateDatastore ;
31
27
blockStateCache : BlockStateCache ;
32
28
bufferPool ?: BufferPool | null ;
@@ -102,24 +98,12 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
102
98
private preComputedCheckpoint : string | null = null ;
103
99
private preComputedCheckpointHits : number | null = null ;
104
100
private readonly maxEpochsInMemory : number ;
105
- // only for testing, default false for production
106
- private readonly processLateBlock : boolean ;
107
101
private readonly datastore : CPStateDatastore ;
108
- private readonly shufflingCache : ShufflingCache ;
109
102
private readonly blockStateCache : BlockStateCache ;
110
103
private readonly bufferPool ?: BufferPool | null ;
111
104
112
105
constructor (
113
- {
114
- metrics,
115
- logger,
116
- clock,
117
- signal,
118
- shufflingCache,
119
- datastore,
120
- blockStateCache,
121
- bufferPool,
122
- } : PersistentCheckpointStateCacheModules ,
106
+ { metrics, logger, clock, signal, datastore, blockStateCache, bufferPool} : PersistentCheckpointStateCacheModules ,
123
107
opts : PersistentCheckpointStateCacheOpts
124
108
) {
125
109
this . cache = new MapTracker ( metrics ?. cpStateCache ) ;
@@ -153,10 +137,8 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
153
137
throw new Error ( "maxEpochsInMemory must be >= 0" ) ;
154
138
}
155
139
this . maxEpochsInMemory = opts . maxCPStateEpochsInMemory ?? DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY ;
156
- this . processLateBlock = opts . processLateBlock ?? false ;
157
140
// Specify different datastore for testing
158
141
this . datastore = datastore ;
159
- this . shufflingCache = shufflingCache ;
160
142
this . blockStateCache = blockStateCache ;
161
143
this . bufferPool = bufferPool ;
162
144
}
@@ -487,12 +469,9 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
487
469
// 2/3 of slot is the most free time of every slot, take that chance to persist checkpoint states
488
470
// normally it should only persist checkpoint states at 2/3 of slot 0 of epoch
489
471
await sleep ( secToTwoThirdsSlot * 1000 , this . signal ) ;
490
- } else if ( ! this . processLateBlock ) {
491
- // normally the block persist happens at 2/3 of slot 0 of epoch, if it's already late then just skip to allow other tasks to run
492
- // there are plenty of chances in the same epoch to persist checkpoint states, also if block is late it could be reorged
493
- this . logger . verbose ( "Skip persist checkpoint states" , { blockSlot, root : blockRootHex } ) ;
494
- return 0 ;
495
472
}
473
+ // at syncing time, it's critical to persist checkpoint states as soon as possible to avoid OOM during unfinality time
474
+ // if node is synced this is not a hot time because block comes late, we'll likely miss attestation already, or the block is orphaned
496
475
497
476
const persistEpochs = sortedEpochs . slice ( 0 , sortedEpochs . length - this . maxEpochsInMemory ) ;
498
477
for ( const lowestEpoch of persistEpochs ) {
0 commit comments