github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/docker/test_env/genesis_generator_helpers.go (about) 1 package test_env 2 3 import ( 4 "bytes" 5 "context" 6 "html/template" 7 "time" 8 9 tcwait "github.com/testcontainers/testcontainers-go/wait" 10 ) 11 12 func generateEnvValues(config *EthereumChainConfig) (string, error) { 13 // GenesisTimestamp needs to be exported in order to be used in the template 14 // but I don't want to expose it in config struct, user should not set it manually 15 data := struct { 16 EthereumChainConfig 17 GenesisTimestamp int 18 }{ 19 EthereumChainConfig: *config, 20 GenesisTimestamp: config.genesisTimestamp, 21 } 22 tmpl, err := template.New("valuesEnv").Funcs(funcMap).Parse(valuesEnv) 23 if err != nil { 24 return "", err 25 } 26 var buf bytes.Buffer 27 err = tmpl.Execute(&buf, data) 28 if err != nil { 29 return "", err 30 } 31 return buf.String(), nil 32 } 33 34 var funcMap = template.FuncMap{ 35 "decrement": func(i int) int { 36 return i - 1 37 }, 38 } 39 40 var valuesEnv = ` 41 export CHAIN_ID="{{.ChainID}}" 42 export DEPOSIT_CONTRACT_ADDRESS="0x4242424242424242424242424242424242424242" 43 export EL_AND_CL_MNEMONIC="giant issue aisle success illegal bike spike question tent bar rely arctic volcano long crawl hungry vocal artwork sniff fantasy very lucky have athlete" 44 export CL_EXEC_BLOCK="0" 45 export SLOT_DURATION_IN_SECONDS={{.SecondsPerSlot}} 46 export DEPOSIT_CONTRACT_BLOCK="0x0000000000000000000000000000000000000000000000000000000000000000" 47 export NUMBER_OF_VALIDATORS={{.ValidatorCount}} 48 export GENESIS_FORK_VERSION="0x10000038" 49 export ALTAIR_FORK_VERSION="0x20000038" 50 export BELLATRIX_FORK_VERSION="0x30000038" 51 export CAPELLA_FORK_VERSION="0x40000038" 52 export CAPELLA_FORK_EPOCH="0" 53 export DENEB_FORK_VERSION="0x50000038" 54 export DENEB_FORK_EPOCH="500" 55 export ELECTRA_FORK_VERSION="0x60000038" 56 export ELECTRA_FORK_EPOCH="" 57 export WITHDRAWAL_TYPE="0x00" 58 export WITHDRAWAL_ADDRESS=0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134 59 export BEACON_STATIC_ENR="enr:-Iq4QJk4WqRkjsX5c2CXtOra6HnxN-BMXnWhmhEQO9Bn9iABTJGdjUOurM7Btj1ouKaFkvTRoju5vz2GPmVON2dffQKGAX53x8JigmlkgnY0gmlwhLKAlv6Jc2VjcDI1NmsxoQK6S-Cii_KmfFdUJL2TANL3ksaKUnNXvTCv1tLwXs0QgIN1ZHCCIyk" 60 export GENESIS_TIMESTAMP={{.GenesisTimestamp}} 61 export GENESIS_DELAY={{.GenesisDelay}} 62 export MAX_CHURN=8 63 export EJECTION_BALANCE=16000000000 64 export SLOTS_PER_EPOCH={{.SlotsPerEpoch}} 65 export PREMINE_ADDRS={{ if .AddressesToFund }}' 66 {{- $lastIndex := decrement (len .AddressesToFund) }} 67 {{- range $i, $addr := .AddressesToFund }} 68 "{{ $addr }}": 1000000000ETH 69 {{- end }}' 70 {{ else }}{} 71 {{ end }} 72 ` 73 74 var elGenesisConfig = ` 75 chain_id: ${CHAIN_ID} 76 deposit_contract_address: "${DEPOSIT_CONTRACT_ADDRESS}" 77 mnemonic: ${EL_AND_CL_MNEMONIC} 78 el_premine: 79 "m/44'/60'/0'/0/0": 1000000000ETH 80 "m/44'/60'/0'/0/1": 1000000000ETH 81 "m/44'/60'/0'/0/2": 1000000000ETH 82 "m/44'/60'/0'/0/3": 1000000000ETH 83 "m/44'/60'/0'/0/4": 1000000000ETH 84 "m/44'/60'/0'/0/5": 1000000000ETH 85 "m/44'/60'/0'/0/6": 1000000000ETH 86 "m/44'/60'/0'/0/7": 1000000000ETH 87 "m/44'/60'/0'/0/8": 1000000000ETH 88 "m/44'/60'/0'/0/9": 1000000000ETH 89 "m/44'/60'/0'/0/10": 1000000000ETH 90 "m/44'/60'/0'/0/11": 1000000000ETH 91 "m/44'/60'/0'/0/12": 1000000000ETH 92 "m/44'/60'/0'/0/13": 1000000000ETH 93 "m/44'/60'/0'/0/14": 1000000000ETH 94 "m/44'/60'/0'/0/15": 1000000000ETH 95 "m/44'/60'/0'/0/16": 1000000000ETH 96 "m/44'/60'/0'/0/17": 1000000000ETH 97 "m/44'/60'/0'/0/18": 1000000000ETH 98 "m/44'/60'/0'/0/19": 1000000000ETH 99 "m/44'/60'/0'/0/20": 1000000000ETH 100 el_premine_addrs: ${PREMINE_ADDRS} 101 genesis_timestamp: ${GENESIS_TIMESTAMP} 102 genesis_delay: ${GENESIS_DELAY} 103 slot_duration_in_seconds: ${SLOT_DURATION_IN_SECONDS} 104 deneb_fork_epoch: ${DENEB_FORK_EPOCH} 105 slots_per_epoch: ${SLOTS_PER_EPOCH} 106 ` 107 108 var clGenesisConfig = ` 109 # Extends the mainnet preset 110 PRESET_BASE: 'mainnet' 111 CONFIG_NAME: testnet # needs to exist because of Prysm. Otherwise it conflicts with mainnet genesis 112 113 # Genesis 114 # --------------------------------------------------------------- 115 # 2**14 (= 16,384) 116 MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: $NUMBER_OF_VALIDATORS 117 # Mar-01-2021 08:53:32 AM +UTC 118 # This is an invalid valid and should be updated when you create the genesis 119 MIN_GENESIS_TIME: $GENESIS_TIMESTAMP 120 GENESIS_FORK_VERSION: $GENESIS_FORK_VERSION 121 GENESIS_DELAY: $GENESIS_DELAY 122 123 124 # Forking 125 # --------------------------------------------------------------- 126 # Some forks are disabled for now: 127 # - These may be re-assigned to another fork-version later 128 # - Temporarily set to max uint64 value: 2**64 - 1 129 130 # Altair 131 ALTAIR_FORK_VERSION: $ALTAIR_FORK_VERSION 132 ALTAIR_FORK_EPOCH: 0 133 # Merge 134 BELLATRIX_FORK_VERSION: $BELLATRIX_FORK_VERSION 135 BELLATRIX_FORK_EPOCH: 0 136 TERMINAL_TOTAL_DIFFICULTY: 0 137 TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000 138 TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615 139 140 # Capella 141 CAPELLA_FORK_VERSION: $CAPELLA_FORK_VERSION 142 CAPELLA_FORK_EPOCH: 0 143 144 # DENEB 145 DENEB_FORK_VERSION: $DENEB_FORK_VERSION 146 DENEB_FORK_EPOCH: $DENEB_FORK_EPOCH 147 148 # Time parameters 149 # --------------------------------------------------------------- 150 # 12 seconds 151 SECONDS_PER_SLOT: $SLOT_DURATION_IN_SECONDS 152 # 14 (estimate from Eth1 mainnet) 153 SECONDS_PER_ETH1_BLOCK: $SLOT_DURATION_IN_SECONDS 154 # 2**0 (= 1) epochs ~1 hours 155 MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 1 156 # 2**8 (= 256) epochs ~27 hours 157 SHARD_COMMITTEE_PERIOD: 1 158 # 2**11 (= 2,048) Eth1 blocks ~8 hours 159 ETH1_FOLLOW_DISTANCE: 12 160 161 SLOTS_PER_EPOCH: $SLOTS_PER_EPOCH 162 163 # Validator cycle 164 # --------------------------------------------------------------- 165 # 2**2 (= 4) 166 INACTIVITY_SCORE_BIAS: 4 167 # 2**4 (= 16) 168 INACTIVITY_SCORE_RECOVERY_RATE: 16 169 # 2**4 * 10**9 (= 16,000,000,000) Gwei 170 EJECTION_BALANCE: $EJECTION_BALANCE 171 # 2**2 (= 4) 172 MIN_PER_EPOCH_CHURN_LIMIT: 4 173 # 2**16 (= 65,536) 174 CHURN_LIMIT_QUOTIENT: 65536 175 # [New in Deneb:EIP7514] 2**3 (= 8) 176 MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: $MAX_CHURN 177 178 # Fork choice 179 # --------------------------------------------------------------- 180 # 40% 181 PROPOSER_SCORE_BOOST: 40 182 183 # Deposit contract 184 # --------------------------------------------------------------- 185 DEPOSIT_CHAIN_ID: $CHAIN_ID 186 DEPOSIT_NETWORK_ID: $CHAIN_ID 187 DEPOSIT_CONTRACT_ADDRESS: $DEPOSIT_CONTRACT_ADDRESS 188 189 # Networking 190 # --------------------------------------------------------------- 191 # 10 * 2**20 (= 10485760, 10 MiB) 192 GOSSIP_MAX_SIZE: 10485760 193 # 2**10 (= 1024) 194 MAX_REQUEST_BLOCKS: 1024 195 # 2**8 (= 256) 196 EPOCHS_PER_SUBNET_SUBSCRIPTION: 256 197 # MIN_VALIDATOR_WITHDRAWABILITY_DELAY + CHURN_LIMIT_QUOTIENT // 2 (= 33024, ~5 months) 198 MIN_EPOCHS_FOR_BLOCK_REQUESTS: 33024 199 # 10 * 2**20 (=10485760, 10 MiB) 200 MAX_CHUNK_SIZE: 10485760 201 # 5s 202 TTFB_TIMEOUT: 5 203 # 10s 204 RESP_TIMEOUT: 10 205 ATTESTATION_PROPAGATION_SLOT_RANGE: 32 206 # 500ms 207 MAXIMUM_GOSSIP_CLOCK_DISPARITY: 500 208 MESSAGE_DOMAIN_INVALID_SNAPPY: 0x00000000 209 MESSAGE_DOMAIN_VALID_SNAPPY: 0x01000000 210 # 2 subnets per node 211 SUBNETS_PER_NODE: 2 212 # 2**8 (= 64) 213 ATTESTATION_SUBNET_COUNT: 64 214 ATTESTATION_SUBNET_EXTRA_BITS: 0 215 # ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS 216 ATTESTATION_SUBNET_PREFIX_BITS: 6 217 218 # Deneb 219 # 2**7 (=128) 220 MAX_REQUEST_BLOCKS_DENEB: 128 221 # MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK 222 MAX_REQUEST_BLOB_SIDECARS: 768 223 # 2**12 (= 4096 epochs, ~18 days) 224 MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096 225 # 6 226 BLOB_SIDECAR_SUBNET_COUNT: 6 227 # uint64(6) 228 MAX_BLOBS_PER_BLOCK: 6 229 ` 230 231 var mnemonics = ` 232 - mnemonic: "${EL_AND_CL_MNEMONIC}" # a 24 word BIP 39 mnemonic 233 count: $NUMBER_OF_VALIDATORS 234 ` 235 236 type ExitCodeStrategy struct { 237 expectedExitCode int 238 timeout time.Duration 239 pollInterval time.Duration 240 } 241 242 func NewExitCodeStrategy() *ExitCodeStrategy { 243 return &ExitCodeStrategy{ 244 expectedExitCode: 0, 245 timeout: 2 * time.Minute, 246 pollInterval: 2 * time.Second, 247 } 248 } 249 250 func (w *ExitCodeStrategy) WithTimeout(timeout time.Duration) *ExitCodeStrategy { 251 w.timeout = timeout 252 return w 253 } 254 255 func (w *ExitCodeStrategy) WithExitCode(exitCode int) *ExitCodeStrategy { 256 w.expectedExitCode = exitCode 257 return w 258 } 259 260 func (w *ExitCodeStrategy) WithPollInterval(pollInterval time.Duration) *ExitCodeStrategy { 261 w.pollInterval = pollInterval 262 return w 263 } 264 265 // WaitUntilReady implements Strategy.WaitUntilReady 266 func (w *ExitCodeStrategy) WaitUntilReady(ctx context.Context, target tcwait.StrategyTarget) (err error) { 267 268 ctx, cancel := context.WithTimeout(ctx, w.timeout) 269 defer cancel() 270 271 for { 272 select { 273 case <-ctx.Done(): 274 return ctx.Err() 275 case <-time.After(100 * time.Millisecond): 276 state, err := target.State(ctx) 277 if err != nil { 278 return err 279 } 280 281 if state.ExitCode != w.expectedExitCode { 282 time.Sleep(w.pollInterval) 283 continue 284 } 285 return nil 286 } 287 } 288 }