@lodestar/beacon-node 1.38.0 → 1.39.0-dev.39dac0f03d
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/utils.js +1 -1
- package/lib/api/impl/beacon/blocks/utils.js.map +1 -1
- package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/state/index.js +4 -5
- package/lib/api/impl/beacon/state/index.js.map +1 -1
- package/lib/api/impl/validator/index.js +1 -1
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.js +1 -21
- package/lib/chain/blocks/verifyBlock.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts +1 -6
- package/lib/chain/blocks/verifyBlocksExecutionPayloads.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +9 -128
- package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksSignatures.d.ts +3 -2
- package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlocksSignatures.js +2 -2
- package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
- package/lib/chain/chain.d.ts +1 -4
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +10 -28
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/initState.d.ts +1 -14
- package/lib/chain/initState.d.ts.map +1 -1
- package/lib/chain/initState.js +1 -62
- package/lib/chain/initState.js.map +1 -1
- package/lib/chain/interface.d.ts +0 -2
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/interface.js.map +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.d.ts +4 -4
- package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.js +4 -4
- package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
- package/lib/chain/opPools/opPool.d.ts +3 -0
- package/lib/chain/opPools/opPool.d.ts.map +1 -1
- package/lib/chain/opPools/opPool.js +9 -8
- package/lib/chain/opPools/opPool.js.map +1 -1
- package/lib/chain/options.d.ts +0 -4
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +0 -2
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts +0 -4
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +2 -22
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts +2 -22
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +32 -98
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/rewards/attestationsRewards.d.ts +3 -2
- package/lib/chain/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/chain/rewards/attestationsRewards.js +9 -9
- package/lib/chain/rewards/attestationsRewards.js.map +1 -1
- package/lib/chain/rewards/blockRewards.d.ts +2 -1
- package/lib/chain/rewards/blockRewards.d.ts.map +1 -1
- package/lib/chain/rewards/blockRewards.js +5 -5
- package/lib/chain/rewards/blockRewards.js.map +1 -1
- package/lib/chain/rewards/syncCommitteeRewards.d.ts +3 -2
- package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +1 -1
- package/lib/chain/rewards/syncCommitteeRewards.js +2 -3
- package/lib/chain/rewards/syncCommitteeRewards.js.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +4 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.js +4 -2
- package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
- package/lib/chain/validation/attesterSlashing.js +2 -2
- package/lib/chain/validation/attesterSlashing.js.map +1 -1
- package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
- package/lib/chain/validation/blobSidecar.js +2 -2
- package/lib/chain/validation/blobSidecar.js.map +1 -1
- package/lib/chain/validation/block.js +1 -1
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/blsToExecutionChange.js +1 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +2 -2
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/chain/validation/proposerSlashing.js +1 -1
- package/lib/chain/validation/proposerSlashing.js.map +1 -1
- package/lib/chain/validation/signatureSets/aggregateAndProof.js +1 -1
- package/lib/chain/validation/signatureSets/aggregateAndProof.js.map +1 -1
- package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +3 -2
- package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
- package/lib/chain/validation/signatureSets/contributionAndProof.js +3 -4
- package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommittee.d.ts +3 -2
- package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommittee.js +3 -3
- package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -1
- package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
- package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +3 -2
- package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +2 -3
- package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
- package/lib/chain/validation/syncCommittee.js +1 -1
- package/lib/chain/validation/syncCommittee.js.map +1 -1
- package/lib/chain/validation/syncCommitteeContributionAndProof.d.ts.map +1 -1
- package/lib/chain/validation/syncCommitteeContributionAndProof.js +5 -4
- package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
- package/lib/chain/validation/voluntaryExit.js +1 -1
- package/lib/chain/validation/voluntaryExit.js.map +1 -1
- package/lib/db/beacon.d.ts +3 -7
- package/lib/db/beacon.d.ts.map +1 -1
- package/lib/db/beacon.js +33 -12
- package/lib/db/beacon.js.map +1 -1
- package/lib/db/buckets.d.ts +12 -6
- package/lib/db/buckets.d.ts.map +1 -1
- package/lib/db/buckets.js +6 -1
- package/lib/db/buckets.js.map +1 -1
- package/lib/db/interface.d.ts +2 -7
- package/lib/db/interface.d.ts.map +1 -1
- package/lib/db/repositories/index.d.ts +0 -3
- package/lib/db/repositories/index.d.ts.map +1 -1
- package/lib/db/repositories/index.js +0 -3
- package/lib/db/repositories/index.js.map +1 -1
- package/lib/execution/engine/http.d.ts +5 -13
- package/lib/execution/engine/http.d.ts.map +1 -1
- package/lib/execution/engine/http.js +6 -15
- package/lib/execution/engine/http.js.map +1 -1
- package/lib/execution/engine/index.d.ts.map +1 -1
- package/lib/execution/engine/index.js +1 -1
- package/lib/execution/engine/index.js.map +1 -1
- package/lib/execution/engine/interface.d.ts +1 -1
- package/lib/execution/engine/interface.d.ts.map +1 -1
- package/lib/execution/engine/interface.js.map +1 -1
- package/lib/{eth1/provider → execution/engine}/jsonRpcHttpClient.d.ts +1 -1
- package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -0
- package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -0
- package/lib/execution/engine/jwt.d.ts.map +1 -0
- package/lib/execution/engine/jwt.js.map +1 -0
- package/lib/execution/engine/mock.d.ts +2 -6
- package/lib/execution/engine/mock.d.ts.map +1 -1
- package/lib/execution/engine/mock.js +4 -15
- package/lib/execution/engine/mock.js.map +1 -1
- package/lib/execution/engine/payloadIdCache.d.ts +1 -1
- package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
- package/lib/execution/engine/types.d.ts +1 -1
- package/lib/execution/engine/types.d.ts.map +1 -1
- package/lib/execution/engine/types.js +1 -1
- package/lib/execution/engine/types.js.map +1 -1
- package/lib/execution/engine/utils.d.ts +64 -2
- package/lib/execution/engine/utils.d.ts.map +1 -1
- package/lib/execution/engine/utils.js +91 -2
- package/lib/execution/engine/utils.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +0 -49
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +0 -134
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/core/events.d.ts +1 -1
- package/lib/network/core/events.d.ts.map +1 -1
- package/lib/network/core/events.js +1 -1
- package/lib/network/core/events.js.map +1 -1
- package/lib/network/events.d.ts +6 -1
- package/lib/network/events.d.ts.map +1 -1
- package/lib/network/events.js +7 -1
- package/lib/network/events.js.map +1 -1
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +10 -9
- package/lib/node/nodejs.js.map +1 -1
- package/lib/node/notifier.d.ts.map +1 -1
- package/lib/node/notifier.js +0 -13
- package/lib/node/notifier.js.map +1 -1
- package/lib/node/options.d.ts +0 -2
- package/lib/node/options.d.ts.map +1 -1
- package/lib/node/options.js +0 -2
- package/lib/node/options.js.map +1 -1
- package/lib/node/utils/interop/deposits.d.ts +2 -1
- package/lib/node/utils/interop/deposits.d.ts.map +1 -1
- package/lib/node/utils/interop/deposits.js.map +1 -1
- package/lib/node/utils/interop/state.d.ts +1 -1
- package/lib/node/utils/interop/state.d.ts.map +1 -1
- package/lib/node/utils/state.d.ts +1 -7
- package/lib/node/utils/state.d.ts.map +1 -1
- package/lib/node/utils/state.js +1 -14
- package/lib/node/utils/state.js.map +1 -1
- package/lib/sync/backfill/backfill.d.ts.map +1 -1
- package/lib/sync/backfill/backfill.js +2 -2
- package/lib/sync/backfill/backfill.js.map +1 -1
- package/lib/sync/backfill/verify.d.ts +2 -2
- package/lib/sync/backfill/verify.d.ts.map +1 -1
- package/lib/sync/backfill/verify.js +3 -3
- package/lib/sync/backfill/verify.js.map +1 -1
- package/lib/util/workerEvents.d.ts +1 -6
- package/lib/util/workerEvents.d.ts.map +1 -1
- package/lib/util/workerEvents.js +8 -8
- package/lib/util/workerEvents.js.map +1 -1
- package/package.json +14 -21
- package/src/api/impl/beacon/blocks/utils.ts +1 -1
- package/src/api/impl/beacon/state/index.ts +4 -5
- package/src/api/impl/validator/index.ts +1 -1
- package/src/chain/blocks/verifyBlock.ts +3 -24
- package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +9 -161
- package/src/chain/blocks/verifyBlocksSignatures.ts +5 -2
- package/src/chain/chain.ts +9 -32
- package/src/chain/initState.ts +1 -97
- package/src/chain/interface.ts +0 -2
- package/src/chain/opPools/aggregatedAttestationPool.ts +7 -7
- package/src/chain/opPools/opPool.ts +8 -8
- package/src/chain/options.ts +0 -6
- package/src/chain/prepareNextSlot.ts +2 -29
- package/src/chain/produceBlock/produceBlockBody.ts +33 -132
- package/src/chain/rewards/attestationsRewards.ts +18 -8
- package/src/chain/rewards/blockRewards.ts +6 -3
- package/src/chain/rewards/syncCommitteeRewards.ts +5 -3
- package/src/chain/stateCache/persistentCheckpointsCache.ts +15 -2
- package/src/chain/validation/attesterSlashing.ts +2 -2
- package/src/chain/validation/blobSidecar.ts +10 -2
- package/src/chain/validation/block.ts +1 -1
- package/src/chain/validation/blsToExecutionChange.ts +1 -1
- package/src/chain/validation/dataColumnSidecar.ts +6 -1
- package/src/chain/validation/proposerSlashing.ts +1 -1
- package/src/chain/validation/signatureSets/aggregateAndProof.ts +1 -1
- package/src/chain/validation/signatureSets/contributionAndProof.ts +6 -3
- package/src/chain/validation/signatureSets/syncCommittee.ts +6 -2
- package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +3 -1
- package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +5 -2
- package/src/chain/validation/syncCommittee.ts +1 -1
- package/src/chain/validation/syncCommitteeContributionAndProof.ts +10 -6
- package/src/chain/validation/voluntaryExit.ts +1 -1
- package/src/db/beacon.ts +38 -16
- package/src/db/buckets.ts +12 -7
- package/src/db/interface.ts +2 -13
- package/src/db/repositories/index.ts +0 -3
- package/src/execution/engine/http.ts +12 -21
- package/src/execution/engine/index.ts +1 -1
- package/src/execution/engine/interface.ts +1 -1
- package/src/{eth1/provider → execution/engine}/jsonRpcHttpClient.ts +1 -1
- package/src/execution/engine/mock.ts +4 -17
- package/src/execution/engine/payloadIdCache.ts +1 -1
- package/src/execution/engine/types.ts +9 -9
- package/src/execution/engine/utils.ts +111 -5
- package/src/index.ts +1 -2
- package/src/metrics/metrics/lodestar.ts +0 -144
- package/src/network/core/events.ts +1 -1
- package/src/network/events.ts +7 -1
- package/src/node/nodejs.ts +11 -9
- package/src/node/notifier.ts +0 -16
- package/src/node/options.ts +0 -3
- package/src/node/utils/interop/deposits.ts +3 -1
- package/src/node/utils/interop/state.ts +1 -1
- package/src/node/utils/state.ts +3 -18
- package/src/sync/backfill/backfill.ts +14 -2
- package/src/sync/backfill/verify.ts +10 -2
- package/src/util/workerEvents.ts +9 -8
- package/lib/chain/genesis/genesis.d.ts +0 -51
- package/lib/chain/genesis/genesis.d.ts.map +0 -1
- package/lib/chain/genesis/genesis.js +0 -123
- package/lib/chain/genesis/genesis.js.map +0 -1
- package/lib/chain/genesis/interface.d.ts +0 -13
- package/lib/chain/genesis/interface.d.ts.map +0 -1
- package/lib/chain/genesis/interface.js +0 -2
- package/lib/chain/genesis/interface.js.map +0 -1
- package/lib/db/repositories/depositDataRoot.d.ts +0 -22
- package/lib/db/repositories/depositDataRoot.d.ts.map +0 -1
- package/lib/db/repositories/depositDataRoot.js +0 -62
- package/lib/db/repositories/depositDataRoot.js.map +0 -1
- package/lib/db/repositories/depositEvent.d.ts +0 -13
- package/lib/db/repositories/depositEvent.d.ts.map +0 -1
- package/lib/db/repositories/depositEvent.js +0 -27
- package/lib/db/repositories/depositEvent.js.map +0 -1
- package/lib/db/repositories/eth1Data.d.ts +0 -13
- package/lib/db/repositories/eth1Data.d.ts.map +0 -1
- package/lib/db/repositories/eth1Data.js +0 -26
- package/lib/db/repositories/eth1Data.js.map +0 -1
- package/lib/db/single/index.d.ts +0 -3
- package/lib/db/single/index.d.ts.map +0 -1
- package/lib/db/single/index.js +0 -3
- package/lib/db/single/index.js.map +0 -1
- package/lib/db/single/preGenesisState.d.ts +0 -16
- package/lib/db/single/preGenesisState.d.ts.map +0 -1
- package/lib/db/single/preGenesisState.js +0 -29
- package/lib/db/single/preGenesisState.js.map +0 -1
- package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts +0 -14
- package/lib/db/single/preGenesisStateLastProcessedBlock.d.ts.map +0 -1
- package/lib/db/single/preGenesisStateLastProcessedBlock.js +0 -27
- package/lib/db/single/preGenesisStateLastProcessedBlock.js.map +0 -1
- package/lib/eth1/errors.d.ts +0 -66
- package/lib/eth1/errors.d.ts.map +0 -1
- package/lib/eth1/errors.js +0 -27
- package/lib/eth1/errors.js.map +0 -1
- package/lib/eth1/eth1DataCache.d.ts +0 -19
- package/lib/eth1/eth1DataCache.d.ts.map +0 -1
- package/lib/eth1/eth1DataCache.js +0 -19
- package/lib/eth1/eth1DataCache.js.map +0 -1
- package/lib/eth1/eth1DepositDataTracker.d.ts +0 -80
- package/lib/eth1/eth1DepositDataTracker.d.ts.map +0 -1
- package/lib/eth1/eth1DepositDataTracker.js +0 -317
- package/lib/eth1/eth1DepositDataTracker.js.map +0 -1
- package/lib/eth1/eth1DepositsCache.d.ts +0 -42
- package/lib/eth1/eth1DepositsCache.d.ts.map +0 -1
- package/lib/eth1/eth1DepositsCache.js +0 -119
- package/lib/eth1/eth1DepositsCache.js.map +0 -1
- package/lib/eth1/eth1MergeBlockTracker.d.ts +0 -65
- package/lib/eth1/eth1MergeBlockTracker.d.ts.map +0 -1
- package/lib/eth1/eth1MergeBlockTracker.js +0 -262
- package/lib/eth1/eth1MergeBlockTracker.js.map +0 -1
- package/lib/eth1/index.d.ts +0 -46
- package/lib/eth1/index.d.ts.map +0 -1
- package/lib/eth1/index.js +0 -121
- package/lib/eth1/index.js.map +0 -1
- package/lib/eth1/interface.d.ts +0 -112
- package/lib/eth1/interface.d.ts.map +0 -1
- package/lib/eth1/interface.js +0 -8
- package/lib/eth1/interface.js.map +0 -1
- package/lib/eth1/options.d.ts +0 -22
- package/lib/eth1/options.d.ts.map +0 -1
- package/lib/eth1/options.js +0 -8
- package/lib/eth1/options.js.map +0 -1
- package/lib/eth1/provider/eth1Provider.d.ts +0 -39
- package/lib/eth1/provider/eth1Provider.d.ts.map +0 -1
- package/lib/eth1/provider/eth1Provider.js +0 -147
- package/lib/eth1/provider/eth1Provider.js.map +0 -1
- package/lib/eth1/provider/jsonRpcHttpClient.d.ts.map +0 -1
- package/lib/eth1/provider/jsonRpcHttpClient.js.map +0 -1
- package/lib/eth1/provider/jwt.d.ts.map +0 -1
- package/lib/eth1/provider/jwt.js.map +0 -1
- package/lib/eth1/provider/utils.d.ts +0 -65
- package/lib/eth1/provider/utils.d.ts.map +0 -1
- package/lib/eth1/provider/utils.js +0 -120
- package/lib/eth1/provider/utils.js.map +0 -1
- package/lib/eth1/stream.d.ts +0 -15
- package/lib/eth1/stream.d.ts.map +0 -1
- package/lib/eth1/stream.js +0 -54
- package/lib/eth1/stream.js.map +0 -1
- package/lib/eth1/utils/depositContract.d.ts +0 -14
- package/lib/eth1/utils/depositContract.d.ts.map +0 -1
- package/lib/eth1/utils/depositContract.js +0 -33
- package/lib/eth1/utils/depositContract.js.map +0 -1
- package/lib/eth1/utils/deposits.d.ts +0 -8
- package/lib/eth1/utils/deposits.d.ts.map +0 -1
- package/lib/eth1/utils/deposits.js +0 -47
- package/lib/eth1/utils/deposits.js.map +0 -1
- package/lib/eth1/utils/eth1Data.d.ts +0 -22
- package/lib/eth1/utils/eth1Data.d.ts.map +0 -1
- package/lib/eth1/utils/eth1Data.js +0 -77
- package/lib/eth1/utils/eth1Data.js.map +0 -1
- package/lib/eth1/utils/eth1DepositEvent.d.ts +0 -7
- package/lib/eth1/utils/eth1DepositEvent.d.ts.map +0 -1
- package/lib/eth1/utils/eth1DepositEvent.js +0 -13
- package/lib/eth1/utils/eth1DepositEvent.js.map +0 -1
- package/lib/eth1/utils/eth1Vote.d.ts +0 -17
- package/lib/eth1/utils/eth1Vote.d.ts.map +0 -1
- package/lib/eth1/utils/eth1Vote.js +0 -111
- package/lib/eth1/utils/eth1Vote.js.map +0 -1
- package/lib/eth1/utils/groupDepositEventsByBlock.d.ts +0 -9
- package/lib/eth1/utils/groupDepositEventsByBlock.d.ts.map +0 -1
- package/lib/eth1/utils/groupDepositEventsByBlock.js +0 -17
- package/lib/eth1/utils/groupDepositEventsByBlock.js.map +0 -1
- package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts +0 -10
- package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.d.ts.map +0 -1
- package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js +0 -14
- package/lib/eth1/utils/optimizeNextBlockDiffForGenesis.js.map +0 -1
- package/src/chain/genesis/genesis.ts +0 -190
- package/src/chain/genesis/interface.ts +0 -14
- package/src/db/repositories/depositDataRoot.ts +0 -80
- package/src/db/repositories/depositEvent.ts +0 -32
- package/src/db/repositories/eth1Data.ts +0 -33
- package/src/db/single/index.ts +0 -2
- package/src/db/single/preGenesisState.ts +0 -37
- package/src/db/single/preGenesisStateLastProcessedBlock.ts +0 -34
- package/src/eth1/errors.ts +0 -40
- package/src/eth1/eth1DataCache.ts +0 -26
- package/src/eth1/eth1DepositDataTracker.ts +0 -410
- package/src/eth1/eth1DepositsCache.ts +0 -141
- package/src/eth1/eth1MergeBlockTracker.ts +0 -328
- package/src/eth1/index.ts +0 -157
- package/src/eth1/interface.ts +0 -131
- package/src/eth1/options.ts +0 -28
- package/src/eth1/provider/eth1Provider.ts +0 -229
- package/src/eth1/provider/utils.ts +0 -136
- package/src/eth1/stream.ts +0 -75
- package/src/eth1/utils/depositContract.ts +0 -37
- package/src/eth1/utils/deposits.ts +0 -70
- package/src/eth1/utils/eth1Data.ts +0 -100
- package/src/eth1/utils/eth1DepositEvent.ts +0 -12
- package/src/eth1/utils/eth1Vote.ts +0 -142
- package/src/eth1/utils/groupDepositEventsByBlock.ts +0 -19
- package/src/eth1/utils/optimizeNextBlockDiffForGenesis.ts +0 -18
- /package/lib/{eth1/provider → execution/engine}/jsonRpcHttpClient.js +0 -0
- /package/lib/{eth1/provider → execution/engine}/jwt.d.ts +0 -0
- /package/lib/{eth1/provider → execution/engine}/jwt.js +0 -0
- /package/src/{eth1/provider → execution/engine}/jwt.ts +0 -0
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import {ChainConfig} from "@lodestar/config";
|
|
2
|
-
import {Logger} from "@lodestar/logger";
|
|
3
|
-
import {phase0} from "@lodestar/types";
|
|
4
|
-
import {
|
|
5
|
-
FetchError,
|
|
6
|
-
createElapsedTimeTracker,
|
|
7
|
-
fromHex,
|
|
8
|
-
isErrorAborted,
|
|
9
|
-
isFetchError,
|
|
10
|
-
toHex,
|
|
11
|
-
toPrintableUrl,
|
|
12
|
-
} from "@lodestar/utils";
|
|
13
|
-
import {HTTP_CONNECTION_ERROR_CODES, HTTP_FATAL_ERROR_CODES} from "../../execution/engine/utils.js";
|
|
14
|
-
import {isValidAddress} from "../../util/address.js";
|
|
15
|
-
import {linspace} from "../../util/numpy.js";
|
|
16
|
-
import {Eth1Block, Eth1ProviderState, EthJsonRpcBlockRaw, IEth1Provider} from "../interface.js";
|
|
17
|
-
import {DEFAULT_PROVIDER_URLS, Eth1Options} from "../options.js";
|
|
18
|
-
import {depositEventTopics, parseDepositLog} from "../utils/depositContract.js";
|
|
19
|
-
import {
|
|
20
|
-
ErrorJsonRpcResponse,
|
|
21
|
-
HttpRpcError,
|
|
22
|
-
JsonRpcHttpClient,
|
|
23
|
-
JsonRpcHttpClientEvent,
|
|
24
|
-
JsonRpcHttpClientMetrics,
|
|
25
|
-
ReqOpts,
|
|
26
|
-
} from "./jsonRpcHttpClient.js";
|
|
27
|
-
import {dataToBytes, isJsonRpcTruncatedError, numToQuantity, quantityToNum} from "./utils.js";
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Binds return types to Ethereum JSON RPC methods
|
|
31
|
-
*/
|
|
32
|
-
type EthJsonRpcReturnTypes = {
|
|
33
|
-
eth_getBlockByNumber: EthJsonRpcBlockRaw | null;
|
|
34
|
-
eth_getBlockByHash: EthJsonRpcBlockRaw | null;
|
|
35
|
-
eth_blockNumber: string;
|
|
36
|
-
eth_getCode: string;
|
|
37
|
-
eth_getLogs: {
|
|
38
|
-
removed: boolean;
|
|
39
|
-
logIndex: string;
|
|
40
|
-
transactionIndex: string;
|
|
41
|
-
transactionHash: string;
|
|
42
|
-
blockHash: string;
|
|
43
|
-
blockNumber: string;
|
|
44
|
-
address: string;
|
|
45
|
-
data: string;
|
|
46
|
-
topics: string[];
|
|
47
|
-
}[];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Define static options once to prevent extra allocations
|
|
51
|
-
const getBlocksByNumberOpts: ReqOpts = {routeId: "getBlockByNumber_batched"};
|
|
52
|
-
const getBlockByNumberOpts: ReqOpts = {routeId: "getBlockByNumber"};
|
|
53
|
-
const getBlockByHashOpts: ReqOpts = {routeId: "getBlockByHash"};
|
|
54
|
-
const getBlockNumberOpts: ReqOpts = {routeId: "getBlockNumber"};
|
|
55
|
-
const getLogsOpts: ReqOpts = {routeId: "getLogs"};
|
|
56
|
-
|
|
57
|
-
const isOneMinutePassed = createElapsedTimeTracker({minElapsedTime: 60_000});
|
|
58
|
-
|
|
59
|
-
export class Eth1Provider implements IEth1Provider {
|
|
60
|
-
readonly deployBlock: number;
|
|
61
|
-
private readonly depositContractAddress: string;
|
|
62
|
-
private readonly rpc: JsonRpcHttpClient;
|
|
63
|
-
// The default state is ONLINE, it will be updated to offline if we receive a http error
|
|
64
|
-
private state: Eth1ProviderState = Eth1ProviderState.ONLINE;
|
|
65
|
-
private logger?: Logger;
|
|
66
|
-
|
|
67
|
-
constructor(
|
|
68
|
-
config: Pick<ChainConfig, "DEPOSIT_CONTRACT_ADDRESS">,
|
|
69
|
-
opts: Pick<Eth1Options, "depositContractDeployBlock" | "providerUrls" | "jwtSecretHex" | "jwtId" | "jwtVersion"> & {
|
|
70
|
-
logger?: Logger;
|
|
71
|
-
},
|
|
72
|
-
signal?: AbortSignal,
|
|
73
|
-
metrics?: JsonRpcHttpClientMetrics | null
|
|
74
|
-
) {
|
|
75
|
-
this.logger = opts.logger;
|
|
76
|
-
this.deployBlock = opts.depositContractDeployBlock ?? 0;
|
|
77
|
-
this.depositContractAddress = toHex(config.DEPOSIT_CONTRACT_ADDRESS);
|
|
78
|
-
|
|
79
|
-
const providerUrls = opts.providerUrls ?? DEFAULT_PROVIDER_URLS;
|
|
80
|
-
this.rpc = new JsonRpcHttpClient(providerUrls, {
|
|
81
|
-
signal,
|
|
82
|
-
// Don't fallback with is truncated error. Throw early and let the retry on this class handle it
|
|
83
|
-
shouldNotFallback: isJsonRpcTruncatedError,
|
|
84
|
-
jwtSecret: opts.jwtSecretHex ? fromHex(opts.jwtSecretHex) : undefined,
|
|
85
|
-
jwtId: opts.jwtId,
|
|
86
|
-
jwtVersion: opts.jwtVersion,
|
|
87
|
-
metrics: metrics,
|
|
88
|
-
});
|
|
89
|
-
this.logger?.info("Eth1 provider", {urls: providerUrls.map(toPrintableUrl).toString()});
|
|
90
|
-
|
|
91
|
-
this.rpc.emitter.on(JsonRpcHttpClientEvent.RESPONSE, () => {
|
|
92
|
-
const oldState = this.state;
|
|
93
|
-
this.state = Eth1ProviderState.ONLINE;
|
|
94
|
-
|
|
95
|
-
if (oldState !== Eth1ProviderState.ONLINE) {
|
|
96
|
-
this.logger?.info("Eth1 provider is back online", {oldState, newState: this.state});
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
this.rpc.emitter.on(JsonRpcHttpClientEvent.ERROR, ({error}) => {
|
|
101
|
-
if (isErrorAborted(error)) {
|
|
102
|
-
this.state = Eth1ProviderState.ONLINE;
|
|
103
|
-
} else if ((error as unknown) instanceof HttpRpcError || (error as unknown) instanceof ErrorJsonRpcResponse) {
|
|
104
|
-
this.state = Eth1ProviderState.ERROR;
|
|
105
|
-
} else if (error && isFetchError(error) && HTTP_FATAL_ERROR_CODES.includes((error as FetchError).code)) {
|
|
106
|
-
this.state = Eth1ProviderState.OFFLINE;
|
|
107
|
-
} else if (error && isFetchError(error) && HTTP_CONNECTION_ERROR_CODES.includes((error as FetchError).code)) {
|
|
108
|
-
this.state = Eth1ProviderState.AUTH_FAILED;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (this.state !== Eth1ProviderState.ONLINE && isOneMinutePassed()) {
|
|
112
|
-
this.logger?.error(
|
|
113
|
-
"Eth1 provider error",
|
|
114
|
-
{
|
|
115
|
-
state: this.state,
|
|
116
|
-
lastErrorAt: new Date(Date.now() - isOneMinutePassed.msSinceLastCall).toLocaleTimeString(),
|
|
117
|
-
},
|
|
118
|
-
error
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
getState(): Eth1ProviderState {
|
|
125
|
-
return this.state;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async validateContract(): Promise<void> {
|
|
129
|
-
if (!isValidAddress(this.depositContractAddress)) {
|
|
130
|
-
throw Error(`Invalid contract address: ${this.depositContractAddress}`);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const code = await this.getCode(this.depositContractAddress);
|
|
134
|
-
if (!code || code === "0x") {
|
|
135
|
-
throw new Error(`There is no deposit contract at given address: ${this.depositContractAddress}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async getDepositEvents(fromBlock: number, toBlock: number): Promise<phase0.DepositEvent[]> {
|
|
140
|
-
const logsRawArr = await this.getLogs({
|
|
141
|
-
fromBlock,
|
|
142
|
-
toBlock,
|
|
143
|
-
address: this.depositContractAddress,
|
|
144
|
-
topics: depositEventTopics,
|
|
145
|
-
});
|
|
146
|
-
return logsRawArr.flat(1).map((log) => parseDepositLog(log));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Fetches an arbitrary array of block numbers in batch
|
|
151
|
-
*/
|
|
152
|
-
async getBlocksByNumber(fromBlock: number, toBlock: number): Promise<EthJsonRpcBlockRaw[]> {
|
|
153
|
-
const method = "eth_getBlockByNumber";
|
|
154
|
-
const blocksArr = await this.rpc.fetchBatch<EthJsonRpcReturnTypes[typeof method]>(
|
|
155
|
-
linspace(fromBlock, toBlock).map((blockNumber) => ({method, params: [numToQuantity(blockNumber), false]})),
|
|
156
|
-
getBlocksByNumberOpts
|
|
157
|
-
);
|
|
158
|
-
const blocks: EthJsonRpcBlockRaw[] = [];
|
|
159
|
-
for (const block of blocksArr.flat(1)) {
|
|
160
|
-
if (block) blocks.push(block);
|
|
161
|
-
}
|
|
162
|
-
return blocks;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
async getBlockByNumber(blockNumber: number | "latest"): Promise<EthJsonRpcBlockRaw | null> {
|
|
166
|
-
const method = "eth_getBlockByNumber";
|
|
167
|
-
const blockNumberHex = typeof blockNumber === "string" ? blockNumber : numToQuantity(blockNumber);
|
|
168
|
-
return this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>(
|
|
169
|
-
// false = include only transaction roots, not full objects
|
|
170
|
-
{method, params: [blockNumberHex, false]},
|
|
171
|
-
getBlockByNumberOpts
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async getBlockByHash(blockHashHex: string): Promise<EthJsonRpcBlockRaw | null> {
|
|
176
|
-
const method = "eth_getBlockByHash";
|
|
177
|
-
return this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>(
|
|
178
|
-
// false = include only transaction roots, not full objects
|
|
179
|
-
{method, params: [blockHashHex, false]},
|
|
180
|
-
getBlockByHashOpts
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async getBlockNumber(): Promise<number> {
|
|
185
|
-
const method = "eth_blockNumber";
|
|
186
|
-
const blockNumberRaw = await this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>(
|
|
187
|
-
{method, params: []},
|
|
188
|
-
getBlockNumberOpts
|
|
189
|
-
);
|
|
190
|
-
return parseInt(blockNumberRaw, 16);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async getCode(address: string): Promise<string> {
|
|
194
|
-
const method = "eth_getCode";
|
|
195
|
-
return this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>({method, params: [address, "latest"]});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async getLogs(options: {
|
|
199
|
-
fromBlock: number;
|
|
200
|
-
toBlock: number;
|
|
201
|
-
address: string;
|
|
202
|
-
topics: string[];
|
|
203
|
-
}): Promise<{blockNumber: number; data: string; topics: string[]}[]> {
|
|
204
|
-
const method = "eth_getLogs";
|
|
205
|
-
const hexOptions = {
|
|
206
|
-
...options,
|
|
207
|
-
fromBlock: numToQuantity(options.fromBlock),
|
|
208
|
-
toBlock: numToQuantity(options.toBlock),
|
|
209
|
-
};
|
|
210
|
-
const logsRaw = await this.rpc.fetch<EthJsonRpcReturnTypes[typeof method]>(
|
|
211
|
-
{method, params: [hexOptions]},
|
|
212
|
-
getLogsOpts
|
|
213
|
-
);
|
|
214
|
-
return logsRaw.map((logRaw) => ({
|
|
215
|
-
blockNumber: parseInt(logRaw.blockNumber, 16),
|
|
216
|
-
data: logRaw.data,
|
|
217
|
-
topics: logRaw.topics,
|
|
218
|
-
}));
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export function parseEth1Block(blockRaw: EthJsonRpcBlockRaw): Eth1Block {
|
|
223
|
-
if (typeof blockRaw !== "object") throw Error("block is not an object");
|
|
224
|
-
return {
|
|
225
|
-
blockHash: dataToBytes(blockRaw.hash, 32),
|
|
226
|
-
blockNumber: quantityToNum(blockRaw.number, "block.number"),
|
|
227
|
-
timestamp: quantityToNum(blockRaw.timestamp, "block.timestamp"),
|
|
228
|
-
};
|
|
229
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import {RootHex} from "@lodestar/types";
|
|
2
|
-
import {bigIntToBytes, bytesToBigInt, fromHex, fromHexInto, toHex} from "@lodestar/utils";
|
|
3
|
-
import {ErrorParseJson} from "./jsonRpcHttpClient.js";
|
|
4
|
-
|
|
5
|
-
/** QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API */
|
|
6
|
-
export type QUANTITY = string;
|
|
7
|
-
/** DATA as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API */
|
|
8
|
-
export type DATA = string;
|
|
9
|
-
|
|
10
|
-
export const rootHexRegex = /^0x[a-fA-F0-9]{64}$/;
|
|
11
|
-
|
|
12
|
-
export function numberToHex(n: number | bigint): string {
|
|
13
|
-
return "0x" + n.toString(16);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function isJsonRpcTruncatedError(error: Error): boolean {
|
|
17
|
-
return (
|
|
18
|
-
// Truncated responses usually get as 200 but since it's truncated the JSON will be invalid
|
|
19
|
-
error instanceof ErrorParseJson ||
|
|
20
|
-
// Otherwise guess Infura error message of too many events
|
|
21
|
-
(error instanceof Error && error.message.includes("query returned more than 10000 results")) ||
|
|
22
|
-
// Nethermind enforces limits on JSON RPC batch calls
|
|
23
|
-
(error instanceof Error && error.message.toLowerCase().includes("batch size limit exceeded"))
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function bytesToHex(bytes: Uint8Array): string {
|
|
28
|
-
// Handle special case in Ethereum hex formating where hex values may include a single letter
|
|
29
|
-
// 0x0, 0x1 are valid values
|
|
30
|
-
if (bytes.length === 1 && bytes[0] <= 0xf) {
|
|
31
|
-
return "0x" + bytes[0].toString(16);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return toHex(bytes);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
|
|
39
|
-
*
|
|
40
|
-
* When encoding QUANTITIES (integers, numbers): encode as hex, prefix with “0x”, the most compact representation (slight exception: zero should be represented as “0x0”). Examples:
|
|
41
|
-
* - 0x41 (65 in decimal)
|
|
42
|
-
* - 0x400 (1024 in decimal)
|
|
43
|
-
* - WRONG: 0x (should always have at least one digit - zero is “0x0”)
|
|
44
|
-
* - WRONG: 0x0400 (no leading zeroes allowed)
|
|
45
|
-
* - WRONG: ff (must be prefixed 0x)
|
|
46
|
-
*/
|
|
47
|
-
export function numToQuantity(num: number | bigint): QUANTITY {
|
|
48
|
-
return "0x" + num.toString(16);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
|
|
53
|
-
*/
|
|
54
|
-
export function quantityToNum(hex: QUANTITY, id = ""): number {
|
|
55
|
-
const num = parseInt(hex, 16);
|
|
56
|
-
if (Number.isNaN(num) || num < 0) throw Error(`Invalid hex decimal ${id} '${hex}'`);
|
|
57
|
-
return num;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API.
|
|
62
|
-
* Typesafe fn to convert hex string to bigint. The BigInt constructor param is any
|
|
63
|
-
*/
|
|
64
|
-
export function quantityToBigint(hex: QUANTITY, id = ""): bigint {
|
|
65
|
-
try {
|
|
66
|
-
return BigInt(hex);
|
|
67
|
-
} catch (e) {
|
|
68
|
-
throw Error(`Invalid hex bigint ${id} '${hex}': ${(e as Error).message}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API.
|
|
74
|
-
*/
|
|
75
|
-
export function quantityToBytes(hex: QUANTITY): Uint8Array {
|
|
76
|
-
const bn = quantityToBigint(hex);
|
|
77
|
-
return bigIntToBytes(bn, 32, "le");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API.
|
|
82
|
-
* Compress a 32 ByteVector into a QUANTITY
|
|
83
|
-
*/
|
|
84
|
-
export function bytesToQuantity(bytes: Uint8Array): QUANTITY {
|
|
85
|
-
const bn = bytesToBigInt(bytes, "le");
|
|
86
|
-
return numToQuantity(bn);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* DATA as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
|
|
91
|
-
*
|
|
92
|
-
* When encoding UNFORMATTED DATA (byte arrays, account addresses, hashes, bytecode arrays): encode as hex, prefix with
|
|
93
|
-
* “0x”, two hex digits per byte. Examples:
|
|
94
|
-
*
|
|
95
|
-
* - 0x41 (size 1, “A”)
|
|
96
|
-
* - 0x004200 (size 3, “\0B\0”)
|
|
97
|
-
* - 0x (size 0, “”)
|
|
98
|
-
* - WRONG: 0xf0f0f (must be even number of digits)
|
|
99
|
-
* - WRONG: 004200 (must be prefixed 0x)
|
|
100
|
-
*/
|
|
101
|
-
export function bytesToData(bytes: Uint8Array): DATA {
|
|
102
|
-
return toHex(bytes);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* DATA as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
|
|
107
|
-
*/
|
|
108
|
-
export function dataToBytes(hex: DATA, fixedLength: number | null): Uint8Array {
|
|
109
|
-
try {
|
|
110
|
-
const bytes = fromHex(hex);
|
|
111
|
-
if (fixedLength != null && bytes.length !== fixedLength) {
|
|
112
|
-
throw Error(`Wrong data length ${bytes.length} expected ${fixedLength}`);
|
|
113
|
-
}
|
|
114
|
-
return bytes;
|
|
115
|
-
} catch (e) {
|
|
116
|
-
(e as Error).message = `Invalid hex string: ${(e as Error).message}`;
|
|
117
|
-
throw e;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Convert DATA into a preallocated buffer
|
|
123
|
-
* fromHexInto will throw if buffer's length is not the same as the decoded hex length
|
|
124
|
-
*/
|
|
125
|
-
export function dataIntoBytes(hex: DATA, buffer: Uint8Array): Uint8Array {
|
|
126
|
-
fromHexInto(hex, buffer);
|
|
127
|
-
return buffer;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* DATA as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
|
|
132
|
-
*/
|
|
133
|
-
export function dataToRootHex(hex: DATA, id = ""): RootHex {
|
|
134
|
-
if (!rootHexRegex.test(hex)) throw Error(`Invalid hex root ${id} '${hex}'`);
|
|
135
|
-
return hex;
|
|
136
|
-
}
|
package/src/eth1/stream.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import {phase0} from "@lodestar/types";
|
|
2
|
-
import {sleep} from "@lodestar/utils";
|
|
3
|
-
import {BatchDepositEvents, Eth1Block, IEth1Provider, IEth1StreamParams} from "./interface.js";
|
|
4
|
-
import {parseEth1Block} from "./provider/eth1Provider.js";
|
|
5
|
-
import {groupDepositEventsByBlock} from "./utils/groupDepositEventsByBlock.js";
|
|
6
|
-
import {optimizeNextBlockDiffForGenesis} from "./utils/optimizeNextBlockDiffForGenesis.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Phase 1 of genesis building.
|
|
10
|
-
* Not enough validators, only stream deposits
|
|
11
|
-
* @param signal Abort stream returning after a while loop cycle. Aborts internal sleep
|
|
12
|
-
*/
|
|
13
|
-
export async function* getDepositsStream(
|
|
14
|
-
fromBlock: number,
|
|
15
|
-
provider: IEth1Provider,
|
|
16
|
-
params: IEth1StreamParams,
|
|
17
|
-
signal?: AbortSignal
|
|
18
|
-
): AsyncGenerator<BatchDepositEvents> {
|
|
19
|
-
fromBlock = Math.max(fromBlock, provider.deployBlock);
|
|
20
|
-
|
|
21
|
-
while (true) {
|
|
22
|
-
const remoteFollowBlock = await getRemoteFollowBlock(provider, params);
|
|
23
|
-
const toBlock = Math.min(remoteFollowBlock, fromBlock + params.maxBlocksPerPoll);
|
|
24
|
-
const logs = await provider.getDepositEvents(fromBlock, toBlock);
|
|
25
|
-
for (const batchedDeposits of groupDepositEventsByBlock(logs)) {
|
|
26
|
-
yield batchedDeposits;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
fromBlock = toBlock;
|
|
30
|
-
|
|
31
|
-
// If reached head, sleep for an eth1 block. Throws if signal is aborted
|
|
32
|
-
await sleep(toBlock >= remoteFollowBlock ? params.SECONDS_PER_ETH1_BLOCK * 1000 : 10, signal);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Phase 2 of genesis building.
|
|
38
|
-
* There are enough validators, stream deposits and blocks
|
|
39
|
-
* @param signal Abort stream returning after a while loop cycle. Aborts internal sleep
|
|
40
|
-
*/
|
|
41
|
-
export async function* getDepositsAndBlockStreamForGenesis(
|
|
42
|
-
fromBlock: number,
|
|
43
|
-
provider: IEth1Provider,
|
|
44
|
-
params: IEth1StreamParams,
|
|
45
|
-
signal?: AbortSignal
|
|
46
|
-
): AsyncGenerator<[phase0.DepositEvent[], Eth1Block]> {
|
|
47
|
-
fromBlock = Math.max(fromBlock, provider.deployBlock);
|
|
48
|
-
fromBlock = Math.min(fromBlock, await getRemoteFollowBlock(provider, params));
|
|
49
|
-
let toBlock = fromBlock; // First, fetch only the first block
|
|
50
|
-
|
|
51
|
-
while (true) {
|
|
52
|
-
const [logs, blockRaw] = await Promise.all([
|
|
53
|
-
provider.getDepositEvents(fromBlock, toBlock),
|
|
54
|
-
provider.getBlockByNumber(toBlock),
|
|
55
|
-
]);
|
|
56
|
-
|
|
57
|
-
if (!blockRaw) throw Error(`No block found for number ${toBlock}`);
|
|
58
|
-
const block = parseEth1Block(blockRaw);
|
|
59
|
-
|
|
60
|
-
yield [logs, block];
|
|
61
|
-
|
|
62
|
-
const remoteFollowBlock = await getRemoteFollowBlock(provider, params);
|
|
63
|
-
const nextBlockDiff = optimizeNextBlockDiffForGenesis(block, params);
|
|
64
|
-
fromBlock = toBlock;
|
|
65
|
-
toBlock = Math.min(remoteFollowBlock, fromBlock + Math.min(nextBlockDiff, params.maxBlocksPerPoll));
|
|
66
|
-
|
|
67
|
-
// If reached head, sleep for an eth1 block. Throws if signal is aborted
|
|
68
|
-
await sleep(toBlock >= remoteFollowBlock ? params.SECONDS_PER_ETH1_BLOCK * 1000 : 10, signal);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function getRemoteFollowBlock(provider: IEth1Provider, params: IEth1StreamParams): Promise<number> {
|
|
73
|
-
const remoteHighestBlock = await provider.getBlockNumber();
|
|
74
|
-
return Math.max(remoteHighestBlock - params.ETH1_FOLLOW_DISTANCE, 0);
|
|
75
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {Interface} from "@ethersproject/abi";
|
|
2
|
-
import {phase0, ssz} from "@lodestar/types";
|
|
3
|
-
import {fromHex} from "@lodestar/utils";
|
|
4
|
-
|
|
5
|
-
const depositEventFragment =
|
|
6
|
-
"event DepositEvent(bytes pubkey, bytes withdrawal_credentials, bytes amount, bytes signature, bytes index)";
|
|
7
|
-
|
|
8
|
-
const depositContractInterface = new Interface([depositEventFragment]);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Precomputed topics of DepositEvent logs
|
|
12
|
-
*/
|
|
13
|
-
export const depositEventTopics = [depositContractInterface.getEventTopic("DepositEvent")];
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Parse DepositEvent log
|
|
17
|
-
*/
|
|
18
|
-
export function parseDepositLog(log: {blockNumber: number; data: string; topics: string[]}): phase0.DepositEvent {
|
|
19
|
-
const event = depositContractInterface.parseLog(log);
|
|
20
|
-
const values = event.args;
|
|
21
|
-
if (values === undefined) throw Error(`DepositEvent at ${log.blockNumber} has no values`);
|
|
22
|
-
return {
|
|
23
|
-
blockNumber: log.blockNumber,
|
|
24
|
-
index: parseHexNumLittleEndian(values.index),
|
|
25
|
-
depositData: {
|
|
26
|
-
pubkey: fromHex(values.pubkey),
|
|
27
|
-
withdrawalCredentials: fromHex(values.withdrawal_credentials),
|
|
28
|
-
amount: parseHexNumLittleEndian(values.amount),
|
|
29
|
-
signature: fromHex(values.signature),
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function parseHexNumLittleEndian(hex: string): number {
|
|
35
|
-
// Can't use parseInt() because amount is a hex string in little endian
|
|
36
|
-
return ssz.UintNum64.deserialize(fromHex(hex));
|
|
37
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {Tree, toGindex} from "@chainsafe/persistent-merkle-tree";
|
|
2
|
-
import {FilterOptions} from "@lodestar/db";
|
|
3
|
-
import {CachedBeaconStateAllForks, getEth1DepositCount} from "@lodestar/state-transition";
|
|
4
|
-
import {phase0, ssz} from "@lodestar/types";
|
|
5
|
-
import {toRootHex} from "@lodestar/utils";
|
|
6
|
-
import {DepositTree} from "../../db/repositories/depositDataRoot.js";
|
|
7
|
-
import {Eth1Error, Eth1ErrorCode} from "../errors.js";
|
|
8
|
-
|
|
9
|
-
export type DepositGetter<T> = (indexRange: FilterOptions<number>, eth1Data: phase0.Eth1Data) => Promise<T[]>;
|
|
10
|
-
|
|
11
|
-
export async function getDeposits<T>(
|
|
12
|
-
// eth1_deposit_index represents the next deposit index to be added
|
|
13
|
-
state: CachedBeaconStateAllForks,
|
|
14
|
-
eth1Data: phase0.Eth1Data,
|
|
15
|
-
depositsGetter: DepositGetter<T>
|
|
16
|
-
): Promise<T[]> {
|
|
17
|
-
const depositIndex = state.eth1DepositIndex;
|
|
18
|
-
const depositCount = eth1Data.depositCount;
|
|
19
|
-
|
|
20
|
-
if (depositIndex > depositCount) {
|
|
21
|
-
throw new Eth1Error({code: Eth1ErrorCode.DEPOSIT_INDEX_TOO_HIGH, depositIndex, depositCount});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const depositsLen = getEth1DepositCount(state, eth1Data);
|
|
25
|
-
|
|
26
|
-
if (depositsLen === 0) {
|
|
27
|
-
return []; // If depositsLen === 0, we can return early since no deposit with be returned from depositsGetter
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const indexRange = {gte: depositIndex, lt: depositIndex + depositsLen};
|
|
31
|
-
const deposits = await depositsGetter(indexRange, eth1Data);
|
|
32
|
-
|
|
33
|
-
if (deposits.length < depositsLen) {
|
|
34
|
-
throw new Eth1Error({code: Eth1ErrorCode.NOT_ENOUGH_DEPOSITS, len: deposits.length, expectedLen: depositsLen});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (deposits.length > depositsLen) {
|
|
38
|
-
throw new Eth1Error({code: Eth1ErrorCode.TOO_MANY_DEPOSITS, len: deposits.length, expectedLen: depositsLen});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return deposits;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function getDepositsWithProofs(
|
|
45
|
-
depositEvents: phase0.DepositEvent[],
|
|
46
|
-
depositRootTree: DepositTree,
|
|
47
|
-
eth1Data: phase0.Eth1Data
|
|
48
|
-
): phase0.Deposit[] {
|
|
49
|
-
// Get tree at this particular depositCount to compute correct proofs
|
|
50
|
-
const viewAtDepositCount = depositRootTree.sliceTo(eth1Data.depositCount - 1);
|
|
51
|
-
|
|
52
|
-
const depositRoot = viewAtDepositCount.hashTreeRoot();
|
|
53
|
-
|
|
54
|
-
if (!ssz.Root.equals(depositRoot, eth1Data.depositRoot)) {
|
|
55
|
-
throw new Eth1Error({
|
|
56
|
-
code: Eth1ErrorCode.WRONG_DEPOSIT_ROOT,
|
|
57
|
-
root: toRootHex(depositRoot),
|
|
58
|
-
expectedRoot: toRootHex(eth1Data.depositRoot),
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Already commited for .hashTreeRoot()
|
|
63
|
-
const treeAtDepositCount = new Tree(viewAtDepositCount.node);
|
|
64
|
-
const depositTreeDepth = viewAtDepositCount.type.depth;
|
|
65
|
-
|
|
66
|
-
return depositEvents.map((log) => ({
|
|
67
|
-
proof: treeAtDepositCount.getSingleProof(toGindex(depositTreeDepth, BigInt(log.index))),
|
|
68
|
-
data: log.depositData,
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {Root, phase0} from "@lodestar/types";
|
|
2
|
-
import {DepositTree} from "../../db/repositories/depositDataRoot.js";
|
|
3
|
-
import {binarySearchLte} from "../../util/binarySearch.js";
|
|
4
|
-
import {Eth1Error, Eth1ErrorCode} from "../errors.js";
|
|
5
|
-
import {Eth1Block} from "../interface.js";
|
|
6
|
-
|
|
7
|
-
type BlockNumber = number;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Appends partial eth1 data (depositRoot, depositCount) in a sequence of blocks
|
|
11
|
-
* eth1 data deposit is inferred from sparse eth1 data obtained from the deposit logs
|
|
12
|
-
*/
|
|
13
|
-
export async function getEth1DataForBlocks(
|
|
14
|
-
blocks: Eth1Block[],
|
|
15
|
-
depositDescendingStream: AsyncIterable<phase0.DepositEvent>,
|
|
16
|
-
depositRootTree: DepositTree,
|
|
17
|
-
lastProcessedDepositBlockNumber: BlockNumber | null
|
|
18
|
-
): Promise<(phase0.Eth1Data & Eth1Block)[]> {
|
|
19
|
-
// Exclude blocks for which there is no valid eth1 data deposit
|
|
20
|
-
if (lastProcessedDepositBlockNumber !== null) {
|
|
21
|
-
blocks = blocks.filter((block) => block.blockNumber <= lastProcessedDepositBlockNumber);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// A valid block can be constructed using previous `state.eth1Data`, don't throw
|
|
25
|
-
if (blocks.length === 0) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Collect the latest deposit of each blockNumber in a block number range
|
|
30
|
-
const fromBlock = blocks[0].blockNumber;
|
|
31
|
-
const toBlock = blocks.at(-1)?.blockNumber as number;
|
|
32
|
-
const depositsByBlockNumber = await getDepositsByBlockNumber(fromBlock, toBlock, depositDescendingStream);
|
|
33
|
-
if (depositsByBlockNumber.length === 0) {
|
|
34
|
-
throw new Eth1Error({code: Eth1ErrorCode.NO_DEPOSITS_FOR_BLOCK_RANGE, fromBlock, toBlock});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Precompute a map of depositCount => depositRoot (from depositRootTree)
|
|
38
|
-
const depositCounts = depositsByBlockNumber.map((event) => event.index + 1);
|
|
39
|
-
const depositRootByDepositCount = getDepositRootByDepositCount(depositCounts, depositRootTree);
|
|
40
|
-
|
|
41
|
-
const eth1Datas: (phase0.Eth1Data & Eth1Block)[] = [];
|
|
42
|
-
for (const block of blocks) {
|
|
43
|
-
const deposit = binarySearchLte(depositsByBlockNumber, block.blockNumber, (event) => event.blockNumber);
|
|
44
|
-
const depositCount = deposit.index + 1;
|
|
45
|
-
const depositRoot = depositRootByDepositCount.get(depositCount);
|
|
46
|
-
if (depositRoot === undefined) {
|
|
47
|
-
throw new Eth1Error({code: Eth1ErrorCode.NO_DEPOSIT_ROOT, depositCount});
|
|
48
|
-
}
|
|
49
|
-
eth1Datas.push({...block, depositCount, depositRoot});
|
|
50
|
-
}
|
|
51
|
-
return eth1Datas;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Collect depositCount by blockNumber from a stream matching a block number range
|
|
56
|
-
* For a given blockNumber it's depositCount is equal to the index + 1 of the
|
|
57
|
-
* closest deposit event whose deposit.blockNumber <= blockNumber
|
|
58
|
-
* @returns array ascending by blockNumber
|
|
59
|
-
*/
|
|
60
|
-
export async function getDepositsByBlockNumber(
|
|
61
|
-
fromBlock: BlockNumber,
|
|
62
|
-
toBlock: BlockNumber,
|
|
63
|
-
depositEventDescendingStream: AsyncIterable<phase0.DepositEvent>
|
|
64
|
-
): Promise<phase0.DepositEvent[]> {
|
|
65
|
-
const depositCountMap = new Map<BlockNumber, phase0.DepositEvent>();
|
|
66
|
-
// Take blocks until the block under the range lower bound (included)
|
|
67
|
-
for await (const deposit of depositEventDescendingStream) {
|
|
68
|
-
if (deposit.blockNumber <= toBlock && !depositCountMap.has(deposit.blockNumber)) {
|
|
69
|
-
depositCountMap.set(deposit.blockNumber, deposit);
|
|
70
|
-
}
|
|
71
|
-
if (deposit.blockNumber < fromBlock) {
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return Array.from(depositCountMap.values()).sort((a, b) => a.blockNumber - b.blockNumber);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Precompute a map of depositCount => depositRoot from a depositRootTree filled beforehand
|
|
81
|
-
*/
|
|
82
|
-
export function getDepositRootByDepositCount(depositCounts: number[], depositRootTree: DepositTree): Map<number, Root> {
|
|
83
|
-
// Unique + sort numerically in descending order
|
|
84
|
-
depositCounts = [...new Set(depositCounts)].sort((a, b) => b - a);
|
|
85
|
-
|
|
86
|
-
if (depositCounts.length > 0) {
|
|
87
|
-
const maxIndex = depositCounts[0] - 1;
|
|
88
|
-
const treeLength = depositRootTree.length - 1;
|
|
89
|
-
if (maxIndex > treeLength) {
|
|
90
|
-
throw new Eth1Error({code: Eth1ErrorCode.NOT_ENOUGH_DEPOSIT_ROOTS, index: maxIndex, treeLength});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const depositRootByDepositCount = new Map<number, Root>();
|
|
95
|
-
for (const depositCount of depositCounts) {
|
|
96
|
-
depositRootTree = depositRootTree.sliceTo(depositCount - 1);
|
|
97
|
-
depositRootByDepositCount.set(depositCount, depositRootTree.hashTreeRoot());
|
|
98
|
-
}
|
|
99
|
-
return depositRootByDepositCount;
|
|
100
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Assert that an array of deposits are consecutive and ascending
|
|
3
|
-
*/
|
|
4
|
-
export function assertConsecutiveDeposits(depositEvents: {index: number}[]): void {
|
|
5
|
-
for (let i = 0; i < depositEvents.length - 1; i++) {
|
|
6
|
-
const indexLeft = depositEvents[i].index;
|
|
7
|
-
const indexRight = depositEvents[i + 1].index;
|
|
8
|
-
if (indexLeft !== indexRight - 1) {
|
|
9
|
-
throw Error(`Non consecutive deposits. deposit[${i}] = ${indexLeft}, deposit[${i + 1}] ${indexRight}`);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|