Skip to content
This repository was archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul D Handy committed Sep 23, 2017
1 parent 7bdd83f commit 9e6a570
Show file tree
Hide file tree
Showing 43 changed files with 52,290 additions and 22,581 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ WORKDIR /iri
COPY . /iri
RUN mvn clean package

FROM java:jre-alpine
FROM openjdk:jre-slim
WORKDIR /iri
COPY --from=builder /iri/target/iri-1.3.2.2.jar iri.jar
COPY --from=builder /iri/target/iri-1.4.0.jar iri.jar
COPY logback.xml /iri
VOLUME /iri

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## IOTA

This is the main branch of the main IRI repository, as this is a IOTA reference implementation that is utilized specifically for the we have setup. It is a complete [[IOTA]](http://iota.org/) Node with a JSON-REST HTTP interface.
This is the main branch of the main IRI repository, as this is a IOTA reference implementation that is utilized specifically for what we have setup. It is a complete [[IOTA]](http://iota.org/) Node with a JSON-REST HTTP interface.

It allows to connect easily using java directly to a local or a remote [[IOTA node]](http://learn.iota.org/).

* **Latest release:** 1.3.2.2 Release
* **Latest release:** 1.4.0 Release
* **License:** GPLv3

# How to get started
Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.4.0
- Snapshot at milestone 217000
- Added Curl-P-81 and moved most operations to it (see https://github.com/iotaledger/kerl)
- Adjusted transaction structure - added attachment timestamp
- Adjusted PoW implementation to set attachment timestamp
- Disable Curl signatures for snapshot addresses

1.3.2.2
- Reorganized milestone rescan to improve update time

Expand Down
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.iota</groupId>
<artifactId>iri</artifactId>
<name>IRI</name>
<version>1.3.2.2</version>
<version>1.4.0</version>
<description>IOTA Reference Implementation</description>
<scm>
<connection>scm:git:git://github.com/iotaledger/iri.git</connection>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.iota</groupId>
<artifactId>iri</artifactId>
<version>1.3.2.2</version>
<version>1.4.0</version>

<name>IRI</name>
<description>IOTA Reference Implementation</description>
Expand Down
48 changes: 26 additions & 22 deletions src/main/java/com/iota/iri/BundleValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.iota.iri.controllers.BundleViewModel;
import com.iota.iri.hash.Curl;
import com.iota.iri.hash.ISS;
import com.iota.iri.hash.Sponge;
import com.iota.iri.hash.SpongeFactory;
import com.iota.iri.model.Hash;
import com.iota.iri.controllers.TransactionViewModel;
Expand All @@ -27,13 +28,29 @@ public static List<List<TransactionViewModel>> validate(Tangle tangle, Hash hash
final long lastIndex = transactionViewModel.lastIndex();
long bundleValue = 0;
int i = 0;
final Sponge curlInstance = SpongeFactory.create(SpongeFactory.Mode.KERL);
final Sponge addressInstance = SpongeFactory.create(SpongeFactory.Mode.KERL);

final int[] addressTrits = new int[TransactionViewModel.ADDRESS_TRINARY_SIZE];
final int[] bundleHashTrits = new int[TransactionViewModel.BUNDLE_TRINARY_SIZE];

MAIN_LOOP:
while (true) {

instanceTransactionViewModels.add(transactionViewModel);

if (transactionViewModel.getCurrentIndex() != i || transactionViewModel.lastIndex() != lastIndex
|| ((bundleValue += transactionViewModel.value()) < -TransactionViewModel.SUPPLY || bundleValue > TransactionViewModel.SUPPLY)) {

if (
transactionViewModel.getCurrentIndex() != i
|| transactionViewModel.lastIndex() != lastIndex
|| ((bundleValue = Math.addExact(bundleValue, transactionViewModel.value())) < -TransactionViewModel.SUPPLY
|| bundleValue > TransactionViewModel.SUPPLY)
) {
instanceTransactionViewModels.get(0).setValidity(tangle, -1);
break;
}

if (transactionViewModel.value() != 0 && transactionViewModel.getAddressHash().trits()[Curl.HASH_LENGTH - 1] != 0) {
instanceTransactionViewModels.get(0).setValidity(tangle, -1);
break;
}
Expand All @@ -43,14 +60,11 @@ public static List<List<TransactionViewModel>> validate(Tangle tangle, Hash hash
if (bundleValue == 0) {

if (instanceTransactionViewModels.get(0).getValidity() == 0) {

final Curl bundleHash = SpongeFactory.create(SpongeFactory.Mode.KERL);
curlInstance.reset();
for (final TransactionViewModel transactionViewModel2 : instanceTransactionViewModels) {
bundleHash.absorb(transactionViewModel2.trits(), TransactionViewModel.ESSENCE_TRINARY_OFFSET, TransactionViewModel.ESSENCE_TRINARY_SIZE);
curlInstance.absorb(transactionViewModel2.trits(), TransactionViewModel.ESSENCE_TRINARY_OFFSET, TransactionViewModel.ESSENCE_TRINARY_SIZE);
}
final int[] bundleHashTrits = new int[TransactionViewModel.BUNDLE_TRINARY_SIZE];
bundleHash.squeeze(bundleHashTrits, 0, bundleHashTrits.length);
Hash h = new Hash(bundleHashTrits);
curlInstance.squeeze(bundleHashTrits, 0, bundleHashTrits.length);
if (instanceTransactionViewModels.get(0).getBundleHash().equals(new Hash(Converter.bytes(bundleHashTrits, 0, TransactionViewModel.BUNDLE_TRINARY_SIZE)))) {

final int[] normalizedBundle = ISS.normalizedBundle(bundleHashTrits);
Expand All @@ -59,29 +73,19 @@ public static List<List<TransactionViewModel>> validate(Tangle tangle, Hash hash

transactionViewModel = instanceTransactionViewModels.get(j);
if (transactionViewModel.value() < 0) { // let's recreate the address of the transactionViewModel.
final SpongeFactory.Mode addressMode;
if(Snapshot.initialState.containsKey(transactionViewModel.getAddressHash())) {
addressMode = SpongeFactory.Mode.CURL;
} else {
addressMode = SpongeFactory.Mode.KERL;
}

final Curl address = SpongeFactory.create(addressMode);
addressInstance.reset();
int offset = 0;
do {

address.absorb(
ISS.digest(addressMode, Arrays.copyOfRange(normalizedBundle, offset % (Curl.HASH_LENGTH / Converter.NUMBER_OF_TRITS_IN_A_TRYTE), offset = (offset + ISS.NUMBER_OF_FRAGMENT_CHUNKS - 1) % (Curl.HASH_LENGTH / Converter.NUMBER_OF_TRITS_IN_A_TRYTE) + 1),
addressInstance.absorb(
ISS.digest(SpongeFactory.Mode.KERL, Arrays.copyOfRange(normalizedBundle, offset % (Curl.HASH_LENGTH / Converter.NUMBER_OF_TRITS_IN_A_TRYTE), offset = (offset + ISS.NUMBER_OF_FRAGMENT_CHUNKS - 1) % (Curl.HASH_LENGTH / Converter.NUMBER_OF_TRITS_IN_A_TRYTE) + 1),
Arrays.copyOfRange(instanceTransactionViewModels.get(j).trits(), TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_OFFSET,
TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_OFFSET + TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_SIZE)),
0, Curl.HASH_LENGTH);

} while (++j < instanceTransactionViewModels.size()
&& instanceTransactionViewModels.get(j).getAddressHash().equals(transactionViewModel.getAddressHash())
&& instanceTransactionViewModels.get(j).value() == 0);

final int[] addressTrits = new int[TransactionViewModel.ADDRESS_TRINARY_SIZE];
address.squeeze(addressTrits, 0, addressTrits.length);
addressInstance.squeeze(addressTrits, 0, addressTrits.length);
//if (!Arrays.equals(Converter.bytes(addressTrits, 0, TransactionViewModel.ADDRESS_TRINARY_SIZE), transactionViewModel.getAddress().getHash().bytes())) {
if (! transactionViewModel.getAddressHash().equals(new Hash(Converter.bytes(addressTrits, 0, TransactionViewModel.ADDRESS_TRINARY_SIZE)))) {
instanceTransactionViewModels.get(0).setValidity(tangle, -1);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/iota/iri/IRI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class IRI {

public static final String MAINNET_NAME = "IRI";
public static final String TESTNET_NAME = "IRI Testnet";
public static final String VERSION = "1.3.2.2";
public static final String VERSION = "1.4.0";
public static Iota iota;
public static API api;
public static IXI ixi;
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/iota/iri/Iota.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ public void init() throws Exception {
if (configuration.booling(Configuration.DefaultConfSettings.RESCAN_DB)){
rescan_db();
}
boolean revalidate = configuration.booling(Configuration.DefaultConfSettings.REVALIDATE);

milestone.init(SpongeFactory.Mode.CURL, ledgerValidator, configuration.booling(Configuration.DefaultConfSettings.REVALIDATE));
if (revalidate) {
tangle.clearColumn(com.iota.iri.model.Milestone.class);
tangle.clearColumn(com.iota.iri.model.StateDiff.class);
tangle.clearMetadata(com.iota.iri.model.Transaction.class);
}
milestone.init(SpongeFactory.Mode.CURLP27, ledgerValidator, revalidate);
transactionValidator.init(testnet, configuration.integer(Configuration.DefaultConfSettings.MAINNET_MWM), configuration.integer(Configuration.DefaultConfSettings.TESTNET_MWM));
tipsManager.init();
transactionRequester.init(configuration.doubling(Configuration.DefaultConfSettings.P_REMOVE_REQUEST.name()));
Expand Down
22 changes: 5 additions & 17 deletions src/main/java/com/iota/iri/LedgerValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private Map<Hash,Long> getLatestDiff(Hash tip, int latestSnapshotIndex, boolean
final Hash address = bundleTransactionViewModel.getAddressHash();
final Long value = state.get(address);
state.put(address, value == null ? bundleTransactionViewModel.value()
: (value + bundleTransactionViewModel.value()));
: Math.addExact(value, bundleTransactionViewModel.value()));
}
}

Expand Down Expand Up @@ -205,8 +205,8 @@ private void updateConsistentHashes(Hash tip, int index) throws Exception {
* either reaches the latest solid subtangle milestone, or until it reaches an inconsistent milestone.
* @throws Exception
*/
protected void init(boolean revalidate) throws Exception {
MilestoneViewModel latestConsistentMilestone = buildSnapshot(revalidate);
protected void init() throws Exception {
MilestoneViewModel latestConsistentMilestone = buildSnapshot();
if(latestConsistentMilestone != null) {
milestone.latestSolidSubtangleMilestone = latestConsistentMilestone.getHash();
milestone.latestSolidSubtangleMilestoneIndex = latestConsistentMilestone.index();
Expand All @@ -227,7 +227,7 @@ public boolean isApproved(Hash hash) {
* @return the most recent consistent milestone with a confirmed.
* @throws Exception
*/
private MilestoneViewModel buildSnapshot(boolean revalidate) throws Exception {
private MilestoneViewModel buildSnapshot() throws Exception {
MilestoneViewModel consistentMilestone = null;
synchronized (latestSnapshotSyncObject) {
Snapshot updatedSnapshot = latestSnapshot.patch(new HashMap<>(), 0);
Expand All @@ -236,22 +236,10 @@ private MilestoneViewModel buildSnapshot(boolean revalidate) throws Exception {
while (snapshotMilestone != null) {
stateDiffViewModel = StateDiffViewModel.load(tangle, snapshotMilestone.getHash());
updatedSnapshot = updatedSnapshot.patch(stateDiffViewModel.getDiff(), snapshotMilestone.index());
if (!revalidate && updatedSnapshot.isConsistent()) {
if (updatedSnapshot.isConsistent()) {
consistentMilestone = snapshotMilestone;
latestSnapshot.merge(updatedSnapshot);
snapshotMilestone = snapshotMilestone.nextWithSnapshot(tangle);
} else {
snapshotMilestone = MilestoneViewModel.first(tangle);
do {
StateDiffViewModel.load(tangle, snapshotMilestone.getHash()).delete(tangle);
} while ((snapshotMilestone = snapshotMilestone.nextWithSnapshot(tangle)) != null);
TransactionViewModel transactionViewModel = TransactionViewModel.first(tangle);
transactionViewModel.updateSolid(false);
transactionViewModel.setSnapshot(tangle, 0);
while((transactionViewModel = transactionViewModel.next(tangle)) != null) {
transactionViewModel.updateSolid(false);
transactionViewModel.setSnapshot(tangle, 0);
}
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/iota/iri/Milestone.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Milestone {
public Hash latestMilestone = Hash.NULL_HASH;
public Hash latestSolidSubtangleMilestone = latestMilestone;

public static final int MILESTONE_START_INDEX = 151000;
public static final int MILESTONE_START_INDEX = 217000;
private static final int NUMBER_OF_KEYS_IN_A_MILESTONE = 20;

public int latestMilestoneIndex = MILESTONE_START_INDEX;
Expand All @@ -65,10 +65,6 @@ public Milestone(final Tangle tangle,
public void init(final SpongeFactory.Mode mode, final LedgerValidator ledgerValidator, final boolean revalidate) throws Exception {
this.ledgerValidator = ledgerValidator;
AtomicBoolean ledgerValidatorInitialized = new AtomicBoolean(false);
if (revalidate) {
tangle.clearColumn(com.iota.iri.model.Milestone.class);
tangle.clearColumn(com.iota.iri.model.StateDiff.class);
}
(new Thread(() -> {
while(!ledgerValidatorInitialized.get()) {
try {
Expand Down Expand Up @@ -121,7 +117,7 @@ public void init(final SpongeFactory.Mode mode, final LedgerValidator ledgerVali
(new Thread(() -> {

try {
ledgerValidator.init(revalidate);
ledgerValidator.init();
ledgerValidatorInitialized.set(true);
} catch (Exception e) {
log.error("Error initializing snapshots. Skipping.", e);
Expand Down Expand Up @@ -224,7 +220,7 @@ void updateLatestSolidSubtangleMilestone() throws Exception {
}

static int getIndex(TransactionViewModel transactionViewModel) {
return (int) Converter.longValue(transactionViewModel.trits(), TransactionViewModel.TAG_TRINARY_OFFSET, 15);
return (int) Converter.longValue(transactionViewModel.trits(), TransactionViewModel.OBSOLETE_TAG_TRINARY_OFFSET, 15);
}

void shutDown() {
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/com/iota/iri/Snapshot.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.iota.iri;
import com.iota.iri.hash.Curl;
import com.iota.iri.hash.ISS;
import com.iota.iri.hash.Sponge;
import com.iota.iri.hash.SpongeFactory;
import com.iota.iri.model.Hash;
import com.iota.iri.controllers.TransactionViewModel;
Expand All @@ -19,7 +20,9 @@

public class Snapshot {
private static final Logger log = LoggerFactory.getLogger(Snapshot.class);
private static String snapshotPubKey = "BRUTUMFFJVCXEPKHZBKBHWDKARQEYCUVSCUUESJWBSSAMHAWRVHZZGROIIOETMWDKRFODD9NMC9TPOWGD";
private static String SNAPSHOT_PUBKEY = "ETSYRXPKSCTJAZIJZDVJTQOILVEPHGV9PHPFLJVUFQRPXGNWPDBAKHCWPPEXPCZDIGPJDQGHVIQHQYQDW";
private static int SNAPSHOT_PUBKEY_DEPTH = 6;
private static int SNAPSHOT_INDEX = 0;

public static final Map<Hash, Long> initialState = new HashMap<>();
public static final Snapshot initialSnapshot;
Expand All @@ -29,7 +32,7 @@ public class Snapshot {
InputStream in = Snapshot.class.getResourceAsStream("/Snapshot.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
Curl curl = SpongeFactory.create(SpongeFactory.Mode.KERL);
Sponge curl = SpongeFactory.create(SpongeFactory.Mode.KERL);
int[] trit_value;
int[] trits = new int[Curl.HASH_LENGTH*3];
try {
Expand All @@ -51,15 +54,19 @@ public class Snapshot {
curl.squeeze(trits, 0, Curl.HASH_LENGTH);
int[] digests = new int[0];
int[] bundle = ISS.normalizedBundle(trits);
int i = 0;
int[] root = null;
int i;
in = Snapshot.class.getResourceAsStream("/Snapshot.sig");
reader = new BufferedReader(new InputStreamReader(in));
while((line = reader.readLine()) != null) {
for(i = 0; i < 3 && (line = reader.readLine()) != null; i++) {
digests = ArrayUtils.addAll(digests, ISS.digest(SpongeFactory.Mode.KERL, Arrays.copyOfRange(bundle, i*ISS.NORMALIZED_FRAGMENT_LENGTH, (i+1)*ISS.NORMALIZED_FRAGMENT_LENGTH), Converter.trits(line)));
i++;
}

if(!Arrays.equals(Converter.trits(snapshotPubKey), ISS.address(SpongeFactory.Mode.KERL, digests))) {
if((line = reader.readLine()) != null) {
root = ISS.getMerkleRoot(SpongeFactory.Mode.CURLP81, ISS.address(SpongeFactory.Mode.KERL, digests), Converter.trits(line), 0, SNAPSHOT_INDEX, SNAPSHOT_PUBKEY_DEPTH);
} else {
root = ISS.address(SpongeFactory.Mode.KERL, digests);
}
if(!Arrays.equals(Converter.trits(SNAPSHOT_PUBKEY), root)) {
throw new RuntimeException("Snapshot signature failed.");
}
}
Expand Down
Loading

0 comments on commit 9e6a570

Please sign in to comment.