@lodestar/beacon-node 1.40.0-dev.cc503f86cb → 1.40.0-dev.cd347a28d7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/blocks/blockInput/blockInput.d.ts +28 -0
- package/lib/chain/blocks/blockInput/blockInput.d.ts.map +1 -1
- package/lib/chain/blocks/blockInput/blockInput.js +36 -1
- package/lib/chain/blocks/blockInput/blockInput.js.map +1 -1
- package/lib/chain/blocks/importBlock.js +1 -1
- package/lib/chain/blocks/importBlock.js.map +1 -1
- package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -1
- package/lib/chain/blocks/writeBlockInputToDb.js +8 -0
- package/lib/chain/blocks/writeBlockInputToDb.js.map +1 -1
- package/lib/chain/chain.d.ts +1 -1
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +12 -25
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/options.d.ts +0 -1
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +0 -1
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/regen/interface.d.ts +1 -1
- package/lib/chain/regen/queued.d.ts +1 -1
- package/lib/chain/regen/queued.d.ts.map +1 -1
- package/lib/chain/regen/queued.js.map +1 -1
- package/lib/chain/stateCache/index.d.ts +0 -2
- package/lib/chain/stateCache/index.d.ts.map +1 -1
- package/lib/chain/stateCache/index.js +0 -2
- package/lib/chain/stateCache/index.js.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +2 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.js +3 -0
- package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +1 -2
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/network/gossip/gossipsub.d.ts +19 -0
- package/lib/network/gossip/gossipsub.d.ts.map +1 -1
- package/lib/network/gossip/gossipsub.js +71 -0
- package/lib/network/gossip/gossipsub.js.map +1 -1
- package/lib/network/options.d.ts +6 -0
- package/lib/network/options.d.ts.map +1 -1
- package/lib/network/options.js.map +1 -1
- package/lib/network/peers/peerManager.d.ts.map +1 -1
- package/lib/network/peers/peerManager.js +9 -0
- package/lib/network/peers/peerManager.js.map +1 -1
- package/lib/network/processor/gossipHandlers.js +1 -1
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/package.json +15 -15
- package/src/api/impl/validator/index.ts +2 -1
- package/src/chain/blocks/blockInput/blockInput.ts +45 -2
- package/src/chain/blocks/importBlock.ts +1 -1
- package/src/chain/blocks/writeBlockInputToDb.ts +9 -0
- package/src/chain/chain.ts +17 -29
- package/src/chain/options.ts +0 -2
- package/src/chain/regen/interface.ts +1 -1
- package/src/chain/regen/queued.ts +1 -2
- package/src/chain/stateCache/index.ts +0 -2
- package/src/chain/stateCache/persistentCheckpointsCache.ts +6 -2
- package/src/chain/validation/block.ts +1 -2
- package/src/network/gossip/gossipsub.ts +86 -1
- package/src/network/options.ts +6 -0
- package/src/network/peers/peerManager.ts +11 -0
- package/src/network/processor/gossipHandlers.ts +1 -1
- package/lib/chain/stateCache/blockStateCacheImpl.d.ts +0 -54
- package/lib/chain/stateCache/blockStateCacheImpl.d.ts.map +0 -1
- package/lib/chain/stateCache/blockStateCacheImpl.js +0 -130
- package/lib/chain/stateCache/blockStateCacheImpl.js.map +0 -1
- package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts +0 -60
- package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts.map +0 -1
- package/lib/chain/stateCache/inMemoryCheckpointsCache.js +0 -156
- package/lib/chain/stateCache/inMemoryCheckpointsCache.js.map +0 -1
- package/src/chain/stateCache/blockStateCacheImpl.ts +0 -149
- package/src/chain/stateCache/inMemoryCheckpointsCache.ts +0 -192
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import {routes} from "@lodestar/api";
|
|
2
|
-
import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
|
|
3
|
-
import {Epoch, RootHex, phase0} from "@lodestar/types";
|
|
4
|
-
import {MapDef, toRootHex} from "@lodestar/utils";
|
|
5
|
-
import {Metrics} from "../../metrics/index.js";
|
|
6
|
-
import {MapTracker} from "./mapMetrics.js";
|
|
7
|
-
import {CacheItemType, CheckpointStateCache} from "./types.js";
|
|
8
|
-
|
|
9
|
-
export type CheckpointHex = {epoch: Epoch; rootHex: RootHex};
|
|
10
|
-
const MAX_EPOCHS = 10;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* In memory cache of CachedBeaconState
|
|
14
|
-
* belonging to checkpoint
|
|
15
|
-
*
|
|
16
|
-
* Similar API to Repository
|
|
17
|
-
*/
|
|
18
|
-
export class InMemoryCheckpointStateCache implements CheckpointStateCache {
|
|
19
|
-
private readonly cache: MapTracker<string, CachedBeaconStateAllForks>;
|
|
20
|
-
/** Epoch -> Set<blockRoot> */
|
|
21
|
-
private readonly epochIndex = new MapDef<Epoch, Set<string>>(() => new Set<string>());
|
|
22
|
-
/**
|
|
23
|
-
* Max number of epochs allowed in the cache
|
|
24
|
-
*/
|
|
25
|
-
private readonly maxEpochs: number;
|
|
26
|
-
private readonly metrics: Metrics["cpStateCache"] | null | undefined;
|
|
27
|
-
private preComputedCheckpoint: string | null = null;
|
|
28
|
-
private preComputedCheckpointHits: number | null = null;
|
|
29
|
-
|
|
30
|
-
constructor({metrics = null}: {metrics?: Metrics | null}, {maxEpochs = MAX_EPOCHS}: {maxEpochs?: number} = {}) {
|
|
31
|
-
this.cache = new MapTracker(metrics?.cpStateCache);
|
|
32
|
-
if (metrics) {
|
|
33
|
-
this.metrics = metrics.cpStateCache;
|
|
34
|
-
metrics.cpStateCache.size.addCollect(() =>
|
|
35
|
-
metrics.cpStateCache.size.set({type: CacheItemType.inMemory}, this.cache.size)
|
|
36
|
-
);
|
|
37
|
-
metrics.cpStateCache.epochSize.addCollect(() =>
|
|
38
|
-
metrics.cpStateCache.epochSize.set({type: CacheItemType.inMemory}, this.epochIndex.size)
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
this.maxEpochs = maxEpochs;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async getOrReload(cp: CheckpointHex): Promise<CachedBeaconStateAllForks | null> {
|
|
45
|
-
return this.get(cp);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async getStateOrBytes(cp: CheckpointHex): Promise<Uint8Array | CachedBeaconStateAllForks | null> {
|
|
49
|
-
return this.get(cp);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async getOrReloadLatest(rootHex: string, maxEpoch: number): Promise<CachedBeaconStateAllForks | null> {
|
|
53
|
-
return this.getLatest(rootHex, maxEpoch);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async processState(): Promise<number> {
|
|
57
|
-
// do nothing, this class does not support prunning
|
|
58
|
-
return 0;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get(cp: CheckpointHex): CachedBeaconStateAllForks | null {
|
|
62
|
-
this.metrics?.lookups.inc();
|
|
63
|
-
const cpKey = toCheckpointKey(cp);
|
|
64
|
-
const item = this.cache.get(cpKey);
|
|
65
|
-
|
|
66
|
-
if (!item) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.metrics?.hits.inc();
|
|
71
|
-
|
|
72
|
-
if (cpKey === this.preComputedCheckpoint) {
|
|
73
|
-
this.preComputedCheckpointHits = (this.preComputedCheckpointHits ?? 0) + 1;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.metrics?.stateClonedCount.observe(item.clonedCount);
|
|
77
|
-
|
|
78
|
-
return item;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
add(cp: phase0.Checkpoint, item: CachedBeaconStateAllForks): void {
|
|
82
|
-
const cpHex = toCheckpointHex(cp);
|
|
83
|
-
const key = toCheckpointKey(cpHex);
|
|
84
|
-
if (this.cache.has(key)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
this.metrics?.adds.inc();
|
|
88
|
-
this.cache.set(key, item);
|
|
89
|
-
this.epochIndex.getOrDefault(cp.epoch).add(cpHex.rootHex);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Searches for the latest cached state with a `root`, starting with `epoch` and descending
|
|
94
|
-
*/
|
|
95
|
-
getLatest(rootHex: RootHex, maxEpoch: Epoch): CachedBeaconStateAllForks | null {
|
|
96
|
-
// sort epochs in descending order, only consider epochs lte `epoch`
|
|
97
|
-
const epochs = Array.from(this.epochIndex.keys())
|
|
98
|
-
.sort((a, b) => b - a)
|
|
99
|
-
.filter((e) => e <= maxEpoch);
|
|
100
|
-
for (const epoch of epochs) {
|
|
101
|
-
if (this.epochIndex.get(epoch)?.has(rootHex)) {
|
|
102
|
-
return this.get({rootHex, epoch});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Update the precomputed checkpoint and return the number of his for the
|
|
110
|
-
* previous one (if any).
|
|
111
|
-
*/
|
|
112
|
-
updatePreComputedCheckpoint(rootHex: RootHex, epoch: Epoch): number | null {
|
|
113
|
-
const previousHits = this.preComputedCheckpointHits;
|
|
114
|
-
this.preComputedCheckpoint = toCheckpointKey({rootHex, epoch});
|
|
115
|
-
this.preComputedCheckpointHits = 0;
|
|
116
|
-
return previousHits;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
pruneFinalized(finalizedEpoch: Epoch): void {
|
|
120
|
-
for (const epoch of this.epochIndex.keys()) {
|
|
121
|
-
if (epoch < finalizedEpoch) {
|
|
122
|
-
this.deleteAllEpochItems(epoch);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
prune(finalizedEpoch: Epoch, justifiedEpoch: Epoch): void {
|
|
128
|
-
const epochs = Array.from(this.epochIndex.keys()).filter(
|
|
129
|
-
(epoch) => epoch !== finalizedEpoch && epoch !== justifiedEpoch
|
|
130
|
-
);
|
|
131
|
-
if (epochs.length > this.maxEpochs) {
|
|
132
|
-
for (const epoch of epochs.slice(0, epochs.length - this.maxEpochs)) {
|
|
133
|
-
this.deleteAllEpochItems(epoch);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
delete(cp: phase0.Checkpoint): void {
|
|
139
|
-
this.cache.delete(toCheckpointKey(toCheckpointHex(cp)));
|
|
140
|
-
const epochKey = toRootHex(cp.root);
|
|
141
|
-
const value = this.epochIndex.get(cp.epoch);
|
|
142
|
-
if (value) {
|
|
143
|
-
value.delete(epochKey);
|
|
144
|
-
if (value.size === 0) {
|
|
145
|
-
this.epochIndex.delete(cp.epoch);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
deleteAllEpochItems(epoch: Epoch): void {
|
|
151
|
-
for (const rootHex of this.epochIndex.get(epoch) || []) {
|
|
152
|
-
this.cache.delete(toCheckpointKey({rootHex, epoch}));
|
|
153
|
-
}
|
|
154
|
-
this.epochIndex.delete(epoch);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
clear(): void {
|
|
158
|
-
this.cache.clear();
|
|
159
|
-
this.epochIndex.clear();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** ONLY FOR DEBUGGING PURPOSES. For lodestar debug API */
|
|
163
|
-
dumpSummary(): routes.lodestar.StateCacheItem[] {
|
|
164
|
-
return Array.from(this.cache.entries()).map(([key, state]) => ({
|
|
165
|
-
slot: state.slot,
|
|
166
|
-
root: toRootHex(state.hashTreeRoot()),
|
|
167
|
-
reads: this.cache.readCount.get(key) ?? 0,
|
|
168
|
-
lastRead: this.cache.lastRead.get(key) ?? 0,
|
|
169
|
-
checkpointState: true,
|
|
170
|
-
}));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
getStates(): IterableIterator<CachedBeaconStateAllForks> {
|
|
174
|
-
return this.cache.values();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** ONLY FOR DEBUGGING PURPOSES. For spec tests on error */
|
|
178
|
-
dumpCheckpointKeys(): string[] {
|
|
179
|
-
return Array.from(this.cache.keys());
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function toCheckpointHex(checkpoint: phase0.Checkpoint): CheckpointHex {
|
|
184
|
-
return {
|
|
185
|
-
epoch: checkpoint.epoch,
|
|
186
|
-
rootHex: toRootHex(checkpoint.root),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export function toCheckpointKey(cp: CheckpointHex): string {
|
|
191
|
-
return `${cp.rootHex}:${cp.epoch}`;
|
|
192
|
-
}
|