@lodestar/beacon-node 1.50.0-dev.5866a397b6 → 1.50.0-dev.58d40975f9
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/beacon/blocks/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/blocks/index.js +6 -1
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/api/impl/beacon/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/index.js +13 -0
- package/lib/api/impl/beacon/index.js.map +1 -1
- package/lib/api/impl/beacon/pool/index.js +4 -4
- package/lib/api/impl/beacon/pool/index.js.map +1 -1
- package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/state/index.js +23 -3
- package/lib/api/impl/beacon/state/index.js.map +1 -1
- package/lib/api/impl/debug/index.d.ts.map +1 -1
- package/lib/api/impl/debug/index.js +26 -18
- package/lib/api/impl/debug/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts +1 -0
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +23 -1
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/archiveStore/archiveStore.d.ts +6 -0
- package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
- package/lib/chain/archiveStore/archiveStore.js +18 -24
- package/lib/chain/archiveStore/archiveStore.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts +2 -2
- package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js +5 -7
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/historicalStateRegen.js +1 -1
- package/lib/chain/archiveStore/historicalState/historicalStateRegen.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/types.d.ts +2 -2
- package/lib/chain/archiveStore/historicalState/types.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/worker.js +1 -1
- package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
- package/lib/chain/archiveStore/interface.d.ts +1 -1
- package/lib/chain/archiveStore/interface.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.d.ts +4 -1
- package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.js +5 -3
- package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
- package/lib/chain/blocks/importBlock.d.ts.map +1 -1
- package/lib/chain/blocks/importBlock.js +17 -6
- package/lib/chain/blocks/importBlock.js.map +1 -1
- package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +2 -1
- package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.js +7 -7
- package/lib/chain/blocks/verifyBlock.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts +2 -1
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +5 -4
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
- package/lib/chain/chain.d.ts +9 -5
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +90 -36
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/emitter.d.ts +7 -1
- package/lib/chain/emitter.d.ts.map +1 -1
- package/lib/chain/emitter.js +5 -0
- package/lib/chain/emitter.js.map +1 -1
- package/lib/chain/errors/envelopeReconstructionError.d.ts +5 -0
- package/lib/chain/errors/envelopeReconstructionError.d.ts.map +1 -1
- package/lib/chain/errors/envelopeReconstructionError.js +2 -0
- package/lib/chain/errors/envelopeReconstructionError.js.map +1 -1
- package/lib/chain/errors/gossipValidation.d.ts +3 -1
- package/lib/chain/errors/gossipValidation.d.ts.map +1 -1
- package/lib/chain/errors/gossipValidation.js +2 -0
- package/lib/chain/errors/gossipValidation.js.map +1 -1
- package/lib/chain/forkChoice/index.d.ts.map +1 -1
- package/lib/chain/forkChoice/index.js +2 -0
- package/lib/chain/forkChoice/index.js.map +1 -1
- package/lib/chain/initState.d.ts +2 -9
- package/lib/chain/initState.d.ts.map +1 -1
- package/lib/chain/initState.js +5 -38
- package/lib/chain/initState.js.map +1 -1
- package/lib/chain/interface.d.ts +3 -2
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.d.ts +4 -2
- package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.js +30 -8
- package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
- package/lib/chain/opPools/opPool.d.ts +5 -4
- package/lib/chain/opPools/opPool.d.ts.map +1 -1
- package/lib/chain/opPools/opPool.js +62 -18
- package/lib/chain/opPools/opPool.js.map +1 -1
- package/lib/chain/opPools/proposerPreferencesPool.d.ts +4 -4
- package/lib/chain/opPools/proposerPreferencesPool.d.ts.map +1 -1
- package/lib/chain/opPools/proposerPreferencesPool.js +14 -11
- package/lib/chain/opPools/proposerPreferencesPool.js.map +1 -1
- package/lib/chain/opPools/utils.d.ts +4 -1
- package/lib/chain/opPools/utils.d.ts.map +1 -1
- package/lib/chain/opPools/utils.js +11 -1
- package/lib/chain/opPools/utils.js.map +1 -1
- package/lib/chain/options.d.ts +2 -1
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +1 -1
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +5 -2
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/computeNewStateRoot.js +1 -1
- package/lib/chain/produceBlock/computeNewStateRoot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts +3 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +6 -2
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/regen/regen.d.ts +2 -0
- package/lib/chain/regen/regen.d.ts.map +1 -1
- package/lib/chain/regen/regen.js +10 -4
- package/lib/chain/regen/regen.js.map +1 -1
- package/lib/chain/seenCache/seenGossipBlockInput.d.ts +7 -0
- package/lib/chain/seenCache/seenGossipBlockInput.d.ts.map +1 -1
- package/lib/chain/seenCache/seenGossipBlockInput.js +21 -0
- package/lib/chain/seenCache/seenGossipBlockInput.js.map +1 -1
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +9 -2
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +23 -13
- package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
- package/lib/chain/shufflingCache.d.ts +18 -8
- package/lib/chain/shufflingCache.d.ts.map +1 -1
- package/lib/chain/shufflingCache.js +72 -18
- package/lib/chain/shufflingCache.js.map +1 -1
- package/lib/chain/validation/attesterSlashing.d.ts +4 -4
- package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
- package/lib/chain/validation/attesterSlashing.js +3 -0
- package/lib/chain/validation/attesterSlashing.js.map +1 -1
- package/lib/chain/validation/proposerSlashing.d.ts +3 -3
- package/lib/chain/validation/proposerSlashing.d.ts.map +1 -1
- package/lib/chain/validation/proposerSlashing.js +3 -0
- package/lib/chain/validation/proposerSlashing.js.map +1 -1
- package/lib/chain/validatorMonitor.d.ts +5 -1
- package/lib/chain/validatorMonitor.d.ts.map +1 -1
- package/lib/chain/validatorMonitor.js +64 -54
- package/lib/chain/validatorMonitor.js.map +1 -1
- package/lib/db/beacon.d.ts +2 -0
- package/lib/db/beacon.d.ts.map +1 -1
- package/lib/db/beacon.js +5 -0
- package/lib/db/beacon.js.map +1 -1
- package/lib/db/buckets.d.ts +2 -1
- package/lib/db/buckets.d.ts.map +1 -1
- package/lib/db/buckets.js +1 -0
- package/lib/db/buckets.js.map +1 -1
- package/lib/db/interface.d.ts +2 -0
- package/lib/db/interface.d.ts.map +1 -1
- package/lib/db/repositories/blockArchiveIndex.d.ts +2 -2
- package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
- package/lib/db/repositories/earliestAvailableSlot.d.ts +11 -0
- package/lib/db/repositories/earliestAvailableSlot.d.ts.map +1 -0
- package/lib/db/repositories/earliestAvailableSlot.js +19 -0
- package/lib/db/repositories/earliestAvailableSlot.js.map +1 -0
- package/lib/db/repositories/proposerSlashing.d.ts +1 -0
- package/lib/db/repositories/proposerSlashing.d.ts.map +1 -1
- package/lib/db/repositories/proposerSlashing.js +5 -1
- package/lib/db/repositories/proposerSlashing.js.map +1 -1
- package/lib/execution/engine/disabled.d.ts +0 -2
- package/lib/execution/engine/disabled.d.ts.map +1 -1
- package/lib/execution/engine/disabled.js +0 -6
- package/lib/execution/engine/disabled.js.map +1 -1
- package/lib/execution/engine/http.d.ts +1 -3
- package/lib/execution/engine/http.d.ts.map +1 -1
- package/lib/execution/engine/http.js +2 -17
- package/lib/execution/engine/http.js.map +1 -1
- package/lib/execution/engine/interface.d.ts +2 -4
- package/lib/execution/engine/interface.d.ts.map +1 -1
- package/lib/execution/engine/mock.d.ts +0 -2
- package/lib/execution/engine/mock.d.ts.map +1 -1
- package/lib/execution/engine/mock.js +0 -8
- package/lib/execution/engine/mock.js.map +1 -1
- package/lib/execution/engine/types.d.ts +0 -8
- package/lib/execution/engine/types.d.ts.map +1 -1
- package/lib/execution/engine/types.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/metrics/metrics/beacon.d.ts +1 -1
- package/lib/metrics/metrics/beacon.d.ts.map +1 -1
- package/lib/metrics/metrics/beacon.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +7 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +17 -0
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/metrics/metrics.d.ts +7 -3
- package/lib/metrics/metrics.d.ts.map +1 -1
- package/lib/metrics/metrics.js +4 -4
- package/lib/metrics/metrics.js.map +1 -1
- package/lib/network/metadata.d.ts +1 -1
- package/lib/network/metadata.d.ts.map +1 -1
- package/lib/network/metadata.js +17 -17
- package/lib/network/metadata.js.map +1 -1
- package/lib/network/peers/datastore.d.ts +9 -9
- package/lib/network/peers/datastore.d.ts.map +1 -1
- package/lib/network/peers/datastore.js +36 -36
- package/lib/network/peers/datastore.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +66 -67
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/processor/gossipValidatorFn.d.ts +7 -3
- package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
- package/lib/network/processor/gossipValidatorFn.js +7 -3
- package/lib/network/processor/gossipValidatorFn.js.map +1 -1
- package/lib/network/processor/index.d.ts +9 -0
- package/lib/network/processor/index.d.ts.map +1 -1
- package/lib/network/processor/index.js +77 -10
- package/lib/network/processor/index.js.map +1 -1
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +41 -26
- package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -1
- package/lib/node/nodejs.d.ts +3 -1
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +27 -4
- package/lib/node/nodejs.js.map +1 -1
- package/lib/sync/range/batch.d.ts +11 -5
- package/lib/sync/range/batch.d.ts.map +1 -1
- package/lib/sync/range/batch.js +21 -17
- package/lib/sync/range/batch.js.map +1 -1
- package/lib/sync/range/chain.d.ts +4 -4
- package/lib/sync/range/chain.d.ts.map +1 -1
- package/lib/sync/range/chain.js +12 -6
- package/lib/sync/range/chain.js.map +1 -1
- package/lib/sync/range/range.d.ts.map +1 -1
- package/lib/sync/range/range.js +75 -29
- package/lib/sync/range/range.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts +14 -7
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +132 -66
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +38 -14
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +84 -39
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/util/execution.d.ts +11 -11
- package/lib/util/execution.d.ts.map +1 -1
- package/lib/util/execution.js +11 -7
- package/lib/util/execution.js.map +1 -1
- package/package.json +17 -17
- package/src/api/impl/beacon/blocks/index.ts +7 -4
- package/src/api/impl/beacon/index.ts +15 -0
- package/src/api/impl/beacon/pool/index.ts +4 -4
- package/src/api/impl/beacon/state/index.ts +31 -3
- package/src/api/impl/debug/index.ts +28 -19
- package/src/api/impl/validator/index.ts +24 -2
- package/src/chain/archiveStore/archiveStore.ts +26 -26
- package/src/chain/archiveStore/historicalState/getHistoricalState.ts +5 -7
- package/src/chain/archiveStore/historicalState/historicalStateRegen.ts +1 -1
- package/src/chain/archiveStore/historicalState/types.ts +2 -2
- package/src/chain/archiveStore/historicalState/worker.ts +1 -2
- package/src/chain/archiveStore/interface.ts +1 -1
- package/src/chain/archiveStore/utils/pruneHistory.ts +9 -4
- package/src/chain/blocks/importBlock.ts +20 -5
- package/src/chain/blocks/payloadEnvelopeInput/types.ts +2 -1
- package/src/chain/blocks/verifyBlock.ts +8 -6
- package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +6 -3
- package/src/chain/chain.ts +118 -38
- package/src/chain/emitter.ts +7 -1
- package/src/chain/errors/envelopeReconstructionError.ts +3 -0
- package/src/chain/errors/gossipValidation.ts +2 -0
- package/src/chain/forkChoice/index.ts +2 -0
- package/src/chain/initState.ts +8 -60
- package/src/chain/interface.ts +3 -2
- package/src/chain/opPools/aggregatedAttestationPool.ts +34 -10
- package/src/chain/opPools/opPool.ts +91 -18
- package/src/chain/opPools/proposerPreferencesPool.ts +14 -10
- package/src/chain/opPools/utils.ts +31 -3
- package/src/chain/options.ts +3 -3
- package/src/chain/prepareNextSlot.ts +6 -3
- package/src/chain/produceBlock/computeNewStateRoot.ts +1 -1
- package/src/chain/produceBlock/produceBlockBody.ts +8 -1
- package/src/chain/regen/regen.ts +12 -4
- package/src/chain/seenCache/seenGossipBlockInput.ts +23 -0
- package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +31 -13
- package/src/chain/shufflingCache.ts +84 -22
- package/src/chain/validation/attesterSlashing.ts +7 -4
- package/src/chain/validation/proposerSlashing.ts +7 -4
- package/src/chain/validatorMonitor.ts +75 -57
- package/src/db/beacon.ts +5 -0
- package/src/db/buckets.ts +1 -0
- package/src/db/interface.ts +2 -0
- package/src/db/repositories/earliestAvailableSlot.ts +19 -0
- package/src/db/repositories/proposerSlashing.ts +6 -1
- package/src/execution/engine/disabled.ts +0 -8
- package/src/execution/engine/http.ts +1 -30
- package/src/execution/engine/interface.ts +2 -6
- package/src/execution/engine/mock.ts +1 -19
- package/src/execution/engine/types.ts +0 -10
- package/src/index.ts +1 -1
- package/src/metrics/metrics/beacon.ts +1 -1
- package/src/metrics/metrics/lodestar.ts +18 -0
- package/src/metrics/metrics.ts +21 -6
- package/src/network/metadata.ts +17 -17
- package/src/network/peers/datastore.ts +36 -36
- package/src/network/processor/gossipHandlers.ts +97 -80
- package/src/network/processor/gossipValidatorFn.ts +13 -3
- package/src/network/processor/index.ts +89 -10
- package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +42 -28
- package/src/node/nodejs.ts +35 -3
- package/src/sync/range/batch.ts +25 -19
- package/src/sync/range/chain.ts +15 -8
- package/src/sync/range/range.ts +76 -30
- package/src/sync/unknownBlock.ts +156 -71
- package/src/sync/utils/downloadByRange.ts +123 -58
- package/src/util/execution.ts +26 -14
package/lib/network/metadata.js
CHANGED
|
@@ -29,12 +29,12 @@ export class MetadataController {
|
|
|
29
29
|
onSetValue;
|
|
30
30
|
networkConfig;
|
|
31
31
|
logger;
|
|
32
|
-
|
|
32
|
+
metadata;
|
|
33
33
|
constructor(opts, modules) {
|
|
34
34
|
this.networkConfig = modules.networkConfig;
|
|
35
35
|
this.logger = modules.logger;
|
|
36
36
|
this.onSetValue = modules.onSetValue;
|
|
37
|
-
this.
|
|
37
|
+
this.metadata = opts.metadata ?? {
|
|
38
38
|
...ssz.fulu.Metadata.defaultValue(),
|
|
39
39
|
custodyGroupCount: modules.networkConfig.custodyConfig.targetCustodyGroupCount,
|
|
40
40
|
};
|
|
@@ -42,50 +42,50 @@ export class MetadataController {
|
|
|
42
42
|
upstreamValues(currentEpoch) {
|
|
43
43
|
// updateEth2Field() MUST be called with clock epoch
|
|
44
44
|
this.updateEth2Field(currentEpoch);
|
|
45
|
-
this.onSetValue(ENRKey.attnets, ssz.phase0.AttestationSubnets.serialize(this.
|
|
45
|
+
this.onSetValue(ENRKey.attnets, ssz.phase0.AttestationSubnets.serialize(this.metadata.attnets));
|
|
46
46
|
const config = this.networkConfig.config;
|
|
47
47
|
if (config.getForkSeq(computeStartSlotAtEpoch(currentEpoch)) >= ForkSeq.altair) {
|
|
48
48
|
// Only persist syncnets if altair fork is already activated. If currentFork is altair but head is phase0
|
|
49
49
|
// adding syncnets to the ENR is not a problem, we will just have a useless field for a few hours.
|
|
50
|
-
this.onSetValue(ENRKey.syncnets, ssz.altair.SyncSubnets.serialize(this.
|
|
50
|
+
this.onSetValue(ENRKey.syncnets, ssz.altair.SyncSubnets.serialize(this.metadata.syncnets));
|
|
51
51
|
}
|
|
52
52
|
// Set CGC regardless of fork. It may be useful to clients before Fulu, and will be ignored otherwise.
|
|
53
|
-
this.onSetValue(ENRKey.cgc, serializeCgc(this.
|
|
53
|
+
this.onSetValue(ENRKey.cgc, serializeCgc(this.metadata.custodyGroupCount));
|
|
54
54
|
}
|
|
55
55
|
get seqNumber() {
|
|
56
|
-
return this.
|
|
56
|
+
return this.metadata.seqNumber;
|
|
57
57
|
}
|
|
58
58
|
get syncnets() {
|
|
59
|
-
return this.
|
|
59
|
+
return this.metadata.syncnets;
|
|
60
60
|
}
|
|
61
61
|
set syncnets(syncnets) {
|
|
62
62
|
this.onSetValue(ENRKey.syncnets, ssz.altair.SyncSubnets.serialize(syncnets));
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
63
|
+
this.metadata.seqNumber++;
|
|
64
|
+
this.metadata.syncnets = syncnets;
|
|
65
65
|
}
|
|
66
66
|
get attnets() {
|
|
67
|
-
return this.
|
|
67
|
+
return this.metadata.attnets;
|
|
68
68
|
}
|
|
69
69
|
set attnets(attnets) {
|
|
70
70
|
this.onSetValue(ENRKey.attnets, ssz.phase0.AttestationSubnets.serialize(attnets));
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
71
|
+
this.metadata.seqNumber++;
|
|
72
|
+
this.metadata.attnets = attnets;
|
|
73
73
|
}
|
|
74
74
|
get custodyGroupCount() {
|
|
75
|
-
return this.
|
|
75
|
+
return this.metadata.custodyGroupCount;
|
|
76
76
|
}
|
|
77
77
|
set custodyGroupCount(custodyGroupCount) {
|
|
78
|
-
if (custodyGroupCount === this.
|
|
78
|
+
if (custodyGroupCount === this.metadata.custodyGroupCount) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
this.onSetValue(ENRKey.cgc, serializeCgc(custodyGroupCount));
|
|
82
82
|
this.logger.debug("Updated cgc field in ENR", { custodyGroupCount });
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
83
|
+
this.metadata.seqNumber++;
|
|
84
|
+
this.metadata.custodyGroupCount = custodyGroupCount;
|
|
85
85
|
}
|
|
86
86
|
/** Consumers that need the phase0.Metadata type can just ignore the .syncnets property */
|
|
87
87
|
get json() {
|
|
88
|
-
return this.
|
|
88
|
+
return this.metadata;
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* From spec:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/network/metadata.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAC,uBAAuB,EAAC,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAsB,GAAG,EAAC,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAS,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAC,6BAA6B,EAAC,MAAM,YAAY,CAAC;AAGzD,MAAM,CAAN,IAAY,MAQX;AARD,WAAY,MAAM;IAChB,qBAAW,CAAA;IACX,uBAAa,CAAA;IACb,uBAAa,CAAA;IACb,6BAAmB,CAAA;IACnB,+BAAqB,CAAA;IACrB,qBAAW,CAAA;IACX,qBAAW,CAAA;AACb,CAAC,EARW,MAAM,KAAN,MAAM,QAQjB;AACD,MAAM,CAAN,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,iCAAmB,CAAA;IACnB,mCAAqB,CAAA;AACvB,CAAC,EAHW,UAAU,KAAV,UAAU,QAGrB;AAYD;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACrB,UAAU,CAA2C;IACrD,aAAa,CAAgB;IAC7B,MAAM,CAAS;IACf,
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/network/metadata.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAC,uBAAuB,EAAC,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAsB,GAAG,EAAC,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAS,KAAK,EAAC,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K,CAAC,eAAe,CAAC;YACvC,aAAa;SACd,CAAC,CAAC;QAEH,MAAM,cAAc,GAClB,aAAa,KAAK,gBAAgB;YAChC,CAAC,CAAC,MAAM,CAAC,uBAAuB,CAAC,MAAM,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC;YAC9E,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC;QACpC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,EAAC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,EAAC,CAAC,CAAC;QAEvF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,MAAoB,EAAE,UAAiB;IAClE,MAAM,EAAC,eAAe,EAAE,YAAY,EAAC,GAAG,6BAA6B,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAE1F,OAAO;QACL,sBAAsB;QACtB,UAAU,EAAE,MAAM,CAAC,uBAAuB,CAAC,eAAe,CAAC;QAC3D,4BAA4B;QAC5B,eAAe,EAAE,YAAY;YAC3B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO;YACzC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,OAAO;QAC9C,kBAAkB;QAClB,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB;KACpE,CAAC;AACJ,CAAC"}
|
|
@@ -8,23 +8,23 @@ type AwaitGenerator<T, TReturn = any, TNext = any> = Generator<T, TReturn, TNext
|
|
|
8
8
|
* This has a memory issue because all peer data stays in memory and loaded at startup time
|
|
9
9
|
* This is written for libp2p >=0.35, we maintain the same mechanism but with bounded data structure
|
|
10
10
|
* This datastore includes a memory datastore and fallback to db datastore
|
|
11
|
-
* Use an in-memory datastore with last accessed time and
|
|
11
|
+
* Use an in-memory datastore with last accessed time and maxMemoryItems, on start it's empty (lazy load)
|
|
12
12
|
* - get: Search in-memory datastore first, if not found search from db.
|
|
13
13
|
* - If found from db, add back to the in-memory datastore
|
|
14
14
|
* - Update lastAccessedMs
|
|
15
|
-
* - put: move oldest items from memory to db if there are more than
|
|
16
|
-
* - update memory datastore, only update db datastore if there are at least
|
|
15
|
+
* - put: move oldest items from memory to db if there are more than maxMemoryItems items in memory
|
|
16
|
+
* - update memory datastore, only update db datastore if there are at least threshold dirty items
|
|
17
17
|
* - Update lastAccessedMs
|
|
18
18
|
*/
|
|
19
19
|
export declare class Eth2PeerDataStore extends BaseDatastore {
|
|
20
|
-
private
|
|
21
|
-
private
|
|
20
|
+
private dbDatastore;
|
|
21
|
+
private memoryDatastore;
|
|
22
22
|
/** Same to PersistentPeerStore of the old libp2p implementation */
|
|
23
|
-
private
|
|
23
|
+
private dirtyItems;
|
|
24
24
|
/** If there are more dirty items than threshold, commit data to db */
|
|
25
|
-
private
|
|
25
|
+
private threshold;
|
|
26
26
|
/** If there are more memory items than this, prune oldest ones from memory and move to db */
|
|
27
|
-
private
|
|
27
|
+
private maxMemoryItems;
|
|
28
28
|
constructor(dbDatastore: LevelDatastore | string, { threshold, maxMemoryItems }?: {
|
|
29
29
|
threshold?: number | undefined;
|
|
30
30
|
maxMemoryItems?: number | undefined;
|
|
@@ -34,7 +34,7 @@ export declare class Eth2PeerDataStore extends BaseDatastore {
|
|
|
34
34
|
put(key: Key, val: Uint8Array, _options?: AbortOptions): Promise<Key>;
|
|
35
35
|
/**
|
|
36
36
|
* Same interface to put with "fromDb" option, if this item is updated back from db
|
|
37
|
-
* Move oldest items from memory data store to db if it's over this.
|
|
37
|
+
* Move oldest items from memory data store to db if it's over this.maxMemoryItems
|
|
38
38
|
*/
|
|
39
39
|
_put(key: Key, val: Uint8Array, fromDb?: boolean): Promise<Key>;
|
|
40
40
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datastore.d.ts","sourceRoot":"","sources":["../../../src/network/peers/datastore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAQ/D,KAAK,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,GAAG,EAAE,KAAK,GAAG,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAEtH;;;;;;;;;;;;GAYG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"datastore.d.ts","sourceRoot":"","sources":["../../../src/network/peers/datastore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAQ/D,KAAK,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,GAAG,EAAE,KAAK,GAAG,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAEtH;;;;;;;;;;;;GAYG;AACH,qBAAa,iBAAkB,SAAQ,aAAa;IAClD,OAAO,CAAC,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AG,cAAc,CAAC,GAAG,CAAC,CAKxE;YAEa,aAAa;YASb,WAAW;IAYzB;;OAEG;YACW,oBAAoB;CAkBnC"}
|
|
@@ -6,23 +6,23 @@ import { Key } from "interface-datastore";
|
|
|
6
6
|
* This has a memory issue because all peer data stays in memory and loaded at startup time
|
|
7
7
|
* This is written for libp2p >=0.35, we maintain the same mechanism but with bounded data structure
|
|
8
8
|
* This datastore includes a memory datastore and fallback to db datastore
|
|
9
|
-
* Use an in-memory datastore with last accessed time and
|
|
9
|
+
* Use an in-memory datastore with last accessed time and maxMemoryItems, on start it's empty (lazy load)
|
|
10
10
|
* - get: Search in-memory datastore first, if not found search from db.
|
|
11
11
|
* - If found from db, add back to the in-memory datastore
|
|
12
12
|
* - Update lastAccessedMs
|
|
13
|
-
* - put: move oldest items from memory to db if there are more than
|
|
14
|
-
* - update memory datastore, only update db datastore if there are at least
|
|
13
|
+
* - put: move oldest items from memory to db if there are more than maxMemoryItems items in memory
|
|
14
|
+
* - update memory datastore, only update db datastore if there are at least threshold dirty items
|
|
15
15
|
* - Update lastAccessedMs
|
|
16
16
|
*/
|
|
17
17
|
export class Eth2PeerDataStore extends BaseDatastore {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
dbDatastore;
|
|
19
|
+
memoryDatastore;
|
|
20
20
|
/** Same to PersistentPeerStore of the old libp2p implementation */
|
|
21
|
-
|
|
21
|
+
dirtyItems = new Set();
|
|
22
22
|
/** If there are more dirty items than threshold, commit data to db */
|
|
23
|
-
|
|
23
|
+
threshold;
|
|
24
24
|
/** If there are more memory items than this, prune oldest ones from memory and move to db */
|
|
25
|
-
|
|
25
|
+
maxMemoryItems;
|
|
26
26
|
constructor(dbDatastore, { threshold = 5, maxMemoryItems = 50 } = {}) {
|
|
27
27
|
super();
|
|
28
28
|
if (threshold <= 0 || maxMemoryItems <= 0) {
|
|
@@ -31,31 +31,31 @@ export class Eth2PeerDataStore extends BaseDatastore {
|
|
|
31
31
|
if (threshold > maxMemoryItems) {
|
|
32
32
|
throw Error(`Threshold ${threshold} should be at most maxMemoryItems ${maxMemoryItems}`);
|
|
33
33
|
}
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
34
|
+
this.dbDatastore = typeof dbDatastore === "string" ? new LevelDatastore(dbDatastore) : dbDatastore;
|
|
35
|
+
this.memoryDatastore = new Map();
|
|
36
|
+
this.threshold = threshold;
|
|
37
|
+
this.maxMemoryItems = maxMemoryItems;
|
|
38
38
|
}
|
|
39
39
|
async open() {
|
|
40
|
-
return this.
|
|
40
|
+
return this.dbDatastore.open();
|
|
41
41
|
}
|
|
42
42
|
async close() {
|
|
43
|
-
return this.
|
|
43
|
+
return this.dbDatastore.close();
|
|
44
44
|
}
|
|
45
45
|
async put(key, val, _options) {
|
|
46
46
|
return this._put(key, val, false);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Same interface to put with "fromDb" option, if this item is updated back from db
|
|
50
|
-
* Move oldest items from memory data store to db if it's over this.
|
|
50
|
+
* Move oldest items from memory data store to db if it's over this.maxMemoryItems
|
|
51
51
|
*/
|
|
52
52
|
async _put(key, val, fromDb = false) {
|
|
53
|
-
while (this.
|
|
53
|
+
while (this.memoryDatastore.size >= this.maxMemoryItems) {
|
|
54
54
|
// it's likely this is called only 1 time
|
|
55
55
|
await this.pruneMemoryDatastore();
|
|
56
56
|
}
|
|
57
57
|
const keyStr = key.toString();
|
|
58
|
-
const memoryItem = this.
|
|
58
|
+
const memoryItem = this.memoryDatastore.get(keyStr);
|
|
59
59
|
if (memoryItem) {
|
|
60
60
|
// update existing
|
|
61
61
|
memoryItem.lastAccessedMs = Date.now();
|
|
@@ -63,7 +63,7 @@ export class Eth2PeerDataStore extends BaseDatastore {
|
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
// new
|
|
66
|
-
this.
|
|
66
|
+
this.memoryDatastore.set(keyStr, { data: val, lastAccessedMs: Date.now() });
|
|
67
67
|
}
|
|
68
68
|
if (!fromDb)
|
|
69
69
|
await this._addDirtyItem(keyStr);
|
|
@@ -77,14 +77,14 @@ export class Eth2PeerDataStore extends BaseDatastore {
|
|
|
77
77
|
*/
|
|
78
78
|
async get(key, options) {
|
|
79
79
|
const keyStr = key.toString();
|
|
80
|
-
const memoryItem = this.
|
|
80
|
+
const memoryItem = this.memoryDatastore.get(keyStr);
|
|
81
81
|
if (memoryItem) {
|
|
82
82
|
memoryItem.lastAccessedMs = Date.now();
|
|
83
83
|
return memoryItem.data;
|
|
84
84
|
}
|
|
85
85
|
// this throws error if not found
|
|
86
|
-
const dbValue = await this.
|
|
87
|
-
// don't call this.
|
|
86
|
+
const dbValue = await this.dbDatastore.get(key, options);
|
|
87
|
+
// don't call this.memoryDatastore.set directly
|
|
88
88
|
// we want to get through prune() logic with fromDb as true
|
|
89
89
|
await this._put(key, dbValue, true);
|
|
90
90
|
return dbValue;
|
|
@@ -103,27 +103,27 @@ export class Eth2PeerDataStore extends BaseDatastore {
|
|
|
103
103
|
return true;
|
|
104
104
|
}
|
|
105
105
|
async delete(key, options) {
|
|
106
|
-
this.
|
|
107
|
-
await this.
|
|
106
|
+
this.memoryDatastore.delete(key.toString());
|
|
107
|
+
await this.dbDatastore.delete(key, options);
|
|
108
108
|
}
|
|
109
109
|
async *_all(q, options) {
|
|
110
|
-
for (const [key, value] of this.
|
|
110
|
+
for (const [key, value] of this.memoryDatastore.entries()) {
|
|
111
111
|
yield {
|
|
112
112
|
key: new Key(key),
|
|
113
113
|
value: value.data,
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
-
yield* this.
|
|
116
|
+
yield* this.dbDatastore.query(q, options);
|
|
117
117
|
}
|
|
118
118
|
async *_allKeys(q, options) {
|
|
119
|
-
for (const key of this.
|
|
119
|
+
for (const key of this.memoryDatastore.keys()) {
|
|
120
120
|
yield new Key(key);
|
|
121
121
|
}
|
|
122
|
-
yield* this.
|
|
122
|
+
yield* this.dbDatastore.queryKeys(q, options);
|
|
123
123
|
}
|
|
124
124
|
async _addDirtyItem(keyStr) {
|
|
125
|
-
this.
|
|
126
|
-
if (this.
|
|
125
|
+
this.dirtyItems.add(keyStr);
|
|
126
|
+
if (this.dirtyItems.size >= this.threshold) {
|
|
127
127
|
try {
|
|
128
128
|
await this._commitData();
|
|
129
129
|
}
|
|
@@ -131,15 +131,15 @@ export class Eth2PeerDataStore extends BaseDatastore {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
async _commitData() {
|
|
134
|
-
const batch = this.
|
|
135
|
-
for (const keyStr of this.
|
|
136
|
-
const memoryItem = this.
|
|
134
|
+
const batch = this.dbDatastore.batch();
|
|
135
|
+
for (const keyStr of this.dirtyItems) {
|
|
136
|
+
const memoryItem = this.memoryDatastore.get(keyStr);
|
|
137
137
|
if (memoryItem) {
|
|
138
138
|
batch.put(new Key(keyStr), memoryItem.data);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
await batch.commit();
|
|
142
|
-
this.
|
|
142
|
+
this.dirtyItems.clear();
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* Prune from memory and move to db
|
|
@@ -148,7 +148,7 @@ export class Eth2PeerDataStore extends BaseDatastore {
|
|
|
148
148
|
let oldestAccessedMs = Date.now() + 1000;
|
|
149
149
|
let oldestKey = undefined;
|
|
150
150
|
let oldestValue = undefined;
|
|
151
|
-
for (const [key, value] of this.
|
|
151
|
+
for (const [key, value] of this.memoryDatastore) {
|
|
152
152
|
if (value.lastAccessedMs < oldestAccessedMs) {
|
|
153
153
|
oldestAccessedMs = value.lastAccessedMs;
|
|
154
154
|
oldestKey = key;
|
|
@@ -156,8 +156,8 @@ export class Eth2PeerDataStore extends BaseDatastore {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
if (oldestKey && oldestValue) {
|
|
159
|
-
await this.
|
|
160
|
-
this.
|
|
159
|
+
await this.dbDatastore.put(new Key(oldestKey), oldestValue);
|
|
160
|
+
this.memoryDatastore.delete(oldestKey);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datastore.js","sourceRoot":"","sources":["../../../src/network/peers/datastore.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAC,GAAG,EAAwB,MAAM,qBAAqB,CAAC;AAU/D;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAC1C,
|
|
1
|
+
{"version":3,"file":"datastore.js","sourceRoot":"","sources":["../../../src/network/peers/datastore.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAC,GAAG,EAAwB,MAAM,qBAAqB,CAAC;AAU/D;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAC1C,WAAW,CAAiB;IAC5B,eAAe,CAA0B;IACjD,mEAAmE;IAC3D,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IACvC,sEAAsE;IAC9D,SAAS,CAAS;IAC1B,6FAA6F;IACrF,cAAc,CAAS;IAE/B,YACE,WAAoC,EACpC,EAAC,SAAS,GAAG,CAAC,EAAE,cAAc,GAAG,EAAE,EAAC,GAA0E,EAAE;QAEhH,KAAK,EAAE,CAAC;QAER,IAAI,SAAS,IAAI,CAAC,IAAI,cAAc,IAAI,CAAC,EAAE,CAAC;YAC1C,MAAM,KAAK,CAAC,qBAAqB,SAAS,sBAAsB,cAAc,EAAE,CAAC,CAAC;QACpF,CAAC;QACD,IAAI,SAAS,GAAG,cAAc,EAAE,CAAC;YAC/B,MAAM,KAAK,CAAC,aAAa,SAAS,qCAAqC,cAAc,EAAE,CAAC,CAAC;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,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,EAAE,QAAQ,EACjB,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,IAAI,GACd,OAAO,CAAC,CAAC,CAAC,CA+BZ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { routes } from "@lodestar/api";
|
|
2
2
|
import { PayloadStatus } from "@lodestar/fork-choice";
|
|
3
3
|
import { ForkSeq, NUMBER_OF_COLUMNS, isForkPostElectra, isForkPostGloas, } from "@lodestar/params";
|
|
4
|
-
import { computeTimeAtSlot } from "@lodestar/state-transition";
|
|
4
|
+
import { computeTimeAtSlot, signedBlockToSignedHeader } from "@lodestar/state-transition";
|
|
5
5
|
import { isGloasDataColumnSidecar, ssz, sszTypesFor, } from "@lodestar/types";
|
|
6
6
|
import { LogLevel, toHex, toRootHex } from "@lodestar/utils";
|
|
7
7
|
import { BlockInputSource, isBlockInputColumns, } from "../../chain/blocks/blockInput/index.js";
|
|
@@ -14,7 +14,7 @@ import { validateGossipBlobSidecar } from "../../chain/validation/blobSidecar.js
|
|
|
14
14
|
import { validateGossipFuluDataColumnSidecar, validateGossipGloasDataColumnSidecar, } from "../../chain/validation/dataColumnSidecar.js";
|
|
15
15
|
import { validateGossipExecutionPayloadBid } from "../../chain/validation/executionPayloadBid.js";
|
|
16
16
|
import { validateGossipExecutionPayloadEnvelope } from "../../chain/validation/executionPayloadEnvelope.js";
|
|
17
|
-
import { toElectraSingleAttestation, validateGossipAggregateAndProof, validateGossipAttestationsSameAttData, validateGossipAttesterSlashing, validateGossipBlock, validateGossipBlsToExecutionChange, validateGossipProposerSlashing, validateGossipSyncCommittee, validateGossipVoluntaryExit, validateSyncCommitteeGossipContributionAndProof, } from "../../chain/validation/index.js";
|
|
17
|
+
import { toElectraSingleAttestation, validateGossipAggregateAndProof, validateGossipAttestationsSameAttData, validateGossipAttesterSlashing, validateGossipBlock, validateGossipBlsToExecutionChange, validateGossipProposerSlashing, validateGossipSyncCommittee, validateGossipVoluntaryExit, validateSyncCommitteeGossipContributionAndProof, verifyBlockProposerSignature, } from "../../chain/validation/index.js";
|
|
18
18
|
import { validateLightClientFinalityUpdate } from "../../chain/validation/lightClientFinalityUpdate.js";
|
|
19
19
|
import { validateLightClientOptimisticUpdate } from "../../chain/validation/lightClientOptimisticUpdate.js";
|
|
20
20
|
import { validateGossipPayloadAttestationMessage } from "../../chain/validation/payloadAttestationMessage.js";
|
|
@@ -51,28 +51,10 @@ export function getGossipHandlers(modules, options) {
|
|
|
51
51
|
*/
|
|
52
52
|
function getSequentialHandlers(modules, options) {
|
|
53
53
|
const { chain, config, metrics, logger, core } = modules;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const delaySec = chain.clock.secFromSlot(slot, seenTimestampSec);
|
|
59
|
-
const recvToValLatency = Date.now() / 1000 - seenTimestampSec;
|
|
60
|
-
// always set block to seen cache for all forks so that we don't need to download it
|
|
61
|
-
// TODO: validate block before adding to cache
|
|
62
|
-
// tracked in https://github.com/ChainSafe/lodestar/issues/7957
|
|
63
|
-
const logCtx = {
|
|
64
|
-
slot,
|
|
65
|
-
root: blockRootHex,
|
|
66
|
-
currentSlot: chain.clock.currentSlot,
|
|
67
|
-
peerId: peerIdStr,
|
|
68
|
-
delaySec,
|
|
69
|
-
recvToValLatency,
|
|
70
|
-
};
|
|
71
|
-
logger.debug("Received gossip block", { ...logCtx });
|
|
72
|
-
// optimistically add gossip block to the seen cache
|
|
73
|
-
// if validation fails, we will NOT forward this gossip block to peers
|
|
74
|
-
// - if PARENT_BLOCK_UNKNOWN error, blockInput will then be queued inside BlockInputSync. If the gossip block is really invalid, it will be pruned there
|
|
75
|
-
// - if other validator errors, blockInput will stay in the seen cache and will be pruned on finalization
|
|
54
|
+
/**
|
|
55
|
+
* Add a gossip block to the seen caches. The proposer signature of the block MUST be verified.
|
|
56
|
+
*/
|
|
57
|
+
function cacheSignatureVerifiedBlock(signedBlock, blockRootHex, fork, peerIdStr, seenTimestampSec) {
|
|
76
58
|
const blockInput = chain.seenBlockInputCache.getByBlock({
|
|
77
59
|
block: signedBlock,
|
|
78
60
|
blockRootHex,
|
|
@@ -80,8 +62,7 @@ function getSequentialHandlers(modules, options) {
|
|
|
80
62
|
seenTimestampSec,
|
|
81
63
|
peerIdStr,
|
|
82
64
|
});
|
|
83
|
-
//
|
|
84
|
-
// This ensures we have PayloadEnvelopeInput, even through "PARENT_BLOCK_UNKNOWN" error
|
|
65
|
+
// Also seed the payload-envelope cache, so we have PayloadEnvelopeInput even through "PARENT_BLOCK_UNKNOWN" error
|
|
85
66
|
// see https://github.com/ChainSafe/lodestar/issues/9475
|
|
86
67
|
if (isForkPostGloas(fork)) {
|
|
87
68
|
chain.seenPayloadEnvelopeInputCache.add({
|
|
@@ -94,8 +75,27 @@ function getSequentialHandlers(modules, options) {
|
|
|
94
75
|
source: PayloadEnvelopeInputSource.gossip,
|
|
95
76
|
});
|
|
96
77
|
}
|
|
78
|
+
return blockInput;
|
|
79
|
+
}
|
|
80
|
+
async function validateBeaconBlock(signedBlock, fork, peerIdStr, seenTimestampSec) {
|
|
81
|
+
const slot = signedBlock.message.slot;
|
|
82
|
+
const forkTypes = config.getForkTypes(slot);
|
|
83
|
+
const blockRootHex = toRootHex(forkTypes.BeaconBlock.hashTreeRoot(signedBlock.message));
|
|
84
|
+
const delaySec = chain.clock.secFromSlot(slot, seenTimestampSec);
|
|
85
|
+
const recvToValLatency = Date.now() / 1000 - seenTimestampSec;
|
|
86
|
+
const logCtx = {
|
|
87
|
+
slot,
|
|
88
|
+
root: blockRootHex,
|
|
89
|
+
currentSlot: chain.clock.currentSlot,
|
|
90
|
+
peerId: peerIdStr,
|
|
91
|
+
delaySec,
|
|
92
|
+
recvToValLatency,
|
|
93
|
+
};
|
|
94
|
+
logger.debug("Received gossip block", { ...logCtx });
|
|
95
|
+
chain.seenBlockInputCache.markValidatingBlock(blockRootHex);
|
|
97
96
|
try {
|
|
98
97
|
const { skippedSlots } = await validateGossipBlock(config, chain, signedBlock, fork);
|
|
98
|
+
const blockInput = cacheSignatureVerifiedBlock(signedBlock, blockRootHex, fork, peerIdStr, seenTimestampSec);
|
|
99
99
|
const blockInputMeta = blockInput.getLogMeta();
|
|
100
100
|
const recvToValidation = Date.now() / 1000 - seenTimestampSec;
|
|
101
101
|
const validationTime = recvToValidation - recvToValLatency;
|
|
@@ -115,44 +115,41 @@ function getSequentialHandlers(modules, options) {
|
|
|
115
115
|
catch (e) {
|
|
116
116
|
if (e instanceof BlockGossipError) {
|
|
117
117
|
logger.debug("Gossip block has error", { slot, root: blockRootHex, code: e.type.code });
|
|
118
|
-
if (
|
|
119
|
-
e.type.code === BlockErrorCode.PARENT_PAYLOAD_UNKNOWN)
|
|
120
|
-
|
|
118
|
+
if (e.type.code === BlockErrorCode.PARENT_BLOCK_UNKNOWN ||
|
|
119
|
+
e.type.code === BlockErrorCode.PARENT_PAYLOAD_UNKNOWN) {
|
|
120
|
+
// The block is retained for unknown parent sync without full validation. Authenticate it first, this
|
|
121
|
+
// does not need the parent state
|
|
122
|
+
const proposerIndex = signedBlock.message.proposerIndex;
|
|
123
|
+
await verifyBlockProposerSignature(chain, signedBlock, blockRootHex);
|
|
124
|
+
chain.seenBlockProposers.observeBlockRoot(slot, proposerIndex, blockRootHex, signedBlockToSignedHeader(config, signedBlock));
|
|
125
|
+
// Check again after the signature verification so concurrent proposals cannot both be retained
|
|
126
|
+
if (chain.seenBlockProposers.isKnown(slot, proposerIndex)) {
|
|
127
|
+
if (chain.seenBlockProposers.isRepeatProposal(slot, proposerIndex, blockRootHex)) {
|
|
128
|
+
throw new BlockGossipError(GossipAction.IGNORE, {
|
|
129
|
+
code: BlockErrorCode.REPEAT_PROPOSAL,
|
|
130
|
+
proposerIndex,
|
|
131
|
+
root: blockRootHex,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
throw new BlockGossipError(GossipAction.IGNORE, { code: BlockErrorCode.ALREADY_KNOWN, root: blockRootHex });
|
|
135
|
+
}
|
|
136
|
+
chain.seenBlockProposers.add(slot, proposerIndex, blockRootHex);
|
|
137
|
+
const blockInput = cacheSignatureVerifiedBlock(signedBlock, blockRootHex, fork, peerIdStr, seenTimestampSec);
|
|
121
138
|
chain.emitter.emit(ChainEvent.blockUnknownParent, {
|
|
122
139
|
blockInput,
|
|
123
140
|
peer: peerIdStr,
|
|
124
141
|
source: BlockInputSource.gossip,
|
|
125
142
|
});
|
|
126
|
-
// throw error (don't prune the blockInput)
|
|
127
143
|
throw e;
|
|
128
144
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// (provably invalid), unexpected errors and repeat proposals that are not imported prune.
|
|
132
|
-
if (e.action === GossipAction.IGNORE) {
|
|
133
|
-
// Only a signature-verified sibling is imported by the beacon_block handler, any other repeat proposal
|
|
134
|
-
// is dropped from the caches and re-downloaded by sync if it ever becomes relevant. Its signature was not
|
|
135
|
-
// verified, so only its own entry is removed, never its claimed ancestors
|
|
136
|
-
if (e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
|
|
137
|
-
!chain.seenBlockProposers.hasBlockRoot(slot, signedBlock.message.proposerIndex, blockRootHex)) {
|
|
138
|
-
chain.seenBlockInputCache.remove(blockRootHex);
|
|
139
|
-
if (isForkPostGloas(fork)) {
|
|
140
|
-
chain.seenPayloadEnvelopeInputCache.remove(blockRootHex);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
throw e;
|
|
145
|
+
if (e.action === GossipAction.REJECT) {
|
|
146
|
+
chain.persistInvalidSszValue(forkTypes.SignedBeaconBlock, signedBlock, `gossip_reject_slot_${slot}`, blockRootHex);
|
|
144
147
|
}
|
|
145
|
-
chain.persistInvalidSszValue(forkTypes.SignedBeaconBlock, signedBlock, `gossip_reject_slot_${slot}`, blockRootHex);
|
|
146
|
-
}
|
|
147
|
-
// REJECT or unexpected (non-BlockGossipError) error: drop the optimistically-added entries from
|
|
148
|
-
// both caches, keeping them consistent. The block may carry any parent root, so only its own entry is removed
|
|
149
|
-
chain.seenBlockInputCache.remove(blockRootHex);
|
|
150
|
-
if (isForkPostGloas(fork)) {
|
|
151
|
-
chain.seenPayloadEnvelopeInputCache.remove(blockRootHex);
|
|
152
148
|
}
|
|
153
149
|
throw e;
|
|
154
150
|
}
|
|
155
151
|
finally {
|
|
152
|
+
chain.seenBlockInputCache.unmarkValidatingBlock(blockRootHex);
|
|
156
153
|
// The block received from the network may have established an equivocation, either by conflicting
|
|
157
154
|
// with a previously observed block root (REPEAT_PROPOSAL) or with a root observed during validation
|
|
158
155
|
const proposerIndex = signedBlock.message.proposerIndex;
|
|
@@ -549,17 +546,16 @@ function getSequentialHandlers(modules, options) {
|
|
|
549
546
|
e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
|
|
550
547
|
// Only a signature-verified sibling recorded in the seen cache is imported. The cache holds at most two
|
|
551
548
|
// roots per proposer and slot, which bounds full imports over gossip to one alternate
|
|
552
|
-
chain.seenBlockProposers.hasBlockRoot(signedBlock.message.slot, e.type.proposerIndex, e.type.root)
|
|
553
|
-
//
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
}
|
|
549
|
+
chain.seenBlockProposers.hasBlockRoot(signedBlock.message.slot, e.type.proposerIndex, e.type.root) &&
|
|
550
|
+
// A sibling with an unknown parent cannot be imported, sync fetches it if its branch becomes relevant
|
|
551
|
+
chain.forkChoice.getBlockHexDefaultStatus(toRootHex(signedBlock.message.parentRoot)) !== null) {
|
|
552
|
+
const blockInput = cacheSignatureVerifiedBlock(signedBlock, e.type.root, topic.boundary.fork, peerIdStr, seenTimestampSec);
|
|
553
|
+
// We're returning IGNORE (thrown below), so this block is not forwarded to peers. Unlike the
|
|
554
|
+
// happy path there is no rush to forward, so we don't need to wrap in callInNextEventLoop.
|
|
555
|
+
chain.serializedCache.set(signedBlock, serializedData);
|
|
556
|
+
// this is technically not a valid gossip block but gossip validation is a cheap subset of checks
|
|
557
|
+
// this runs the full state transition, so importing an equivocating-but-valid block here is safe.
|
|
558
|
+
handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);
|
|
563
559
|
}
|
|
564
560
|
// rethrow so gossipValidatorFn maps IGNORE -> TopicValidatorResult.Ignore (message not forwarded)
|
|
565
561
|
throw e;
|
|
@@ -780,11 +776,11 @@ function getSequentialHandlers(modules, options) {
|
|
|
780
776
|
const { serializedData } = gossipData;
|
|
781
777
|
const { fork } = topic.boundary;
|
|
782
778
|
const attesterSlashing = sszDeserialize(topic, serializedData);
|
|
783
|
-
await validateGossipAttesterSlashing(chain, attesterSlashing);
|
|
779
|
+
const verifiedDomains = await validateGossipAttesterSlashing(chain, attesterSlashing);
|
|
784
780
|
// Handler - deferred to next event loop so the validation result propagates first
|
|
785
781
|
callInNextEventLoop(() => {
|
|
786
782
|
try {
|
|
787
|
-
chain.opPool.insertAttesterSlashing(fork, attesterSlashing);
|
|
783
|
+
chain.opPool.insertAttesterSlashing(fork, attesterSlashing, verifiedDomains);
|
|
788
784
|
chain.forkChoice.onAttesterSlashing(attesterSlashing);
|
|
789
785
|
chain.emitter.emit(routes.events.EventType.attesterSlashing, attesterSlashing);
|
|
790
786
|
}
|
|
@@ -796,11 +792,11 @@ function getSequentialHandlers(modules, options) {
|
|
|
796
792
|
[GossipType.proposer_slashing]: async ({ gossipData, topic, }) => {
|
|
797
793
|
const { serializedData } = gossipData;
|
|
798
794
|
const proposerSlashing = sszDeserialize(topic, serializedData);
|
|
799
|
-
await validateGossipProposerSlashing(chain, proposerSlashing);
|
|
795
|
+
const verifiedDomain = await validateGossipProposerSlashing(chain, proposerSlashing);
|
|
800
796
|
// Handler - deferred to next event loop so the validation result propagates first
|
|
801
797
|
callInNextEventLoop(() => {
|
|
802
798
|
try {
|
|
803
|
-
chain.opPool.insertProposerSlashing(proposerSlashing);
|
|
799
|
+
chain.opPool.insertProposerSlashing(proposerSlashing, verifiedDomain);
|
|
804
800
|
chain.emitter.emit(routes.events.EventType.proposerSlashing, proposerSlashing);
|
|
805
801
|
}
|
|
806
802
|
catch (e) {
|
|
@@ -981,6 +977,9 @@ function getSequentialHandlers(modules, options) {
|
|
|
981
977
|
case PayloadErrorCode.ENVELOPE_VERIFICATION_ERROR:
|
|
982
978
|
case PayloadErrorCode.EXECUTION_ENGINE_INVALID:
|
|
983
979
|
core.reportPeer(peerIdStr, PeerAction.LowToleranceError, "BadGossipPayload");
|
|
980
|
+
// The builder may have signed another envelope that is valid, keeping this one would make
|
|
981
|
+
// by-root and range sync reuse it and never import the payload
|
|
982
|
+
chain.seenPayloadEnvelopeInputCache.removeInvalid(payloadInput);
|
|
984
983
|
// Misbehaving peer, but could highlight an issue in another client
|
|
985
984
|
logLevel = LogLevel.warn;
|
|
986
985
|
break;
|