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

fix: set user credentials in URL as Authorization header #5884

Merged
merged 7 commits into from
Aug 21, 2023

Conversation

nflaig
Copy link
Member

@nflaig nflaig commented Aug 14, 2023

Motivation

Closes #5881

Description

  • Add functions to encode / decode base64
  • Move URL validation function to utils package
  • Improve URL validation and fail on startup
  • Set user credentials in URL as Authorization header

Note: Basic authorization header is only added in HttpClient and not JsonRpcHttpClient as it implements it's own authentication scheme using JWT as bearer tokens.

@nflaig nflaig force-pushed the nflaig/set-basic-auth-header branch from d521d05 to 7b17f10 Compare August 14, 2023 14:19
@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 6335e46 Previous: 97502c7 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 569.37 us/op 693.22 us/op 0.82
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 99.667 us/op 108.87 us/op 0.92
BLS verify - blst-native 1.3186 ms/op 1.3609 ms/op 0.97
BLS verifyMultipleSignatures 3 - blst-native 2.8743 ms/op 2.8494 ms/op 1.01
BLS verifyMultipleSignatures 8 - blst-native 5.7715 ms/op 5.9464 ms/op 0.97
BLS verifyMultipleSignatures 32 - blst-native 20.463 ms/op 21.047 ms/op 0.97
BLS aggregatePubkeys 32 - blst-native 27.234 us/op 28.303 us/op 0.96
BLS aggregatePubkeys 128 - blst-native 106.73 us/op 109.29 us/op 0.98
getAttestationsForBlock 72.613 ms/op 77.831 ms/op 0.93
isKnown best case - 1 super set check 478.00 ns/op 519.00 ns/op 0.92
isKnown normal case - 2 super set checks 453.00 ns/op 535.00 ns/op 0.85
isKnown worse case - 16 super set checks 463.00 ns/op 535.00 ns/op 0.87
CheckpointStateCache - add get delete 6.1160 us/op 6.9310 us/op 0.88
validate api signedAggregateAndProof - struct 2.9124 ms/op 3.0696 ms/op 0.95
validate gossip signedAggregateAndProof - struct 2.9672 ms/op 3.1420 ms/op 0.94
validate api attestation - struct 1.4212 ms/op 1.4884 ms/op 0.95
validate gossip attestation - struct 1.5234 ms/op 1.5812 ms/op 0.96
pickEth1Vote - no votes 1.3572 ms/op 1.4461 ms/op 0.94
pickEth1Vote - max votes 10.148 ms/op 13.995 ms/op 0.73
pickEth1Vote - Eth1Data hashTreeRoot value x2048 9.7122 ms/op 10.782 ms/op 0.90
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 17.375 ms/op 18.229 ms/op 0.95
pickEth1Vote - Eth1Data fastSerialize value x2048 752.19 us/op 793.61 us/op 0.95
pickEth1Vote - Eth1Data fastSerialize tree x2048 5.6090 ms/op 7.5952 ms/op 0.74
bytes32 toHexString 809.00 ns/op 841.00 ns/op 0.96
bytes32 Buffer.toString(hex) 358.00 ns/op 321.00 ns/op 1.12
bytes32 Buffer.toString(hex) from Uint8Array 576.00 ns/op 579.00 ns/op 0.99
bytes32 Buffer.toString(hex) + 0x 402.00 ns/op 338.00 ns/op 1.19
Object access 1 prop 0.25500 ns/op 0.22700 ns/op 1.12
Map access 1 prop 0.17400 ns/op 0.16200 ns/op 1.07
Object get x1000 8.0800 ns/op 8.7550 ns/op 0.92
Map get x1000 0.75300 ns/op 0.69700 ns/op 1.08
Object set x1000 71.111 ns/op 75.246 ns/op 0.95
Map set x1000 53.670 ns/op 56.926 ns/op 0.94
Return object 10000 times 0.26780 ns/op 0.30600 ns/op 0.88
Throw Error 10000 times 4.3027 us/op 4.3382 us/op 0.99
fastMsgIdFn sha256 / 200 bytes 3.6210 us/op 3.7710 us/op 0.96
fastMsgIdFn h32 xxhash / 200 bytes 365.00 ns/op 374.00 ns/op 0.98
fastMsgIdFn h64 xxhash / 200 bytes 409.00 ns/op 432.00 ns/op 0.95
fastMsgIdFn sha256 / 1000 bytes 12.094 us/op 12.955 us/op 0.93
fastMsgIdFn h32 xxhash / 1000 bytes 517.00 ns/op 510.00 ns/op 1.01
fastMsgIdFn h64 xxhash / 1000 bytes 507.00 ns/op 501.00 ns/op 1.01
fastMsgIdFn sha256 / 10000 bytes 107.48 us/op 114.30 us/op 0.94
fastMsgIdFn h32 xxhash / 10000 bytes 2.1100 us/op 2.1810 us/op 0.97
fastMsgIdFn h64 xxhash / 10000 bytes 1.5210 us/op 1.4970 us/op 1.02
enrSubnets - fastDeserialize 64 bits 1.7700 us/op 1.8580 us/op 0.95
enrSubnets - ssz BitVector 64 bits 580.00 ns/op 607.00 ns/op 0.96
enrSubnets - fastDeserialize 4 bits 241.00 ns/op 259.00 ns/op 0.93
enrSubnets - ssz BitVector 4 bits 593.00 ns/op 605.00 ns/op 0.98
prioritizePeers score -10:0 att 32-0.1 sync 2-0 126.68 us/op 125.74 us/op 1.01
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 152.96 us/op 158.81 us/op 0.96
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 198.72 us/op 212.65 us/op 0.93
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 348.96 us/op 392.99 us/op 0.89
prioritizePeers score 0:0 att 64-1 sync 4-1 415.13 us/op 431.98 us/op 0.96
array of 16000 items push then shift 1.6785 us/op 1.7992 us/op 0.93
LinkedList of 16000 items push then shift 9.9690 ns/op 10.492 ns/op 0.95
array of 16000 items push then pop 63.566 ns/op 69.578 ns/op 0.91
LinkedList of 16000 items push then pop 9.4510 ns/op 10.519 ns/op 0.90
array of 24000 items push then shift 2.5486 us/op 2.7271 us/op 0.93
LinkedList of 24000 items push then shift 10.717 ns/op 10.947 ns/op 0.98
array of 24000 items push then pop 136.23 ns/op 135.18 ns/op 1.01
LinkedList of 24000 items push then pop 9.5570 ns/op 10.421 ns/op 0.92
intersect bitArray bitLen 8 7.1840 ns/op 8.2680 ns/op 0.87
intersect array and set length 8 85.279 ns/op 90.449 ns/op 0.94
intersect bitArray bitLen 128 33.451 ns/op 37.238 ns/op 0.90
intersect array and set length 128 1.0793 us/op 1.1357 us/op 0.95
bitArray.getTrueBitIndexes() bitLen 128 2.0520 us/op 2.0790 us/op 0.99
bitArray.getTrueBitIndexes() bitLen 248 3.3990 us/op 3.3660 us/op 1.01
bitArray.getTrueBitIndexes() bitLen 512 7.1350 us/op 7.2770 us/op 0.98
Buffer.concat 32 items 1.2020 us/op 1.2500 us/op 0.96
Uint8Array.set 32 items 2.0370 us/op 2.3220 us/op 0.88
Set add up to 64 items then delete first 4.7347 us/op 5.0505 us/op 0.94
OrderedSet add up to 64 items then delete first 6.2325 us/op 6.5247 us/op 0.96
Set add up to 64 items then delete last 5.2571 us/op 5.3733 us/op 0.98
OrderedSet add up to 64 items then delete last 6.3930 us/op 7.1459 us/op 0.89
Set add up to 64 items then delete middle 5.1312 us/op 5.4305 us/op 0.94
OrderedSet add up to 64 items then delete middle 8.0107 us/op 8.2251 us/op 0.97
Set add up to 128 items then delete first 10.533 us/op 10.541 us/op 1.00
OrderedSet add up to 128 items then delete first 14.208 us/op 15.647 us/op 0.91
Set add up to 128 items then delete last 10.312 us/op 10.732 us/op 0.96
OrderedSet add up to 128 items then delete last 12.057 us/op 13.944 us/op 0.86
Set add up to 128 items then delete middle 9.8114 us/op 10.229 us/op 0.96
OrderedSet add up to 128 items then delete middle 18.544 us/op 19.194 us/op 0.97
Set add up to 256 items then delete first 20.439 us/op 21.158 us/op 0.97
OrderedSet add up to 256 items then delete first 27.755 us/op 27.790 us/op 1.00
Set add up to 256 items then delete last 20.297 us/op 19.847 us/op 1.02
OrderedSet add up to 256 items then delete last 27.320 us/op 25.024 us/op 1.09
Set add up to 256 items then delete middle 20.400 us/op 20.286 us/op 1.01
OrderedSet add up to 256 items then delete middle 50.392 us/op 49.905 us/op 1.01
transfer serialized Status (84 B) 1.9680 us/op 1.9480 us/op 1.01
copy serialized Status (84 B) 1.8680 us/op 1.6430 us/op 1.14
transfer serialized SignedVoluntaryExit (112 B) 2.2480 us/op 2.2350 us/op 1.01
copy serialized SignedVoluntaryExit (112 B) 1.9410 us/op 1.8270 us/op 1.06
transfer serialized ProposerSlashing (416 B) 2.3030 us/op 2.4380 us/op 0.94
copy serialized ProposerSlashing (416 B) 2.3410 us/op 2.6790 us/op 0.87
transfer serialized Attestation (485 B) 2.9220 us/op 2.8130 us/op 1.04
copy serialized Attestation (485 B) 2.5300 us/op 3.1300 us/op 0.81
transfer serialized AttesterSlashing (33232 B) 2.6870 us/op 2.8670 us/op 0.94
copy serialized AttesterSlashing (33232 B) 7.7640 us/op 5.6650 us/op 1.37
transfer serialized Small SignedBeaconBlock (128000 B) 2.7340 us/op 2.9530 us/op 0.93
copy serialized Small SignedBeaconBlock (128000 B) 21.721 us/op 13.914 us/op 1.56
transfer serialized Avg SignedBeaconBlock (200000 B) 3.2250 us/op 3.3200 us/op 0.97
copy serialized Avg SignedBeaconBlock (200000 B) 28.358 us/op 68.198 us/op 0.42
transfer serialized BlobsSidecar (524380 B) 3.9170 us/op 4.1440 us/op 0.95
copy serialized BlobsSidecar (524380 B) 93.795 us/op 220.63 us/op 0.43
transfer serialized Big SignedBeaconBlock (1000000 B) 4.0490 us/op 3.7870 us/op 1.07
copy serialized Big SignedBeaconBlock (1000000 B) 175.34 us/op 208.06 us/op 0.84
pass gossip attestations to forkchoice per slot 3.6840 ms/op 3.0723 ms/op 1.20
forkChoice updateHead vc 100000 bc 64 eq 0 1.8690 ms/op 1.9791 ms/op 0.94
forkChoice updateHead vc 600000 bc 64 eq 0 14.958 ms/op 16.539 ms/op 0.90
forkChoice updateHead vc 1000000 bc 64 eq 0 24.249 ms/op 23.644 ms/op 1.03
forkChoice updateHead vc 600000 bc 320 eq 0 17.280 ms/op 14.929 ms/op 1.16
forkChoice updateHead vc 600000 bc 1200 eq 0 16.437 ms/op 17.322 ms/op 0.95
forkChoice updateHead vc 600000 bc 7200 eq 0 12.716 ms/op 12.458 ms/op 1.02
forkChoice updateHead vc 600000 bc 64 eq 1000 26.453 ms/op 23.475 ms/op 1.13
forkChoice updateHead vc 600000 bc 64 eq 10000 25.985 ms/op 26.080 ms/op 1.00
forkChoice updateHead vc 600000 bc 64 eq 300000 34.499 ms/op 31.780 ms/op 1.09
computeDeltas 500000 validators 300 proto nodes 19.647 ms/op 19.086 ms/op 1.03
computeDeltas 500000 validators 1200 proto nodes 19.626 ms/op 19.044 ms/op 1.03
computeDeltas 500000 validators 7200 proto nodes 19.669 ms/op 18.556 ms/op 1.06
computeDeltas 750000 validators 300 proto nodes 29.290 ms/op 28.232 ms/op 1.04
computeDeltas 750000 validators 1200 proto nodes 29.073 ms/op 28.478 ms/op 1.02
computeDeltas 750000 validators 7200 proto nodes 29.129 ms/op 28.209 ms/op 1.03
computeDeltas 1400000 validators 300 proto nodes 54.277 ms/op 54.795 ms/op 0.99
computeDeltas 1400000 validators 1200 proto nodes 57.263 ms/op 60.458 ms/op 0.95
computeDeltas 1400000 validators 7200 proto nodes 60.278 ms/op 61.205 ms/op 0.98
computeDeltas 2100000 validators 300 proto nodes 85.381 ms/op 86.840 ms/op 0.98
computeDeltas 2100000 validators 1200 proto nodes 83.821 ms/op 95.411 ms/op 0.88
computeDeltas 2100000 validators 7200 proto nodes 86.193 ms/op 84.516 ms/op 1.02
computeProposerBoostScoreFromBalances 500000 validators 3.7696 ms/op 3.5946 ms/op 1.05
computeProposerBoostScoreFromBalances 750000 validators 3.5653 ms/op 3.4067 ms/op 1.05
computeProposerBoostScoreFromBalances 1400000 validators 3.4731 ms/op 3.5810 ms/op 0.97
computeProposerBoostScoreFromBalances 2100000 validators 3.4398 ms/op 3.8495 ms/op 0.89
altair processAttestation - 250000 vs - 7PWei normalcase 4.2608 ms/op 4.0694 ms/op 1.05
altair processAttestation - 250000 vs - 7PWei worstcase 4.5949 ms/op 6.3652 ms/op 0.72
altair processAttestation - setStatus - 1/6 committees join 177.82 us/op 295.80 us/op 0.60
altair processAttestation - setStatus - 1/3 committees join 312.83 us/op 472.82 us/op 0.66
altair processAttestation - setStatus - 1/2 committees join 423.85 us/op 680.23 us/op 0.62
altair processAttestation - setStatus - 2/3 committees join 522.28 us/op 792.38 us/op 0.66
altair processAttestation - setStatus - 4/5 committees join 777.78 us/op 973.11 us/op 0.80
altair processAttestation - setStatus - 100% committees join 895.74 us/op 1.0849 ms/op 0.83
altair processBlock - 250000 vs - 7PWei normalcase 10.198 ms/op 11.799 ms/op 0.86
altair processBlock - 250000 vs - 7PWei normalcase hashState 19.612 ms/op 22.571 ms/op 0.87
altair processBlock - 250000 vs - 7PWei worstcase 43.991 ms/op 44.786 ms/op 0.98
altair processBlock - 250000 vs - 7PWei worstcase hashState 78.005 ms/op 66.026 ms/op 1.18
phase0 processBlock - 250000 vs - 7PWei normalcase 2.9535 ms/op 2.9017 ms/op 1.02
phase0 processBlock - 250000 vs - 7PWei worstcase 34.066 ms/op 36.729 ms/op 0.93
altair processEth1Data - 250000 vs - 7PWei normalcase 780.16 us/op 696.35 us/op 1.12
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 14.814 us/op 15.920 us/op 0.93
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 57.462 us/op 64.400 us/op 0.89
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 27.288 us/op 25.370 us/op 1.08
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 18.629 us/op 16.494 us/op 1.13
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 178.35 us/op 227.20 us/op 0.79
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.6211 ms/op 2.2028 ms/op 0.74
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.8815 ms/op 2.6033 ms/op 0.72
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 2.0412 ms/op 2.6385 ms/op 0.77
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 4.5588 ms/op 7.0492 ms/op 0.65
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 3.0397 ms/op 5.2457 ms/op 0.58
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 6.6313 ms/op 11.967 ms/op 0.55
Tree 40 250000 create 448.74 ms/op 741.49 ms/op 0.61
Tree 40 250000 get(125000) 226.85 ns/op 238.69 ns/op 0.95
Tree 40 250000 set(125000) 1.2630 us/op 2.2509 us/op 0.56
Tree 40 250000 toArray() 24.088 ms/op 34.786 ms/op 0.69
Tree 40 250000 iterate all - toArray() + loop 24.778 ms/op 35.813 ms/op 0.69
Tree 40 250000 iterate all - get(i) 76.197 ms/op 113.44 ms/op 0.67
MutableVector 250000 create 15.980 ms/op 19.229 ms/op 0.83
MutableVector 250000 get(125000) 6.7150 ns/op 7.5810 ns/op 0.89
MutableVector 250000 set(125000) 398.41 ns/op 516.41 ns/op 0.77
MutableVector 250000 toArray() 4.4138 ms/op 5.2989 ms/op 0.83
MutableVector 250000 iterate all - toArray() + loop 4.6067 ms/op 5.4629 ms/op 0.84
MutableVector 250000 iterate all - get(i) 1.5970 ms/op 1.7391 ms/op 0.92
Array 250000 create 4.2729 ms/op 4.8593 ms/op 0.88
Array 250000 clone - spread 1.2379 ms/op 3.4892 ms/op 0.35
Array 250000 get(125000) 0.53200 ns/op 1.1330 ns/op 0.47
Array 250000 set(125000) 0.60500 ns/op 1.8980 ns/op 0.32
Array 250000 iterate all - loop 87.443 us/op 134.03 us/op 0.65
effectiveBalanceIncrements clone Uint8Array 300000 36.143 us/op 86.730 us/op 0.42
effectiveBalanceIncrements clone MutableVector 300000 222.00 ns/op 714.00 ns/op 0.31
effectiveBalanceIncrements rw all Uint8Array 300000 184.10 us/op 209.04 us/op 0.88
effectiveBalanceIncrements rw all MutableVector 300000 113.88 ms/op 212.14 ms/op 0.54
phase0 afterProcessEpoch - 250000 vs - 7PWei 119.64 ms/op 168.08 ms/op 0.71
phase0 beforeProcessEpoch - 250000 vs - 7PWei 38.481 ms/op 69.123 ms/op 0.56
altair processEpoch - mainnet_e81889 333.04 ms/op 449.72 ms/op 0.74
mainnet_e81889 - altair beforeProcessEpoch 72.170 ms/op 99.913 ms/op 0.72
mainnet_e81889 - altair processJustificationAndFinalization 16.929 us/op 46.744 us/op 0.36
mainnet_e81889 - altair processInactivityUpdates 6.7773 ms/op 11.055 ms/op 0.61
mainnet_e81889 - altair processRewardsAndPenalties 75.370 ms/op 90.664 ms/op 0.83
mainnet_e81889 - altair processRegistryUpdates 3.1300 us/op 7.5390 us/op 0.42
mainnet_e81889 - altair processSlashings 563.00 ns/op 1.6730 us/op 0.34
mainnet_e81889 - altair processEth1DataReset 853.00 ns/op 2.0830 us/op 0.41
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.3041 ms/op 2.3120 ms/op 0.56
mainnet_e81889 - altair processSlashingsReset 3.4200 us/op 7.2760 us/op 0.47
mainnet_e81889 - altair processRandaoMixesReset 8.6720 us/op 9.8600 us/op 0.88
mainnet_e81889 - altair processHistoricalRootsUpdate 1.1370 us/op 1.5000 us/op 0.76
mainnet_e81889 - altair processParticipationFlagUpdates 2.9520 us/op 3.6610 us/op 0.81
mainnet_e81889 - altair processSyncCommitteeUpdates 838.00 ns/op 1.4130 us/op 0.59
mainnet_e81889 - altair afterProcessEpoch 132.03 ms/op 147.01 ms/op 0.90
capella processEpoch - mainnet_e217614 1.2344 s/op 1.0850 s/op 1.14
mainnet_e217614 - capella beforeProcessEpoch 298.90 ms/op 258.17 ms/op 1.16
mainnet_e217614 - capella processJustificationAndFinalization 19.026 us/op 22.647 us/op 0.84
mainnet_e217614 - capella processInactivityUpdates 21.827 ms/op 22.212 ms/op 0.98
mainnet_e217614 - capella processRewardsAndPenalties 328.37 ms/op 309.06 ms/op 1.06
mainnet_e217614 - capella processRegistryUpdates 28.951 us/op 29.165 us/op 0.99
mainnet_e217614 - capella processSlashings 922.00 ns/op 853.00 ns/op 1.08
mainnet_e217614 - capella processEth1DataReset 708.00 ns/op 842.00 ns/op 0.84
mainnet_e217614 - capella processEffectiveBalanceUpdates 4.2684 ms/op 4.4380 ms/op 0.96
mainnet_e217614 - capella processSlashingsReset 2.9560 us/op 3.7950 us/op 0.78
mainnet_e217614 - capella processRandaoMixesReset 6.3310 us/op 5.4450 us/op 1.16
mainnet_e217614 - capella processHistoricalRootsUpdate 701.00 ns/op 1.1190 us/op 0.63
mainnet_e217614 - capella processParticipationFlagUpdates 3.4360 us/op 4.1070 us/op 0.84
mainnet_e217614 - capella afterProcessEpoch 309.20 ms/op 315.68 ms/op 0.98
phase0 processEpoch - mainnet_e58758 345.44 ms/op 373.48 ms/op 0.92
mainnet_e58758 - phase0 beforeProcessEpoch 116.22 ms/op 127.68 ms/op 0.91
mainnet_e58758 - phase0 processJustificationAndFinalization 16.619 us/op 22.479 us/op 0.74
mainnet_e58758 - phase0 processRewardsAndPenalties 61.289 ms/op 66.201 ms/op 0.93
mainnet_e58758 - phase0 processRegistryUpdates 11.998 us/op 16.593 us/op 0.72
mainnet_e58758 - phase0 processSlashings 618.00 ns/op 1.0220 us/op 0.60
mainnet_e58758 - phase0 processEth1DataReset 453.00 ns/op 736.00 ns/op 0.62
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.1181 ms/op 1.0523 ms/op 1.06
mainnet_e58758 - phase0 processSlashingsReset 3.0400 us/op 2.8150 us/op 1.08
mainnet_e58758 - phase0 processRandaoMixesReset 7.2560 us/op 6.2060 us/op 1.17
mainnet_e58758 - phase0 processHistoricalRootsUpdate 923.00 ns/op 725.00 ns/op 1.27
mainnet_e58758 - phase0 processParticipationRecordUpdates 5.1940 us/op 4.9610 us/op 1.05
mainnet_e58758 - phase0 afterProcessEpoch 105.70 ms/op 109.69 ms/op 0.96
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.3667 ms/op 1.9394 ms/op 0.70
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.4510 ms/op 1.6469 ms/op 0.88
altair processInactivityUpdates - 250000 normalcase 28.482 ms/op 27.090 ms/op 1.05
altair processInactivityUpdates - 250000 worstcase 29.348 ms/op 27.166 ms/op 1.08
phase0 processRegistryUpdates - 250000 normalcase 12.101 us/op 13.265 us/op 0.91
phase0 processRegistryUpdates - 250000 badcase_full_deposits 359.08 us/op 437.20 us/op 0.82
phase0 processRegistryUpdates - 250000 worstcase 0.5 147.87 ms/op 163.53 ms/op 0.90
altair processRewardsAndPenalties - 250000 normalcase 68.069 ms/op 80.201 ms/op 0.85
altair processRewardsAndPenalties - 250000 worstcase 67.735 ms/op 76.922 ms/op 0.88
phase0 getAttestationDeltas - 250000 normalcase 7.8574 ms/op 8.8738 ms/op 0.89
phase0 getAttestationDeltas - 250000 worstcase 7.9269 ms/op 8.8835 ms/op 0.89
phase0 processSlashings - 250000 worstcase 2.3566 ms/op 2.7487 ms/op 0.86
altair processSyncCommitteeUpdates - 250000 162.43 ms/op 162.58 ms/op 1.00
BeaconState.hashTreeRoot - No change 274.00 ns/op 274.00 ns/op 1.00
BeaconState.hashTreeRoot - 1 full validator 53.869 us/op 54.373 us/op 0.99
BeaconState.hashTreeRoot - 32 full validator 550.11 us/op 597.19 us/op 0.92
BeaconState.hashTreeRoot - 512 full validator 5.6179 ms/op 7.3596 ms/op 0.76
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 67.409 us/op 68.222 us/op 0.99
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 852.35 us/op 1.0210 ms/op 0.83
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 13.159 ms/op 12.632 ms/op 1.04
BeaconState.hashTreeRoot - 1 balances 51.012 us/op 54.062 us/op 0.94
BeaconState.hashTreeRoot - 32 balances 500.54 us/op 476.05 us/op 1.05
BeaconState.hashTreeRoot - 512 balances 4.6355 ms/op 4.9515 ms/op 0.94
BeaconState.hashTreeRoot - 250000 balances 76.725 ms/op 82.106 ms/op 0.93
aggregationBits - 2048 els - zipIndexesInBitList 16.561 us/op 19.836 us/op 0.83
regular array get 100000 times 45.342 us/op 50.003 us/op 0.91
wrappedArray get 100000 times 35.461 us/op 50.060 us/op 0.71
arrayWithProxy get 100000 times 15.663 ms/op 16.981 ms/op 0.92
ssz.Root.equals 238.00 ns/op 290.00 ns/op 0.82
byteArrayEquals 238.00 ns/op 259.00 ns/op 0.92
shuffle list - 16384 els 7.1422 ms/op 7.4583 ms/op 0.96
shuffle list - 250000 els 104.78 ms/op 108.71 ms/op 0.96
processSlot - 1 slots 9.0550 us/op 9.9440 us/op 0.91
processSlot - 32 slots 1.3745 ms/op 1.6178 ms/op 0.85
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 56.987 ms/op 61.142 ms/op 0.93
getCommitteeAssignments - req 1 vs - 250000 vc 2.5882 ms/op 2.7251 ms/op 0.95
getCommitteeAssignments - req 100 vs - 250000 vc 3.8452 ms/op 4.1442 ms/op 0.93
getCommitteeAssignments - req 1000 vs - 250000 vc 4.1790 ms/op 4.3632 ms/op 0.96
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 5.0200 ns/op 5.7700 ns/op 0.87
state getBlockRootAtSlot - 250000 vs - 7PWei 513.09 ns/op 726.49 ns/op 0.71
computeProposers - vc 250000 9.1169 ms/op 10.576 ms/op 0.86
computeEpochShuffling - vc 250000 106.00 ms/op 110.15 ms/op 0.96
getNextSyncCommittee - vc 250000 155.21 ms/op 179.91 ms/op 0.86
computeSigningRoot for AttestationData 13.363 us/op 15.436 us/op 0.87
hash AttestationData serialized data then Buffer.toString(base64) 2.3574 us/op 2.4913 us/op 0.95
toHexString serialized data 1.0653 us/op 1.4144 us/op 0.75
Buffer.toString(base64) 198.08 ns/op 270.10 ns/op 0.73

by benchmarkbot/action

@nflaig nflaig marked this pull request as ready for review August 14, 2023 16:30
@nflaig nflaig requested a review from a team as a code owner August 14, 2023 16:30
@nflaig nflaig added this to the v1.11.0 milestone Aug 16, 2023
Comment on lines +293 to +295
// Remove the username and password from the URL
url.username = "";
url.password = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

Would prefer to completely remove these fields.

Suggested change
// Remove the username and password from the URL
url.username = "";
url.password = "";
// Remove the username and password from the URL
delete url.username;
delete url.password;

Copy link
Member Author

Choose a reason for hiding this comment

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

TypeScript won't let me The operand of a 'delete' operator must be optional.

And I think this good because downstream code might assume this is a defined string as type is URL.username: string, likely wouldn't cause issues but I prefer to not mess with the type if I pass it to third party code.

If you create a URL object without credentials you also get empty strings

new URL("https://google.com")
URL {
  href: 'https://google.com/',
  origin: 'https://google.com',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'google.com',
  hostname: 'google.com',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

Comment on lines +289 to +292
if (url.username || url.password) {
if (headers["Authorization"] === undefined) {
headers["Authorization"] = `Basic ${toBase64(`${url.username}:${url.password}`)}`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Throw an error if the user sets the Authorization header attribute as well as the username/password as options.

Copy link
Member Author

@nflaig nflaig Aug 17, 2023

Choose a reason for hiding this comment

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

I was thinking about it but after looking at other http client implementations (e.g. native node http) I figured usually they just have a defined order of precedence, and we don't do that for bearer token either.

From node docs:

Sending an Authorization header will override using the auth option to compute basic authentication.

In our case it would be: explicit header > bearer header > basic auth header

As another side note, if we want to throw an error, this can not be implemented here as it would lazily throw the first time a request is done which is not ideal. We have to throw misconfiguration errors on startup. This is why I also added URL validation in the constructor of the http client, these runtime errors are bad, especially if you use fallback URLs which might not be queried for hours / days and when they do you notice that the URL is invalid.

@@ -279,6 +286,14 @@ export class HttpClient implements IHttpClient {
if (bearerToken && headers["Authorization"] === undefined) {
headers["Authorization"] = `Bearer ${bearerToken}`;
}
if (url.username || url.password) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a compound condition for both, we can't generate a valid Authorization header otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

As per RFC (https://datatracker.ietf.org/doc/html/rfc2617) those are optional and can be omitted (*, i.e. 0 or more).

     user-pass   = userid ":" password
      userid      = *<TEXT excluding ":">
      password    = *TEXT

In both cases fetch also throws an error as it does not allow credentials in the URL

fetch("http://user@localhost")
TypeError: Request cannot be constructed from a URL that includes credentials: http://user@localhost
fetch("http://:password@localhost")
> Uncaught:
TypeError: Request cannot be constructed from a URL that includes credentials: http://:password@localhost

@@ -269,7 +276,7 @@ export class HttpClient implements IHttpClient {
const timer = this.metrics?.requestTime.startTimer({routeId});

try {
const url = urlJoin(baseUrl, opts.url) + (opts.query ? "?" + stringifyQuery(opts.query) : "");
const url = new URL(urlJoin(baseUrl, opts.url) + (opts.query ? "?" + stringifyQuery(opts.query) : ""));
Copy link
Contributor

Choose a reason for hiding this comment

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

This function stringifyQuery uses a third-party library. See if we can replace it with the native node:querystring module.

Copy link
Member Author

@nflaig nflaig Aug 17, 2023

Choose a reason for hiding this comment

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

We can't as it does not support all formats required to be openapi compliant.

Specifically we want the "repeat" format like this topic=topic1&topic=topic2, although I think comma-separated should be supported by all clients as well

* - arrayFormat: repeat `topic=topic1&topic=topic2`
*/
export function stringifyQuery(query: unknown): string {

Copy link
Member Author

Choose a reason for hiding this comment

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

As another side note, we use the same library for parsing, last time I looked at this, there was no native alternative for it and qs was the best library I could find

qs.parse(str, {
// Array as comma-separated values must be supported to be OpenAPI spec compliant
comma: true,
// Drop support for array query strings like `id[0]=1&id[1]=2&id[2]=3` as those are not required to
// be OpenAPI spec compliant and results are inconsistent, see https://github.com/ljharb/qs/issues/331.
// The schema validation will catch this and throw an error as parsed query string results in an object.
parseArrays: false,
}),

@@ -279,6 +286,14 @@ export class HttpClient implements IHttpClient {
if (bearerToken && headers["Authorization"] === undefined) {
headers["Authorization"] = `Bearer ${bearerToken}`;
}
if (url.username || url.password) {
if (headers["Authorization"] === undefined) {
headers["Authorization"] = `Basic ${toBase64(`${url.username}:${url.password}`)}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we can move this logic to a utility function generateAuthHeader(username, password), that will be easy to manage in future.

Copy link
Member Author

@nflaig nflaig Aug 17, 2023

Choose a reason for hiding this comment

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

Was considering that as well but opted against it because

  • not reused anywhere else
  • simple enough
  • format of auth header as defined in RFC will never change

Same argument could be made for setting bearer token above but I think the code is clearer as is.

@wemeetagain wemeetagain dismissed nazarhussain’s stale review August 21, 2023 13:52

all review comments have been addressed

@wemeetagain wemeetagain merged commit ae0bf4f into unstable Aug 21, 2023
@wemeetagain wemeetagain deleted the nflaig/set-basic-auth-header branch August 21, 2023 13:53
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.

Basic Auth userdata no longer working in validator client as of v1.10.0
3 participants