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

Commit

Permalink
Merge pull request #184 from iotaledger/dev-hotfix-randomTip
Browse files Browse the repository at this point in the history
Dev hotfix random tip
  • Loading branch information
alon-e authored Jun 28, 2017
2 parents 78a67a9 + bb72c64 commit b4551a3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/iota/iri/TransactionValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ public void updateStatus(TransactionViewModel transactionViewModel) throws Excep
if(transactionViewModel.getApprovers(tangle).size() == 0) {
tipsViewModel.addTipHash(transactionViewModel.getHash());
}
tipsViewModel.removeTipHash(transactionViewModel.getTrunkTransactionHash());
tipsViewModel.removeTipHash(transactionViewModel.getBranchTransactionHash());

if(quickSetSolid(transactionViewModel)) {
addSolidTransaction(transactionViewModel.getHash());
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/iota/iri/conf/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public enum DefaultConfSettings {
P_DROP_TRANSACTION,
P_SELECT_MILESTONE_CHILD,
P_SEND_MILESTONE,
P_REPLY_RANDOM_TIP,
MAIN_DB, EXPORT, // exports transaction trytes to filesystem
SEND_LIMIT,
MAX_PEERS,
Expand Down Expand Up @@ -75,6 +76,7 @@ public enum DefaultConfSettings {
conf.put(DefaultConfSettings.P_DROP_TRANSACTION.name(), "0.0");
conf.put(DefaultConfSettings.P_SELECT_MILESTONE_CHILD.name(), "0.7");
conf.put(DefaultConfSettings.P_SEND_MILESTONE.name(), "0.02");
conf.put(DefaultConfSettings.P_REPLY_RANDOM_TIP.name(), "0.66");
conf.put(DefaultConfSettings.MAIN_DB.name(), "rocksdb");
conf.put(DefaultConfSettings.EXPORT.name(), "false");
conf.put(DefaultConfSettings.SEND_LIMIT.name(), "-1.0");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/iota/iri/controllers/TipsViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean removeTipHash (Hash hash) throws ExecutionException, InterruptedE

public void setSolid(Hash tip) {
synchronized (sync) {
if(!tips.remove(tip)) {
if(tips.remove(tip)) {
solidTips.add(tip);
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/iota/iri/network/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class Node {
private double P_DROP_TRANSACTION;
private static final SecureRandom rnd = new SecureRandom();
private double P_SEND_MILESTONE;
private double P_REPLY_RANDOM_TIP;


private LRUHashCache recentSeenHashes = new LRUHashCache(5000);
private LRUByteCache recentSeenBytes = new LRUByteCache(15000);
Expand Down Expand Up @@ -108,6 +110,7 @@ public void init() throws Exception {
P_DROP_TRANSACTION = configuration.doubling(Configuration.DefaultConfSettings.P_DROP_TRANSACTION.name());
P_SELECT_MILESTONE = configuration.doubling(Configuration.DefaultConfSettings.P_SELECT_MILESTONE_CHILD.name());
P_SEND_MILESTONE = configuration.doubling(Configuration.DefaultConfSettings.P_SEND_MILESTONE.name());
P_REPLY_RANDOM_TIP = configuration.doubling(Configuration.DefaultConfSettings.P_REPLY_RANDOM_TIP.name());

sendLimit = (long) ( (configuration.doubling(Configuration.DefaultConfSettings.SEND_LIMIT.name()) * 1000000) / (TRANSACTION_PACKET_SIZE * 8) );

Expand Down Expand Up @@ -414,7 +417,7 @@ public void replyToRequest(Hash requestedHash, Neighbor neighbor) {
if (requestedHash.equals(Hash.NULL_HASH)) {
//Random Tip Request
try {
if (transactionRequester.numberOfTransactionsToRequest() > 0) {
if (transactionRequester.numberOfTransactionsToRequest() > 0 && rnd.nextDouble() < P_REPLY_RANDOM_TIP) {
neighbor.incRandomTransactionRequests();
transactionPointer = getRandomTipPointer();
transactionViewModel = TransactionViewModel.fromHash(tangle, transactionPointer);
Expand Down Expand Up @@ -452,10 +455,6 @@ public void replyToRequest(Hash requestedHash, Neighbor neighbor) {

private Hash getRandomTipPointer() throws Exception {
Hash tip = rnd.nextDouble() < P_SEND_MILESTONE? milestone.latestMilestone: tipsViewModel.getRandomSolidTipHash();
if (rnd.nextDouble() < 0.5) {
// for better compatibility with old mainnet nodes. Can be removed once all nodes are migrated.
tip = null;
}
return tip == null ? Hash.NULL_HASH: tip;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/iota/iri/service/TipsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void scanTipsForSolidity() throws Exception {
tipsViewModel.removeTipHash(hash);
isTip = false;
}
if(hash != null && transactionValidator.checkSolidity(hash, false) && isTip) {
if(hash != null && isTip && transactionValidator.checkSolidity(hash, false)) {
//if(hash != null && TransactionViewModel.fromHash(hash).isSolid() && isTip) {
tipsViewModel.setSolid(hash);
}
Expand Down

0 comments on commit b4551a3

Please sign in to comment.