Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #297 from radixdlt/feature/rpnv1-1306-refactor-jso…
Browse files Browse the repository at this point in the history
…n-rpc-implementation

New API
  • Loading branch information
shambupujar authored Jun 22, 2021
2 parents 47ccc13 + ec4ba3f commit 4e96308
Show file tree
Hide file tree
Showing 352 changed files with 18,659 additions and 5,548 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ subprojects {
dependency 'commons-cli:commons-cli:1.4'
dependency 'org.xerial.snappy:snappy-java:1.1.8.4'
dependency 'io.netty:netty-all:4.1.51.Final'
dependency('com.google.inject:guice:4.2.3') {
dependency('com.google.inject:guice:5.0.1') {
exclude 'com.google.guava:guava'
}

dependency('com.google.inject.extensions:guice-grapher:4.2.3') {
dependency('com.google.inject.extensions:guice-grapher:5.0.1') {
exclude 'com.google.guava:guava'
}

Expand Down
20 changes: 15 additions & 5 deletions radixdlt-core/docker/Dockerfile.core
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ CMD ["/bin/bash", "-xe", "/opt/radixdlt/bin/radixdlt"]
# set default environment variables
ENV RADIXDLT_HOME=/home/radixdlt \
RADIXDLT_NETWORK_SEEDS_REMOTE=127.0.0.1 \
RADIXDLT_CHAOS_ENABLE=false \
RADIXDLT_DB_LOCATION=./RADIXDB \
RADIXDLT_VALIDATOR_KEY_LOCATION=/home/radixdlt/node.ks \
RADIXDLT_NODE_API_PORT=3333 \
RADIXDLT_ENABLE_CLIENT_API=false \
RADIXDLT_UNIVERSE_ENABLE=false \
RADIXDLT_CLIENT_API_PORT=8080
RADIXDLT_ARCHIVE_API_ENABLE=false \
RADIXDLT_ACCOUNT_API_ENABLE=false \
RADIXDLT_CONSTRUCT_API_ENABLE=false \
RADIXDLT_CHAOS_API_ENABLE=false \
RADIXDLT_FAUCET_API_ENABLE=false \
RADIXDLT_HEALTH_API_ENABLE=false \
RADIXDLT_METRICS_API_ENABLE=false \
RADIXDLT_SYSTEM_API_ENABLE=false \
RADIXDLT_VALIDATION_API_ENABLE=false \
RADIXDLT_UNIVERSE_API_ENABLE=false \
RADIXDLT_VERSION_API_ENABLE=false \
RADIXDLT_ARCHIVE_API_PORT=8080 \
RADIXDLT_HTTP_NODE_BIND_ADDRESS=0.0.0.0 \
RADIXDLT_HTTP_ARCHIVE_BIND_ADDRESS=0.0.0.0

# install the radixdlt package
COPY *.deb /tmp/
Expand All @@ -40,4 +50,4 @@ COPY config/ /home/radixdlt/
# Add healthcheck
COPY scripts/docker-healthcheck.sh /home/radixdlt/
HEALTHCHECK CMD sh /home/radixdlt/docker-healthcheck.sh
RUN chmod +x /home/radixdlt/docker-healthcheck.sh
RUN chmod +x /home/radixdlt/docker-healthcheck.sh
21 changes: 17 additions & 4 deletions radixdlt-core/docker/config/default.config.envsubst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ faucet.enable=$RADIXDLT_ENABLE_FAUCET

db.location=$RADIXDLT_DB_LOCATION

node_api.port=$RADIXDLT_NODE_API_PORT
client_api.enable=$RADIXDLT_ENABLE_CLIENT_API
client_api.port=$RADIXDLT_CLIENT_API_PORT
universe_api.enable=$RADIXDLT_UNIVERSE_ENABLE
api.node.port=$RADIXDLT_NODE_API_PORT
api.archive.port=$RADIXDLT_ARCHIVE_API_PORT

api.archive.enable=$RADIXDLT_ARCHIVE_API_ENABLE
api.account.enable=$RADIXDLT_ACCOUNT_API_ENABLE
api.chaos.enable=$RADIXDLT_CHAOS_API_ENABLE
api.construction.enable=$RADIXDLT_CONSTRUCT_API_ENABLE
api.faucet.enable=$RADIXDLT_FAUCET_API_ENABLE
api.health.enable=$RADIXDLT_HEALTH_API_ENABLE
api.metrics.enable=$RADIXDLT_METRICS_API_ENABLE
api.system.enable=$RADIXDLT_SYSTEM_API_ENABLE
api.validation.enable=$RADIXDLT_VALIDATION_API_ENABLE
api.version.enable=$RADIXDLT_VERSION_API_ENABLE
api.universe.enable=$RADIXDLT_UNIVERSE_API_ENABLE

api.node.bind.address=$RADIXDLT_HTTP_NODE_BIND_ADDRESS
api.archive.bind.address=$RADIXDLT_HTTP_ARCHIVE_BIND_ADDRESS
16 changes: 12 additions & 4 deletions radixdlt-core/docker/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ services:
RADIXDLT_ENABLE_CLIENT_API: "true"
RADIXDLT_CLIENT_API_PORT: 8080
RADIXDLT_NODE_API_PORT: 3333
RADIXDLT_CHAOS_ENABLE: "true"
RADIXDLT_ENABLE_FAUCET: "true"
RADIXDLT_UNIVERSE_ENABLE: "true"
RADIXDLT_ARCHIVE_API_ENABLE: "true"
RADIXDLT_ACCOUNT_API_ENABLE: "true"
RADIXDLT_METRICS_API_ENABLE: "true"
RADIXDLT_CONSTRUCT_API_ENABLE: "true"
RADIXDLT_CHAOS_API_ENABLE: "true"
RADIXDLT_FAUCET_API_ENABLE: "true"
RADIXDLT_HEALTH_API_ENABLE: "true"
RADIXDLT_SYSTEM_API_ENABLE: "true"
RADIXDLT_VALIDATION_API_ENABLE: "true"
RADIXDLT_VERSION_API_ENABLE: "true"
RADIXDLT_UNIVERSE_API_ENABLE: "true"
RADIXDLT_UNIVERSE: ${RADIXDLT_UNIVERSE}
JAVA_OPTS: -server -Xmx512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:+AlwaysPreTouch -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStoreType=jks -Djava.security.egd=file:/dev/urandom -Dcom.sun.management.jmxremote.port=9011 -Dcom.sun.management.jmxremote.rmi.port=9011 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=core -agentlib:jdwp=transport=dt_socket,address=50505,suspend=n,server=y
JAVA_OPTS: -server -Xmx512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:+AlwaysPreTouch -Dguice_bytecode_gen_option=DISABLED -Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStoreType=jks -Djava.security.egd=file:/dev/urandom -Dcom.sun.management.jmxremote.port=9011 -Dcom.sun.management.jmxremote.rmi.port=9011 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=core -agentlib:jdwp=transport=dt_socket,address=50505,suspend=n,server=y
image: radixdlt/radixdlt-core:develop
labels:
com.radixdlt.roles: "core"
Expand Down
2 changes: 1 addition & 1 deletion radixdlt-core/docker/scripts/docker-healthcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -e

# API is the last to come up when starting and node endpoint is always enabled on docker
exec curl http://$HOSTNAME:$RADIXDLT_NODE_API_PORT/node >/dev/null && netstat -ltn | grep -c 30000
exec curl http://$HOSTNAME:$RADIXDLT_NODE_API_PORT/health >/dev/null && netstat -ltn | grep -c 30000
207 changes: 207 additions & 0 deletions radixdlt-core/docs/api-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# New API

This document describes reorganization and proposed changes to the whole node API.

## Old APIs as of May 10, 2021
<details>
<summary>Click to see detailed information about endpoints and configuration</summary>

### HTTP APIs

| Path | Method | Description | Comments |
| --- | --- | --- | --- |
| /node/parse | POST | Transaction blob parsing | No sensitive information |
| /node/txn | POST | Retrieve transaction blob | No sensitive information |
| /node/submit | POST | Submit transaction blob | No sensitive information |
| /node/execute | POST | Submit transaction using node private key to for signature | __Security sensitive__ |
| /node | GET | Get information about node - public address and balance | No sensitive information |
| /node/validator | POST | Get information about node as a validator - stakes, registration status, etc.| No sensitive information |
| /system/config | GET | Get active configuration parameters for consensus, mempool and RE | No sensitive information |
| /system/info | GET | Get system information - public key, agent, supported protocols | No sensitive information |
| /system/checkpoints | GET | Get genesis txn and proof | No sensitive information |
| /system/proof | GET | Get current proof | No sensitive information |
| /system/epochproof | GET | Get epoch proof | No sensitive information |
| /system/peers | GET | Get information about peer nodes | No sensitive information |
| /universe.json | GET | Get Radix Universe | No sensitive information |

### JSON-RPC APIs

| Method | Description |
| --- | --- |
| radix.nativeToken | Information about native token |
| radix.tokenInfo | Information about specified token |
| radix.tokenBalances | Token balances at specified account |
| radix.stakePositions | Stakes made from specified account |
| radix.unstakePositions | Pending unstakes for specified account|
| radix.transactionHistory | Transaction history for specified account |
| radix.lookupTransaction | Lookup specified transaction |
| radix.statusOfTransaction | Status of specified transaction |
| radix.buildTransaction | Assemble transaction given specified actions and optional message |
| radix.finalizeTransaction | Send signed transaction and receive transaction ID|
| radix.submitTransaction | Submit signed transaction for processing by network|
| radix.validators | Get list of validators |
| radix.lookupValidator | Get information about specified validator |
| radix.networkId | Get network ID |
| radix.networkTransactionThroughput | Get number of transactions per second |
| radix.networkTransactionDemand | Get average number of transactions waiting for processing in mempool |

### Configuration Options

Following configuration options control which APIs are enabled at the node:

| Configuration Option | Description |
| --- | --- |
| client_api.enable | Enables JSON-RPC APIs|
| universe_api.enable | Enables `/universe.json` API |

</details>

## New Organization of APIs

The general approach to the API organization is based on the following considerations:
- Most methods are spread across five endpoints:
- `/archive` (formerly `/rpc`) - read-only methods, requiring an archive node
- `/construction` - methods which support building and submitting transactions, which can be enabled by either archive or full nodes
- `/account` supports methods to fetch your associated account info, and a one-step method to build, sign, and submit a transaction
- `/validation` - read-only methods which provide same information as available today via all `/node/*` endpoints
- `/system` - read-only methods which provide same information as available today via all `/system/*` endpoints

- The `/system`, `/account` and `/validation` endpoints are expected to be protected by firewall and/or require authentication/etc.
(similar requirements/setup as we have today)

### HTTP APIs
Majority of the HTTP APIs are replaced with JSON-RPC counterparts. Remaining and new HTTP endpoints:

| Path | Method | Description |
| --- | --- | --- |
| /health | GET | Returns node status (see below) |
| /version | GET | Returns detailed information about software version and build info |
| /universe.json | GET | Get Radix Universe. Used during setup and configuration of the node but if possible looking to remove |
| /metrics | GET | Returns metrics in the [Prometheus text format](https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format). |

Node health status has following format: `{"status" : "<status>" }`, where `<status>` is one of the following:
- BOOTING - node is booting and not ready to accept requests
- SYNCING - node is catching up the network
- UP - node is in sync with consensus
- STALLED - node is out of sync and not trying to sync with network, but network is still available.
- OUT_OF_SYNC - node is out of sync and does not get updates from network (for example, connection to network is lost).

All listed above endpoints are expected to be protected by firewall and/or require authentication/etc.

### JSON-RPC APIs

#### /archive
| Method Name | Old Method Name |
| --- | --- |
| tokens.get_native_token | radix.nativeToken |
| tokens.get_info | radix.tokenInfo |
| account.get_balances | radix.tokenBalances |
| account.get_stake_positions | radix.stakePositions |
| account.get_unstake_positions | radix.unstakePositions |
| account.get_transaction_history | radix.transactionHistory |
| transactions.lookup_transaction | radix.lookupTransaction |
| transactions.get_transaction_status | radix.statusOfTransaction |
| validators.get_next_epoch_set | radix.validators |
| validators.lookup_validator | radix.lookupValidator |
| network.get_id | radix.networkId |
| network.get_throughput | radix.networkTransactionThroughput |
| network.get_demand | radix.networkTransactionDemand |

#### /construction
| Method Name | Old Method Name | Notes |
| --- | --- | --- |
| construction.build_transaction | radix.buildTransaction | Constructs transaction blob for given actions and message |
| construction.finalize_transaction | radix.finalizeTransaction | Calculates transaction ID for given transaction blob, signature and public key |
| construction.submit_transaction | radix.submitTransaction | Submits finalized transaction |

#### /account

| Method | Description |
| --- | --- |
| account.get_info | Your account's address and balances (not node ID) |
| account.submit_transaction_single_step | Equivalent to `transaction.build + transaction.finalize + transaction.submit` methods except does not require keys and signs transaction with node private key. Input parameters are same as for `transaction.build`, output is formatted as for `transaction.submit` method |

#### /system

| Method | Description |
| --- | --- |
| api.get_configuration | Get active configuration parameters for api |
| api.get_data | Get data for api |
| bft.get_configuration | Get active configuration parameters for consensus |
| bft.get_data | Get data for consensus |
| mempool.get_configuration | Get active configuration parameters for mempool |
| mempool.get_data | Get data for mempool |
| ledger.get_latest_proof | Get the latest known ledger proof |
| ledger.get_latest_epoch_proof | Get the latest known ledger epoch proof |
| radix_engine.get_configuration | Get active configuration parameters for radix engine |
| radix_engine.get_data | Get data for radix engine |
| sync.get_configuration | Get active configuration parameters for sync |
| sync.get_data | Get data for sync |
| networking.get_configuration | Get active configuration parameters for networking |
| networking.get_peers | Get information about known peer nodes |
| networking.get_data | Get data for networking |
| checkpoints.get_checkpoints | Get genesis txn and proof |

#### /validation

| Method | Description |
| --- | --- |
| validation.get_node_info | Get information about node as a validator - stakes, registration status, etc.
| validation.get_current_epoch_data | Get information about the current set of validators
| validation.get_next_epoch_data | Get information about the next set of validators


### New Actions
In order to make JSON RPC API complete, we need to support following actions while building transactions:

| Action | Description |
| --- | --- |
| BurnTokens | Burn tokens |
| MintTokens | Mint tokens |
| RegisterValidator | Register node as validator |
| UnregisterValidator | Unregister node as validator |
| CreateFixedSupplyToken | Create fixed supply token |
| CreateMutableSupplyToken | Create mutable supply token |

### Removal of `/node` HTTP endpoints
Note that all the wallet-style actions which were previously done via HTTP
under `/node` are now supported via Actions under the normal transaction
building flow. Node runners can use the `account.submit_transaction_single_step` method
under `/account` in order to build, sign, and submit these transactions in a
single step. This also includes validator registration.

### New Configuration Options

The following configuration options control which APIs are enabled at the node:

| Configuration Option | Path | Default if not configured
| --- | --- | --- |
| api.archive.enable | `/archive` | Disabled
| api.construction.enable | `/construction` | Disabled
| api.metrics.enable | `/metrics` | Disabled
| api.system.enable | `/system` | Disabled
| api.account.enable | `/account` | Disabled
| api.validation.enable | `/validation` | Disabled
| api.universe.enable | `/universe.json` | Disabled
| api.health.enable | `/health` | Enabled
| api.version.enable | `/version` | Enabled

### Endpoint Layout
Depending on configuration we may run up to two HTTP servers.

First server (referred below as _ARCHIVE_) is used to serve client API and related endpoints and by default
is bound to port 8080.

Second server (referred below as _NODE_) is used to serve remaining endpoints and by default is bound to prt 3333.

| Endpoint | Server
| --- | --- |
| `/archive` | ARCHIVE
| `/construction` | ARCHIVE
| `/metrics` | NODE
| `/system` | NODE
| `/account` | NODE
| `/validation` | NODE
| `/universe.json` | NODE
| `/health` | NODE
| `/version` | NODE
5 changes: 5 additions & 0 deletions radixdlt-core/radixdlt/default.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
#Fri Jun 18 13:44:36 CEST 2021
cp.port=8080
universe=v2djcmVhdG9yWCIBAsm/OqGKaQ3cgMWH4pVS0MyICRv0ht248s3H7yjgPmLOa2Rlc2NyaXB0aW9udlRoZSBSYWRpeCBkZXYgVW5pdmVyc2VnZ2VuZXNpc4JZA8gBv2FpkEIBAlhZAb9jcnJpWDkGL0pGZ1YycVM4M0pVYXpiWWZSYkpEMWR4b2ZHcktLeHRpRUFtRzk4RHNCendVTEFnOVNvQy9YUkRic3pzcmFkaXgucGFydGljbGVzLnJyaf9CAQFYkwG/YWFYIQX//////////////////////////////////////////2FnWCEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFjcnJpWDkGL0pGZ1YycVM4M0pVYXpiWWZSYkpEMWR4b2ZHcktLeHRpRUFtRzk4RHNCendVTEFnOVNvQy9YUkRic3pjdV90/0IBAVjnAb9hZHNSYWRpeCBOYXRpdmUgVG9rZW5zYWdYIQUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWFpeDRodHRwczovL2Fzc2V0cy5yYWRpeGRsdC5jb20vaWNvbnMvaWNvbi14cmQtMzJ4MzIucG5nYW5kUmFkc2NycmlYOQYvSkZnVjJxUzgzSlVhemJZZlJiSkQxZHhvZkdyS0t4dGlFQW1HOThEc0J6d1VMQWc5U29DL1hSRGJzemVtX3RrbmN1cmx4HGh0dHBzOi8vdG9rZW5zLnJhZGl4ZGx0LmNvbS//QgEAQQFCAQFYvQG/YWFYIQUAAAAAAAAAAAAAAAAAAAAAAAAAAAM7Ljyf0IA86AAAAGFnWCEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhbfVhb1gnBAICyb86oYppDdyAxYfilVLQzIgJG/SG3bjyzcfvKOA+Ys6FHC6LYXJYOQYvSkZnVjJxUzgzSlVhemJZZlJiSkQxZHhvZkdyS0t4dGlFQW1HOThEc0J6d1VMQWc5U29DL1hSRGJzemF0/0IBBEUBAAAAAUIBAViTAb9hYVghBf///////////////////////////MTRw2Avf8MX////YWdYIQUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWNycmlYOQYvSkZnVjJxUzgzSlVhemJZZlJiSkQxZHhvZkdyS0t4dGlFQW1HOThEc0J6d1VMQWc5U29DL1hSRGJzemN1X3T/QgEAQQFhc79hclghAePQPnf7hdQecg4DUw5M8xQtw7XV/8XTDoLXDlaAM07HYXNYIQEC1yXO+WcbDFLEKDU6VaSlF12hYd89AaG44UkWJzJOg2JzenZjcnlwdG8uZWNkc2Ffc2lnbmF0dXJlYXYB/2JzemRhdG9t/1g9Ab9haYZCAQJRAb9hZQBic3phc2F0AGF2AP9CAQFRAb9hZQFic3phc2F0AGF2AP9CAQBBAWJzemRhdG9t/2VtYWdpYzoxV//9ZG5hbWVsUmFkaXggRGV2bmV0ZHBvcnQZdTBrc2lnbmF0dXJlLnJYIQESw8m8rbKZUZvKDpCULEg61VJDrzEtTutxhlW6U1riAGtzaWduYXR1cmUuc1ghAS2hvdLqQfaUqitEMoEMY5rASE4IjdzR3lNtwnFZms99a3NpZ25hdHVyZS52AGJzem5yYWRpeC51bml2ZXJzZWl0aW1lc3RhbXAbAAWbCMH6QABkdHlwZQL/
ntp.pool=pool.ntp.org
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import com.radixdlt.consensus.Proposal;
import com.radixdlt.consensus.Vote;
import com.radixdlt.consensus.bft.BFTNode;
import com.radixdlt.consensus.sync.GetVerticesResponse;
import com.radixdlt.integration.distributed.simulation.network.LatencyProvider;
import com.radixdlt.integration.distributed.simulation.network.RandomLatencyProvider;
import com.radixdlt.integration.distributed.simulation.network.SimulationNetwork;
import com.radixdlt.integration.distributed.simulation.network.LatencyProvider;
import com.radixdlt.qualifier.LatencyProviderBase;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand All @@ -38,7 +39,7 @@ public final class NetworkLatencies {
public static Module fixed(int latency) {
return new AbstractModule() {
@Provides
@Named("base")
@LatencyProviderBase
LatencyProvider base() {
return msg -> latency;
}
Expand All @@ -53,7 +54,7 @@ public static Module random(int minLatency, int maxLatency) {
return new AbstractModule() {
@Provides
@Singleton
@Named("base")
@LatencyProviderBase
LatencyProvider base() {
return new RandomLatencyProvider(minLatency, maxLatency);
}
Expand All @@ -64,7 +65,7 @@ public static Module oneSlowProposalSender(int inBoundsLatency, int outOfBoundsL
return new AbstractModule() {
@Provides
@Singleton
@Named("base")
@LatencyProviderBase
LatencyProvider base(ImmutableList<BFTNode> nodes) {
return msg -> {
if ((msg.getSender().equals(nodes.get(0)) || msg.getReceiver().equals(nodes.get(0)))
Expand All @@ -84,7 +85,7 @@ public static Module oneOutOfBounds(int inBoundsLatency, int outOfBoundsLatency)
return new AbstractModule() {
@Provides
@Singleton
@Named("base")
@LatencyProviderBase
LatencyProvider base(ImmutableList<BFTNode> nodes) {
Map<BFTNode, Integer> nodeLatencies = IntStream.range(0, nodes.size())
.boxed()
Expand Down
Loading

0 comments on commit 4e96308

Please sign in to comment.