diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index fe40352b4..5263f5808 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -451,9 +451,12 @@ type name: "rest-max-body-size" .}: Natural restMaxRequestHeadersSize* {. - defaultValue: 64 + defaultValue: 128 desc: "Maximum size of REST request headers (kilobytes)" name: "rest-max-headers-size" .}: Natural + ## NOTE: If you going to adjust this value please check value + ## ``ClientMaximumValidatorIds`` and comments in + ## `spec/eth2_apis/rest_types.nim`. This values depend on each other. keymanagerEnabled* {. desc: "Enable the REST keymanager API" diff --git a/beacon_chain/rpc/rest_beacon_api.nim b/beacon_chain/rpc/rest_beacon_api.nim index 56aa8616e..ed279d01e 100644 --- a/beacon_chain/rpc/rest_beacon_api.nim +++ b/beacon_chain/rpc/rest_beacon_api.nim @@ -254,7 +254,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) = return RestApiResponse.jsonError(Http400, InvalidValidatorIdValueError) let ires = id.get() - if len(ires) > MaximumValidatorIds: + if len(ires) > ServerMaximumValidatorIds: return RestApiResponse.jsonError(Http400, MaximumNumberOfValidatorIdsError) ires @@ -445,7 +445,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) = return RestApiResponse.jsonError(Http400, InvalidValidatorIdValueError) let ires = id.get() - if len(ires) > MaximumValidatorIds: + if len(ires) > ServerMaximumValidatorIds: return RestApiResponse.jsonError(Http400, MaximumNumberOfValidatorIdsError) ires diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index d105bef3a..411ee9f0f 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -27,11 +27,35 @@ export forks, phase0, altair, bellatrix, capella, bellatrix_mev const # https://github.com/ethereum/eth2.0-APIs/blob/master/apis/beacon/states/validator_balances.yaml#L17 # https://github.com/ethereum/eth2.0-APIs/blob/master/apis/beacon/states/validators.yaml#L17 - MaximumValidatorIds* = 16384 + # Maximum number of validators that can be served by the REST server in one + # request, if the number of validator exceeds this value REST server + # will return HTTP error 400. + ServerMaximumValidatorIds* = 16384 + + # Maximum number of validators that can be sent in single request by + # validator client (VC). + # NOTE: This value depend on beacon node's `rest-max-headers-size` + # configuration option. + # + # Size of public key in HTTP request could be calculated by formula - + # bytes48 * 2 + len("0x") + len(",") = 99 bytes. + # So 1024 keys will occupy 101,376 bytes. Default value for HTTP headers size + # is 128Kb = 131,072 bytes. + ClientMaximumValidatorIds* = 1024 + + # https://github.com/ethereum/beacon-APIs/blob/master/apis/validator/duties/attester.yaml#L32 + # https://github.com/ethereum/beacon-APIs/blob/master/apis/validator/duties/sync.yaml#L16 + # Maximum number of validator ids sent with validator client's duties + # requests. Validator ids are sent in decimal encoding with comma, so + # number of ids should not exceed beacon node's `rest-max-body-size`. + DutiesMaximumValidatorIds* = 16384 const preferSSZ* = "application/octet-stream,application/json;q=0.9" +static: + doAssert(ClientMaximumValidatorIds <= ServerMaximumValidatorIds) + type EventTopic* {.pure.} = enum Head, Block, Attestation, VoluntaryExit, FinalizedCheckpoint, ChainReorg, diff --git a/beacon_chain/validator_client/duties_service.nim b/beacon_chain/validator_client/duties_service.nim index 0c6516550..aae81356e 100644 --- a/beacon_chain/validator_client/duties_service.nim +++ b/beacon_chain/validator_client/duties_service.nim @@ -51,7 +51,7 @@ proc pollForValidatorIndices*(vc: ValidatorClientRef) {.async.} = var offset = 0 while offset < len(validatorIdents): - let arraySize = min(MaximumValidatorIds, len(validatorIdents)) + let arraySize = min(ClientMaximumValidatorIds, len(validatorIdents)) let idents = block: @@ -119,7 +119,9 @@ proc pollForAttesterDuties*(vc: ValidatorClientRef, var offset = 0 while offset < len(validatorIndices): - let arraySize = min(MaximumValidatorIds, len(validatorIndices)) + let arraySize = min(DutiesMaximumValidatorIds, len(validatorIndices)) + # We use `DutiesMaximumValidatorIds` here because validator ids are sent + # in HTTP request body and NOT in HTTP request headers. let indices = block: var res = newSeq[ValidatorIndex](arraySize) @@ -255,7 +257,9 @@ proc pollForSyncCommitteeDuties*(vc: ValidatorClientRef, while offset < len(validatorIndices): let - arraySize = min(MaximumValidatorIds, remainingItems) + arraySize = min(DutiesMaximumValidatorIds, remainingItems) + # We use `DutiesMaximumValidatorIds` here because validator ids are sent + # in HTTP request body and NOT in HTTP request headers. indices = validatorIndices[offset ..< (offset + arraySize)] res =