Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add core API server in Rust #91

Merged
merged 18 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import com.radixdlt.crypto.exception.KeyStoreException;
import com.radixdlt.networks.Network;
import com.radixdlt.p2p.RadixNodeUri;
import com.radixdlt.utils.FreePortFinder;
import java.io.File;
import java.io.IOException;
import java.net.URI;
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/java/com/radixdlt/networks/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

package com.radixdlt.networks;

import com.radixdlt.crypto.ECKeyPair;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
Expand Down Expand Up @@ -98,7 +99,8 @@ public enum Network {
LOCALSIMULATOR(242 /* 0xF1 */, "simulator", "sim", GenesisSource.fromConfiguration);

// For the Radix Shell to provide a default
public static final String DefaultHexGenesisTransaction = "01";
public static final String DefaultHexGenesisTransaction =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused - why does this say Transaction if it's generating a public key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the genesis from an integer (num of validators), to a list of validators pub keys a while back

ECKeyPair.generateNew().getPublicKey().toHex();

private final int intId;
private final byte byteId;
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ ospackage() {
}
def stateManagerBuildType = project.property("rustBinaryBuildType")

from("${project(':state-manager').projectDir}/target/${target}/${stateManagerBuildType}/libstatemanager.so") {
from("${project(':state-manager').projectDir}/target/${target}/${stateManagerBuildType}/libcorerust.so") {
into "/usr/lib/jni/"
}

Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/com/radixdlt/RadixNodeApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.radixdlt.api.CoreApiServer;
import com.radixdlt.consensus.bft.BFTNode;
import com.radixdlt.consensus.bft.Self;
import com.radixdlt.consensus.safety.BerkeleySafetyStateStore;
Expand Down Expand Up @@ -221,9 +222,14 @@ public static void start(RuntimeProperties properties) {
log.error("Cannot start p2p server", e);
}

// Start the system API server
final var undertow = injector.getInstance(Undertow.class);
undertow.start();

// Start the core API server
final var coreApiServer = injector.getInstance(CoreApiServer.class);
coreApiServer.start();

final var consensusRunner = moduleRunners.get(Runners.CONSENSUS);
consensusRunner.start();

Expand Down
27 changes: 20 additions & 7 deletions core/src/main/java/com/radixdlt/RadixNodeModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import com.google.common.collect.Streams;
import com.google.inject.AbstractModule;
import com.radixdlt.api.ApiModule;
import com.radixdlt.api.CoreApiServerModule;
import com.radixdlt.consensus.MockedConsensusRecoveryModule;
import com.radixdlt.consensus.bft.*;
import com.radixdlt.consensus.epoch.EpochsConsensusModule;
Expand All @@ -90,10 +91,12 @@
import com.radixdlt.rev2.modules.MockedPersistenceStoreModule;
import com.radixdlt.rev2.modules.REv2StateComputerModule;
import com.radixdlt.rev2.modules.REv2StateManagerModule;
import com.radixdlt.statemanager.CoreApiServerConfig;
import com.radixdlt.store.DatabasePropertiesModule;
import com.radixdlt.sync.SyncConfig;
import com.radixdlt.utils.BooleanUtils;
import com.radixdlt.utils.IOUtils;
import com.radixdlt.utils.UInt32;
import com.radixdlt.utils.properties.RuntimeProperties;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -104,8 +107,11 @@

/** Module which manages everything in a single node */
public final class RadixNodeModule extends AbstractModule {
private static final int DEFAULT_CORE_PORT = 3333;
private static final String DEFAULT_BIND_ADDRESS = "0.0.0.0";
private static final int DEFAULT_CORE_API_PORT = 3333;
private static final int DEFAULT_SYSTEM_API_PORT = 3334;
private static final String DEFAULT_CORE_API_BIND_ADDRESS = "0.0.0.0";
private static final String DEFAULT_SYSTEM_API_BIND_ADDRESS = "127.0.0.1";

private static final Logger log = LogManager.getLogger();

private final RuntimeProperties properties;
Expand Down Expand Up @@ -184,6 +190,14 @@ protected void configure() {
install(new MockedPersistenceStoreModule());
install(new REv2StateComputerModule());

// Core API server
final var coreApiBindAddress =
properties.get("api.core.bind_address", DEFAULT_CORE_API_BIND_ADDRESS);
final var coreApiPort = properties.get("api.core.port", DEFAULT_CORE_API_PORT);
final var coreApiServerConfig =
new CoreApiServerConfig(coreApiBindAddress, UInt32.fromNonNegativeInt(coreApiPort));
install(new CoreApiServerModule(coreApiServerConfig));

// Storage
install(new DatabasePropertiesModule());
// install(new PersistenceModule());
Expand Down Expand Up @@ -226,11 +240,10 @@ protected void configure() {
install(new P2PModule(properties));

// API
var bindAddress = properties.get("api.bind.address", DEFAULT_BIND_ADDRESS);
var port = properties.get("api.port", DEFAULT_CORE_PORT);
var enableTransactions = properties.get("api.transactions.enable", false);
var enableSign = properties.get("api.sign.enable", false);
install(new ApiModule(bindAddress, port, enableTransactions, enableSign));
final var systemApiBindAddress =
properties.get("api.system.bind_address", DEFAULT_SYSTEM_API_BIND_ADDRESS);
final var systemApiPort = properties.get("api.system.port", DEFAULT_SYSTEM_API_PORT);
install(new ApiModule(systemApiBindAddress, systemApiPort));

// Capabilities
var capabilitiesLedgerSyncEnabled =
Expand Down
21 changes: 9 additions & 12 deletions core/src/main/java/com/radixdlt/api/ApiModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.radixdlt.api.common.HandlerRoute;
import com.radixdlt.api.core.CoreApiModule;
import com.radixdlt.api.system.SystemApiModule;
import io.undertow.Handlers;
import io.undertow.Undertow;
Expand All @@ -83,22 +82,17 @@ public final class ApiModule extends AbstractModule {
Runtime.getRuntime().availableProcessors() * 8; // same as workerThreads = ioThreads * 8
private static final int QUEUE_SIZE = 2000;

private final int port;
private final String bindAddress;
private final boolean enableTransactions;
private final boolean enableSign;
private final String systemApiBindAddress;
private final int systemApiPort;

public ApiModule(String bindAddress, int port, boolean enableTransactions, boolean enableSign) {
this.bindAddress = bindAddress;
this.port = port;
this.enableTransactions = enableTransactions;
this.enableSign = enableSign;
public ApiModule(String systemApiBindAddress, int systemApiPort) {
this.systemApiBindAddress = systemApiBindAddress;
this.systemApiPort = systemApiPort;
}

@Override
public void configure() {
install(new SystemApiModule());
install(new CoreApiModule(enableTransactions, enableSign));
}

private static void fallbackHandler(HttpServerExchange exchange) {
Expand Down Expand Up @@ -136,6 +130,9 @@ public Undertow undertow(Map<HandlerRoute, HttpHandler> handlers) {
new RequestLimitingHandler(
MAXIMUM_CONCURRENT_REQUESTS, QUEUE_SIZE, configureRoutes(handlers));

return Undertow.builder().addHttpListener(port, bindAddress).setHandler(handler).build();
return Undertow.builder()
.addHttpListener(systemApiPort, systemApiBindAddress)
.setHandler(handler)
.build();
}
}
99 changes: 0 additions & 99 deletions core/src/main/java/com/radixdlt/api/core/CoreApiModule.java

This file was deleted.

Loading