@@ -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,10 +98,7 @@ 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
@@ -115,7 +108,6 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
115
108
logger,
116
109
clock,
117
110
signal,
118
- shufflingCache,
119
111
datastore,
120
112
blockStateCache,
121
113
bufferPool,
@@ -153,10 +145,8 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
153
145
throw new Error ( "maxEpochsInMemory must be >= 0" ) ;
154
146
}
155
147
this . maxEpochsInMemory = opts . maxCPStateEpochsInMemory ?? DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY ;
156
- this . processLateBlock = opts . processLateBlock ?? false ;
157
148
// Specify different datastore for testing
158
149
this . datastore = datastore ;
159
- this . shufflingCache = shufflingCache ;
160
150
this . blockStateCache = blockStateCache ;
161
151
this . bufferPool = bufferPool ;
162
152
}
@@ -487,12 +477,9 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
487
477
// 2/3 of slot is the most free time of every slot, take that chance to persist checkpoint states
488
478
// normally it should only persist checkpoint states at 2/3 of slot 0 of epoch
489
479
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
480
}
481
+ // at syncing time, it's critical to persist checkpoint states as soon as possible to avoid OOM during unfinality time
482
+ // 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
483
497
484
const persistEpochs = sortedEpochs . slice ( 0 , sortedEpochs . length - this . maxEpochsInMemory ) ;
498
485
for ( const lowestEpoch of persistEpochs ) {
0 commit comments