Skip to content

Commit

Permalink
fix: adjust n-historical-states param (#7104)
Browse files Browse the repository at this point in the history
* fix: default params of n-historical-states config

* chore: improve log

* feat: enable nHistoricalStates by default

* chore: fix typo in log
  • Loading branch information
twoeths authored Oct 1, 2024
1 parent fe7e21b commit c4952ee
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const defaultChainOptions: IChainOptions = {
// batching too much may block the I/O thread so if useWorker=false, suggest this value to be 32
// since this batch attestation work is designed to work with useWorker=true, make this the lowest value
minSameMessageSignatureSetsToBatch: 2,
nHistoricalStates: false,
nHistoricalStates: true,
nHistoricalStatesFileDataStore: false,
maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/regen/regen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class StateRegenerator implements IStateRegeneratorInternal {
blockPromises[i] = this.modules.db.block.get(fromHex(protoBlock.blockRoot));
}

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

const loadBlocksTimer = this.modules.metrics?.regenGetState.loadBlocks.startTimer({caller});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ export type FIFOBlockStateCacheOpts = {
};

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

/**
* New implementation of BlockStateCache that keeps the most recent n states consistently
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ type CacheItem = InMemoryCacheItem | PersistedCacheItem;
type LoadedStateBytesData = {persistedKey: DatastoreKey; stateBytes: Uint8Array};

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

/**
* An implementation of CheckpointStateCache that keep up to n epoch checkpoint states in memory and persist the rest to disk
Expand Down
24 changes: 13 additions & 11 deletions packages/beacon-node/src/network/processor/gossipHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ function getDefaultHandlers(modules: ValidatorFnsModules, options: GossipHandler
const blockInputMeta =
config.getForkSeq(signedBlock.message.slot) >= ForkSeq.deneb ? blockInputRes.blockInputMeta : {};

const logCtx = {
slot: slot,
root: blockHex,
currentSlot: chain.clock.currentSlot,
peerId: peerIdStr,
delaySec,
...blockInputMeta,
recvToValLatency,
};

logger.debug("Received gossip block", {...logCtx});

try {
await validateGossipBlock(config, chain, signedBlock, fork);

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

logger.debug("Received gossip block", {
slot: slot,
root: blockHex,
curentSlot: chain.clock.currentSlot,
peerId: peerIdStr,
delaySec,
...blockInputMeta,
recvToValLatency,
recvToValidation,
validationTime,
});
logger.debug("Validated gossip block", {...logCtx, recvToValidation, validationTime});

return blockInput;
} catch (e) {
Expand Down

0 comments on commit c4952ee

Please sign in to comment.