Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust n-historical-states param #7104

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading