From a8aac9656617ff4fc57a8bec41c214df4e61459d Mon Sep 17 00:00:00 2001 From: alon-e Date: Tue, 27 Jun 2017 18:40:36 +0300 Subject: [PATCH] fix solid tips addition remove referenced tips while storing new transactions expose random tip dampening var --- src/main/java/com/iota/iri/TransactionValidator.java | 3 +++ src/main/java/com/iota/iri/conf/Configuration.java | 2 ++ .../java/com/iota/iri/controllers/TipsViewModel.java | 2 +- src/main/java/com/iota/iri/network/Node.java | 9 ++++----- src/main/java/com/iota/iri/service/TipsManager.java | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/iota/iri/TransactionValidator.java b/src/main/java/com/iota/iri/TransactionValidator.java index e2a198698d..e342f122a1 100644 --- a/src/main/java/com/iota/iri/TransactionValidator.java +++ b/src/main/java/com/iota/iri/TransactionValidator.java @@ -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()); } diff --git a/src/main/java/com/iota/iri/conf/Configuration.java b/src/main/java/com/iota/iri/conf/Configuration.java index f49841bcf2..543317aabc 100644 --- a/src/main/java/com/iota/iri/conf/Configuration.java +++ b/src/main/java/com/iota/iri/conf/Configuration.java @@ -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, @@ -74,6 +75,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"); diff --git a/src/main/java/com/iota/iri/controllers/TipsViewModel.java b/src/main/java/com/iota/iri/controllers/TipsViewModel.java index 4a02bf2629..df753d0db1 100644 --- a/src/main/java/com/iota/iri/controllers/TipsViewModel.java +++ b/src/main/java/com/iota/iri/controllers/TipsViewModel.java @@ -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); } } diff --git a/src/main/java/com/iota/iri/network/Node.java b/src/main/java/com/iota/iri/network/Node.java index 9e6751b0aa..96b2fec4df 100644 --- a/src/main/java/com/iota/iri/network/Node.java +++ b/src/main/java/com/iota/iri/network/Node.java @@ -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); @@ -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) ); @@ -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); @@ -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; } diff --git a/src/main/java/com/iota/iri/service/TipsManager.java b/src/main/java/com/iota/iri/service/TipsManager.java index 4e434ee272..b0e00cf566 100644 --- a/src/main/java/com/iota/iri/service/TipsManager.java +++ b/src/main/java/com/iota/iri/service/TipsManager.java @@ -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); }