Skip to content

Commit baff4da

Browse files
committed
Make historicalSummariesFork const
1 parent 5ba6fc8 commit baff4da

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

beacon_chain/rpc/rest_nimbus_api.nim

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -548,28 +548,31 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) =
548548
node.withStateForBlockSlotId(bslot):
549549
return withState(state):
550550
when consensusFork >= ConsensusFork.Capella:
551-
let summariesFork = historicalSummariesForkAtConsensusFork(consensusFork).valueOr:
552-
return RestApiResponse.jsonError(Http404, HistoricalSummariesUnavailable)
553-
554-
withHistoricalSummariesFork(summariesFork):
555-
let response = getHistoricalSummariesResponse(historicalSummariesFork)(
556-
historical_summaries: forkyState.data.historical_summaries,
557-
proof: forkyState.data.build_proof(
558-
historicalSummariesFork.historical_summaries_gindex).expect("Valid gindex"),
559-
slot: bslot.slot)
560-
561-
if contentType == jsonMediaType:
562-
RestApiResponse.jsonResponseFinalizedWVersion(
563-
response,
564-
node.getStateOptimistic(state),
565-
node.dag.isFinalized(bslot.bid),
566-
consensusFork)
567-
elif contentType == sszMediaType:
568-
let headers = [("eth-consensus-version", consensusFork.toString())]
569-
RestApiResponse.sszResponse(response, headers)
570-
else:
571-
RestApiResponse.jsonError(Http500, InvalidAcceptError)
551+
const historicalSummariesFork = historicalSummariesForkAtConsensusFork(
552+
consensusFork
553+
)
554+
.expect("HistoricalSummariesFork for Capella onwards")
555+
556+
let response = getHistoricalSummariesResponse(historicalSummariesFork)(
557+
historical_summaries: forkyState.data.historical_summaries,
558+
proof: forkyState.data
559+
.build_proof(historicalSummariesFork.historical_summaries_gindex)
560+
.expect("Valid gindex"),
561+
slot: bslot.slot,
562+
)
572563

564+
if contentType == jsonMediaType:
565+
RestApiResponse.jsonResponseFinalizedWVersion(
566+
response,
567+
node.getStateOptimistic(state),
568+
node.dag.isFinalized(bslot.bid),
569+
consensusFork,
570+
)
571+
elif contentType == sszMediaType:
572+
let headers = [("eth-consensus-version", consensusFork.toString())]
573+
RestApiResponse.sszResponse(response, headers)
574+
else:
575+
RestApiResponse.jsonError(Http500, InvalidAcceptError)
573576
else:
574577
RestApiResponse.jsonError(Http404, HistoricalSummariesUnavailable)
575578

beacon_chain/spec/eth2_apis/rest_types.nim

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,12 +1165,3 @@ func historicalSummariesForkAtConsensusFork*(consensusFork: ConsensusFork): Opt[
11651165
Opt.some HistoricalSummariesFork.Capella
11661166
else:
11671167
Opt.none HistoricalSummariesFork
1168-
1169-
template withHistoricalSummariesFork*(x: HistoricalSummariesFork, body: untyped): untyped =
1170-
case x
1171-
of HistoricalSummariesFork.Electra:
1172-
const historicalSummariesFork {.inject, used.} = HistoricalSummariesFork.Electra
1173-
body
1174-
of HistoricalSummariesFork.Capella:
1175-
const historicalSummariesFork {.inject, used.} = HistoricalSummariesFork.Capella
1176-
body

0 commit comments

Comments
 (0)