Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: typesafe options and cli args #4576

Merged
merged 5 commits into from
Jun 20, 2023
Merged

Conversation

dapplion
Copy link
Contributor

@dapplion dapplion commented Sep 20, 2022

Motivation

Our current approach to options and CLI arg processing is not typesafe.

Description

Problem: CLI args and options are defined such that it's not guaranteed for the arg to not be undefined.
This PR: modifies ICliCommandOptions to ensure that either a default is set or the option must be marked as optional

Problem: Programmatic use of BeaconNode class has bad DX since many non-essential options must be provided
This PR: Changed options definitions such that BeaconNode class can be instantiated without proving any option

Problem: BeaconNodeOptions current default merging strategy is not typesafe. Options that are typed as not optional may receive undefined
This PR: Remove option deepmerging at the CLI level, and let's each subclass to handle default option setting without nesting

Extra issues

Fix typo bad option merging, mixing retryAttempts and retryDelay

retryDelay: opts?.retryDelay ?? this.opts?.retryAttempts ?? 0,

Set maxPeers to a value that greater than targetPeers if only the latter is set

Closes #4577

@dapplion dapplion requested a review from a team as a code owner September 20, 2022 22:37
@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2022

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 32dcb2c Previous: 7c54a7b Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 748.27 us/op 999.28 us/op 0.75
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 44.572 us/op 49.398 us/op 0.90
BLS verify - blst-native 1.2027 ms/op 1.2294 ms/op 0.98
BLS verifyMultipleSignatures 3 - blst-native 2.4664 ms/op 2.4835 ms/op 0.99
BLS verifyMultipleSignatures 8 - blst-native 5.2614 ms/op 5.3432 ms/op 0.98
BLS verifyMultipleSignatures 32 - blst-native 19.049 ms/op 19.363 ms/op 0.98
BLS aggregatePubkeys 32 - blst-native 25.649 us/op 25.802 us/op 0.99
BLS aggregatePubkeys 128 - blst-native 100.62 us/op 101.26 us/op 0.99
getAttestationsForBlock 52.090 ms/op 58.965 ms/op 0.88
isKnown best case - 1 super set check 264.00 ns/op 263.00 ns/op 1.00
isKnown normal case - 2 super set checks 262.00 ns/op 255.00 ns/op 1.03
isKnown worse case - 16 super set checks 257.00 ns/op 257.00 ns/op 1.00
CheckpointStateCache - add get delete 4.9330 us/op 5.3580 us/op 0.92
validate gossip signedAggregateAndProof - struct 2.7374 ms/op 2.8639 ms/op 0.96
validate gossip attestation - struct 1.3101 ms/op 1.3503 ms/op 0.97
pickEth1Vote - no votes 1.3356 ms/op 1.3847 ms/op 0.96
pickEth1Vote - max votes 8.9314 ms/op 10.475 ms/op 0.85
pickEth1Vote - Eth1Data hashTreeRoot value x2048 8.7728 ms/op 9.4063 ms/op 0.93
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 13.437 ms/op 15.320 ms/op 0.88
pickEth1Vote - Eth1Data fastSerialize value x2048 707.39 us/op 678.66 us/op 1.04
pickEth1Vote - Eth1Data fastSerialize tree x2048 4.7267 ms/op 7.3198 ms/op 0.65
bytes32 toHexString 504.00 ns/op 580.00 ns/op 0.87
bytes32 Buffer.toString(hex) 434.00 ns/op 417.00 ns/op 1.04
bytes32 Buffer.toString(hex) from Uint8Array 626.00 ns/op 616.00 ns/op 1.02
bytes32 Buffer.toString(hex) + 0x 423.00 ns/op 405.00 ns/op 1.04
Object access 1 prop 0.20100 ns/op 0.18900 ns/op 1.06
Map access 1 prop 0.17700 ns/op 0.16800 ns/op 1.05
Object get x1000 9.4550 ns/op 6.8420 ns/op 1.38
Map get x1000 0.66700 ns/op 0.67100 ns/op 0.99
Object set x1000 69.867 ns/op 67.850 ns/op 1.03
Map set x1000 53.138 ns/op 55.320 ns/op 0.96
Return object 10000 times 0.26820 ns/op 0.24930 ns/op 1.08
Throw Error 10000 times 4.5068 us/op 4.4592 us/op 1.01
fastMsgIdFn sha256 / 200 bytes 3.5820 us/op 3.7520 us/op 0.95
fastMsgIdFn h32 xxhash / 200 bytes 318.00 ns/op 331.00 ns/op 0.96
fastMsgIdFn h64 xxhash / 200 bytes 458.00 ns/op 517.00 ns/op 0.89
fastMsgIdFn sha256 / 1000 bytes 11.943 us/op 12.149 us/op 0.98
fastMsgIdFn h32 xxhash / 1000 bytes 459.00 ns/op 468.00 ns/op 0.98
fastMsgIdFn h64 xxhash / 1000 bytes 548.00 ns/op 587.00 ns/op 0.93
fastMsgIdFn sha256 / 10000 bytes 106.59 us/op 110.20 us/op 0.97
fastMsgIdFn h32 xxhash / 10000 bytes 1.9820 us/op 2.0610 us/op 0.96
fastMsgIdFn h64 xxhash / 10000 bytes 1.4510 us/op 1.5160 us/op 0.96
enrSubnets - fastDeserialize 64 bits 1.4500 us/op 2.0830 us/op 0.70
enrSubnets - ssz BitVector 64 bits 546.00 ns/op 699.00 ns/op 0.78
enrSubnets - fastDeserialize 4 bits 192.00 ns/op 233.00 ns/op 0.82
enrSubnets - ssz BitVector 4 bits 574.00 ns/op 696.00 ns/op 0.82
prioritizePeers score -10:0 att 32-0.1 sync 2-0 124.80 us/op 141.38 us/op 0.88
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 163.67 us/op 153.54 us/op 1.07
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 186.42 us/op 195.89 us/op 0.95
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 357.90 us/op 375.83 us/op 0.95
prioritizePeers score 0:0 att 64-1 sync 4-1 426.04 us/op 455.24 us/op 0.94
array of 16000 items push then shift 1.7318 us/op 1.7552 us/op 0.99
LinkedList of 16000 items push then shift 9.7040 ns/op 10.505 ns/op 0.92
array of 16000 items push then pop 118.44 ns/op 130.59 ns/op 0.91
LinkedList of 16000 items push then pop 9.3500 ns/op 10.301 ns/op 0.91
array of 24000 items push then shift 2.3940 us/op 2.4906 us/op 0.96
LinkedList of 24000 items push then shift 9.8310 ns/op 11.606 ns/op 0.85
array of 24000 items push then pop 85.747 ns/op 100.75 ns/op 0.85
LinkedList of 24000 items push then pop 9.0030 ns/op 10.552 ns/op 0.85
intersect bitArray bitLen 8 14.221 ns/op 14.189 ns/op 1.00
intersect array and set length 8 97.433 ns/op 105.05 ns/op 0.93
intersect bitArray bitLen 128 45.631 ns/op 46.730 ns/op 0.98
intersect array and set length 128 1.3265 us/op 1.3194 us/op 1.01
Buffer.concat 32 items 3.1150 us/op 2.9010 us/op 1.07
Uint8Array.set 32 items 2.9930 us/op 2.5610 us/op 1.17
transfer serialized Status (84 B) 2.2530 us/op 2.2690 us/op 0.99
copy serialized Status (84 B) 1.8700 us/op 1.8530 us/op 1.01
transfer serialized SignedVoluntaryExit (112 B) 2.3670 us/op 2.7100 us/op 0.87
copy serialized SignedVoluntaryExit (112 B) 1.9550 us/op 1.9140 us/op 1.02
transfer serialized ProposerSlashing (416 B) 2.8430 us/op 2.8090 us/op 1.01
copy serialized ProposerSlashing (416 B) 2.7020 us/op 3.4940 us/op 0.77
transfer serialized Attestation (485 B) 2.4120 us/op 2.9190 us/op 0.83
copy serialized Attestation (485 B) 2.3140 us/op 3.4120 us/op 0.68
transfer serialized AttesterSlashing (33232 B) 2.5280 us/op 2.9080 us/op 0.87
copy serialized AttesterSlashing (33232 B) 8.3110 us/op 8.3450 us/op 1.00
transfer serialized Small SignedBeaconBlock (128000 B) 3.3570 us/op 2.8980 us/op 1.16
copy serialized Small SignedBeaconBlock (128000 B) 54.288 us/op 21.109 us/op 2.57
transfer serialized Avg SignedBeaconBlock (200000 B) 3.5790 us/op 3.4130 us/op 1.05
copy serialized Avg SignedBeaconBlock (200000 B) 30.967 us/op 36.623 us/op 0.85
transfer serialized BlobsSidecar (524380 B) 4.7310 us/op 3.3190 us/op 1.43
copy serialized BlobsSidecar (524380 B) 113.05 us/op 83.488 us/op 1.35
transfer serialized Big SignedBeaconBlock (1000000 B) 5.0270 us/op 3.6590 us/op 1.37
copy serialized Big SignedBeaconBlock (1000000 B) 329.68 us/op 385.38 us/op 0.86
pass gossip attestations to forkchoice per slot 2.8131 ms/op 2.7385 ms/op 1.03
forkChoice updateHead vc 100000 bc 64 eq 0 2.1549 ms/op 2.2827 ms/op 0.94
forkChoice updateHead vc 600000 bc 64 eq 0 11.886 ms/op 15.436 ms/op 0.77
forkChoice updateHead vc 1000000 bc 64 eq 0 23.555 ms/op 18.979 ms/op 1.24
forkChoice updateHead vc 600000 bc 320 eq 0 17.812 ms/op 17.071 ms/op 1.04
forkChoice updateHead vc 600000 bc 1200 eq 0 84.828 ms/op 85.143 ms/op 1.00
forkChoice updateHead vc 600000 bc 64 eq 1000 21.060 ms/op 21.018 ms/op 1.00
forkChoice updateHead vc 600000 bc 64 eq 10000 22.882 ms/op 22.753 ms/op 1.01
forkChoice updateHead vc 600000 bc 64 eq 300000 32.317 ms/op 33.689 ms/op 0.96
computeDeltas 3.4823 ms/op 3.0721 ms/op 1.13
computeProposerBoostScoreFromBalances 1.9057 ms/op 1.8093 ms/op 1.05
altair processAttestation - 250000 vs - 7PWei normalcase 2.4106 ms/op 3.4067 ms/op 0.71
altair processAttestation - 250000 vs - 7PWei worstcase 4.3190 ms/op 4.3271 ms/op 1.00
altair processAttestation - setStatus - 1/6 committees join 148.84 us/op 150.63 us/op 0.99
altair processAttestation - setStatus - 1/3 committees join 298.05 us/op 299.13 us/op 1.00
altair processAttestation - setStatus - 1/2 committees join 381.44 us/op 399.18 us/op 0.96
altair processAttestation - setStatus - 2/3 committees join 480.16 us/op 483.36 us/op 0.99
altair processAttestation - setStatus - 4/5 committees join 665.65 us/op 695.04 us/op 0.96
altair processAttestation - setStatus - 100% committees join 778.33 us/op 809.25 us/op 0.96
altair processBlock - 250000 vs - 7PWei normalcase 16.982 ms/op 18.498 ms/op 0.92
altair processBlock - 250000 vs - 7PWei normalcase hashState 29.298 ms/op 27.078 ms/op 1.08
altair processBlock - 250000 vs - 7PWei worstcase 51.683 ms/op 50.977 ms/op 1.01
altair processBlock - 250000 vs - 7PWei worstcase hashState 78.238 ms/op 74.414 ms/op 1.05
phase0 processBlock - 250000 vs - 7PWei normalcase 1.9777 ms/op 2.3185 ms/op 0.85
phase0 processBlock - 250000 vs - 7PWei worstcase 28.523 ms/op 31.311 ms/op 0.91
altair processEth1Data - 250000 vs - 7PWei normalcase 538.35 us/op 587.80 us/op 0.92
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 10.482 us/op 8.8160 us/op 1.19
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 35.644 us/op 29.622 us/op 1.20
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 14.714 us/op 11.396 us/op 1.29
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 9.7990 us/op 10.031 us/op 0.98
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 114.70 us/op 121.88 us/op 0.94
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 665.48 us/op 1.0109 ms/op 0.66
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 905.20 us/op 969.32 us/op 0.93
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 896.36 us/op 909.13 us/op 0.99
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 2.5726 ms/op 2.7209 ms/op 0.95
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 1.6953 ms/op 1.5087 ms/op 1.12
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 4.9116 ms/op 4.1415 ms/op 1.19
Tree 40 250000 create 377.67 ms/op 416.49 ms/op 0.91
Tree 40 250000 get(125000) 201.62 ns/op 190.85 ns/op 1.06
Tree 40 250000 set(125000) 1.0509 us/op 1.0286 us/op 1.02
Tree 40 250000 toArray() 24.073 ms/op 22.266 ms/op 1.08
Tree 40 250000 iterate all - toArray() + loop 24.201 ms/op 21.139 ms/op 1.14
Tree 40 250000 iterate all - get(i) 78.462 ms/op 76.250 ms/op 1.03
MutableVector 250000 create 12.592 ms/op 11.697 ms/op 1.08
MutableVector 250000 get(125000) 6.6820 ns/op 6.4500 ns/op 1.04
MutableVector 250000 set(125000) 300.27 ns/op 293.80 ns/op 1.02
MutableVector 250000 toArray() 4.3695 ms/op 4.3259 ms/op 1.01
MutableVector 250000 iterate all - toArray() + loop 4.3589 ms/op 4.0404 ms/op 1.08
MutableVector 250000 iterate all - get(i) 1.6743 ms/op 1.5584 ms/op 1.07
Array 250000 create 3.5370 ms/op 2.9307 ms/op 1.21
Array 250000 clone - spread 1.1853 ms/op 1.1283 ms/op 1.05
Array 250000 get(125000) 0.57300 ns/op 0.55700 ns/op 1.03
Array 250000 set(125000) 0.65700 ns/op 0.62700 ns/op 1.05
Array 250000 iterate all - loop 85.475 us/op 83.141 us/op 1.03
effectiveBalanceIncrements clone Uint8Array 300000 41.147 us/op 30.999 us/op 1.33
effectiveBalanceIncrements clone MutableVector 300000 348.00 ns/op 338.00 ns/op 1.03
effectiveBalanceIncrements rw all Uint8Array 300000 169.37 us/op 170.44 us/op 0.99
effectiveBalanceIncrements rw all MutableVector 300000 84.187 ms/op 90.105 ms/op 0.93
phase0 afterProcessEpoch - 250000 vs - 7PWei 117.96 ms/op 117.89 ms/op 1.00
phase0 beforeProcessEpoch - 250000 vs - 7PWei 44.127 ms/op 43.978 ms/op 1.00
altair processEpoch - mainnet_e81889 310.78 ms/op 327.52 ms/op 0.95
mainnet_e81889 - altair beforeProcessEpoch 53.857 ms/op 53.086 ms/op 1.01
mainnet_e81889 - altair processJustificationAndFinalization 19.368 us/op 19.284 us/op 1.00
mainnet_e81889 - altair processInactivityUpdates 5.5844 ms/op 6.3005 ms/op 0.89
mainnet_e81889 - altair processRewardsAndPenalties 60.141 ms/op 65.228 ms/op 0.92
mainnet_e81889 - altair processRegistryUpdates 2.5450 us/op 2.7470 us/op 0.93
mainnet_e81889 - altair processSlashings 724.00 ns/op 541.00 ns/op 1.34
mainnet_e81889 - altair processEth1DataReset 530.00 ns/op 572.00 ns/op 0.93
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.2433 ms/op 1.2623 ms/op 0.98
mainnet_e81889 - altair processSlashingsReset 4.1280 us/op 4.7430 us/op 0.87
mainnet_e81889 - altair processRandaoMixesReset 5.2690 us/op 7.2620 us/op 0.73
mainnet_e81889 - altair processHistoricalRootsUpdate 983.00 ns/op 838.00 ns/op 1.17
mainnet_e81889 - altair processParticipationFlagUpdates 2.4970 us/op 2.4060 us/op 1.04
mainnet_e81889 - altair processSyncCommitteeUpdates 466.00 ns/op 779.00 ns/op 0.60
mainnet_e81889 - altair afterProcessEpoch 126.45 ms/op 131.69 ms/op 0.96
phase0 processEpoch - mainnet_e58758 355.74 ms/op 371.22 ms/op 0.96
mainnet_e58758 - phase0 beforeProcessEpoch 138.74 ms/op 114.26 ms/op 1.21
mainnet_e58758 - phase0 processJustificationAndFinalization 17.708 us/op 17.820 us/op 0.99
mainnet_e58758 - phase0 processRewardsAndPenalties 62.763 ms/op 61.876 ms/op 1.01
mainnet_e58758 - phase0 processRegistryUpdates 8.4050 us/op 8.6890 us/op 0.97
mainnet_e58758 - phase0 processSlashings 590.00 ns/op 565.00 ns/op 1.04
mainnet_e58758 - phase0 processEth1DataReset 520.00 ns/op 709.00 ns/op 0.73
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.0066 ms/op 1.1167 ms/op 0.90
mainnet_e58758 - phase0 processSlashingsReset 5.0050 us/op 3.9500 us/op 1.27
mainnet_e58758 - phase0 processRandaoMixesReset 4.2800 us/op 4.9880 us/op 0.86
mainnet_e58758 - phase0 processHistoricalRootsUpdate 790.00 ns/op 1.1200 us/op 0.71
mainnet_e58758 - phase0 processParticipationRecordUpdates 4.2620 us/op 4.7860 us/op 0.89
mainnet_e58758 - phase0 afterProcessEpoch 95.029 ms/op 102.27 ms/op 0.93
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.2227 ms/op 1.2511 ms/op 0.98
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.4992 ms/op 1.5188 ms/op 0.99
altair processInactivityUpdates - 250000 normalcase 24.740 ms/op 25.358 ms/op 0.98
altair processInactivityUpdates - 250000 worstcase 24.050 ms/op 29.813 ms/op 0.81
phase0 processRegistryUpdates - 250000 normalcase 6.9990 us/op 7.9780 us/op 0.88
phase0 processRegistryUpdates - 250000 badcase_full_deposits 233.00 us/op 274.66 us/op 0.85
phase0 processRegistryUpdates - 250000 worstcase 0.5 125.23 ms/op 114.42 ms/op 1.09
altair processRewardsAndPenalties - 250000 normalcase 69.266 ms/op 72.339 ms/op 0.96
altair processRewardsAndPenalties - 250000 worstcase 68.624 ms/op 77.500 ms/op 0.89
phase0 getAttestationDeltas - 250000 normalcase 6.5416 ms/op 10.486 ms/op 0.62
phase0 getAttestationDeltas - 250000 worstcase 6.4825 ms/op 9.5280 ms/op 0.68
phase0 processSlashings - 250000 worstcase 3.4720 ms/op 3.9337 ms/op 0.88
altair processSyncCommitteeUpdates - 250000 172.90 ms/op 185.02 ms/op 0.93
BeaconState.hashTreeRoot - No change 348.00 ns/op 280.00 ns/op 1.24
BeaconState.hashTreeRoot - 1 full validator 50.774 us/op 53.718 us/op 0.95
BeaconState.hashTreeRoot - 32 full validator 495.31 us/op 571.64 us/op 0.87
BeaconState.hashTreeRoot - 512 full validator 5.0600 ms/op 5.7095 ms/op 0.89
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 62.785 us/op 67.097 us/op 0.94
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 855.37 us/op 908.80 us/op 0.94
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 11.703 ms/op 12.471 ms/op 0.94
BeaconState.hashTreeRoot - 1 balances 48.157 us/op 51.750 us/op 0.93
BeaconState.hashTreeRoot - 32 balances 443.76 us/op 459.68 us/op 0.97
BeaconState.hashTreeRoot - 512 balances 4.4746 ms/op 4.5646 ms/op 0.98
BeaconState.hashTreeRoot - 250000 balances 76.789 ms/op 77.613 ms/op 0.99
aggregationBits - 2048 els - zipIndexesInBitList 14.972 us/op 18.862 us/op 0.79
regular array get 100000 times 32.025 us/op 43.459 us/op 0.74
wrappedArray get 100000 times 32.090 us/op 33.290 us/op 0.96
arrayWithProxy get 100000 times 16.394 ms/op 17.213 ms/op 0.95
ssz.Root.equals 514.00 ns/op 572.00 ns/op 0.90
byteArrayEquals 510.00 ns/op 570.00 ns/op 0.89
shuffle list - 16384 els 6.5458 ms/op 7.0420 ms/op 0.93
shuffle list - 250000 els 94.688 ms/op 102.63 ms/op 0.92
processSlot - 1 slots 8.4560 us/op 9.9770 us/op 0.85
processSlot - 32 slots 1.2841 ms/op 1.4398 ms/op 0.89
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 37.027 ms/op 37.287 ms/op 0.99
getCommitteeAssignments - req 1 vs - 250000 vc 2.9009 ms/op 2.9839 ms/op 0.97
getCommitteeAssignments - req 100 vs - 250000 vc 4.0206 ms/op 4.2224 ms/op 0.95
getCommitteeAssignments - req 1000 vs - 250000 vc 4.3920 ms/op 4.5788 ms/op 0.96
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.6100 ns/op 4.9900 ns/op 0.92
state getBlockRootAtSlot - 250000 vs - 7PWei 831.55 ns/op 1.1684 us/op 0.71
computeProposers - vc 250000 11.395 ms/op 11.336 ms/op 1.01
computeEpochShuffling - vc 250000 105.28 ms/op 105.83 ms/op 0.99
getNextSyncCommittee - vc 250000 175.40 ms/op 186.06 ms/op 0.94
computeSigningRoot for AttestationData 13.755 us/op 14.331 us/op 0.96
hash AttestationData serialized data then Buffer.toString(base64) 2.4397 us/op 2.5052 us/op 0.97
toHexString serialized data 1.0366 us/op 1.2089 us/op 0.86
Buffer.toString(base64) 311.91 ns/op 359.56 ns/op 0.87

by benchmarkbot/action

@dapplion
Copy link
Contributor Author

Anyone understands what is this error?

 @chainsafe/lodestar: $ tsc -p tsconfig.build.json && yarn write-git-data
@chainsafe/lodestar: ../beacon-node/lib/api/options.d.ts:17:28 - error TS7016: Could not find a declaration file for module '@lodestar/api/lib'. '/home/runner/work/lodestar/lodestar/packages/api/lib/index.js' implicitly has an 'any' type.
@chainsafe/lodestar:   If the '@lodestar/api' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module '@lodestar/api/lib';`
@chainsafe/lodestar: 17         api: (keyof import("@lodestar/api/lib").Api)[];

The file referenced packages/beacon-node/lib/api/options.d.ts is

import { BeaconRestApiServerOpts } from "./rest/index.js";
export interface IApiOptions {
    maxGindicesInProof?: number;
    rest?: BeaconRestApiServerOpts & {
        enabled?: boolean;
    };
    version?: string;
}
export declare const defaultApiOptions: {
    maxGindicesInProof: number;
    rest: {
        enabled: boolean;
        port: number;
        address: string;
        bodyLimit: number;
        cors: string;
        api: (keyof import("@lodestar/api/lib").Api)[];
    };
};

and @lodestar/api/lib/index.d.ts, packages/api/lib/index.d.ts exists 🤷

@@ -1,6 +1,13 @@
import {Options, Argv} from "yargs";

export type ICliCommandOptions<OwnArgs> = Required<{[key in keyof OwnArgs]: Options}>;
export type ICliCommandOptions<OwnArgs> = Required<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is some nifty typescript! ❤️

const address = node.opts.api.rest.address || "localhost";
const port = node.opts.api.rest.port || 19596;
const address = node.opts.api?.rest?.address ?? "localhost";
const port = node.opts.api?.rest?.port ?? 19596;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the beacon node api was being hosted at 19596 earlier

{
db: {name: tmpDir.name},
eth1: {enabled: false},
api: {rest: {api: ["beacon", "config", "events", "node", "validator"], port: 19596}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this endpoint has been removed, but validator still uses it

@dapplion dapplion marked this pull request as draft October 5, 2022 09:17
@dapplion dapplion mentioned this pull request Dec 12, 2022
@dapplion dapplion force-pushed the dapplion/cli-typesafe-args branch 2 times, most recently from 1e30ffc to 8aaf742 Compare May 29, 2023 12:02
@dapplion dapplion changed the title Typesafe options and cli args chore: typesafe options and cli args May 29, 2023
@dapplion
Copy link
Contributor Author

dapplion commented May 29, 2023

Split original PR into two parts:

  • This one: ONLY ensure that CLI args have proper defaults. Such there are no surpises with undefined args
  • Future 1: remove deepmerge defaults in favor a typesafe transparent default setting
  • Future 2: make as non required BeaconNode class args optional so that it can actually be used programatically

Previous branch with all parts before rebase: https://github.com/ChainSafe/lodestar/tree/dapplion/cli-typesafe-args_BACKUP

@dapplion dapplion force-pushed the dapplion/cli-typesafe-args branch from 8aaf742 to ddea9f8 Compare May 29, 2023 13:53
@dapplion dapplion marked this pull request as ready for review June 15, 2023 10:50
Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved all conflicts and re-reviewed it. Updated PR description to not close #3758.

@dapplion
Copy link
Contributor Author

Thank you so much @nflaig ❤️

@dapplion dapplion merged commit e8b53ea into unstable Jun 20, 2023
@dapplion dapplion deleted the dapplion/cli-typesafe-args branch June 20, 2023 09:57
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.10.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All lodestar CLI commands are broken if not setting --dataDir
4 participants