2019-10-01 13:52:28 +00:00
|
|
|
# beacon_chain
|
2020-02-21 12:16:58 +00:00
|
|
|
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
2019-10-01 13:52:28 +00:00
|
|
|
# Licensed and distributed under either of
|
2019-11-25 15:30:02 +00:00
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
2019-10-01 13:52:28 +00:00
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2020-04-22 05:53:02 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2020-04-15 02:41:22 +00:00
|
|
|
import
|
|
|
|
strformat,
|
|
|
|
datatypes
|
2020-02-21 12:16:58 +00:00
|
|
|
|
2019-10-01 13:52:28 +00:00
|
|
|
const
|
2020-04-15 02:41:22 +00:00
|
|
|
topicBeaconBlocksSuffix* = "beacon_block/ssz"
|
2020-05-14 11:19:10 +00:00
|
|
|
topicMainnetAttestationsSuffix* = "_beacon_attestation/ssz"
|
2020-04-15 02:41:22 +00:00
|
|
|
topicVoluntaryExitsSuffix* = "voluntary_exit/ssz"
|
|
|
|
topicProposerSlashingsSuffix* = "proposer_slashing/ssz"
|
|
|
|
topicAttesterSlashingsSuffix* = "attester_slashing/ssz"
|
|
|
|
topicAggregateAndProofsSuffix* = "beacon_aggregate_and_proof/ssz"
|
2020-02-21 12:16:58 +00:00
|
|
|
|
2020-04-24 07:16:40 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#configuration
|
2020-02-21 12:16:58 +00:00
|
|
|
ATTESTATION_SUBNET_COUNT* = 64
|
|
|
|
|
2020-03-16 22:28:54 +00:00
|
|
|
defaultEth2TcpPort* = 9000
|
|
|
|
|
|
|
|
# This is not part of the spec yet!
|
|
|
|
defaultEth2RpcPort* = 9090
|
|
|
|
|
2020-06-09 16:48:51 +00:00
|
|
|
when ETH2_SPEC == "v0.11.3":
|
|
|
|
const topicInteropAttestationSuffix* = "beacon_attestation/ssz"
|
|
|
|
|
2020-05-14 11:19:10 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#topics-and-messages
|
2020-04-15 02:41:22 +00:00
|
|
|
func getBeaconBlocksTopic*(forkDigest: ForkDigest): string =
|
2020-04-22 05:53:02 +00:00
|
|
|
try:
|
2020-05-11 18:08:52 +00:00
|
|
|
&"/eth2/{$forkDigest}/{topicBeaconBlocksSuffix}"
|
2020-04-22 05:53:02 +00:00
|
|
|
except ValueError as e:
|
|
|
|
raiseAssert e.msg
|
2020-04-15 02:41:22 +00:00
|
|
|
|
2020-05-14 11:19:10 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#topics-and-messages
|
2020-04-15 03:11:45 +00:00
|
|
|
func getVoluntaryExitsTopic*(forkDigest: ForkDigest): string =
|
2020-04-22 05:53:02 +00:00
|
|
|
try:
|
2020-05-11 18:08:52 +00:00
|
|
|
&"/eth2/{$forkDigest}/{topicVoluntaryExitsSuffix}"
|
2020-04-22 05:53:02 +00:00
|
|
|
except ValueError as e:
|
|
|
|
raiseAssert e.msg
|
2020-04-15 02:41:22 +00:00
|
|
|
|
2020-05-14 11:19:10 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#topics-and-messages
|
2020-04-15 02:41:22 +00:00
|
|
|
func getProposerSlashingsTopic*(forkDigest: ForkDigest): string =
|
2020-04-22 05:53:02 +00:00
|
|
|
try:
|
2020-05-11 18:08:52 +00:00
|
|
|
&"/eth2/{$forkDigest}/{topicProposerSlashingsSuffix}"
|
2020-04-22 05:53:02 +00:00
|
|
|
except ValueError as e:
|
|
|
|
raiseAssert e.msg
|
2020-04-15 02:41:22 +00:00
|
|
|
|
2020-05-14 11:19:10 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#topics-and-messages
|
2020-04-15 02:41:22 +00:00
|
|
|
func getAttesterSlashingsTopic*(forkDigest: ForkDigest): string =
|
2020-04-22 05:53:02 +00:00
|
|
|
try:
|
2020-05-11 18:08:52 +00:00
|
|
|
&"/eth2/{$forkDigest}/{topicAttesterSlashingsSuffix}"
|
2020-04-22 05:53:02 +00:00
|
|
|
except ValueError as e:
|
|
|
|
raiseAssert e.msg
|
2020-04-15 02:41:22 +00:00
|
|
|
|
2020-05-14 11:19:10 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#topics-and-messages
|
2020-04-15 02:41:22 +00:00
|
|
|
func getAggregateAndProofsTopic*(forkDigest: ForkDigest): string =
|
2020-04-22 05:53:02 +00:00
|
|
|
try:
|
2020-05-11 18:08:52 +00:00
|
|
|
&"/eth2/{$forkDigest}/{topicAggregateAndProofsSuffix}"
|
2020-04-22 05:53:02 +00:00
|
|
|
except ValueError as e:
|
|
|
|
raiseAssert e.msg
|
2020-04-15 02:41:22 +00:00
|
|
|
|
2020-06-09 16:48:51 +00:00
|
|
|
when ETH2_SPEC == "v0.11.3":
|
|
|
|
func getInteropAttestationTopic*(forkDigest: ForkDigest): string =
|
|
|
|
try:
|
|
|
|
&"/eth2/{$forkDigest}/{topicInteropAttestationSuffix}"
|
|
|
|
except ValueError as e:
|
|
|
|
raiseAssert e.msg
|
|
|
|
|
2020-05-14 11:19:10 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#mainnet-3
|
|
|
|
func getMainnetAttestationTopic*(forkDigest: ForkDigest, committeeIndex: uint64): string =
|
2020-04-22 05:53:02 +00:00
|
|
|
try:
|
|
|
|
let topicIndex = committeeIndex mod ATTESTATION_SUBNET_COUNT
|
2020-05-14 11:19:10 +00:00
|
|
|
&"/eth2/{$forkDigest}/committee_index{topicIndex}{topicMainnetAttestationsSuffix}"
|
2020-04-22 05:53:02 +00:00
|
|
|
except ValueError as e:
|
|
|
|
raiseAssert e.msg
|