Skip to content

Commit c4952ee

Browse files
authored
fix: adjust n-historical-states param (#7104)
* fix: default params of n-historical-states config * chore: improve log * feat: enable nHistoricalStates by default * chore: fix typo in log
1 parent fe7e21b commit c4952ee

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

packages/beacon-node/src/chain/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const defaultChainOptions: IChainOptions = {
111111
// batching too much may block the I/O thread so if useWorker=false, suggest this value to be 32
112112
// since this batch attestation work is designed to work with useWorker=true, make this the lowest value
113113
minSameMessageSignatureSetsToBatch: 2,
114-
nHistoricalStates: false,
114+
nHistoricalStates: true,
115115
nHistoricalStatesFileDataStore: false,
116116
maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
117117
maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,

packages/beacon-node/src/chain/regen/regen.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
218218
blockPromises[i] = this.modules.db.block.get(fromHex(protoBlock.blockRoot));
219219
}
220220

221-
const logCtx = {stateRoot, replaySlots: replaySlots.join(",")};
221+
const logCtx = {stateRoot, caller, replaySlots: replaySlots.join(",")};
222222
this.modules.logger.debug("Replaying blocks to get state", logCtx);
223223

224224
const loadBlocksTimer = this.modules.metrics?.regenGetState.loadBlocks.startTimer({caller});

packages/beacon-node/src/chain/stateCache/fifoBlockStateCache.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ export type FIFOBlockStateCacheOpts = {
1313
};
1414

1515
/**
16-
* Regen state if there's a reorg distance > 32 slots.
16+
* Given `maxSkipSlots` = 32 and `DEFAULT_EARLIEST_PERMISSIBLE_SLOT_DISTANCE` = 32, lodestar doesn't need to
17+
* reload states in order to process a gossip block.
18+
*
19+
* |-----------------------------------------------|-----------------------------------------------|
20+
* maxSkipSlots DEFAULT_EARLIEST_PERMISSIBLE_SLOT_DISTANCE ^
21+
* clock slot
1722
*/
18-
export const DEFAULT_MAX_BLOCK_STATES = 32;
23+
export const DEFAULT_MAX_BLOCK_STATES = 64;
1924

2025
/**
2126
* New implementation of BlockStateCache that keeps the most recent n states consistently

packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ type CacheItem = InMemoryCacheItem | PersistedCacheItem;
5353
type LoadedStateBytesData = {persistedKey: DatastoreKey; stateBytes: Uint8Array};
5454

5555
/**
56-
* Before n-historical states, lodestar keeps mostly 3 states in memory with 1 finalized state
57-
* Since Jan 2024, lodestar stores the finalized state in disk and keeps up to 2 epochs in memory
56+
* Before n-historical states, lodestar keeps all checkpoint states since finalized
57+
* Since Sep 2024, lodestar stores 3 most recent checkpoint states in memory and the rest on disk. The finalized state
58+
* may not be available in memory, and stay on disk instead.
5859
*/
59-
export const DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY = 2;
60+
export const DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY = 3;
6061

6162
/**
6263
* An implementation of CheckpointStateCache that keep up to n epoch checkpoint states in memory and persist the rest to disk

packages/beacon-node/src/network/processor/gossipHandlers.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ function getDefaultHandlers(modules: ValidatorFnsModules, options: GossipHandler
144144
const blockInputMeta =
145145
config.getForkSeq(signedBlock.message.slot) >= ForkSeq.deneb ? blockInputRes.blockInputMeta : {};
146146

147+
const logCtx = {
148+
slot: slot,
149+
root: blockHex,
150+
currentSlot: chain.clock.currentSlot,
151+
peerId: peerIdStr,
152+
delaySec,
153+
...blockInputMeta,
154+
recvToValLatency,
155+
};
156+
157+
logger.debug("Received gossip block", {...logCtx});
158+
147159
try {
148160
await validateGossipBlock(config, chain, signedBlock, fork);
149161

@@ -153,17 +165,7 @@ function getDefaultHandlers(modules: ValidatorFnsModules, options: GossipHandler
153165
metrics?.gossipBlock.gossipValidation.recvToValidation.observe(recvToValidation);
154166
metrics?.gossipBlock.gossipValidation.validationTime.observe(validationTime);
155167

156-
logger.debug("Received gossip block", {
157-
slot: slot,
158-
root: blockHex,
159-
curentSlot: chain.clock.currentSlot,
160-
peerId: peerIdStr,
161-
delaySec,
162-
...blockInputMeta,
163-
recvToValLatency,
164-
recvToValidation,
165-
validationTime,
166-
});
168+
logger.debug("Validated gossip block", {...logCtx, recvToValidation, validationTime});
167169

168170
return blockInput;
169171
} catch (e) {

0 commit comments

Comments
 (0)