diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index 61270ccbf..753d4b5d2 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -49,13 +49,17 @@ type ProposerSlashing | phase0.SignedBeaconBlock | altair.SignedBeaconBlock | - SignedVoluntaryExit + SignedVoluntaryExit | + SyncCommitteeIndex EncodeArrays* = seq[ValidatorIndex] | seq[Attestation] | seq[SignedAggregateAndProof] | - seq[RestCommitteeSubscription] + seq[RestCommitteeSubscription] | + seq[RestSyncCommitteeSubscription] | + seq[RestSyncCommitteeMessage] | + seq[RestSignedContributionAndProof] DecodeTypes* = DataEnclosedObject | @@ -874,8 +878,10 @@ proc readValue*(reader: var JsonReader[RestJson], raises: [IOError, SerializationError, Defect].} = let res = Base10.decode(uint8, reader.readValue(string)) if res.isOk(): - # TODO (cheatfate): Here should be present check for maximum value. - value = SyncCommitteeIndex(res.get()) + if res.get() < SYNC_COMMITTEE_SUBNET_COUNT: + value = SyncCommitteeIndex(res.get()) + else: + reader.raiseUnexpectedValue("Sync sub-committee index out of rage") else: reader.raiseUnexpectedValue($res.error()) @@ -976,7 +982,7 @@ proc decodeBytes*[T: SszDecodeTypes](t: typedesc[T], value: openarray[byte], proc encodeString*(value: string): RestResult[string] = ok(value) -proc encodeString*(value: Epoch|Slot|CommitteeIndex): RestResult[string] = +proc encodeString*(value: Epoch|Slot|CommitteeIndex|SyncCommitteeIndex): RestResult[string] = ok(Base10.toString(uint64(value))) proc encodeString*(value: ValidatorSig): RestResult[string] = @@ -1214,6 +1220,14 @@ proc decodeString*(t: typedesc[CommitteeIndex], let res = ? Base10.decode(uint64, value) ok(CommitteeIndex(res)) +proc decodeString*(t: typedesc[SyncCommitteeIndex], + value: string): Result[SyncCommitteeIndex, cstring] = + let res = ? Base10.decode(uint8, value) + if res.get < SYNC_COMMITTEE_SUBNET_COUNT: + ok(CommitteeIndex(res)) + else: + err("sync subcommittee index out of range") + proc decodeString*(t: typedesc[Eth2Digest], value: string): Result[Eth2Digest, cstring] = if len(value) != RootHashSize + 2: diff --git a/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim b/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim index 005884d28..b90971dcf 100644 --- a/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim +++ b/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim @@ -258,11 +258,10 @@ proc submitPoolProposerSlashings*(body: ProposerSlashing): RestPlainResponse {. meth: MethodPost.} ## https://ethereum.github.io/beacon-APIs/#/Beacon/submitPoolProposerSlashings -# TODO Altair -# proc submitPoolSyncCommitteeSignatures*(body: seq[RestSyncCommitteeSignature]): RestPlainResponse {. -# rest, endpoint: "/eth/v1/beacon/pool/sync_committees", -# meth: MethodPost.} -# ## https://ethereum.github.io/beacon-APIs/#/Beacon/submitPoolSyncCommitteeSignatures +proc submitPoolSyncCommitteeSignatures*(body: seq[RestSyncCommitteeMessage]): RestPlainResponse {. + rest, endpoint: "/eth/v1/beacon/pool/sync_committees", + meth: MethodPost.} + ## https://ethereum.github.io/beacon-APIs/#/Beacon/submitPoolSyncCommitteeSignatures proc getPoolVoluntaryExits*(): RestResponse[GetPoolVoluntaryExitsResponse] {. rest, endpoint: "/api/eth/v1/beacon/pool/voluntary_exits", diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index f48ae5070..f4629aad7 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -107,6 +107,28 @@ type validator_index*: ValidatorIndex validator_sync_committee_indices*: seq[SyncCommitteeIndex] + RestSyncCommitteeMessage* = object + slot*: Slot + beacon_block_root*: Eth2Digest + validator_index*: uint64 + signature*: ValidatorSig + + RestSyncCommitteeContribution* = object + slot*: Slot + beacon_block_root*: Eth2Digest + subcommittee_index*: uint64 + aggregation_bits*: SyncCommitteeAggregationBits ##\ + signature*: ValidatorSig + + RestContributionAndProof* = object + aggregator_index*: uint64 + selection_proof*: ValidatorSig + contribution*: RestSyncCommitteeContribution + + RestSignedContributionAndProof* = object + message*: RestContributionAndProof + signature*: ValidatorSig + RestCommitteeSubscription* = object validator_index*: ValidatorIndex committee_index*: CommitteeIndex @@ -291,7 +313,7 @@ type RestBlockInfo* = object slot*: Slot blck* {.serializedFieldName: "block".}: Eth2Digest - + RestEpochSyncCommittee* = object validators*: seq[ValidatorIndex] validator_aggregates*: seq[seq[ValidatorIndex]] @@ -347,6 +369,7 @@ type GetPoolProposerSlashingsResponse* = DataEnclosedObject[seq[ProposerSlashing]] GetPoolVoluntaryExitsResponse* = DataEnclosedObject[seq[SignedVoluntaryExit]] GetProposerDutiesResponse* = DataRootEnclosedObject[seq[RestProposerDuty]] + GetSyncCommitteeDutiesResponse* = DataEnclosedObject[seq[RestSyncCommitteeDuty]] GetSpecResponse* = DataEnclosedObject[RestSpec] GetStateFinalityCheckpointsResponse* = DataEnclosedObject[RestBeaconStatesFinalityCheckpoints] GetStateForkResponse* = DataEnclosedObject[Fork] diff --git a/beacon_chain/spec/eth2_apis/rest_validator_calls.nim b/beacon_chain/spec/eth2_apis/rest_validator_calls.nim index ffa6a0320..3377930bb 100644 --- a/beacon_chain/spec/eth2_apis/rest_validator_calls.nim +++ b/beacon_chain/spec/eth2_apis/rest_validator_calls.nim @@ -24,11 +24,12 @@ proc getProposerDuties*(epoch: Epoch): RestResponse[GetProposerDutiesResponse] { meth: MethodGet.} ## https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties -# TODO altair -# proc getSyncCommitteeDuties*(epoch: Epoch): RestResponse[DataRestSyncCommitteeDuties] {. -# rest, endpoint: "/eth/v1/validator/duties/sync/{epoch}", -# meth: MethodPost.} -# ## https://ethereum.github.io/beacon-APIs/#/Validator/getSyncCommitteeDuties +proc getSyncCommitteeDuties*(epoch: Epoch, + body: seq[ValidatorIndex] + ): RestResponse[GetSyncCommitteeDutiesResponse] {. + rest, endpoint: "/eth/v1/validator/duties/sync/{epoch}", + meth: MethodPost.} + ## https://ethereum.github.io/beacon-APIs/#/Validator/getSyncCommitteeDuties proc produceBlock*(slot: Slot, randao_reveal: ValidatorSig, graffiti: GraffitiBytes @@ -68,21 +69,19 @@ proc prepareBeaconCommitteeSubnet*(body: seq[RestCommitteeSubscription]): RestPl meth: MethodPost.} ## https://ethereum.github.io/beacon-APIs/#/Validator/prepareBeaconCommitteeSubnet -# TODO altair -# proc prepareSyncCommitteeSubnets*(body: seq[int] -# ): RestPlainResponse {. -# rest, endpoint: "/eth/v1/validator/sync_committee_subscriptions", -# meth: MethodPost.} -# ## https://ethereum.github.io/beacon-APIs/#/Validator/prepareSyncCommitteeSubnets +proc prepareSyncCommitteeSubnets*(body: seq[RestSyncCommitteeSubscription]): RestPlainResponse {. + rest, endpoint: "/eth/v1/validator/sync_committee_subscriptions", + meth: MethodPost.} + ## https://ethereum.github.io/beacon-APIs/#/Validator/prepareSyncCommitteeSubnets -# proc produceSyncCommitteeContribution*(body: seq[int] -# ): RestPlainResponse {. -# rest, endpoint: "/eth/v1/validator/sync_committee_contribution", -# meth: MethodPost.} -# ## https://ethereum.github.io/beacon-APIs/#/Validator/produceSyncCommitteeContribution +proc produceSyncCommitteeContribution*(slot: Slot, + subcommittee_index: SyncCommitteeIndex, + beacon_block_root: Eth2Digest): RestPlainResponse {. + rest, endpoint: "/eth/v1/validator/sync_committee_contribution", + meth: MethodGet.} + ## https://ethereum.github.io/beacon-APIs/#/Validator/produceSyncCommitteeContribution -# proc publishContributionAndProofs*(body: seq[RestCommitteeSubscription] -# ): RestPlainResponse {. -# rest, endpoint: "/eth/v1/validator/contribution_and_proofs", -# meth: MethodPost.} -# ## https://ethereum.github.io/beacon-APIs/#/Validator/publishContributionAndProofs +proc publishContributionAndProofs*(body: seq[RestSignedContributionAndProof]): RestPlainResponse {. + rest, endpoint: "/eth/v1/validator/contribution_and_proofs", + meth: MethodPost.} + ## https://ethereum.github.io/beacon-APIs/#/Validator/publishContributionAndProofs