Skip to main content

Prysm's service interface definitions for the Ethereum 2.0 API

Project description

Ethereum APIs

Build status Discord Gitter ETH2.0_Spec_Version 0.12.0 PyPI

This repository hosts Prysm's service interface definitions for the Ethereum 2.0 API. These protocol buffer service definitions support gRPC as well as JSON over HTTP.

Need assistance?

More indepth descriptions of each service are available in this section of our official documentation. For more general information on the functionality of gRPC and protocol buffers, see the gRPC guide. If you still have questions, feel free to stop by either our Discord or Gitter and a member of the team or our community will be happy to assist you.

Service definitions

Package Service Version Description
eth BeaconChain v1alpha1 This service is used to retrieve critical data relevant to the Ethereum 2.0 phase 0 beacon chain, including the most recent head block, current pending deposits, the chain state and more.
eth Node v1alpha1 The Node service returns information about the Ethereum node itself, including versioning and general information as well as network sync status and a list of services currently implemented on the node.
eth Validator v1alpha1 This API provides the information a validator needs to retrieve throughout its life cycle, including recieved assignments from the network, its current index in the state as well as the rewards and penalties that have been applied to it.

Contributing

Thanks for wanting to contribute to our eth2 API! Go libraries may be generated from the ethereumapis repository using Bazel, making it easy to make changes to the schemas needed and generate Go files from them.

Python libraries can be generated using scripts/build-py-package.py; we regularly push these libraries to PyPI as ethereumapis.

Dependencies

Here's what you need to get started:

  • A modern, UNIX operating system
  • The latest release of Bazel installed
  • The cmake package installed
  • The git package installed

Making API Schema Changes

Say you want to add a new endpoint to the BeaconChain gRPC service in our API schema to retrieve orphaned blocks. First, make sure the functionality you wish to add is not already covered by one of our endpoints on https://api.prylabs.network. Also, keep in mind making strict changes to the API schema can often times be difficult without a significant reason as this API is used by many different developers building on eth2. If you are confident in your desired changes, you can proceed by modifying the protobuf schema:

service BeaconChain {
    // Retrieve orphaned blocks from the eth2 chain.
    rpc GetOrphanedBlocks(OrphanedBlocksRequest) returns (OrphanedBlocksResponse) {
        option (google.api.http) = {
            get: "/eth/v1alpha1/beacon/blocks/orphaned"
        };
    }
    ...
}

message OrphanedBlocksRequest {
    uint64 slot = 1;
}

message OrphanedBlocksResponse {
    repeated BeaconBlock blocks = 1;
}

After making your changes, you can regenerate the Go libraries from the schema by running:

$ ./scripts/update-go-pbs.sh

Then, open a pull request with your changes on https://github.com/prysmaticlabs/ethereumapis. Next, you'll be ready to implement your new changes in Prysm itself.

Implementing Your Changes in Prysm

Ensure you have read our contribution guidelines first. Then, once your changes to the API schema are merged into the master branch of ethereumapis, you can update Prysm's dependency on ethereumapis to its latest version with the command:

$ bazel run //:gazelle -- update-repos github.com/prysmaticlabs/ethereumapis

Prysm also utilizes generated mocks for testing gRPC requests/responses, so you will also need to regenerate the required mocks by running:

$ ./scripts/update-mockgen.sh

Now, you will be able to implement your required changes in Prysm.

RESTful endpoints (gRPC Transcoding)

All of the gRPC services should define JSON over HTTP endpoints by specifying HTTPRules. Developers may choose to bundle a REST service of gRPC with their client implementation binaries, or alternatively, they may use a JSON encoding proxy such as Envoy Proxy, grpc-gateway, etc.

For more information on gRPC transcoding, see the examples found here.

Code sample:

service Messaging {
    rpc GetMessage(GetMessageRequest) returns (Message) {
        option (google.api.http) = {
            get: "/v1/{name=messages/*}"
        };
    }
}
message GetMessageRequest {
    string name = 1; // Mapped to URL Path.
}
message Message {
    string text = 1; // The resource content.
}

This enables an HTTP REST to gRPC mapping, as shown below:

HTTP gRPC
GET /v1/messages/123456 GetMessage(name: "messages/123456")

JSON mapping

The majority of field primitive types for Ethereum are either bytes or uint64. The canonical JSON mapping for those fields are a Base64 encoded string for bytes, or a string representation of uint64. Since JavaScript loses precision for values over MAX_SAFE_INTEGER, uint64 must be a JSON string in order to accommodate those values. If the field value not changed and is still set to protobuf's default, this field will be omitted from the JSON encoding entirely.

For more details on JSON mapping for other types, view the relevant section in the proto3 language guide.

gRPC tooling and resources

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ethereumapis-0.12.0.tar.gz (83.6 kB view details)

Uploaded Source

Built Distribution

ethereumapis-0.12.0-py3-none-any.whl (91.0 kB view details)

Uploaded Python 3

File details

Details for the file ethereumapis-0.12.0.tar.gz.

File metadata

  • Download URL: ethereumapis-0.12.0.tar.gz
  • Upload date:
  • Size: 83.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for ethereumapis-0.12.0.tar.gz
Algorithm Hash digest
SHA256 2b90ab1829722b03dc357858de60af3d56eeda67606091eb958fe8f8a5270f93
MD5 8a63f9cdfefd74a6158ce745cb207e05
BLAKE2b-256 2176b74434eff39a89d9ee59ffa4b11d863337c1bafc94e67af73c9b0414bafe

See more details on using hashes here.

File details

Details for the file ethereumapis-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: ethereumapis-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 91.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for ethereumapis-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb6b95c7694ab77e14bc85d7f86727b2a39a4284cc5ecf7c8de78259e1e766df
MD5 27fbbea9cfe9ce5eda76cc312d360d67
BLAKE2b-256 d46cfe2dd7da5fa370cc69672e1ec4c97e21b1db0086da4c96e1602772c3e776

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page