-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #648 from ChainSafe/mpetrunic/aggregate-attestations
Attestation collection
- Loading branch information
Showing
43 changed files
with
787 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [0.2.0] - unreleased | ||
### Added | ||
- `RANDOM_SUBNETS_PER_VALIDATOR` and `EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION` constant params | ||
- TODO: check what else is added |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {IBeaconSSZTypes} from "../interface"; | ||
import {ContainerType} from "@chainsafe/ssz"; | ||
|
||
export const SubscribeToCommitteeSubnetPayload = (ssz: IBeaconSSZTypes): ContainerType => new ContainerType({ | ||
fields: { | ||
slot: ssz.Slot, | ||
slotSignature: ssz.BLSSignature, | ||
committeeIndex: ssz.CommitteeIndex, | ||
aggregatorPubkey: ssz.BLSPubkey | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* eslint-disable @typescript-eslint/interface-name-prefix */ | ||
import {BLSPubkey, BLSSignature, CommitteeIndex, Slot} from "./primitive"; | ||
|
||
export interface SubscribeToCommitteeSubnetPayload { | ||
slot: Slot; | ||
slotSignature: BLSSignature; | ||
committeeIndex: CommitteeIndex; | ||
aggregatorPubkey: BLSPubkey; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/lodestar/src/api/rest/routes/validator/subscribeToCommitteeSubnet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {IFastifyServer} from "../../index"; | ||
import fastify, {DefaultBody, DefaultHeaders, DefaultParams, DefaultQuery} from "fastify"; | ||
import {IApiModules} from "../../../interface"; | ||
import {verify} from "@chainsafe/bls"; | ||
import {hexToBuffer} from "../../../../util/hex"; | ||
import {computeEpochAtSlot, getDomain} from "@chainsafe/eth2.0-state-transition"; | ||
import {DomainType} from "../../../../constants"; | ||
|
||
|
||
const opts: fastify.RouteShorthandOptions = { | ||
schema: { | ||
body: { | ||
type: "object", | ||
requiredKeys: ["committee_index", "slot", "slot_signature", "aggregator_pubkey"], | ||
"committee_index": { | ||
type: "string" | ||
}, | ||
"slot": { | ||
type: "string" | ||
}, | ||
"slot_signature": { | ||
type: "string" | ||
}, | ||
"aggregator_pubkey": { | ||
type: "string" | ||
}, | ||
}, | ||
} | ||
}; | ||
|
||
interface IBody extends DefaultBody { | ||
committee_index: string; | ||
slot: string; | ||
slot_signature: string; | ||
aggregator_pubkey: string; | ||
} | ||
|
||
export const registerSubscribeToCommitteeSubnet = (fastify: IFastifyServer, modules: IApiModules): void => { | ||
fastify.post<DefaultQuery, DefaultParams, DefaultHeaders, IBody>( | ||
"/beacon_committee_subscription", | ||
opts, | ||
async (request, reply) => { | ||
const slot = Number(request.body.slot); | ||
const valid = verify( | ||
hexToBuffer(request.body.aggregator_pubkey), | ||
modules.config.types.Slot.hashTreeRoot(slot), | ||
hexToBuffer(request.body.slot_signature), | ||
getDomain( | ||
modules.config, | ||
modules.chain.latestState, | ||
DomainType.BEACON_ATTESTER, | ||
computeEpochAtSlot(modules.config, slot)) | ||
); | ||
if(!valid) { | ||
reply | ||
.code(403) | ||
.send(); | ||
return; | ||
} | ||
modules.sync.regularSync.collectAttestations( | ||
slot, | ||
Number(request.body.committee_index) | ||
); | ||
reply | ||
.code(200) | ||
.type("application/json") | ||
.send(); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.