Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.5.8
- Cleanup Converter
- Refactor hexString() (#83)
- Refactor hbytes: new param name, "txs", for `attachToTangle`, `storeTransaction`, `broadcastTransaction`.

# 0.5.7
- Added APIIntegrationTest
- Added SnapshotMockUtils
Expand Down
88 changes: 41 additions & 47 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,53 @@
# Docker
The Dockerfile included in this repo builds a working SBX docker container whilst trying to stay the least opinionated as possible. This allows system administrators the option to deploy and configure SBX based on their own individual circumstances and needs.
To run a Helix docker container you have two options:

When building SBX via the Dockerfile provided, Docker 17.05 minimum is required, due to the use of Docker build stages. During docker build, these are the stages invoked:
- java: installs Oracle Java on top of Ubuntu
- build: installs Maven on top of the java stage and compiles SBX
- final container: copies the SBX jar file using the java stage as base
- Build your own image using the provided dockerfile
- Run container from provided dockerhub image
Both options require that you have [docker](https://www.docker.com/get-started) (>=17.05) installed on your machine.

The built container assumes the WORKDIR inside the container is /sbx/data: this means that the database directory will be written inside that directory by default. If a system administrator wants to retain the database across restarts, it is his/her job to mount a docker volume in the right folder.
The provided dockerfile only contains the bare minimum of configuration parameters, as to enable higher degree of customization in terms of configuration and deployment to the node operator.

The docker conatiner supports the env variables to configure advanced options. These variables can be set but are not required to run SBX.
Build stages:
1. java: installs Oracle Java on top of Ubuntu
2. build: installs Maven on top of the java stage and compiles Helix
3. final container: copies the helix jar file using the java stage as base

`JAVA_OPTIONS`: these are the java options to pass right after the java command. It must not contain -Xms nor -Xmx. Defaults to a safe value
`JAVA_MIN_MEMORY`: the value of -Xms option. Defaults to 2G
`JAVA_MAX_MEMORY`: the value of -Xmx option. Defaults to 4G
`DOCKER_SBX_JAR_PATH`: defaults to /sbx/target/sbx*.jar as pushed by the Dockerfile. This is useful if custom SBX binaries want to be executed and the default path needs to be overridden
`DOCKER_SBX_REMOTE_LIMIT_API`: defaults to "interruptAttachToTangle, attachToTangle, addNeighbors, removeNeighbors, getNeighbors"
`DOCKER_SBX_MONITORING_API_PORT_ENABLE`: defaults to 0. If set to 1, a socat on port 14266 directed to 127.0.0.1:DOCKER_SBX_MONITORING_API_PORT_DESTINATION will be open in order to allow all API calls regardless of the DOCKER_SBX_REMOTE_LIMIT_API setting. This is useful to give access to restricted API calls to local tools and still denying access to restricted API calls to the internet. It is highly recommended to use this option together with docker networks (docker run --net).
The built container assumes the WORKDIR inside the container is /helix/data: this means that the database directory will be written inside that directory by default. If a system administrator wants to retain the database across restarts, it is his/her job to mount a docker volume in the right folder

The container entry point is a shell script that performs few additional steps before launching SBX:
- verifies if `DOCKER_SBX_MONITORING_API_PORT_ENABLE` is set to 1
- launches SBX with all parameters passed as desired
## Getting Started
This section will cover usage information for the provided docker container.

It is important to note that other than --remote and --remote-limit-api "$DOCKER_SBX_REMOTE_LIMIT_API", neither the entrypoint nor the Dockerfile are aware of any SBX configuration option. This is to not tie the Dockerfile and its container to a specific set of SBX options. Instead, this contain still allows the use of an INI file or command line options. Please refer to the SBX documentation to learn what are the allowed options at command line and via the INI file.
### Prerequisities
In order to run this container you'll need docker installed.

**At the time of writing, SBX requires -p to be passed either via INI or via command line. The entrypoint of this docker container does not do that for you.**
* [Windows](https://docs.docker.com/windows/started)
* [OS X](https://docs.docker.com/mac/started/)
* [Linux](https://docs.docker.com/linux/started/)

Here is a systemd unit example you can use with this Docker container. This is just an example and customisation is possible and recommended. In this example the docker network sbx must be created and the paths /mnt/sbx/conf and /mnt/sbx/data are used on the docker host to serve respectively the neighbors file and the data directory. No INI files are used in this example, instead options are passed via command line options, such as --testnet and --zmq-enabled.
### Example

```shell
sudo docker run helixnetwork/helix-1.0:latest -p 8085
```
[Unit]
Description=SBX
After=docker.service
Requires=docker.service

[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker rm %n
ExecStart=/usr/bin/docker run \
--name %n \
--hostname sbx \
--net=sbx \
-v /mnt/sbx/conf:/sbx/conf \
-v /mnt/sbx/data:/sbx/data \
-p 14265:14265 \
-p 15600:15600 \
-p 14600:14600/udp \
helixnetwork/sbx:v1.5.0 \
-p 14700 \
--zmq-enabled \
--testnet

ExecStop=/usr/bin/docker stop %n
ExecReload=/usr/bin/docker restart %n

[Install]
WantedBy=multi-user.target
This will run the helix with its API listening on port 8085, with no peers and a fresh database.
The helix docker container is configured to read data from /helix/data. Use the -v option of the docker run command to mount volumes so to have persistent data.
You can also pass more command line options to the docker run command and those will be passed to Helix. Please refer to the [README.md]() for all command line and ini options.


### Load options from INI
If you want to use a `<conf_name>`.ini file with the docker container, supposing it's stored under /path/to/conf/iri.ini on your docker host, then pass -v /path/to/conf:/iri/conf and add -c /iri/conf/iri.ini as docker run arguments. So for example the docker run command above would become:

```shell
docker run -v /path/to/conf:/helix/conf -v /path/to/data:/helix/data helixnetwork/helix-1.0:latest -p 8085 -c /helix/conf/<conf_name>.ini
```

## Security

Helix-1.0 should be run as a non-administrative user with no root privileges!
An unprivileged user can be created on the host and the UID passed to the docker command (e.g. --user 1001). Directories that are mounted to the container from the host should be owned by this user.
In addition the --cap-drop=ALL passed to docker restricts process capabilities and adheres to the principle of least privilege. See https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities for more information.





20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
FROM helixnetwork/base16.04:latest as builder
MAINTAINER Dario Tietz

WORKDIR /testnet-1.0
COPY . /testnet-1.0
WORKDIR /helix-1.0
COPY . /helix-1.0
RUN mvn clean package

FROM openjdk:jre-slim
WORKDIR /testnet-1.0
WORKDIR /helix-1.0
COPY --from=builder /testnet-1.0/target/helix*.jar helix*.jar
VOLUME /testnet-1.0
VOLUME /helix-1.0

EXPOSE 14700/udp
EXPOSE 14700
EXPOSE 14600/udp

ENTRYPOINT ["/usr/bin/java", "-XX:+DisableAttachMechanism", "-Xmx8g", "-Xms256m", "-Dlogback.configurationFile=/testnet-1.0/conf/logback.xml", "-Djava.net.preferIPv4Stack=true", "-jar", "helix*.jar", "-p", "14700", "-u", "14600", "--remote", "$@"]
EXPOSE 8085
EXPOSE 4100/udp
EXPOSE 5100/tcp
EXPOSE 5556/tcp

WORKDIR /helix/data

ENTRYPOINT ["/usr/bin/java", "-XX:+DisableAttachMechanism", "-Xmx8g", "-Xms256m", "-Dlogback.configurationFile=/helix-1.0/conf/logback.xml", "-Djava.net.preferIPv4Stack=true", "-jar", "helix*.jar", "-p", "8085", "$@"]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@

# Helix-1.0
This is the 1.0 implementation of the Helix Protocol based on [**IRI**](https://github.com/iotaledger/iri/).
* **Latest release:** 0.5.7 pre-release
* **Latest release:** 0.5.8 pre-release
* **License:** GPLv3

## Developers

- Please see the [CONTRIBUTING.md](https://github.com/HelixNetwork/helix-1.0/blob/dev/CONTRIBUTING.md) and [STYLEGUIDE.md](https://github.com/HelixNetwork/helix-1.0/blob/dev/STYLEGUIDE.md) if you wish to contribute to this repository!
- Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
- Please read the [helix-1.0-specifications](https://github.com/HelixNetwork/helix-specs/blob/master/specs/helix-1.0.md) before contributing.
- Disable proof of work in the course of testing by passing `--pow-disabled` flag.

## Installing
Make sure you have [**Maven**](https://maven.apache.org/) and [**Java 8**](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) installed on your computer.
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

<groupId>net.helix</groupId>
<artifactId>helix</artifactId>
<version>0.5.7</version>
<version>0.5.8</version>

<name>Helix</name>
<description>Helix-1.0</description>

<scm>
<url>https://github.com/helixnetwork/testnet-1.0/</url>
<connection>scm:git:git://github.com/helixnetwork/testnet-1.0.git</connection>
<developerConnection>scm:git:git@github.com/helixnetwork/testnet-1.0.git</developerConnection>
<url>https://github.com/helixnetwork/helix-1.0/</url>
<connection>scm:git:git://github.com/helixnetwork/helix-1.0.git</connection>
<developerConnection>scm:git:git@github.com/helixnetwork/helix-1.0.git</developerConnection>
</scm>

<properties>
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/net/helix/hlx/Converter.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/net/helix/hlx/HLX.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class HLX {

public static final String MAINNET_NAME = "HLX";
public static final String TESTNET_NAME = "HLX Testnet";
public static final String VERSION = "0.5.7";
public static final String VERSION = "0.5.8";

/**
* The entry point of the helix sandbox.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/helix/hlx/conf/APIConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public interface APIConfig extends Config {
int getMaxRequestsList();

/**
* @return {@value Descriptions#MAX_GET_BYTES}
* @return {@value Descriptions#MAX_GET_TRANSACTION_STRINGS}
*/
int getMaxBytes();
int getMaxTransactionStrings();

/**
* @return {@value Descriptions#MAX_BODY_LENGTH}
Expand All @@ -65,7 +65,7 @@ interface Descriptions {
String REMOTE_AUTH = "A string in the form of <user>:<password>. Used to access the API";
String MAX_FIND_TRANSACTIONS = "The maximal number of transactions that may be returned by the \"findTransactions\" API call. If the number of transactions found exceeds this number an error will be returned.";
String MAX_REQUESTS_LIST = "The maximal number of parameters one can place in an API call. If the number parameters exceeds this number an error will be returned";
String MAX_GET_BYTES = "The maximal number of bytes that may be returned by the \"getHBytes\" API call. If the number of transactions found exceeds this number an error will be returned.";
String MAX_GET_TRANSACTION_STRINGS = "The maximal number of transaction strings that may be returned by the \"getTransactionStrings\" API call. If the number of transactions found exceeds this number an error will be returned.";
String MAX_BODY_LENGTH = "The maximal number of characters the body of an API call may hold. If a request body length exceeds this number an error will be returned.";
String REMOTE = "Open the API interface to any host. Equivalent to \"--api-host 0.0.0.0\"";
String IS_POW_DISABLED = "If pow is disabled the node will not require a valid nonce.";
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/net/helix/hlx/conf/BaseHelixConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class BaseHelixConfig implements HelixConfig {
protected List<InetAddress> remoteTrustedApiHosts = Defaults.REMOTE_LIMIT_API_HOSTS;
protected int maxFindTransactions = Defaults.MAX_FIND_TRANSACTIONS;
protected int maxRequestsList = Defaults.MAX_REQUESTS_LIST;
protected int maxGetBytes = Defaults.MAX_GET_BYTES;
protected int maxGetTransactionStrings = Defaults.MAX_GET_TRANSACTION_STRINGS;
protected int maxBodyLength = Defaults.MAX_BODY_LENGTH;
protected String remoteAuth = Defaults.REMOTE_AUTH;
protected boolean powDisabled = Defaults.IS_POW_DISABLED;
Expand Down Expand Up @@ -239,14 +239,14 @@ protected void setMaxRequestsList(int maxRequestsList) {
}

@Override
public int getMaxBytes() {
return maxGetBytes;
public int getMaxTransactionStrings() {
return maxGetTransactionStrings;
}

@JsonProperty
@Parameter(names = {"--max-get-bytes"}, description = APIConfig.Descriptions.MAX_GET_BYTES)
protected void setMaxGetBytes(int maxGetBytes) {
this.maxGetBytes = maxGetBytes;
@Parameter(names = {"--max-get-transaction-strings"}, description = APIConfig.Descriptions.MAX_GET_TRANSACTION_STRINGS)
protected void setMaxGetTransactionStrings(int maxGetTransactionStrings) {
this.maxGetTransactionStrings = maxGetTransactionStrings;
}

@Override
Expand Down Expand Up @@ -865,7 +865,7 @@ public interface Defaults {
List<InetAddress> REMOTE_LIMIT_API_HOSTS = HelixUtils.createImmutableList(REMOTE_LIMIT_API_DEFAULT_HOST);
int MAX_FIND_TRANSACTIONS = 100_000;
int MAX_REQUESTS_LIST = 1_000;
int MAX_GET_BYTES = 10_000;
int MAX_GET_TRANSACTION_STRINGS = 10_000;
int MAX_BODY_LENGTH = 1_000_000;
String REMOTE_AUTH = "";
boolean IS_POW_DISABLED = false;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/helix/hlx/crypto/Winternitz.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static byte[] digest(SpongeFactory.Mode mode, final byte[] bundleFragment
* Deterministically Normalize the bundle hash. <br>
* <ol>
* <li>map each byte in {@code bundle} to base 16 {@code [-13 , 13]} </li>
* <li>sum all mapped hbytes together</li>
* <li>sum all mapped bytes together</li>
* <li>if sum != 0, start inc/dec each byte till sum equals 0</li>
* </ol>
*
Expand Down
25 changes: 8 additions & 17 deletions src/main/java/net/helix/hlx/model/AbstractHash.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.helix.hlx.model;

import net.helix.hlx.utils.Converter;
import net.helix.hlx.model.persistables.Transaction;
import net.helix.hlx.model.safe.ByteSafe;
import net.helix.hlx.storage.Indexable;

import org.bouncycastle.util.encoders.Hex;

import java.io.Serializable;
Expand Down Expand Up @@ -112,9 +114,11 @@ public byte[] bytes() {
return safe.getData();
}

public String hexString() {
return Hex.toHexString(bytes());
}
/**
* Convert to hex string
* @return <code> string </code> string in hex representation
*/
public String toString() { return Hex.toHexString(bytes()); }

/**
* Reading byte array. @see #fullRead(byte[])
Expand Down Expand Up @@ -146,23 +150,10 @@ public int compareTo(Indexable indexable) {
if (this.equals(hash)) {
return 0;
}
long diff = bytesToLong(hash.bytes(), 0) - bytesToLong(bytes(), 0);
long diff = Converter.bytesToLong(hash.bytes(), 0) - Converter.bytesToLong(bytes(), 0);
if (Math.abs(diff) > Integer.MAX_VALUE) {
return diff > 0L ? Integer.MAX_VALUE : Integer.MIN_VALUE + 1;
}
return (int) diff;
}

public static long bytesToLong(byte[] array, int offset) {
return
((long)(array[offset] & 0xff) << 56) |
((long)(array[offset+1] & 0xff) << 48) |
((long)(array[offset+2] & 0xff) << 40) |
((long)(array[offset+3] & 0xff) << 32) |
((long)(array[offset+4] & 0xff) << 24) |
((long)(array[offset+5] & 0xff) << 16) |
((long)(array[offset+6] & 0xff) << 8) |
((long)(array[offset+7] & 0xff));
}

}
8 changes: 1 addition & 7 deletions src/main/java/net/helix/hlx/model/Hash.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Hash is an implementation of the Serializable, Indexable and HashID interface.
* The model class contains a hash <code> Hash </code>, the size of the hash, lock
* and the inner classes <code> ByteSafe </code> and <code> TritSafe </code>.
* and the inner classes <code> ByteSafe </code>
*/
public interface Hash extends Indexable, HashId {
Hash NULL_HASH = HashFactory.TRANSACTION.create(new byte[Sha3.HASH_LENGTH]);
Expand All @@ -24,12 +24,6 @@ public interface Hash extends Indexable, HashId {
*/
public byte[] bytes();

/**
* The data of this hash as hexString
* @return the hexString
*/
public String hexString();

/**
* The amount of zeros this hash has on the end.
* Defines the weightMagnitude for a transaction.
Expand Down
Loading