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

Commit

Permalink
Merge pull request #193 from HelixNetwork/dev
Browse files Browse the repository at this point in the history
1.0.0-release
  • Loading branch information
oracle58 authored Oct 1, 2019
2 parents c516264 + 688547d commit f4cdcdb
Show file tree
Hide file tree
Showing 31 changed files with 469 additions and 373 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 1.0.0
- Added new implementation of `TransactionTestUtils.buildTransaction()`
- Added test for DAGHelper
- Added test for SpentAddressesProvider
- Update SpentAddressesProviderImpl for multi-testing
- Uniform random tip selection with config param `TIPSELECTION_ALPHA` = 0
- Allow `X-HELIX-API-Version` header in CORS
- Fix for logging-issue #180
- The config param "port" was called, API_PORT in the APIConfig class, but PORT in the BasePendulumConfig class. To remain consistent, all instances of PORT when API_PORT was meant have been updated.
- Fixed The logback-save.xml producing some unnecessary messages at the start of a node.

## 0.6.9
- Set `GENESIS_TIME` to [mainnet-genesis-time](https://github.com/HelixNetwork/helix-dao-data#genesis-time)
- Update Undertow from 1.4.6 to 2.0.26
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Pendulum

Pendulum is a quorum based [Tangle](https://github.com/iotaledger/iri/) implementation designed towards reliable timekeeping and high-throughput messaging.
- **Latest release:** 0.6.9 pre-release
- **Latest release:** 1.0.0 pre-release
- **License:** GPLv3

Special thanks to all of the [IOTA Contributors](https://github.com/iotaledger/iri/graphs/contributors)!
Expand Down Expand Up @@ -83,13 +83,13 @@ server {
proxy_hide_header Access-Control-Allow-Origin;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-HELIX-API-Version,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-HELIX-API-Version,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>net.pendulum</groupId>
<artifactId>pendulum</artifactId>

<version>0.6.9</version>
<version>1.0.0</version>

<name>Pendulum</name>
<description>Pendulum Protocol</description>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/helix/pendulum/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Main {

public static final String MAINNET_NAME = "Pendulum";
public static final String TESTNET_NAME = "Pendulum Testnet";
public static final String VERSION = "0.6.9";
public static final String VERSION = "1.0.0";

/**
* The entry point of Pendulum.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/helix/pendulum/TransactionValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void runValidation(TransactionViewModel transactionViewModel, final int m
}

int weightMagnitude = transactionViewModel.weightMagnitude;
if((weightMagnitude < minWeightMagnitude) && !config.isPoWDisabled()) {
if((weightMagnitude < minWeightMagnitude)) {
throw new IllegalStateException("Invalid transaction hash");
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/helix/pendulum/conf/APIConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
public interface APIConfig extends Config {
/**
* @return {@value Descriptions#PORT}
* @return {@value Descriptions#API_PORT}
*/
int getPort();
int getApiPort();

/**
* @return {@value Descriptions#API_HOST}
Expand Down Expand Up @@ -63,7 +63,7 @@ public interface APIConfig extends Config {
String getResourcePath();

interface Descriptions {
String PORT = "The port that will be used by the API.";
String API_PORT = "The port that will be used by the API.";
String API_HOST = "The host on which the API will listen to. Set to 0.0.0.0 to accept any host.";
String REMOTE_LIMIT_API = "Commands that should be ignored by API.";
String REMOTE_TRUSTED_API_HOSTS = "Open the API interface to defined hosts. You can specify multiple hosts in a comma separated list \"--remote-trusted-api-hosts 192.168.0.55,10.0.0.10\". You must also provide the \"--remote\" parameter. Warning: \"--remote-limit-api\" will have no effect for these hosts.";
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/helix/pendulum/conf/BasePendulumConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class BasePendulumConfig implements PendulumConfig {
private boolean help;

//API
protected int port = Defaults.API_PORT;
protected int apiPort = Defaults.API_PORT;
protected String apiHost = Defaults.API_HOST;
protected List<String> remoteLimitApi = Defaults.REMOTE_LIMIT_API;
protected List<InetAddress> remoteTrustedApiHosts = Defaults.REMOTE_LIMIT_API_HOSTS;
Expand Down Expand Up @@ -170,14 +170,14 @@ public void setHelp(boolean help) {
}

@Override
public int getPort() {
return port;
public int getApiPort() {
return apiPort;
}

@JsonProperty
@Parameter(names = {"--port", "-p"}, description = APIConfig.Descriptions.PORT)
public void setPort(int port) {
this.port = port;
@Parameter(names = {"--api-port", "-p"}, description = APIConfig.Descriptions.API_PORT)
public void setPort(int apiPort) {
this.apiPort = apiPort;
}

@Override
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/net/helix/pendulum/network/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void preProcessReceivedData(byte[] receivedData, SocketAddress senderAddr
TransactionViewModel receivedTransactionViewModel = new TransactionViewModel(receivedData, TransactionHash.calculate(receivedData, TransactionViewModel.SIZE, SpongeFactory.create(SpongeFactory.Mode.S256)));
receivedTransactionHash = receivedTransactionViewModel.getHash();
transactionValidator.runValidation(receivedTransactionViewModel, transactionValidator.getMinWeightMagnitude());

log.debug("Received_txvm = {} {}", receivedTransactionHash.toString(), senderAddress.toString());
synchronized (recentSeenBytes) {
recentSeenBytes.put(digest, receivedTransactionHash);
}
Expand Down Expand Up @@ -471,6 +471,7 @@ public void processReceivedData(TransactionViewModel receivedTransactionViewMode
} catch (Exception e) {
log.error("Error updating transactions.", e);
}
log.debug("Stored_txhash = {}", receivedTransactionViewModel.getHash().toString());
neighbor.incNewTransactions();
broadcast(receivedTransactionViewModel);

Expand Down Expand Up @@ -539,9 +540,7 @@ public void replyToRequest(Hash requestedHash, Neighbor neighbor) {
} else {
//find requested txvm
try {
//transactionViewModel = TransactionViewModel.find(Arrays.copyOf(requestedHash.bytes(), TransactionRequester.REQUEST_HASH_SIZE));
transactionViewModel = TransactionViewModel.fromHash(tangle, HashFactory.TRANSACTION.create(requestedHash.bytes(), 0, reqHashSize));
//log.debug("Requested Hash: " + requestedHash + " \nFound: " + transactionViewModel.getHash()); TODO: remove unused code
} catch (Exception e) {
log.error("Error while searching for transaction.", e);
}
Expand Down Expand Up @@ -602,7 +601,7 @@ public void sendPacket(DatagramPacket sendingPacket, TransactionViewModel transa
}
if (sendLimit >= 0 && sendPacketsCounter.get() > sendLimit) {
//if exceeded limit - don't send
//log.info("exceeded limit - don't send - {}",sendPacketsCounter.get());
log.debug("Send limit exceeded! Send_packet_counter = {}", sendPacketsCounter.get());
return;
}

Expand Down
42 changes: 18 additions & 24 deletions src/main/java/net/helix/pendulum/service/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,31 +588,33 @@ private synchronized AbstractResponse getTipsStatement() throws Exception {
**/

public void storeTransactionsStatement(final List<String> txString) throws Exception {
final List<TransactionViewModel> elements = new LinkedList<>();
byte[] txBytes;
for (final String hex : txString) {
//validate all tx
txBytes = Hex.decode(hex);
final TransactionViewModel transactionViewModel = transactionValidator.validateBytes(txBytes,
transactionValidator.getMinWeightMagnitude());
elements.add(transactionViewModel);
}

final List<TransactionViewModel> elements = addValidTxvmToList(txString);
for (final TransactionViewModel transactionViewModel : elements) {
//store transactions
if(transactionViewModel.store(tangle, snapshotProvider.getInitialSnapshot())) { // v
if(transactionViewModel.store(tangle, snapshotProvider.getInitialSnapshot())) {
transactionViewModel.setArrivalTime(System.currentTimeMillis() / 1000L);
if (transactionViewModel.isMilestoneBundle(tangle) == null) {
transactionValidator.updateStatus(transactionViewModel);
}
transactionViewModel.updateSender("local");
transactionViewModel.update(tangle, snapshotProvider.getInitialSnapshot(), "sender");
//System.out.println("published tx: " + transactionViewModel.getHash());
}

}
}

private LinkedList addValidTxvmToList(List<String> txString){
final List<TransactionViewModel> elements = new LinkedList<>();
byte[] txBytes;
for (final String hex : txString) {
//validate all tx
txBytes = Hex.decode(hex);
final TransactionViewModel transactionViewModel = transactionValidator.validateBytes(
txBytes, transactionValidator.getMinWeightMagnitude()
);
elements.add(transactionViewModel);
}
return (LinkedList) elements;
}
/**
* Interrupts and completely aborts the <tt>attachToTangle</tt> process.
*
Expand Down Expand Up @@ -986,15 +988,7 @@ private HashSet<String> getParameterAsSet(Map<String, Object> request, String pa
* @param txString the list of transaction bytes to broadcast
**/
public void broadcastTransactionsStatement(final List<String> txString) {
final List<TransactionViewModel> elements = new LinkedList<>();
byte[] txBytes;
for (final String hex : txString) {
//validate all tx
txBytes = Hex.decode(hex);
// TODO something possibly going wrong here.
final TransactionViewModel transactionViewModel = transactionValidator.validateBytes(txBytes, transactionValidator.getMinWeightMagnitude());
elements.add(transactionViewModel);
}
final List<TransactionViewModel> elements = addValidTxvmToList(txString);
for (final TransactionViewModel transactionViewModel : elements) {
//push first in line to broadcast
transactionViewModel.weightMagnitude = Sha3.HASH_LENGTH;
Expand Down Expand Up @@ -1155,7 +1149,6 @@ public static void incEllapsedTimePoW(long ellapsedTime) {

public synchronized List<String> attachToTangleStatement(final Hash trunkTransaction, final Hash branchTransaction, int minWeightMagnitude, final List<String> txs) {
final List<TransactionViewModel> transactionViewModels = new LinkedList<>();

Hash prevTransaction = null;
miner = new GreedyMiner();

Expand Down Expand Up @@ -1191,7 +1184,7 @@ public synchronized List<String> attachToTangleStatement(final Hash trunkTransac
System.arraycopy(Serializer.serialize(MAX_TIMESTAMP_VALUE),0,txBytes,TransactionViewModel.ATTACHMENT_TIMESTAMP_UPPER_BOUND_OFFSET,
TransactionViewModel.ATTACHMENT_TIMESTAMP_UPPER_BOUND_SIZE);

if (!configuration.isPoWDisabled() && !miner.mine(txBytes, minWeightMagnitude, 4)) {
if (!miner.mine(txBytes, minWeightMagnitude, 4)) {
transactionViewModels.clear();
break;
}
Expand Down Expand Up @@ -1524,6 +1517,7 @@ public void publishMilestone(final String address, final int minWeightMagnitude,

int currentRoundIndex = milestoneTracker.getCurrentRoundIndex();
List<Hash> confirmedTips = getConfirmedTips();
confirmedTips.forEach(tx->log.info("Confirmed_tx = {}", tx.toString()));
byte[] tipsBytes = Hex.decode(confirmedTips.stream().map(Hash::toString).collect(Collectors.joining()));

List<Hash> txToApprove = addMilestoneReferences(confirmedTips, currentRoundIndex);
Expand Down
60 changes: 0 additions & 60 deletions src/main/java/net/helix/pendulum/service/Graphstream.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public RestEasy() {
*/
public RestEasy(APIConfig configuration) {
maxBodyLength = configuration.getMaxBodyLength();
port = configuration.getPort();
port = configuration.getApiPort();
apiHost = configuration.getApiHost();

remoteAuth = configuration.getRemoteAuth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
*/
public class SpentAddressesProviderImpl implements SpentAddressesProvider {

private RocksDBPersistenceProvider rocksDBPersistenceProvider;
//@VisibleForTesting
public RocksDBPersistenceProvider rocksDBPersistenceProvider;

private SnapshotConfig config;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.helix.pendulum.service.tipselection;

import java.util.Map;

import net.helix.pendulum.model.Hash;
import net.helix.pendulum.utils.collections.interfaces.UnIterableMap;


/**
* Selects an {@code entryPoint} for tip selection.
* <p>
* this point is used as the starting point for {@link Walker#walk(Hash, UnIterableMap, WalkValidator)}
* this point is used as the starting point for {@link Walker#walk(Hash, Map, WalkValidator)}
* </p>
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.helix.pendulum.service.tipselection;

import java.util.Map;

import net.helix.pendulum.model.Hash;
import net.helix.pendulum.model.HashId;
import net.helix.pendulum.utils.collections.interfaces.UnIterableMap;


/**
* Calculates the rating for a sub graph
Expand All @@ -22,5 +24,5 @@ public interface RatingCalculator {
* @throws Exception If DB fails to retrieve transactions
*/

UnIterableMap<HashId, Integer> calculate(Hash entryPoint) throws Exception;
Map<Hash, Integer> calculate(Hash entryPoint) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.helix.pendulum.service.tipselection;

import java.util.Map;

import net.helix.pendulum.model.Hash;
import net.helix.pendulum.model.HashId;
import net.helix.pendulum.utils.collections.interfaces.UnIterableMap;


/**
* Walks the tangle from an entry point towards tips
Expand All @@ -24,5 +26,5 @@ public interface Walker {
* @return Transaction hash of tip.
* @throws Exception If DB fails to retrieve transactions
*/
Hash walk(Hash entryPoint, UnIterableMap<HashId, Integer> ratings, WalkValidator walkValidator) throws Exception;
Hash walk(Hash entryPoint, Map<Hash, Integer> ratings, WalkValidator walkValidator) throws Exception;
}
Loading

0 comments on commit f4cdcdb

Please sign in to comment.