diff --git a/beacon_chain/spec/presets.nim b/beacon_chain/spec/presets.nim index ef4213e432..f13c98ce4f 100644 --- a/beacon_chain/spec/presets.nim +++ b/beacon_chain/spec/presets.nim @@ -586,6 +586,10 @@ else: const SLOTS_PER_SYNC_COMMITTEE_PERIOD* = SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD +# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/phase0/p2p-interface.md#configuration +func safeMinEpochsForBlockRequests*(cfg: RuntimeConfig): uint64 = + cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY + cfg.CHURN_LIMIT_QUOTIENT div 2 + func parse(T: type uint64, input: string): T {.raises: [ValueError].} = var res: BiggestUInt if input.len > 2 and input[0] == '0' and input[1] == 'x': @@ -784,11 +788,7 @@ proc readRuntimeConfig*( msg: "Config not compatible with binary, compile with -d:const_preset=" & cfg.PRESET_BASE) # Requires initialized `cfg` - - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.3/specs/phase0/p2p-interface.md#configuration - let safeMinEpochsForBlockRequests = - cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY + cfg.CHURN_LIMIT_QUOTIENT div 2 - checkCompatibility safeMinEpochsForBlockRequests, + checkCompatibility cfg.safeMinEpochsForBlockRequests(), "MIN_EPOCHS_FOR_BLOCK_REQUESTS", `>=` var unknowns: seq[string] diff --git a/tests/test_blockchain_dag.nim b/tests/test_blockchain_dag.nim index 8dd5640801..757bd992ec 100644 --- a/tests/test_blockchain_dag.nim +++ b/tests/test_blockchain_dag.nim @@ -1145,6 +1145,7 @@ suite "Pruning": var res = defaultRuntimeConfig res.MIN_VALIDATOR_WITHDRAWABILITY_DELAY = 4 res.CHURN_LIMIT_QUOTIENT = 1 + res.MIN_EPOCHS_FOR_BLOCK_REQUESTS = cfg.safeMinEpochsForBlockRequests() doAssert res.MIN_EPOCHS_FOR_BLOCK_REQUESTS == 4 res db = makeTestDB(SLOTS_PER_EPOCH)