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: switch to native fetch implementation #5811

Merged
merged 13 commits into from
Jul 31, 2023
Merged

Conversation

nflaig
Copy link
Member

@nflaig nflaig commented Jul 27, 2023

Motivation

With recent issues we faced using cross-fetch (#5765 and Failed to execute 'fetch' on 'Window': Illegal invocation) I would suggest we get rid of it and use native fetch instead as technically there is no reason not to do it.

We already dropped support for node versions below 18.15.0 and native fetch is available on later versions and has to be explicitly be disabled by setting --no-experimental-fetch flag.

Native fetch in node is still Stability: 1 but based on the requirement for it to be compatible with the browser implementation I don't expect there will be breaking changes in the future.

Advantages

  • more consistent behavior node vs. browser
  • less likely to have regressions when updating node
  • better maintenance, cross-fetch is still on node-fetch v2 (http://lquixada/cross-fetch#146)

Disadvantages

Errors are not that great as details are inside cause property which itself is of type Error. The errors thrown by node-fetch are much better for us as they have their own error handling which is different from native fetch in browser.

The error message is not detailed at all, it just says fetch failed, no context at all unless you look into cause

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11576:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///home/nico/projects/test/fetch-test/addr-not-found.js:2:3 {
  cause: Error: getaddrinfo ENOTFOUND non-existant-domain.com
      at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'non-existant-domain.com'
  }
}

Description

Removes cross-fetch and uses native fetch implementation instead. Inconsistent errors and intransparent messages are addressed by wrapping the native fetch implementation and throwing a custom FetchError, similar to node-fetch error handling.

Details about error handling can be found here

export class FetchError extends Error {

Compatibility

See Fetch_API#browser_compatibility for more details.

image

Closes #5765

@nflaig nflaig requested a review from a team as a code owner July 27, 2023 15:57
@github-actions
Copy link
Contributor

github-actions bot commented Jul 27, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: e87c20c Previous: 19b723c Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 664.37 us/op 772.23 us/op 0.86
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 73.916 us/op 75.456 us/op 0.98
BLS verify - blst-native 1.2368 ms/op 1.2092 ms/op 1.02
BLS verifyMultipleSignatures 3 - blst-native 2.5673 ms/op 2.4736 ms/op 1.04
BLS verifyMultipleSignatures 8 - blst-native 5.4522 ms/op 5.3734 ms/op 1.01
BLS verifyMultipleSignatures 32 - blst-native 19.514 ms/op 19.118 ms/op 1.02
BLS aggregatePubkeys 32 - blst-native 25.790 us/op 25.582 us/op 1.01
BLS aggregatePubkeys 128 - blst-native 101.05 us/op 99.168 us/op 1.02
getAttestationsForBlock 58.824 ms/op 50.251 ms/op 1.17
isKnown best case - 1 super set check 295.00 ns/op 271.00 ns/op 1.09
isKnown normal case - 2 super set checks 293.00 ns/op 263.00 ns/op 1.11
isKnown worse case - 16 super set checks 291.00 ns/op 284.00 ns/op 1.02
CheckpointStateCache - add get delete 4.6470 us/op 4.7000 us/op 0.99
validate api signedAggregateAndProof - struct 2.7305 ms/op 2.7113 ms/op 1.01
validate gossip signedAggregateAndProof - struct 2.7333 ms/op 2.7131 ms/op 1.01
validate api attestation - struct 1.3768 ms/op 1.2954 ms/op 1.06
validate gossip attestation - struct 1.3178 ms/op 1.3149 ms/op 1.00
pickEth1Vote - no votes 1.0825 ms/op 1.1595 ms/op 0.93
pickEth1Vote - max votes 10.570 ms/op 10.659 ms/op 0.99
pickEth1Vote - Eth1Data hashTreeRoot value x2048 8.0747 ms/op 8.5414 ms/op 0.95
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 18.073 ms/op 14.207 ms/op 1.27
pickEth1Vote - Eth1Data fastSerialize value x2048 566.23 us/op 562.29 us/op 1.01
pickEth1Vote - Eth1Data fastSerialize tree x2048 8.4752 ms/op 6.5854 ms/op 1.29
bytes32 toHexString 476.00 ns/op 486.00 ns/op 0.98
bytes32 Buffer.toString(hex) 290.00 ns/op 294.00 ns/op 0.99
bytes32 Buffer.toString(hex) from Uint8Array 414.00 ns/op 430.00 ns/op 0.96
bytes32 Buffer.toString(hex) + 0x 292.00 ns/op 298.00 ns/op 0.98
Object access 1 prop 0.15400 ns/op 0.15700 ns/op 0.98
Map access 1 prop 0.15600 ns/op 0.14300 ns/op 1.09
Object get x1000 7.4090 ns/op 7.7880 ns/op 0.95
Map get x1000 0.62700 ns/op 0.51400 ns/op 1.22
Object set x1000 47.945 ns/op 48.961 ns/op 0.98
Map set x1000 38.053 ns/op 38.750 ns/op 0.98
Return object 10000 times 0.23290 ns/op 0.23430 ns/op 0.99
Throw Error 10000 times 3.7976 us/op 3.8302 us/op 0.99
fastMsgIdFn sha256 / 200 bytes 3.2430 us/op 3.3130 us/op 0.98
fastMsgIdFn h32 xxhash / 200 bytes 269.00 ns/op 285.00 ns/op 0.94
fastMsgIdFn h64 xxhash / 200 bytes 329.00 ns/op 339.00 ns/op 0.97
fastMsgIdFn sha256 / 1000 bytes 11.068 us/op 11.251 us/op 0.98
fastMsgIdFn h32 xxhash / 1000 bytes 384.00 ns/op 414.00 ns/op 0.93
fastMsgIdFn h64 xxhash / 1000 bytes 398.00 ns/op 413.00 ns/op 0.96
fastMsgIdFn sha256 / 10000 bytes 100.81 us/op 103.33 us/op 0.98
fastMsgIdFn h32 xxhash / 10000 bytes 1.8140 us/op 1.9110 us/op 0.95
fastMsgIdFn h64 xxhash / 10000 bytes 1.2380 us/op 1.2980 us/op 0.95
enrSubnets - fastDeserialize 64 bits 1.1710 us/op 1.2210 us/op 0.96
enrSubnets - ssz BitVector 64 bits 402.00 ns/op 417.00 ns/op 0.96
enrSubnets - fastDeserialize 4 bits 160.00 ns/op 169.00 ns/op 0.95
enrSubnets - ssz BitVector 4 bits 402.00 ns/op 419.00 ns/op 0.96
prioritizePeers score -10:0 att 32-0.1 sync 2-0 99.803 us/op 96.667 us/op 1.03
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 126.66 us/op 132.24 us/op 0.96
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 152.61 us/op 165.05 us/op 0.92
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 269.57 us/op 288.00 us/op 0.94
prioritizePeers score 0:0 att 64-1 sync 4-1 327.91 us/op 335.54 us/op 0.98
array of 16000 items push then shift 1.5165 us/op 1.5907 us/op 0.95
LinkedList of 16000 items push then shift 8.6280 ns/op 8.9420 ns/op 0.96
array of 16000 items push then pop 67.115 ns/op 50.794 ns/op 1.32
LinkedList of 16000 items push then pop 8.5430 ns/op 8.4350 ns/op 1.01
array of 24000 items push then shift 2.3867 us/op 2.3434 us/op 1.02
LinkedList of 24000 items push then shift 8.7280 ns/op 8.5630 ns/op 1.02
array of 24000 items push then pop 99.074 ns/op 68.658 ns/op 1.44
LinkedList of 24000 items push then pop 8.3110 ns/op 8.5060 ns/op 0.98
intersect bitArray bitLen 8 6.5270 ns/op 6.7400 ns/op 0.97
intersect array and set length 8 52.638 ns/op 57.759 ns/op 0.91
intersect bitArray bitLen 128 30.841 ns/op 31.584 ns/op 0.98
intersect array and set length 128 722.00 ns/op 784.92 ns/op 0.92
bitArray.getTrueBitIndexes() bitLen 128 1.4150 us/op 1.4950 us/op 0.95
bitArray.getTrueBitIndexes() bitLen 248 2.4410 us/op 2.5520 us/op 0.96
bitArray.getTrueBitIndexes() bitLen 512 4.6430 us/op 4.8640 us/op 0.95
Buffer.concat 32 items 924.00 ns/op 1.0250 us/op 0.90
Uint8Array.set 32 items 2.2440 us/op 1.8930 us/op 1.19
transfer serialized Status (84 B) 1.9100 us/op 1.8460 us/op 1.03
copy serialized Status (84 B) 1.4490 us/op 1.5110 us/op 0.96
transfer serialized SignedVoluntaryExit (112 B) 1.8390 us/op 1.9650 us/op 0.94
copy serialized SignedVoluntaryExit (112 B) 1.5200 us/op 1.5820 us/op 0.96
transfer serialized ProposerSlashing (416 B) 2.8740 us/op 2.3650 us/op 1.22
copy serialized ProposerSlashing (416 B) 3.1020 us/op 2.2130 us/op 1.40
transfer serialized Attestation (485 B) 2.9920 us/op 2.3860 us/op 1.25
copy serialized Attestation (485 B) 3.0990 us/op 2.1920 us/op 1.41
transfer serialized AttesterSlashing (33232 B) 2.7770 us/op 2.5160 us/op 1.10
copy serialized AttesterSlashing (33232 B) 4.8910 us/op 4.6540 us/op 1.05
transfer serialized Small SignedBeaconBlock (128000 B) 2.8290 us/op 2.5950 us/op 1.09
copy serialized Small SignedBeaconBlock (128000 B) 11.509 us/op 11.326 us/op 1.02
transfer serialized Avg SignedBeaconBlock (200000 B) 2.8190 us/op 2.8410 us/op 0.99
copy serialized Avg SignedBeaconBlock (200000 B) 16.731 us/op 16.421 us/op 1.02
transfer serialized BlobsSidecar (524380 B) 2.7350 us/op 2.6100 us/op 1.05
copy serialized BlobsSidecar (524380 B) 189.40 us/op 112.55 us/op 1.68
transfer serialized Big SignedBeaconBlock (1000000 B) 2.7580 us/op 2.6740 us/op 1.03
copy serialized Big SignedBeaconBlock (1000000 B) 158.04 us/op 143.95 us/op 1.10
pass gossip attestations to forkchoice per slot 2.1264 ms/op 2.0369 ms/op 1.04
forkChoice updateHead vc 100000 bc 64 eq 0 2.2105 ms/op 2.0181 ms/op 1.10
forkChoice updateHead vc 600000 bc 64 eq 0 10.928 ms/op 13.460 ms/op 0.81
forkChoice updateHead vc 1000000 bc 64 eq 0 18.403 ms/op 21.844 ms/op 0.84
forkChoice updateHead vc 600000 bc 320 eq 0 15.909 ms/op 17.198 ms/op 0.93
forkChoice updateHead vc 600000 bc 1200 eq 0 81.093 ms/op 80.755 ms/op 1.00
forkChoice updateHead vc 600000 bc 64 eq 1000 18.647 ms/op 22.175 ms/op 0.84
forkChoice updateHead vc 600000 bc 64 eq 10000 20.596 ms/op 24.339 ms/op 0.85
forkChoice updateHead vc 600000 bc 64 eq 300000 27.197 ms/op 29.180 ms/op 0.93
computeDeltas 2.9436 ms/op 2.9503 ms/op 1.00
computeProposerBoostScoreFromBalances 375.89 us/op 384.86 us/op 0.98
altair processAttestation - 250000 vs - 7PWei normalcase 2.1055 ms/op 2.0761 ms/op 1.01
altair processAttestation - 250000 vs - 7PWei worstcase 3.1894 ms/op 3.1726 ms/op 1.01
altair processAttestation - setStatus - 1/6 committees join 228.66 us/op 238.06 us/op 0.96
altair processAttestation - setStatus - 1/3 committees join 444.59 us/op 416.74 us/op 1.07
altair processAttestation - setStatus - 1/2 committees join 582.76 us/op 593.36 us/op 0.98
altair processAttestation - setStatus - 2/3 committees join 666.74 us/op 754.87 us/op 0.88
altair processAttestation - setStatus - 4/5 committees join 1.0137 ms/op 991.22 us/op 1.02
altair processAttestation - setStatus - 100% committees join 1.2455 ms/op 1.1930 ms/op 1.04
altair processBlock - 250000 vs - 7PWei normalcase 9.6178 ms/op 9.2007 ms/op 1.05
altair processBlock - 250000 vs - 7PWei normalcase hashState 16.133 ms/op 16.968 ms/op 0.95
altair processBlock - 250000 vs - 7PWei worstcase 40.552 ms/op 36.412 ms/op 1.11
altair processBlock - 250000 vs - 7PWei worstcase hashState 59.389 ms/op 57.850 ms/op 1.03
phase0 processBlock - 250000 vs - 7PWei normalcase 1.9440 ms/op 1.9233 ms/op 1.01
phase0 processBlock - 250000 vs - 7PWei worstcase 27.611 ms/op 27.850 ms/op 0.99
altair processEth1Data - 250000 vs - 7PWei normalcase 466.19 us/op 487.17 us/op 0.96
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 17.430 us/op 9.1750 us/op 1.90
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 88.207 us/op 49.336 us/op 1.79
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 16.433 us/op 15.560 us/op 1.06
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 17.842 us/op 7.1280 us/op 2.50
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 194.80 us/op 126.64 us/op 1.54
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.1178 ms/op 1.0489 ms/op 1.07
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 2.8370 ms/op 1.4673 ms/op 1.93
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.5941 ms/op 1.4084 ms/op 1.13
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 3.2566 ms/op 2.8806 ms/op 1.13
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 2.5424 ms/op 2.3301 ms/op 1.09
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 5.3207 ms/op 4.9232 ms/op 1.08
Tree 40 250000 create 326.44 ms/op 291.91 ms/op 1.12
Tree 40 250000 get(125000) 188.90 ns/op 192.20 ns/op 0.98
Tree 40 250000 set(125000) 900.27 ns/op 840.51 ns/op 1.07
Tree 40 250000 toArray() 16.802 ms/op 17.658 ms/op 0.95
Tree 40 250000 iterate all - toArray() + loop 17.077 ms/op 18.109 ms/op 0.94
Tree 40 250000 iterate all - get(i) 67.803 ms/op 65.648 ms/op 1.03
MutableVector 250000 create 16.600 ms/op 11.733 ms/op 1.41
MutableVector 250000 get(125000) 6.3390 ns/op 6.4960 ns/op 0.98
MutableVector 250000 set(125000) 230.17 ns/op 252.85 ns/op 0.91
MutableVector 250000 toArray() 3.8048 ms/op 2.7413 ms/op 1.39
MutableVector 250000 iterate all - toArray() + loop 3.4650 ms/op 2.9264 ms/op 1.18
MutableVector 250000 iterate all - get(i) 1.5345 ms/op 1.5347 ms/op 1.00
Array 250000 create 2.9212 ms/op 2.5461 ms/op 1.15
Array 250000 clone - spread 968.87 us/op 1.1248 ms/op 0.86
Array 250000 get(125000) 0.51800 ns/op 0.55600 ns/op 0.93
Array 250000 set(125000) 0.58900 ns/op 0.62900 ns/op 0.94
Array 250000 iterate all - loop 81.718 us/op 79.735 us/op 1.02
effectiveBalanceIncrements clone Uint8Array 300000 21.583 us/op 25.705 us/op 0.84
effectiveBalanceIncrements clone MutableVector 300000 284.00 ns/op 335.00 ns/op 0.85
effectiveBalanceIncrements rw all Uint8Array 300000 177.42 us/op 173.48 us/op 1.02
effectiveBalanceIncrements rw all MutableVector 300000 75.818 ms/op 78.684 ms/op 0.96
phase0 afterProcessEpoch - 250000 vs - 7PWei 111.75 ms/op 112.18 ms/op 1.00
phase0 beforeProcessEpoch - 250000 vs - 7PWei 43.489 ms/op 30.511 ms/op 1.43
altair processEpoch - mainnet_e81889 350.49 ms/op 315.03 ms/op 1.11
mainnet_e81889 - altair beforeProcessEpoch 60.158 ms/op 58.395 ms/op 1.03
mainnet_e81889 - altair processJustificationAndFinalization 23.421 us/op 13.324 us/op 1.76
mainnet_e81889 - altair processInactivityUpdates 5.8925 ms/op 5.3442 ms/op 1.10
mainnet_e81889 - altair processRewardsAndPenalties 89.584 ms/op 62.663 ms/op 1.43
mainnet_e81889 - altair processRegistryUpdates 3.1690 us/op 2.3690 us/op 1.34
mainnet_e81889 - altair processSlashings 695.00 ns/op 400.00 ns/op 1.74
mainnet_e81889 - altair processEth1DataReset 919.00 ns/op 507.00 ns/op 1.81
mainnet_e81889 - altair processEffectiveBalanceUpdates 2.3865 ms/op 1.2134 ms/op 1.97
mainnet_e81889 - altair processSlashingsReset 4.1950 us/op 2.7880 us/op 1.50
mainnet_e81889 - altair processRandaoMixesReset 6.1550 us/op 4.9070 us/op 1.25
mainnet_e81889 - altair processHistoricalRootsUpdate 1.1670 us/op 852.00 ns/op 1.37
mainnet_e81889 - altair processParticipationFlagUpdates 2.3310 us/op 1.9910 us/op 1.17
mainnet_e81889 - altair processSyncCommitteeUpdates 999.00 ns/op 543.00 ns/op 1.84
mainnet_e81889 - altair afterProcessEpoch 125.90 ms/op 124.65 ms/op 1.01
capella processEpoch - mainnet_e217614 1.0840 s/op 1.0235 s/op 1.06
mainnet_e217614 - capella beforeProcessEpoch 237.36 ms/op 218.86 ms/op 1.08
mainnet_e217614 - capella processJustificationAndFinalization 12.320 us/op 14.202 us/op 0.87
mainnet_e217614 - capella processInactivityUpdates 18.798 ms/op 19.071 ms/op 0.99
mainnet_e217614 - capella processRewardsAndPenalties 340.27 ms/op 282.90 ms/op 1.20
mainnet_e217614 - capella processRegistryUpdates 25.214 us/op 16.740 us/op 1.51
mainnet_e217614 - capella processSlashings 782.00 ns/op 475.00 ns/op 1.65
mainnet_e217614 - capella processEth1DataReset 634.00 ns/op 452.00 ns/op 1.40
mainnet_e217614 - capella processEffectiveBalanceUpdates 3.9502 ms/op 3.9466 ms/op 1.00
mainnet_e217614 - capella processSlashingsReset 2.1390 us/op 2.1860 us/op 0.98
mainnet_e217614 - capella processRandaoMixesReset 4.4040 us/op 3.6940 us/op 1.19
mainnet_e217614 - capella processHistoricalRootsUpdate 745.00 ns/op 546.00 ns/op 1.36
mainnet_e217614 - capella processParticipationFlagUpdates 4.5040 us/op 1.6230 us/op 2.78
mainnet_e217614 - capella afterProcessEpoch 280.61 ms/op 294.70 ms/op 0.95
phase0 processEpoch - mainnet_e58758 386.46 ms/op 320.02 ms/op 1.21
mainnet_e58758 - phase0 beforeProcessEpoch 148.73 ms/op 114.76 ms/op 1.30
mainnet_e58758 - phase0 processJustificationAndFinalization 22.494 us/op 14.577 us/op 1.54
mainnet_e58758 - phase0 processRewardsAndPenalties 69.615 ms/op 53.374 ms/op 1.30
mainnet_e58758 - phase0 processRegistryUpdates 13.297 us/op 9.4150 us/op 1.41
mainnet_e58758 - phase0 processSlashings 695.00 ns/op 504.00 ns/op 1.38
mainnet_e58758 - phase0 processEth1DataReset 626.00 ns/op 424.00 ns/op 1.48
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.9567 ms/op 940.48 us/op 2.08
mainnet_e58758 - phase0 processSlashingsReset 2.8940 us/op 2.0910 us/op 1.38
mainnet_e58758 - phase0 processRandaoMixesReset 5.4810 us/op 3.7730 us/op 1.45
mainnet_e58758 - phase0 processHistoricalRootsUpdate 638.00 ns/op 587.00 ns/op 1.09
mainnet_e58758 - phase0 processParticipationRecordUpdates 5.5460 us/op 3.3140 us/op 1.67
mainnet_e58758 - phase0 afterProcessEpoch 93.512 ms/op 100.72 ms/op 0.93
phase0 processEffectiveBalanceUpdates - 250000 normalcase 2.3376 ms/op 1.1883 ms/op 1.97
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.3740 ms/op 1.4424 ms/op 0.95
altair processInactivityUpdates - 250000 normalcase 29.501 ms/op 18.413 ms/op 1.60
altair processInactivityUpdates - 250000 worstcase 27.205 ms/op 20.601 ms/op 1.32
phase0 processRegistryUpdates - 250000 normalcase 14.421 us/op 8.6520 us/op 1.67
phase0 processRegistryUpdates - 250000 badcase_full_deposits 651.30 us/op 307.09 us/op 2.12
phase0 processRegistryUpdates - 250000 worstcase 0.5 137.51 ms/op 123.62 ms/op 1.11
altair processRewardsAndPenalties - 250000 normalcase 81.961 ms/op 57.403 ms/op 1.43
altair processRewardsAndPenalties - 250000 worstcase 83.455 ms/op 56.468 ms/op 1.48
phase0 getAttestationDeltas - 250000 normalcase 7.4798 ms/op 7.5840 ms/op 0.99
phase0 getAttestationDeltas - 250000 worstcase 7.7118 ms/op 7.6661 ms/op 1.01
phase0 processSlashings - 250000 worstcase 2.5222 ms/op 2.1955 ms/op 1.15
altair processSyncCommitteeUpdates - 250000 145.63 ms/op 139.13 ms/op 1.05
BeaconState.hashTreeRoot - No change 285.00 ns/op 278.00 ns/op 1.03
BeaconState.hashTreeRoot - 1 full validator 49.135 us/op 47.548 us/op 1.03
BeaconState.hashTreeRoot - 32 full validator 484.07 us/op 462.29 us/op 1.05
BeaconState.hashTreeRoot - 512 full validator 5.0285 ms/op 4.8522 ms/op 1.04
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 65.445 us/op 57.723 us/op 1.13
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 825.43 us/op 790.89 us/op 1.04
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 10.162 ms/op 9.7362 ms/op 1.04
BeaconState.hashTreeRoot - 1 balances 46.465 us/op 44.944 us/op 1.03
BeaconState.hashTreeRoot - 32 balances 417.41 us/op 400.38 us/op 1.04
BeaconState.hashTreeRoot - 512 balances 3.7992 ms/op 3.6808 ms/op 1.03
BeaconState.hashTreeRoot - 250000 balances 82.969 ms/op 73.866 ms/op 1.12
aggregationBits - 2048 els - zipIndexesInBitList 15.046 us/op 14.156 us/op 1.06
regular array get 100000 times 31.560 us/op 31.925 us/op 0.99
wrappedArray get 100000 times 31.562 us/op 42.530 us/op 0.74
arrayWithProxy get 100000 times 14.307 ms/op 13.905 ms/op 1.03
ssz.Root.equals 206.00 ns/op 202.00 ns/op 1.02
byteArrayEquals 204.00 ns/op 197.00 ns/op 1.04
shuffle list - 16384 els 6.6320 ms/op 6.7637 ms/op 0.98
shuffle list - 250000 els 98.979 ms/op 99.316 ms/op 1.00
processSlot - 1 slots 7.9140 us/op 7.4210 us/op 1.07
processSlot - 32 slots 1.2812 ms/op 1.2950 ms/op 0.99
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 60.452 ms/op 53.001 ms/op 1.14
getCommitteeAssignments - req 1 vs - 250000 vc 2.5554 ms/op 2.5032 ms/op 1.02
getCommitteeAssignments - req 100 vs - 250000 vc 3.7337 ms/op 3.6998 ms/op 1.01
getCommitteeAssignments - req 1000 vs - 250000 vc 4.0612 ms/op 4.0178 ms/op 1.01
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.7000 ns/op 4.4500 ns/op 1.06
state getBlockRootAtSlot - 250000 vs - 7PWei 919.40 ns/op 703.29 ns/op 1.31
computeProposers - vc 250000 8.7316 ms/op 8.4577 ms/op 1.03
computeEpochShuffling - vc 250000 100.42 ms/op 101.50 ms/op 0.99
getNextSyncCommittee - vc 250000 149.11 ms/op 140.68 ms/op 1.06
computeSigningRoot for AttestationData 13.077 us/op 12.793 us/op 1.02
hash AttestationData serialized data then Buffer.toString(base64) 2.2473 us/op 2.3185 us/op 0.97
toHexString serialized data 1.0317 us/op 1.0698 us/op 0.96
Buffer.toString(base64) 217.61 ns/op 215.96 ns/op 1.01

by benchmarkbot/action

@nflaig nflaig marked this pull request as draft July 27, 2023 16:30
@ChainSafe ChainSafe deleted a comment from codecov bot Jul 28, 2023
@ChainSafe ChainSafe deleted a comment from codecov bot Jul 28, 2023
@ChainSafe ChainSafe deleted a comment from codecov bot Jul 28, 2023
@ChainSafe ChainSafe deleted a comment from codecov bot Jul 28, 2023
@ChainSafe ChainSafe deleted a comment from codecov bot Jul 28, 2023
@ChainSafe ChainSafe deleted a comment from codecov bot Jul 28, 2023
@ChainSafe ChainSafe deleted a comment from codecov bot Jul 28, 2023
@nflaig nflaig marked this pull request as ready for review July 28, 2023 19:29
Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

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

Looks good!

@nflaig
Copy link
Member Author

nflaig commented Jul 31, 2023

Just mentioned in EL offline PR (#5797), we might wanna cover all error codes used here

export const HTTP_FATAL_ERROR_CODES = ["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN"];
export const HTTP_CONNECTION_ERROR_CODES = ["ECONNRESET", "ECONNABORTED"];

I can try find out when those are thrown and add them in this PR

@nflaig
Copy link
Member Author

nflaig commented Jul 31, 2023

After looking at further error scenarios outlined here (https://betterstack.com/community/guides/scaling-nodejs/nodejs-errors/) and in Node.js docs (https://nodejs.org/api/errors.html) I think the test coverage is sufficient. The underlying http client implementation is still the same, fetch is just a higher level abstraction.

These errors are hard to test for locally / in tests:

  • EAI_AGAIN: This happens due to a DNS lookup timeout error (https://stackoverflow.com/a/40182520/10577550), this is non-deterministic and will produce false positives
  • ECONNRESET: It's a low-level, non-deterministic network error that's dependent on underlying TCP conditions. Can be reproduced by modifying client behavior but that's not that helpful in my opinion, this is the issue we faced here #5765 due to client reusing a closed socket.
  • ECONNABORTED: Approach outlined here #7-econnaborted is not reproducible locally, I am guessing due to local / loopback connection.

It might be good to add UND_ERR_SOCKET to HTTP_FATAL_ERROR_CODES as this happens when server shuts down abruptly while there is a pending request but could cause false positives as this can happen due to other network issues as well.

export const HTTP_FATAL_ERROR_CODES = ["ECONNREFUSED", "ENOTFOUND", "EAI_AGAIN"];

@nflaig nflaig merged commit 3e65be7 into unstable Jul 31, 2023
13 checks passed
@nflaig nflaig deleted the nflaig/native-fetch branch July 31, 2023 15:32
@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.

Consecutive HTTP requests cause socket hang up on node v20
2 participants