Skip to content

Commit ebb2ec4

Browse files
committed
Address feedback: add gindex and response templates
1 parent 5ea738f commit ebb2ec4

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

beacon_chain/rpc/rest_nimbus_api.nim

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -547,47 +547,19 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) =
547547

548548
node.withStateForBlockSlotId(bslot):
549549
return withState(state):
550-
when consensusFork >= ConsensusFork.Electra:
551-
var proof: HistoricalSummariesProofElectra
552-
if forkyState.data.build_proof(HISTORICAL_SUMMARIES_GINDEX_ELECTRA, proof).isErr:
553-
return RestApiResponse.jsonError(Http500, InvalidMerkleProofIndexError)
554-
555-
let response = GetHistoricalSummariesV1ResponseElectra(
556-
historical_summaries: forkyState.data.historical_summaries,
557-
proof: proof,
558-
slot: bslot.slot,
559-
)
560-
561-
if contentType == jsonMediaType:
562-
RestApiResponse.jsonResponseFinalizedWVersion(
563-
response,
564-
node.getStateOptimistic(state),
565-
node.dag.isFinalized(bslot.bid),
566-
consensusFork,
567-
)
568-
elif contentType == sszMediaType:
569-
let headers = [("eth-consensus-version", consensusFork.toString())]
570-
RestApiResponse.sszResponse(response, headers)
571-
else:
572-
RestApiResponse.jsonError(Http500, InvalidAcceptError)
573-
elif consensusFork >= ConsensusFork.Capella:
574-
var proof: HistoricalSummariesProof
575-
if forkyState.data.build_proof(HISTORICAL_SUMMARIES_GINDEX, proof).isErr:
576-
return RestApiResponse.jsonError(Http500, InvalidMerkleProofIndexError)
577-
578-
let response = GetHistoricalSummariesV1Response(
550+
when consensusFork >= ConsensusFork.Capella:
551+
let response = consensusFork.GetHistoricalSummariesResponse(
579552
historical_summaries: forkyState.data.historical_summaries,
580-
proof: proof,
581-
slot: bslot.slot,
582-
)
553+
proof: forkyState.data.build_proof(
554+
consensusFork.historical_summaries_gindex).expect("Valid gindex"),
555+
slot: bslot.slot)
583556

584557
if contentType == jsonMediaType:
585558
RestApiResponse.jsonResponseFinalizedWVersion(
586559
response,
587560
node.getStateOptimistic(state),
588561
node.dag.isFinalized(bslot.bid),
589-
consensusFork,
590-
)
562+
consensusFork)
591563
elif contentType == sszMediaType:
592564
let headers = [("eth-consensus-version", consensusFork.toString())]
593565
RestApiResponse.sszResponse(response, headers)

beacon_chain/spec/eth2_apis/rest_types.nim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,24 @@ type
11121112
of ConsensusFork.Electra: electraData*: GetHistoricalSummariesV1ResponseElectra
11131113
of ConsensusFork.Fulu: fuluData*: GetHistoricalSummariesV1ResponseElectra
11141114

1115+
template historical_summaries_gindex*(
1116+
kind: static ConsensusFork): GeneralizedIndex =
1117+
when kind >= ConsensusFork.Electra:
1118+
HISTORICAL_SUMMARIES_GINDEX_ELECTRA
1119+
elif kind >= ConsensusFork.Capella:
1120+
HISTORICAL_SUMMARIES_GINDEX
1121+
else:
1122+
{.error: "historical_summaries_gindex does not support " & $kind.}
1123+
1124+
template GetHistoricalSummariesResponse*(
1125+
kind: static ConsensusFork): auto =
1126+
when kind >= ConsensusFork.Electra:
1127+
GetHistoricalSummariesV1ResponseElectra
1128+
elif kind >= ConsensusFork.Capella:
1129+
GetHistoricalSummariesV1Response
1130+
else:
1131+
{.error: "GetHistoricalSummariesResponse does not support " & $kind.}
1132+
11151133
template init*(
11161134
T: type ForkedHistoricalSummariesWithProof,
11171135
historical_summaries: GetHistoricalSummariesV1Response,

0 commit comments

Comments
 (0)