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

Feat: Fixes + Improvements for IRI that are required for local snapshots #1095

Merged
merged 11 commits into from Nov 1, 2018
20 changes: 10 additions & 10 deletions src/main/java/com/iota/iri/controllers/TransactionViewModel.java
Expand Up @@ -413,34 +413,34 @@ public void setSnapshot(Tangle tangle, final int index) throws Exception {
}

/**
* This method is the setter for the isSnapshot flag of a transaction.
* This method is the setter for the isMilestone flag of a transaction.
*
* It gets automatically called by the "Latest Milestone Tracker" and marks transactions that represent a milestone
* accordingly. It first checks if the value has actually changed and then issues a database update.
*
* @param tangle Tangle instance which acts as a database interface
* @param isSnapshot true if the transaction is a snapshot and false otherwise
* @param isMilestone true if the transaction is a milestone and false otherwise
* @throws Exception if something goes wrong while saving the changes to the database
*/
public void isSnapshot(Tangle tangle, final boolean isSnapshot) throws Exception {
if (isSnapshot != transaction.isSnapshot) {
transaction.isSnapshot = isSnapshot;
update(tangle, "isSnapshot");
public void isMilestone(Tangle tangle, final boolean isMilestone) throws Exception {
if (isMilestone != transaction.isMilestone) {
transaction.isMilestone = isMilestone;
update(tangle, "isMilestone");
}
}

/**
* This method is the getter for the isSnapshot flag of a transaction.
* This method is the getter for the isMilestone flag of a transaction.
*
* The isSnapshot flag indicates if the transaction is a coordinator issued milestone. It allows us to differentiate
* The isMilestone flag indicates if the transaction is a coordinator issued milestone. It allows us to differentiate
* the two types of transactions (normal transactions / milestones) very fast and efficiently without issuing
* further database queries or even full verifications of the signature. If it is set to true one can for example
* use the snapshotIndex() method to retrieve the corresponding MilestoneViewModel object.
*
* @return true if the transaction is a milestone and false otherwise
*/
public boolean isSnapshot() {
return transaction.isSnapshot;
public boolean isMilestone() {
return transaction.isMilestone;
hmoog marked this conversation as resolved.
Show resolved Hide resolved
}

public long getHeight() {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/iota/iri/model/persistables/Transaction.java
Expand Up @@ -17,9 +17,9 @@ public class Transaction implements Persistable {
public static final int IS_SOLID_BITMASK = 0b01;

/**
* Bitmask used to access and store the isSnapshot flag.
* Bitmask used to access and store the isMilestone flag.
*/
public static final int IS_SNAPSHOT_BITMASK = 0b10;
public static final int IS_MILESTONE_BITMASK = 0b10;

public byte[] bytes;

Expand Down Expand Up @@ -49,7 +49,7 @@ public class Transaction implements Persistable {
/**
* This flag indicates if the transaction is a coordinator issued milestone.
*/
public boolean isSnapshot = false;
public boolean isMilestone = false;

public long height = 0;
public String sender = "";
Expand Down Expand Up @@ -100,7 +100,7 @@ public byte[] metadata() {
// encode booleans in 1 byte
byte flags = 0;
flags |= solid ? IS_SOLID_BITMASK : 0;
flags |= isSnapshot ? IS_SNAPSHOT_BITMASK : 0;
flags |= isMilestone ? IS_MILESTONE_BITMASK : 0;
buffer.put(flags);

buffer.put(Serializer.serialize(snapshot));
Expand Down Expand Up @@ -155,7 +155,7 @@ public void readMetadata(byte[] bytes) {

// decode the boolean byte by checking the bitmasks
solid = (bytes[i] & IS_SOLID_BITMASK) != 0;
isSnapshot = (bytes[i] & IS_SNAPSHOT_BITMASK) != 0;
isMilestone = (bytes[i] & IS_MILESTONE_BITMASK) != 0;
i++;

snapshot = Serializer.getInteger(bytes, i);
Expand Down