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

refactor(beacon-node): simplify libp2p init #5774

Merged
merged 6 commits into from
Jul 21, 2023

Conversation

wemeetagain
Copy link
Member

Motivation

Looking at libp2p initialization, I noticed that the connectToDiscv5Bootnodes feature was bugged, and no longer functioned.
Upon fixing, I noticed an opportunity to simplify the whole thing.

Description

  • fix connectToDiscv5Bootnodes
  • combine the two createNodeJsLibp2p functions
  • rename src/network/nodejs directory to src/network/libp2p

@wemeetagain wemeetagain requested a review from a team as a code owner July 18, 2023 18:32
@github-actions
Copy link
Contributor

github-actions bot commented Jul 18, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: f9353e6 Previous: d7f35a6 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 485.13 us/op 767.84 us/op 0.63
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 77.181 us/op 78.467 us/op 0.98
BLS verify - blst-native 1.2356 ms/op 1.2471 ms/op 0.99
BLS verifyMultipleSignatures 3 - blst-native 2.5102 ms/op 2.6061 ms/op 0.96
BLS verifyMultipleSignatures 8 - blst-native 5.3924 ms/op 5.4775 ms/op 0.98
BLS verifyMultipleSignatures 32 - blst-native 19.474 ms/op 19.787 ms/op 0.98
BLS aggregatePubkeys 32 - blst-native 25.621 us/op 26.198 us/op 0.98
BLS aggregatePubkeys 128 - blst-native 101.03 us/op 103.32 us/op 0.98
getAttestationsForBlock 56.346 ms/op 56.980 ms/op 0.99
isKnown best case - 1 super set check 285.00 ns/op 288.00 ns/op 0.99
isKnown normal case - 2 super set checks 267.00 ns/op 282.00 ns/op 0.95
isKnown worse case - 16 super set checks 281.00 ns/op 286.00 ns/op 0.98
CheckpointStateCache - add get delete 5.4740 us/op 5.4750 us/op 1.00
validate api signedAggregateAndProof - struct 2.7901 ms/op 2.8320 ms/op 0.99
validate gossip signedAggregateAndProof - struct 2.8606 ms/op 2.8360 ms/op 1.01
validate api attestation - struct 1.3608 ms/op 1.3547 ms/op 1.00
validate gossip attestation - struct 1.4220 ms/op 1.3770 ms/op 1.03
pickEth1Vote - no votes 1.3564 ms/op 1.2249 ms/op 1.11
pickEth1Vote - max votes 13.288 ms/op 9.6227 ms/op 1.38
pickEth1Vote - Eth1Data hashTreeRoot value x2048 10.030 ms/op 9.3558 ms/op 1.07
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 15.590 ms/op 16.836 ms/op 0.93
pickEth1Vote - Eth1Data fastSerialize value x2048 664.28 us/op 653.58 us/op 1.02
pickEth1Vote - Eth1Data fastSerialize tree x2048 5.0149 ms/op 4.8956 ms/op 1.02
bytes32 toHexString 582.00 ns/op 603.00 ns/op 0.97
bytes32 Buffer.toString(hex) 327.00 ns/op 305.00 ns/op 1.07
bytes32 Buffer.toString(hex) from Uint8Array 515.00 ns/op 479.00 ns/op 1.08
bytes32 Buffer.toString(hex) + 0x 300.00 ns/op 302.00 ns/op 0.99
Object access 1 prop 0.16900 ns/op 0.16900 ns/op 1.00
Map access 1 prop 0.14500 ns/op 0.15400 ns/op 0.94
Object get x1000 7.4600 ns/op 7.9900 ns/op 0.93
Map get x1000 0.56500 ns/op 0.62000 ns/op 0.91
Object set x1000 52.635 ns/op 56.521 ns/op 0.93
Map set x1000 41.441 ns/op 43.183 ns/op 0.96
Return object 10000 times 0.23970 ns/op 0.25330 ns/op 0.95
Throw Error 10000 times 3.8645 us/op 4.1147 us/op 0.94
fastMsgIdFn sha256 / 200 bytes 3.3780 us/op 3.4440 us/op 0.98
fastMsgIdFn h32 xxhash / 200 bytes 295.00 ns/op 315.00 ns/op 0.94
fastMsgIdFn h64 xxhash / 200 bytes 355.00 ns/op 380.00 ns/op 0.93
fastMsgIdFn sha256 / 1000 bytes 11.598 us/op 12.073 us/op 0.96
fastMsgIdFn h32 xxhash / 1000 bytes 425.00 ns/op 476.00 ns/op 0.89
fastMsgIdFn h64 xxhash / 1000 bytes 435.00 ns/op 467.00 ns/op 0.93
fastMsgIdFn sha256 / 10000 bytes 105.33 us/op 107.15 us/op 0.98
fastMsgIdFn h32 xxhash / 10000 bytes 1.9530 us/op 2.0260 us/op 0.96
fastMsgIdFn h64 xxhash / 10000 bytes 1.3360 us/op 1.3850 us/op 0.96
enrSubnets - fastDeserialize 64 bits 1.2790 us/op 1.4510 us/op 0.88
enrSubnets - ssz BitVector 64 bits 466.00 ns/op 509.00 ns/op 0.92
enrSubnets - fastDeserialize 4 bits 180.00 ns/op 205.00 ns/op 0.88
enrSubnets - ssz BitVector 4 bits 420.00 ns/op 517.00 ns/op 0.81
prioritizePeers score -10:0 att 32-0.1 sync 2-0 106.28 us/op 117.79 us/op 0.90
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 137.30 us/op 154.71 us/op 0.89
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 182.23 us/op 205.38 us/op 0.89
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 340.09 us/op 348.01 us/op 0.98
prioritizePeers score 0:0 att 64-1 sync 4-1 365.39 us/op 386.38 us/op 0.95
array of 16000 items push then shift 1.6336 us/op 1.6495 us/op 0.99
LinkedList of 16000 items push then shift 9.3970 ns/op 9.4690 ns/op 0.99
array of 16000 items push then pop 58.624 ns/op 62.669 ns/op 0.94
LinkedList of 16000 items push then pop 8.9850 ns/op 9.0210 ns/op 1.00
array of 24000 items push then shift 2.4890 us/op 2.5042 us/op 0.99
LinkedList of 24000 items push then shift 9.9310 ns/op 9.4570 ns/op 1.05
array of 24000 items push then pop 122.04 ns/op 123.82 ns/op 0.99
LinkedList of 24000 items push then pop 8.9070 ns/op 8.9060 ns/op 1.00
intersect bitArray bitLen 8 6.9950 ns/op 7.0300 ns/op 1.00
intersect array and set length 8 65.397 ns/op 63.172 ns/op 1.04
intersect bitArray bitLen 128 32.361 ns/op 32.360 ns/op 1.00
intersect array and set length 128 902.66 ns/op 993.84 ns/op 0.91
bitArray.getTrueBitIndexes() bitLen 128 1.7300 us/op 1.8630 us/op 0.93
bitArray.getTrueBitIndexes() bitLen 248 2.9390 us/op 3.2970 us/op 0.89
bitArray.getTrueBitIndexes() bitLen 512 6.2070 us/op 6.6770 us/op 0.93
Buffer.concat 32 items 1.2000 us/op 1.0730 us/op 1.12
Uint8Array.set 32 items 2.4070 us/op 2.1880 us/op 1.10
transfer serialized Status (84 B) 1.9520 us/op 1.9210 us/op 1.02
copy serialized Status (84 B) 1.5560 us/op 1.6500 us/op 0.94
transfer serialized SignedVoluntaryExit (112 B) 1.9590 us/op 2.1250 us/op 0.92
copy serialized SignedVoluntaryExit (112 B) 1.5940 us/op 1.8510 us/op 0.86
transfer serialized ProposerSlashing (416 B) 2.0990 us/op 3.5030 us/op 0.60
copy serialized ProposerSlashing (416 B) 2.1210 us/op 3.2150 us/op 0.66
transfer serialized Attestation (485 B) 2.1710 us/op 3.4430 us/op 0.63
copy serialized Attestation (485 B) 2.1530 us/op 3.4940 us/op 0.62
transfer serialized AttesterSlashing (33232 B) 2.3220 us/op 2.7990 us/op 0.83
copy serialized AttesterSlashing (33232 B) 7.6620 us/op 7.8440 us/op 0.98
transfer serialized Small SignedBeaconBlock (128000 B) 3.5700 us/op 3.7150 us/op 0.96
copy serialized Small SignedBeaconBlock (128000 B) 17.854 us/op 22.417 us/op 0.80
transfer serialized Avg SignedBeaconBlock (200000 B) 4.0880 us/op 4.3000 us/op 0.95
copy serialized Avg SignedBeaconBlock (200000 B) 23.838 us/op 29.594 us/op 0.81
transfer serialized BlobsSidecar (524380 B) 3.9190 us/op 4.3000 us/op 0.91
copy serialized BlobsSidecar (524380 B) 93.043 us/op 201.17 us/op 0.46
transfer serialized Big SignedBeaconBlock (1000000 B) 3.9980 us/op 4.1880 us/op 0.95
copy serialized Big SignedBeaconBlock (1000000 B) 160.13 us/op 207.55 us/op 0.77
pass gossip attestations to forkchoice per slot 2.2314 ms/op 2.2823 ms/op 0.98
forkChoice updateHead vc 100000 bc 64 eq 0 2.2670 ms/op 2.2368 ms/op 1.01
forkChoice updateHead vc 600000 bc 64 eq 0 14.494 ms/op 14.874 ms/op 0.97
forkChoice updateHead vc 1000000 bc 64 eq 0 19.028 ms/op 23.466 ms/op 0.81
forkChoice updateHead vc 600000 bc 320 eq 0 21.360 ms/op 17.246 ms/op 1.24
forkChoice updateHead vc 600000 bc 1200 eq 0 88.506 ms/op 90.722 ms/op 0.98
forkChoice updateHead vc 600000 bc 64 eq 1000 19.642 ms/op 23.050 ms/op 0.85
forkChoice updateHead vc 600000 bc 64 eq 10000 21.911 ms/op 25.247 ms/op 0.87
forkChoice updateHead vc 600000 bc 64 eq 300000 38.855 ms/op 38.332 ms/op 1.01
computeDeltas 3.4220 ms/op 3.2745 ms/op 1.05
computeProposerBoostScoreFromBalances 415.63 us/op 399.63 us/op 1.04
altair processAttestation - 250000 vs - 7PWei normalcase 4.8808 ms/op 3.5941 ms/op 1.36
altair processAttestation - 250000 vs - 7PWei worstcase 4.2537 ms/op 4.6121 ms/op 0.92
altair processAttestation - setStatus - 1/6 committees join 200.59 us/op 256.64 us/op 0.78
altair processAttestation - setStatus - 1/3 committees join 371.19 us/op 448.20 us/op 0.83
altair processAttestation - setStatus - 1/2 committees join 527.34 us/op 681.54 us/op 0.77
altair processAttestation - setStatus - 2/3 committees join 648.68 us/op 767.55 us/op 0.85
altair processAttestation - setStatus - 4/5 committees join 920.03 us/op 1.0569 ms/op 0.87
altair processAttestation - setStatus - 100% committees join 1.0394 ms/op 1.2263 ms/op 0.85
altair processBlock - 250000 vs - 7PWei normalcase 10.141 ms/op 10.450 ms/op 0.97
altair processBlock - 250000 vs - 7PWei normalcase hashState 18.158 ms/op 18.751 ms/op 0.97
altair processBlock - 250000 vs - 7PWei worstcase 40.421 ms/op 42.055 ms/op 0.96
altair processBlock - 250000 vs - 7PWei worstcase hashState 61.929 ms/op 63.905 ms/op 0.97
phase0 processBlock - 250000 vs - 7PWei normalcase 2.6306 ms/op 2.3320 ms/op 1.13
phase0 processBlock - 250000 vs - 7PWei worstcase 32.820 ms/op 30.792 ms/op 1.07
altair processEth1Data - 250000 vs - 7PWei normalcase 507.36 us/op 560.24 us/op 0.91
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 12.114 us/op 13.337 us/op 0.91
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 60.457 us/op 63.041 us/op 0.96
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 20.523 us/op 21.938 us/op 0.94
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 14.293 us/op 20.927 us/op 0.68
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 146.14 us/op 207.14 us/op 0.71
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.1421 ms/op 1.7433 ms/op 0.66
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 2.1286 ms/op 2.2807 ms/op 0.93
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.5440 ms/op 2.0790 ms/op 0.74
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 3.3390 ms/op 4.0024 ms/op 0.83
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 2.6455 ms/op 2.5172 ms/op 1.05
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 5.7127 ms/op 6.1955 ms/op 0.92
Tree 40 250000 create 337.27 ms/op 429.27 ms/op 0.79
Tree 40 250000 get(125000) 210.75 ns/op 210.73 ns/op 1.00
Tree 40 250000 set(125000) 969.45 ns/op 1.0184 us/op 0.95
Tree 40 250000 toArray() 22.915 ms/op 22.413 ms/op 1.02
Tree 40 250000 iterate all - toArray() + loop 22.325 ms/op 23.908 ms/op 0.93
Tree 40 250000 iterate all - get(i) 73.601 ms/op 77.846 ms/op 0.95
MutableVector 250000 create 11.964 ms/op 12.756 ms/op 0.94
MutableVector 250000 get(125000) 6.7840 ns/op 7.1010 ns/op 0.96
MutableVector 250000 set(125000) 249.74 ns/op 423.79 ns/op 0.59
MutableVector 250000 toArray() 3.6827 ms/op 3.4055 ms/op 1.08
MutableVector 250000 iterate all - toArray() + loop 3.8930 ms/op 3.5276 ms/op 1.10
MutableVector 250000 iterate all - get(i) 1.5408 ms/op 1.6012 ms/op 0.96
Array 250000 create 3.4676 ms/op 3.1833 ms/op 1.09
Array 250000 clone - spread 1.0975 ms/op 1.0265 ms/op 1.07
Array 250000 get(125000) 0.52200 ns/op 0.53100 ns/op 0.98
Array 250000 set(125000) 0.62000 ns/op 0.60400 ns/op 1.03
Array 250000 iterate all - loop 84.879 us/op 91.968 us/op 0.92
effectiveBalanceIncrements clone Uint8Array 300000 31.788 us/op 32.127 us/op 0.99
effectiveBalanceIncrements clone MutableVector 300000 289.00 ns/op 259.00 ns/op 1.12
effectiveBalanceIncrements rw all Uint8Array 300000 182.63 us/op 189.30 us/op 0.96
effectiveBalanceIncrements rw all MutableVector 300000 85.684 ms/op 80.063 ms/op 1.07
phase0 afterProcessEpoch - 250000 vs - 7PWei 116.38 ms/op 119.10 ms/op 0.98
phase0 beforeProcessEpoch - 250000 vs - 7PWei 41.472 ms/op 36.064 ms/op 1.15
altair processEpoch - mainnet_e81889 331.49 ms/op 351.64 ms/op 0.94
mainnet_e81889 - altair beforeProcessEpoch 69.956 ms/op 68.867 ms/op 1.02
mainnet_e81889 - altair processJustificationAndFinalization 15.458 us/op 19.308 us/op 0.80
mainnet_e81889 - altair processInactivityUpdates 6.9589 ms/op 6.4276 ms/op 1.08
mainnet_e81889 - altair processRewardsAndPenalties 51.350 ms/op 73.660 ms/op 0.70
mainnet_e81889 - altair processRegistryUpdates 2.7540 us/op 3.2690 us/op 0.84
mainnet_e81889 - altair processSlashings 753.00 ns/op 989.00 ns/op 0.76
mainnet_e81889 - altair processEth1DataReset 1.0050 us/op 708.00 ns/op 1.42
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.4247 ms/op 1.5494 ms/op 0.92
mainnet_e81889 - altair processSlashingsReset 4.2860 us/op 5.0350 us/op 0.85
mainnet_e81889 - altair processRandaoMixesReset 6.8740 us/op 6.6690 us/op 1.03
mainnet_e81889 - altair processHistoricalRootsUpdate 865.00 ns/op 1.0340 us/op 0.84
mainnet_e81889 - altair processParticipationFlagUpdates 3.9010 us/op 2.7560 us/op 1.42
mainnet_e81889 - altair processSyncCommitteeUpdates 1.0250 us/op 744.00 ns/op 1.38
mainnet_e81889 - altair afterProcessEpoch 134.87 ms/op 139.33 ms/op 0.97
phase0 processEpoch - mainnet_e58758 404.67 ms/op 399.99 ms/op 1.01
mainnet_e58758 - phase0 beforeProcessEpoch 159.45 ms/op 184.95 ms/op 0.86
mainnet_e58758 - phase0 processJustificationAndFinalization 21.858 us/op 17.555 us/op 1.25
mainnet_e58758 - phase0 processRewardsAndPenalties 73.223 ms/op 72.220 ms/op 1.01
mainnet_e58758 - phase0 processRegistryUpdates 12.785 us/op 16.416 us/op 0.78
mainnet_e58758 - phase0 processSlashings 619.00 ns/op 827.00 ns/op 0.75
mainnet_e58758 - phase0 processEth1DataReset 502.00 ns/op 660.00 ns/op 0.76
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 2.4342 ms/op 1.2586 ms/op 1.93
mainnet_e58758 - phase0 processSlashingsReset 2.9380 us/op 3.4010 us/op 0.86
mainnet_e58758 - phase0 processRandaoMixesReset 7.1770 us/op 6.4320 us/op 1.12
mainnet_e58758 - phase0 processHistoricalRootsUpdate 1.0510 us/op 636.00 ns/op 1.65
mainnet_e58758 - phase0 processParticipationRecordUpdates 4.4000 us/op 4.5830 us/op 0.96
mainnet_e58758 - phase0 afterProcessEpoch 103.58 ms/op 115.50 ms/op 0.90
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.2518 ms/op 1.6013 ms/op 0.78
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.4676 ms/op 1.5053 ms/op 0.97
altair processInactivityUpdates - 250000 normalcase 28.574 ms/op 31.438 ms/op 0.91
altair processInactivityUpdates - 250000 worstcase 26.860 ms/op 29.878 ms/op 0.90
phase0 processRegistryUpdates - 250000 normalcase 12.203 us/op 11.800 us/op 1.03
phase0 processRegistryUpdates - 250000 badcase_full_deposits 417.14 us/op 460.29 us/op 0.91
phase0 processRegistryUpdates - 250000 worstcase 0.5 367.59 ms/op 148.41 ms/op 2.48
altair processRewardsAndPenalties - 250000 normalcase 95.322 ms/op 78.014 ms/op 1.22
altair processRewardsAndPenalties - 250000 worstcase 79.385 ms/op 78.384 ms/op 1.01
phase0 getAttestationDeltas - 250000 normalcase 10.139 ms/op 8.7361 ms/op 1.16
phase0 getAttestationDeltas - 250000 worstcase 11.480 ms/op 8.2886 ms/op 1.39
phase0 processSlashings - 250000 worstcase 3.0170 ms/op 2.3815 ms/op 1.27
altair processSyncCommitteeUpdates - 250000 203.76 ms/op 168.49 ms/op 1.21
BeaconState.hashTreeRoot - No change 275.00 ns/op 295.00 ns/op 0.93
BeaconState.hashTreeRoot - 1 full validator 70.438 us/op 49.718 us/op 1.42
BeaconState.hashTreeRoot - 32 full validator 712.89 us/op 491.67 us/op 1.45
BeaconState.hashTreeRoot - 512 full validator 6.1094 ms/op 5.2645 ms/op 1.16
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 67.883 us/op 61.908 us/op 1.10
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 960.85 us/op 854.93 us/op 1.12
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 13.686 ms/op 10.662 ms/op 1.28
BeaconState.hashTreeRoot - 1 balances 50.355 us/op 47.601 us/op 1.06
BeaconState.hashTreeRoot - 32 balances 521.00 us/op 433.57 us/op 1.20
BeaconState.hashTreeRoot - 512 balances 4.4101 ms/op 4.0046 ms/op 1.10
BeaconState.hashTreeRoot - 250000 balances 85.020 ms/op 79.309 ms/op 1.07
aggregationBits - 2048 els - zipIndexesInBitList 16.534 us/op 15.908 us/op 1.04
regular array get 100000 times 33.972 us/op 33.820 us/op 1.00
wrappedArray get 100000 times 33.749 us/op 33.879 us/op 1.00
arrayWithProxy get 100000 times 14.702 ms/op 14.839 ms/op 0.99
ssz.Root.equals 221.00 ns/op 235.00 ns/op 0.94
byteArrayEquals 259.00 ns/op 233.00 ns/op 1.11
shuffle list - 16384 els 7.3727 ms/op 7.0613 ms/op 1.04
shuffle list - 250000 els 105.16 ms/op 104.69 ms/op 1.00
processSlot - 1 slots 8.5210 us/op 7.9970 us/op 1.07
processSlot - 32 slots 1.3462 ms/op 1.3267 ms/op 1.01
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 55.525 ms/op 54.774 ms/op 1.01
getCommitteeAssignments - req 1 vs - 250000 vc 2.5486 ms/op 2.5569 ms/op 1.00
getCommitteeAssignments - req 100 vs - 250000 vc 3.7731 ms/op 3.7617 ms/op 1.00
getCommitteeAssignments - req 1000 vs - 250000 vc 4.1099 ms/op 4.0990 ms/op 1.00
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.7500 ns/op 4.6000 ns/op 1.03
state getBlockRootAtSlot - 250000 vs - 7PWei 516.74 ns/op 958.98 ns/op 0.54
computeProposers - vc 250000 9.0790 ms/op 10.252 ms/op 0.89
computeEpochShuffling - vc 250000 106.58 ms/op 106.72 ms/op 1.00
getNextSyncCommittee - vc 250000 154.25 ms/op 166.93 ms/op 0.92
computeSigningRoot for AttestationData 13.409 us/op 14.054 us/op 0.95
hash AttestationData serialized data then Buffer.toString(base64) 2.3568 us/op 2.3169 us/op 1.02
toHexString serialized data 1.1347 us/op 1.0790 us/op 1.05
Buffer.toString(base64) 227.38 ns/op 237.62 ns/op 0.96

by benchmarkbot/action

@wemeetagain wemeetagain merged commit 03c36e2 into unstable Jul 21, 2023
@wemeetagain wemeetagain deleted the cayman/refactor-libp2p-init branch July 21, 2023 14:22
@nflaig
Copy link
Member

nflaig commented Aug 2, 2023

After looking at different behavior with and without --network.connectToDiscv5Bootnodes it is not clear to me what the expected behavior of this flag is. The description says "Attempt direct connection to discv5 bootnodes" and before my PR #5834 it also had "from network.discv5.bootEnrs option" which I removed because it didn't make sense to me.

But there seems to be two places this is used

In case of libp2p

...(networkOpts.connectToDiscv5Bootnodes ? await getDiscv5Multiaddrs(networkOpts.discv5?.bootEnrs ?? []) : []),

  • With connectToDiscv5Bootnodes it always adds all bootnodes from file + from github url + --bootnodes flag to bootMultiaddrs which is passed to createLibp2p
  • Without connectToDiscv5Bootnodes it seems like bootMultiaddrs is always empty

In case of discv5

if (this.connectToDiscv5BootnodesOnStart) {

  • With connectToDiscv5Bootnodes the enr value is decoded right at start and we call onDiscoveredENR(Edit: This seems to dial the bootnodes if they were discovered through discv5), if an invalid enr value is provided this will throw the error reported here Error decoding ENRs from mainnet/bootstrap_nodes.txt #5833
  • Without connectToDiscv5Bootnodes it seems to lazily connect bootnodes (Edit: is it connecting? I guess it just uses those nodes to discover peers, maybe someone with better discv5 understanding can clarify this), in this case we just call addEnr on the worker and ENR.decodeTxt is handled within discv5 which creates a DEBUG log but ignores the error (worker addEnr call, discv5 addEnr)

Also note that the internal option network.discv5.bootEnrs always contains all bootnodes (file + from github url + --bootnodes flag) not matter if --network.connectToDiscv5Bootnodes flag is set or not.

const extraBootnodes = (beaconNodeOptions.get().network?.discv5?.bootEnrs ?? []).concat(
args.bootnodesFile ? readBootnodes(args.bootnodesFile) : [],
isKnownNetworkName(network) ? await getNetworkBootnodes(network) : []
);
beaconNodeOptions.set({network: {discv5: {bootEnrs: extraBootnodes}}});

There is a comment in the code which I am not sure it is accurate since we dial discv5.bootEnrs either way, just not on start? (Edit: Maybe just my misunderstanding what connect means, i.e. it means connect as peers (libp2p) and not connect as discv5 nodes to discover more peers?)

if (this.connectToDiscv5BootnodesOnStart) {
// In devnet scenarios, especially, we want more control over which peers we connect to.
// Only dial the discv5.bootEnrs if the option
// network.connectToDiscv5Bootnodes has been set to true.
for (const bootENR of opts.discv5.bootEnrs) {

When the flag was initially added it seems like the purpose was limited to "append parsed bootnode ENRs to bootMultiaddrs" which as far as I understand are the nodes we dial over libp2p.

Based on my understanding, the core functionality of --network.connectToDiscv5Bootnodes is to connect to discv5 bootnodes directly on the network (libp2p) as peers and not just for discovery.

The second behavior "connect on start" was added in this PR #3672 and it seems like this is required as otherwise starting two nodes using dev scripts won't connect to each other, this will dial the enrs directly through libp2p as if they were discovered by discv5.

void this.dialPeer(cachedPeer);

If my understanding is correct I think it makes sense to update the CLI description to indicate that it specifically means that Lodestar should dial bootnodes through/over libp2p as peers, perhaps Attempt direct connection to discv5 bootnodes over libp2p to make it a bit more concise.

"network.connectToDiscv5Bootnodes": {
type: "boolean",
description: "Attempt direct connection to discv5 bootnodes",

@wemeetagain
Copy link
Member Author

Yes, connectToDiscv5Bootnodes is meant to establish libp2p connections with the connectable enrs (those with ip+tcp records).

It seems that there are some duplicate connectToDiscv5Bootnodes behavior.
We use libp2p's "bootstrap" peer discovery module to have libp2p emit peer discovery events. Which is handled in our peer discovery module, onDiscoveredPeer.
We use our peer discovery module to simulate emitting newly discovered ENRs, onDiscoveredENR.

@wemeetagain
Copy link
Member Author

Without connectToDiscv5Bootnodes it seems to lazily connect bootnodes (Edit: is it connecting? I guess it just uses those nodes to discover peers, maybe someone with better discv5 understanding can clarify this)

It's adding ENRs to our discv5 kad table, which will be used when we perform a discv5 lookup, to discover more peers.

@wemeetagain
Copy link
Member Author

🎉 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.

3 participants