Skip to content

Commit 5dfa5c8

Browse files
committed
upgrade to v0.4.1
1 parent cf78f14 commit 5dfa5c8

File tree

9 files changed

+31
-13
lines changed

9 files changed

+31
-13
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.qubiclite</groupId>
88
<artifactId>qlite.lib.java</artifactId>
9-
<version>0.4-SNAPSHOT</version>
9+
<version>0.4.1</version>
1010
<packaging>pom</packaging>
1111
<name>QLite</name>
1212
<description>The Qubic Lite library provides a framework to interact with the Qubic Lite protocol by creating, reading and processing qubics.</description>

qlite/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.qubiclite</groupId>
77
<artifactId>qlite.lib.java</artifactId>
8-
<version>0.4-SNAPSHOT</version>
8+
<version>0.4.1</version>
99
</parent>
1010

1111
<name>QLite : Library</name>

qlite/src/main/java/constants/GeneralConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class GeneralConstants {
44

5-
public static final String VERSION = "ql-0.4-SNAPSHOT";
5+
public static final String VERSION = "ql-0.4.1";
66

77
public static final int QLVM_MAX_VALUE_LENGTH = 5000;
88

qlite/src/main/java/oracle/Assembly.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package oracle;
22

33
import jota.model.Transaction;
4+
import oracle.statements.StatementType;
45
import oracle.statements.result.ResultStatement;
56
import oracle.statements.StatementIAMIndex;
67
import qubic.QubicReader;
@@ -21,6 +22,8 @@ public class Assembly {
2122
private final ConsensusBuilder consensusBuilder = new ConsensusBuilder(this);
2223
private int[] ratings;
2324

25+
private int firstEpochIndex = -1; // epoch at which the oracle started monitoring the qubic epochs. necessary to decide when to use InterQubicResultFetcher for own assembly
26+
2427
public Assembly(QubicReader qubicReader) {
2528
this.qubicReader = qubicReader;
2629
}
@@ -43,6 +46,8 @@ public void addOracles(List<String> oracleIDs) {
4346
* TODO optimize fetching by putting all findTransaction() requests into a single API call
4447
* */
4548
public void fetchStatements(List<OracleReader> selection, StatementIAMIndex index) {
49+
if(firstEpochIndex < 0 && index.getStatementType() == StatementType.RESULT_STATEMENT)
50+
firstEpochIndex = index.getEpoch();
4651

4752
String[] addresses = buildStatementAddresses(selection, index);
4853

@@ -126,6 +131,10 @@ public List<OracleReader> selectRandomOracleReaders(int amount) {
126131
return selection;
127132
}
128133

134+
public boolean hasMonitoredEpoch(int epochIndex) {
135+
return firstEpochIndex >= 0 && firstEpochIndex <= epochIndex;
136+
}
137+
129138
/**
130139
* @return amount of oracles in the assembly
131140
* */

qlite/src/main/java/oracle/ConsensusBuilder.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public QuorumBasedResult buildConsensus(List<OracleReader> selection, int epochI
4747
if(epochIndex < 0 || epochIndex > assembly.getQubicReader().lastCompletedEpoch())
4848
return new QuorumBasedResult(0, selection.size(),null);
4949

50-
// TODO decide whether this is okay when using probabilistic quorum
5150
// return result from history if already determined -> increases efficiency
5251
if(alreadyDeterminedQuorumBasedResults.keySet().contains(epochIndex))
5352
return alreadyDeterminedQuorumBasedResults.get(epochIndex);
53+
5454
// empty assembly
5555
if(selection.size() == 0)
5656
return new QuorumBasedResult(0, 0, null);
@@ -63,6 +63,11 @@ public QuorumBasedResult buildConsensus(List<OracleReader> selection, int epochI
6363

6464
return quorumBasedResult;
6565
}
66+
67+
public boolean hasAlreadyDeterminedQuorumBasedResult(int epochIndex) {
68+
return alreadyDeterminedQuorumBasedResults.containsKey(epochIndex);
69+
}
70+
6671
public QuorumBasedResult buildIAMConsensus(IAMIndex index) {
6772
List<IAMReader> selection = new LinkedList<>();
6873
for(OracleReader or : assembly.selectRandomOracleReaders(GeneralConstants.QUORUM_MAX_ORACLE_SELECTION_SIZE))
@@ -90,7 +95,7 @@ private static Map<String, Double> accumulateIAMVotings(List<IAMReader> voters,
9095
private static void addOraclesVoteToVoting(OracleReader oracleReader, int epochIndex, Map<String, Double> voting) {
9196
oracleReader.getHashStatementReader().read(epochIndex);
9297
ResultStatement resultStatement = oracleReader.getResultStatementReader().read(epochIndex);
93-
System.out.println(oracleReader.getID() + " " + (resultStatement != null ? resultStatement.isHashStatementValid() : "_") + " " + epochIndex);
98+
9499
if(resultStatement != null && resultStatement.isHashStatementValid())
95100
addVote(voting, resultStatement.getContent());
96101
}

qlite/src/main/java/oracle/OracleManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public void run() {
3030
}.start();
3131
}
3232

33+
3334
/**
34-
* Runs the oracle life cycle synchronously as opposted to start().
35+
* Runs the oracle life cycle synchronously as opposed to start().
3536
* */
3637
public void startSynchronous() {
3738

qlite/src/main/java/oracle/OracleWriter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class OracleWriter {
3131
private final HastStatementWriter hashStatementWriter;
3232
private final ResultStatementWriter resultStatementWriter;
3333

34-
private int firstEpochIndex = -1; // epoch at which the oracle started monitoring the qubic epochs. necessary to decide when to use InterQubicResultFetcher for own assembly
3534
private String name = "ql-node";
3635
private final LinkedList<OracleListener> oracleListeners = new LinkedList<>();
3736

@@ -66,8 +65,6 @@ public OracleWriter(QubicReader qubicReader, IAMWriter writer) {
6665
* @param epochIndex index of the current epoch
6766
* */
6867
public void doHashStatement(int epochIndex) {
69-
if(firstEpochIndex < 0)
70-
firstEpochIndex = epochIndex;
7168

7269
if(epochIndex > 0)
7370
fetchStatements(new ResultStatementIAMIndex(epochIndex-1));

qlite/src/main/java/qlvm/InterQubicResultFetcher.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ public static QuorumBasedResult fetchResult(QubicReader qubicReader, int epochIn
4949

5050
private static QuorumBasedResult findConsensus(Assembly assembly, int epochIndex) {
5151
List<OracleReader> selection = assembly.selectRandomOracleReaders(GeneralConstants.QUORUM_MAX_ORACLE_SELECTION_SIZE);
52-
assembly.fetchStatements(selection, new HashStatementIAMIndex(epochIndex));
53-
assembly.fetchStatements(selection, new ResultStatementIAMIndex(epochIndex));
52+
if(!assembly.getConsensusBuilder().hasAlreadyDeterminedQuorumBasedResult(epochIndex)) {
53+
assembly.fetchStatements(selection, new HashStatementIAMIndex(epochIndex));
54+
assembly.fetchStatements(selection, new ResultStatementIAMIndex(epochIndex));
55+
}
5456
return assembly.getConsensusBuilder().buildConsensus(selection, epochIndex);
5557
}
5658

qlite/src/main/java/qlvm/functions/qubic/FunctionQubicFetch.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package qlvm.functions.qubic;
22

3+
import oracle.OracleWriter;
34
import qlvm.InterQubicResultFetcher;
45
import oracle.QuorumBasedResult;
56
import qlvm.QLVM;
67
import qlvm.exceptions.runtime.QLRunTimeException;
78
import qlvm.exceptions.runtime.UnknownFunctionException;
89
import qlvm.functions.Function;
10+
import qubic.QubicWriter;
911

1012
public class FunctionQubicFetch extends Function {
1113

@@ -25,8 +27,10 @@ public String call(QLVM qlvm, String[] par) {
2527

2628
QuorumBasedResult qbr;
2729

28-
if(qubicRoot.equals(qlvm.getOracleWriter().getQubicReader().getID()))
29-
qbr = qlvm.getOracleWriter().getAssembly().getConsensusBuilder().buildConsensus(epochIndex);
30+
OracleWriter oracleWriter = qlvm.getOracleWriter();
31+
32+
if(qubicRoot.equals(oracleWriter.getQubicReader().getID()) && oracleWriter.getAssembly().hasMonitoredEpoch(epochIndex))
33+
qbr = oracleWriter.getAssembly().getConsensusBuilder().buildConsensus(epochIndex);
3034
else
3135
qbr = InterQubicResultFetcher.fetchResult(qubicRoot, epochIndex);
3236

0 commit comments

Comments
 (0)