ChainSafe / ChainSafe/lodestar

Non-checkpoint states are added into checkpoint cache

Open
#5,848 5 comments 0 reactions 0 assignees View on GitHub
meta-bug meta-investigate prio-medium
Dominant language
TypeScript
Stars
1.4k
Forks
483
Avg merge
1d 16h
Merged PRs (30d)
150

Description

Currently it looks like we are adding non-checkpoint states into the checkpoint cache

https://github.com/ChainSafe/lodestar/blob/5f7f9951f09c3e8ab0187fe05e47b9a4c7786f5b/packages/beacon-node/src/chain/stateCache/stateContextCheckpointsCache.ts#L55

This happens when importing a block once every epoch

https://github.com/ChainSafe/lodestar/blob/903483107414fd64395c575b709f5158173bc607/packages/beacon-node/src/chain/blocks/importBlock.ts#L331-L335

Non-checkpoint states can be determined by checking the state root in block header is a zero hash

```ts
// ...
add(cp: phase0.Checkpoint, item: CachedBeaconStateAllForks): void {
console.log("added checkpoint state");
if (byteArrayEquals(item.latestBlockHeader.stateRoot, ZERO_HASH)) {
console.log("not a checkpoint state");
}
// ...
```

We add 2 different states to checkpoint cache each epoch and one of them is not a checkpoint state
```
Aug-04 16:01:52.999[] info: Synced - slot: 7027807 - head: 0x0300…1e75 - exec-block: valid(17842082 0xdacd…) - finalized: 0xdfe0…1817:219616 - peers: 32
added checkpoint state
Aug-04 16:02:05.051[] info: Synced - slot: 7027808 - head: (slot -1) 0x0300…1e75 - exec-block: valid(17842082 0xdacd…) - finalized: 0x9f2e…87f6:219617 - peers: 31
added checkpoint state
not a checkpoint state <-- this should never happen
Aug-04 16:02:17.000[] info: Synced - slot: 7027809 - head: 0xc202…3c70 - exec-block: valid(17842084 0x1b1f…) - finalized: 0x9f2e…87f6:219617 - peers: 33
....
Aug-04 16:08:17.001[] info: Synced - slot: 7027839 - head: 0xe276…f61c - exec-block: valid(17842114 0x445d…) - finalized: 0x9f2e…87f6:219617 - peers: 41
added checkpoint state
Aug-04 16:08:29.024[] info: Synced - slot: 7027840 - head: (slot -1) 0xe276…f61c - exec-block: valid(17842114 0x445d…) - finalized: 0xadc1…d8a6:219618 - peers: 42
added checkpoint state
not a checkpoint state <-- this should never happen
Aug-04 16:08:41.246[] info: Synced - slot: 7027841 - head: 0xe6ee…4149 - exec-block: valid(17842116 0x8354…) - finalized: 0xadc1…d8a6:219618 - peers: 41
```

cc @dapplion @tuyennhv @wemeetagain

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.