@lodestar/beacon-node 1.36.0-dev.6f46a8bd20 → 1.36.0-dev.88fbac9fcf
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/lodestar/index.d.ts +5 -0
- package/lib/api/impl/lodestar/index.d.ts.map +1 -1
- package/lib/api/impl/lodestar/index.js +29 -1
- package/lib/api/impl/lodestar/index.js.map +1 -1
- package/lib/api/impl/node/utils.js +1 -1
- package/lib/api/impl/node/utils.js.map +1 -1
- package/lib/chain/chain.d.ts +5 -2
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +32 -16
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/forkChoice/index.d.ts +9 -1
- package/lib/chain/forkChoice/index.d.ts.map +1 -1
- package/lib/chain/forkChoice/index.js +109 -4
- package/lib/chain/forkChoice/index.js.map +1 -1
- package/lib/chain/interface.d.ts +2 -0
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/options.d.ts +0 -2
- 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/stateCache/datastore/db.d.ts +12 -0
- package/lib/chain/stateCache/datastore/db.d.ts.map +1 -1
- package/lib/chain/stateCache/datastore/db.js +70 -0
- package/lib/chain/stateCache/datastore/db.js.map +1 -1
- package/lib/chain/stateCache/datastore/file.d.ts +1 -0
- package/lib/chain/stateCache/datastore/file.d.ts.map +1 -1
- package/lib/chain/stateCache/datastore/file.js +7 -0
- package/lib/chain/stateCache/datastore/file.js.map +1 -1
- package/lib/chain/stateCache/datastore/types.d.ts +1 -0
- package/lib/chain/stateCache/datastore/types.d.ts.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/network/core/networkCore.d.ts.map +1 -1
- package/lib/network/core/networkCore.js +5 -1
- package/lib/network/core/networkCore.js.map +1 -1
- package/lib/network/gossip/encoding.js +1 -1
- package/lib/network/gossip/encoding.js.map +1 -1
- package/lib/network/gossip/snappy_bun.d.ts +3 -0
- package/lib/network/gossip/snappy_bun.d.ts.map +1 -0
- package/lib/network/gossip/snappy_bun.js +3 -0
- package/lib/network/gossip/snappy_bun.js.map +1 -0
- package/lib/network/metadata.d.ts +1 -1
- package/lib/network/metadata.d.ts.map +1 -1
- package/lib/network/metadata.js +1 -0
- package/lib/network/metadata.js.map +1 -1
- package/lib/network/options.d.ts +0 -1
- package/lib/network/options.d.ts.map +1 -1
- package/lib/network/options.js.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js +3 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
- package/lib/node/nodejs.d.ts +2 -1
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +2 -1
- package/lib/node/nodejs.js.map +1 -1
- package/lib/sync/range/range.d.ts.map +1 -1
- package/lib/sync/range/range.js +2 -1
- package/lib/sync/range/range.js.map +1 -1
- package/lib/sync/utils/remoteSyncType.d.ts +2 -1
- package/lib/sync/utils/remoteSyncType.d.ts.map +1 -1
- package/lib/sync/utils/remoteSyncType.js +19 -4
- package/lib/sync/utils/remoteSyncType.js.map +1 -1
- package/lib/util/sszBytes.d.ts +2 -0
- package/lib/util/sszBytes.d.ts.map +1 -1
- package/lib/util/sszBytes.js +25 -0
- package/lib/util/sszBytes.js.map +1 -1
- package/package.json +19 -14
- package/src/api/impl/lodestar/index.ts +36 -1
- package/src/api/impl/node/utils.ts +1 -1
- package/src/chain/chain.ts +48 -23
- package/src/chain/forkChoice/index.ts +178 -2
- package/src/chain/interface.ts +2 -0
- package/src/chain/options.ts +0 -3
- package/src/chain/stateCache/datastore/db.ts +89 -1
- package/src/chain/stateCache/datastore/file.ts +8 -0
- package/src/chain/stateCache/datastore/types.ts +1 -0
- package/src/index.ts +2 -0
- package/src/network/core/networkCore.ts +5 -1
- package/src/network/gossip/encoding.ts +1 -1
- package/src/network/gossip/snappy_bun.ts +2 -0
- package/src/network/metadata.ts +3 -1
- package/src/network/options.ts +0 -1
- package/src/network/reqresp/handlers/beaconBlocksByRange.ts +3 -1
- package/src/node/nodejs.ts +3 -0
- package/src/sync/range/range.ts +2 -1
- package/src/sync/utils/remoteSyncType.ts +23 -4
- package/src/util/sszBytes.ts +30 -0
package/src/node/nodejs.ts
CHANGED
|
@@ -53,6 +53,7 @@ export type BeaconNodeInitModules = {
|
|
|
53
53
|
dataDir: string;
|
|
54
54
|
peerStoreDir?: string;
|
|
55
55
|
anchorState: BeaconStateAllForks;
|
|
56
|
+
isAnchorStateFinalized: boolean;
|
|
56
57
|
wsCheckpoint?: phase0.Checkpoint;
|
|
57
58
|
metricsRegistries?: Registry[];
|
|
58
59
|
};
|
|
@@ -154,6 +155,7 @@ export class BeaconNode {
|
|
|
154
155
|
dataDir,
|
|
155
156
|
peerStoreDir,
|
|
156
157
|
anchorState,
|
|
158
|
+
isAnchorStateFinalized,
|
|
157
159
|
wsCheckpoint,
|
|
158
160
|
metricsRegistries = [],
|
|
159
161
|
}: BeaconNodeInitModules): Promise<T> {
|
|
@@ -217,6 +219,7 @@ export class BeaconNode {
|
|
|
217
219
|
metrics,
|
|
218
220
|
validatorMonitor,
|
|
219
221
|
anchorState,
|
|
222
|
+
isAnchorStateFinalized,
|
|
220
223
|
eth1: initializeEth1ForBlockProduction(opts.eth1, {
|
|
221
224
|
config,
|
|
222
225
|
db,
|
package/src/sync/range/range.ts
CHANGED
|
@@ -114,13 +114,14 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
|
|
|
114
114
|
*/
|
|
115
115
|
addPeer(peerId: PeerIdStr, localStatus: Status, peerStatus: Status): void {
|
|
116
116
|
// Compute if we should do a Finalized or Head sync with this peer
|
|
117
|
-
const {syncType, startEpoch, target} = getRangeSyncTarget(localStatus, peerStatus, this.chain
|
|
117
|
+
const {syncType, startEpoch, target} = getRangeSyncTarget(localStatus, peerStatus, this.chain);
|
|
118
118
|
this.logger.debug("Sync peer joined", {
|
|
119
119
|
peer: peerId,
|
|
120
120
|
syncType,
|
|
121
121
|
startEpoch,
|
|
122
122
|
targetSlot: target.slot,
|
|
123
123
|
targetRoot: toRootHex(target.root),
|
|
124
|
+
localHeadSlot: localStatus.headSlot,
|
|
124
125
|
earliestAvailableSlot: (peerStatus as fulu.Status).earliestAvailableSlot ?? Infinity,
|
|
125
126
|
});
|
|
126
127
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {IForkChoice} from "@lodestar/fork-choice";
|
|
2
2
|
import {computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition";
|
|
3
3
|
import {Slot, Status} from "@lodestar/types";
|
|
4
|
+
import {IBeaconChain} from "../../chain/interface.ts";
|
|
4
5
|
import {ChainTarget} from "../range/utils/index.js";
|
|
5
6
|
|
|
6
7
|
/** The type of peer relative to our current state */
|
|
@@ -103,8 +104,11 @@ export function getRangeSyncType(local: Status, remote: Status, forkChoice: IFor
|
|
|
103
104
|
export function getRangeSyncTarget(
|
|
104
105
|
local: Status,
|
|
105
106
|
remote: Status,
|
|
106
|
-
|
|
107
|
+
chain: IBeaconChain
|
|
107
108
|
): {syncType: RangeSyncType; startEpoch: Slot; target: ChainTarget} {
|
|
109
|
+
const forkChoice = chain.forkChoice;
|
|
110
|
+
|
|
111
|
+
// finalized sync
|
|
108
112
|
if (remote.finalizedEpoch > local.finalizedEpoch && !forkChoice.hasBlock(remote.finalizedRoot)) {
|
|
109
113
|
return {
|
|
110
114
|
// If RangeSyncType.Finalized, the range of blocks fetchable from startEpoch and target must allow to switch
|
|
@@ -131,11 +135,26 @@ export function getRangeSyncTarget(
|
|
|
131
135
|
},
|
|
132
136
|
};
|
|
133
137
|
}
|
|
138
|
+
|
|
139
|
+
// we don't want to sync from epoch < minEpoch
|
|
140
|
+
// if we boot from an unfinalized checkpoint state, we don't want to sync before anchorStateLatestBlockSlot
|
|
141
|
+
// if we boot from a finalized checkpoint state, anchorStateLatestBlockSlot is trusted and we also don't want to sync before it
|
|
142
|
+
const minEpoch = Math.max(remote.finalizedEpoch, computeEpochAtSlot(chain.anchorStateLatestBlockSlot));
|
|
143
|
+
|
|
144
|
+
// head sync
|
|
134
145
|
return {
|
|
135
146
|
syncType: RangeSyncType.Head,
|
|
136
|
-
// The new peer has the same finalized
|
|
137
|
-
//
|
|
138
|
-
|
|
147
|
+
// The new peer has the same finalized `remote.finalizedEpoch == local.finalizedEpoch` since
|
|
148
|
+
// previous filters should prevent a peer with an earlier finalized chain from reaching here.
|
|
149
|
+
//
|
|
150
|
+
// By default and during stable network conditions, the head sync always starts from
|
|
151
|
+
// the finalized epoch (even though it's the head sync) because finalized epoch is < local head.
|
|
152
|
+
// This is to prevent the issue noted here https://github.com/ChainSafe/lodestar/pull/7509#discussion_r1984353063.
|
|
153
|
+
//
|
|
154
|
+
// During non-finality of the network, when starting from an unfinalized checkpoint state, we don't want
|
|
155
|
+
// to sync before anchorStateLatestBlockSlot as finalized epoch is too far away. Local head will also be
|
|
156
|
+
// the same to that value at startup, the head sync always starts from anchorStateLatestBlockSlot in this case.
|
|
157
|
+
startEpoch: Math.min(computeEpochAtSlot(local.headSlot), minEpoch),
|
|
139
158
|
target: {
|
|
140
159
|
slot: remote.headSlot,
|
|
141
160
|
root: remote.headRoot,
|
package/src/util/sszBytes.ts
CHANGED
|
@@ -417,6 +417,36 @@ export function getSlotFromDataColumnSidecarSerialized(data: Uint8Array): Slot |
|
|
|
417
417
|
return getSlotFromOffset(data, SLOT_BYTES_POSITION_IN_SIGNED_DATA_COLUMN_SIDECAR);
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
+
/**
|
|
421
|
+
* BeaconState of all forks (up until Electra, check with new forks)
|
|
422
|
+
* class BeaconState(Container):
|
|
423
|
+
* genesis_time: uint64 - 8 bytes
|
|
424
|
+
* genesis_validators_root: Root - 32 bytes
|
|
425
|
+
* slot: Slot - 8 bytes
|
|
426
|
+
* fork: Fork - 16 bytes
|
|
427
|
+
* latest_block_header: BeaconBlockHeader - fixed size
|
|
428
|
+
* slot: Slot - 8 bytes
|
|
429
|
+
*
|
|
430
|
+
*/
|
|
431
|
+
|
|
432
|
+
const BLOCK_HEADER_SLOT_BYTES_POSITION_IN_BEACON_STATE = 8 + 32 + 8 + 16;
|
|
433
|
+
export function getLastProcessedSlotFromBeaconStateSerialized(data: Uint8Array): Slot | null {
|
|
434
|
+
if (data.length < BLOCK_HEADER_SLOT_BYTES_POSITION_IN_BEACON_STATE + SLOT_SIZE) {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return getSlotFromOffset(data, BLOCK_HEADER_SLOT_BYTES_POSITION_IN_BEACON_STATE);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const SLOT_BYTES_POSITION_IN_BEACON_STATE = 8 + 32;
|
|
442
|
+
export function getSlotFromBeaconStateSerialized(data: Uint8Array): Slot | null {
|
|
443
|
+
if (data.length < SLOT_BYTES_POSITION_IN_BEACON_STATE) {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return getSlotFromOffset(data, SLOT_BYTES_POSITION_IN_BEACON_STATE);
|
|
448
|
+
}
|
|
449
|
+
|
|
420
450
|
/**
|
|
421
451
|
* Read only the first 4 bytes of Slot, max value is 4,294,967,295 will be reached 1634 years after genesis
|
|
422
452
|
*
|