|
| 1 | +package network |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "math" |
| 6 | +) |
| 7 | + |
| 8 | +// ethereumStorageProfile is the single source of truth for Ethereum local |
| 9 | +// node storage sizing. The profile is intentionally conservative because |
| 10 | +// local-path storage does not reserve bytes up front, but sized storage |
| 11 | +// classes do enforce these requests. |
| 12 | +type ethereumStorageProfile struct { |
| 13 | + ExecutionSize string |
| 14 | + ConsensusSize string |
| 15 | + DiskRequirementGB uint64 |
| 16 | + Label string |
| 17 | +} |
| 18 | + |
| 19 | +func resolveEthereumStorageProfile(network, mode, executionClient string, scope ArchiveScope) ethereumStorageProfile { |
| 20 | + if mode != "archive" { |
| 21 | + if network == "mainnet" { |
| 22 | + return ethereumStorageProfile{ |
| 23 | + ExecutionSize: "500Gi", |
| 24 | + ConsensusSize: "200Gi", |
| 25 | + DiskRequirementGB: 700, |
| 26 | + Label: "full mainnet", |
| 27 | + } |
| 28 | + } |
| 29 | + return ethereumStorageProfile{ |
| 30 | + ExecutionSize: "100Gi", |
| 31 | + ConsensusSize: "50Gi", |
| 32 | + DiskRequirementGB: 150, |
| 33 | + Label: "full testnet", |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + if network != "mainnet" { |
| 38 | + return ethereumStorageProfile{ |
| 39 | + ExecutionSize: "300Gi", |
| 40 | + ConsensusSize: "100Gi", |
| 41 | + DiskRequirementGB: 400, |
| 42 | + Label: "archive testnet", |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + if !partialArchiveClients[executionClient] || scope.Kind == "" || scope.Kind == "all" { |
| 47 | + return ethereumStorageProfile{ |
| 48 | + ExecutionSize: "4500Gi", |
| 49 | + ConsensusSize: "500Gi", |
| 50 | + DiskRequirementGB: 5000, |
| 51 | + Label: "archive mainnet from genesis", |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + switch scope.Kind { |
| 56 | + case "before": |
| 57 | + if hf := hardforkProfileForBlock(scope.Block); hf != nil { |
| 58 | + execGi := roundUpGiB(uint64(math.Ceil(hf.ApproxArchiveSizeTB * 1024 * 1.2))) |
| 59 | + return ethereumStorageProfile{ |
| 60 | + ExecutionSize: formatGi(execGi), |
| 61 | + ConsensusSize: "500Gi", |
| 62 | + DiskRequirementGB: execGi + 700, |
| 63 | + Label: "partial archive mainnet " + hf.Name, |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + // A raw block before the oldest known partial-archive preset could |
| 68 | + // retain almost all history, so size it as a full archive. |
| 69 | + return ethereumStorageProfile{ |
| 70 | + ExecutionSize: "4500Gi", |
| 71 | + ConsensusSize: "500Gi", |
| 72 | + DiskRequirementGB: 5000, |
| 73 | + Label: "custom archive mainnet block", |
| 74 | + } |
| 75 | + case "distance": |
| 76 | + execGi := executionGiForDistance(scope.Distance) |
| 77 | + return ethereumStorageProfile{ |
| 78 | + ExecutionSize: formatGi(execGi), |
| 79 | + ConsensusSize: "500Gi", |
| 80 | + DiskRequirementGB: diskRequirementForMainnetArchive(execGi), |
| 81 | + Label: "partial archive mainnet distance", |
| 82 | + } |
| 83 | + default: |
| 84 | + return ethereumStorageProfile{ |
| 85 | + ExecutionSize: "4500Gi", |
| 86 | + ConsensusSize: "500Gi", |
| 87 | + DiskRequirementGB: 5000, |
| 88 | + Label: "archive mainnet", |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +func hardforkProfileForBlock(block uint64) *Hardfork { |
| 94 | + var matched *Hardfork |
| 95 | + for i := range MainnetHardforks { |
| 96 | + if MainnetHardforks[i].Block <= block { |
| 97 | + matched = &MainnetHardforks[i] |
| 98 | + continue |
| 99 | + } |
| 100 | + break |
| 101 | + } |
| 102 | + return matched |
| 103 | +} |
| 104 | + |
| 105 | +func diskRequirementForMainnetArchive(execGi uint64) uint64 { |
| 106 | + if execGi >= 4500 { |
| 107 | + return 5000 |
| 108 | + } |
| 109 | + return execGi + 700 |
| 110 | +} |
| 111 | + |
| 112 | +func executionGiForDistance(distance uint64) uint64 { |
| 113 | + days := float64(distance*12) / float64(24*60*60) |
| 114 | + execGi := uint64(math.Ceil(500 + days*0.82)) |
| 115 | + if execGi < 500 { |
| 116 | + execGi = 500 |
| 117 | + } |
| 118 | + if execGi > 4500 { |
| 119 | + execGi = 4500 |
| 120 | + } |
| 121 | + return roundUpGiB(execGi) |
| 122 | +} |
| 123 | + |
| 124 | +func roundUpGiB(gib uint64) uint64 { |
| 125 | + const step = 100 |
| 126 | + if gib%step == 0 { |
| 127 | + return gib |
| 128 | + } |
| 129 | + return ((gib / step) + 1) * step |
| 130 | +} |
| 131 | + |
| 132 | +func formatGi(gib uint64) string { |
| 133 | + return fmt.Sprintf("%dGi", gib) |
| 134 | +} |
0 commit comments