From 06ad631a438b07e932ea3de58ffac6e4c5b6e74b Mon Sep 17 00:00:00 2001 From: Gal Rogozinski Date: Wed, 1 Aug 2018 20:42:47 +0300 Subject: [PATCH 1/2] Remove WalkValidator cache of tips that are below max depth (#903) * remove cache * Add unit-regression test * Add second unit-regression test --- src/main/java/com/iota/iri/IRI.java | 13 -- src/main/java/com/iota/iri/Iota.java | 8 +- .../java/com/iota/iri/conf/Configuration.java | 3 - src/main/java/com/iota/iri/service/API.java | 3 +- .../tipselection/impl/TipSelectorImpl.java | 13 +- .../tipselection/impl/WalkValidatorImpl.java | 29 +--- .../impl/WalkValidatorImplTest.java | 125 +++++++++++++++--- 7 files changed, 114 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/iota/iri/IRI.java b/src/main/java/com/iota/iri/IRI.java index 95cf1c3e3a..cf238f85ec 100644 --- a/src/main/java/com/iota/iri/IRI.java +++ b/src/main/java/com/iota/iri/IRI.java @@ -155,7 +155,6 @@ private static boolean isValidated(final Configuration configuration, final Stri final Option milestoneKeys = parser.addIntegerOption("milestone-keys"); final Option snapshotTime = parser.addLongOption("snapshot-timestamp"); final Option belowMaxDepthTxLimit = parser.addIntegerOption("max-depth-tx-limit"); - final Option walkValidatorCacheSize = parser.addIntegerOption("walk-validator-cache"); try { parser.parse(args); @@ -332,19 +331,7 @@ private static boolean isValidated(final Configuration configuration, final Stri configuration.put(DefaultConfSettings.MAX_PEERS, vmaxPeers); } - final Integer belowMaxDepthLimit = parser.getOptionValue(belowMaxDepthTxLimit); - if (belowMaxDepthLimit != null) { - configuration.put(DefaultConfSettings.BELOW_MAX_DEPTH_TRANSACTION_LIMIT, - String.valueOf(belowMaxDepthLimit)); - } - - final Integer walkValidatorCache = parser.getOptionValue(walkValidatorCacheSize); - if (walkValidatorCache != null) { - configuration.put(DefaultConfSettings.WALK_VALIDATOR_CACHE_SIZE, String.valueOf(walkValidatorCache)); - } - return true; - } private static void printUsage() { diff --git a/src/main/java/com/iota/iri/Iota.java b/src/main/java/com/iota/iri/Iota.java index 94fe8ea2cf..beea41adf7 100644 --- a/src/main/java/com/iota/iri/Iota.java +++ b/src/main/java/com/iota/iri/Iota.java @@ -68,7 +68,6 @@ public Iota(Configuration configuration) throws IOException { double alpha = configuration.doubling(Configuration.DefaultConfSettings.TIPSELECTION_ALPHA.name()); int belowMaxDepthTxLimit = configuration.integer( Configuration.DefaultConfSettings.BELOW_MAX_DEPTH_TRANSACTION_LIMIT); - int walkValidatorCacheSize = configuration.integer(Configuration.DefaultConfSettings.WALK_VALIDATOR_CACHE_SIZE); boolean dontValidateMilestoneSig = configuration.booling(Configuration.DefaultConfSettings .DONT_VALIDATE_TESTNET_MILESTONE_SIG); @@ -104,7 +103,7 @@ public Iota(Configuration configuration) throws IOException { udpReceiver = new UDPReceiver(udpPort, node, configuration.integer(Configuration.DefaultConfSettings.TRANSACTION_PACKET_SIZE)); ledgerValidator = new LedgerValidator(tangle, milestone, transactionRequester, messageQ); tipsSolidifier = new TipsSolidifier(tangle, transactionValidator, tipsViewModel); - tipsSelector = createTipSelector(milestoneStartIndex, alpha, belowMaxDepthTxLimit, walkValidatorCacheSize); + tipsSelector = createTipSelector(milestoneStartIndex, alpha, belowMaxDepthTxLimit); } public void init() throws Exception { @@ -201,13 +200,12 @@ private void initializeTangle() { } } - private TipSelector createTipSelector(int milestoneStartIndex, double alpha, int belowMaxDepthTxLimit, - int walkValidatorCacheSize) { + private TipSelector createTipSelector(int milestoneStartIndex, double alpha, int belowMaxDepthTxLimit) { EntryPointSelector entryPointSelector = new EntryPointSelectorImpl(tangle, milestone, testnet, milestoneStartIndex); RatingCalculator ratingCalculator = new CumulativeWeightCalculator(tangle); TailFinder tailFinder = new TailFinderImpl(tangle); Walker walker = new WalkerAlpha(alpha, new SecureRandom(), tangle, messageQ, tailFinder); return new TipSelectorImpl(tangle, ledgerValidator, transactionValidator, entryPointSelector, ratingCalculator, - walker, milestone, maxTipSearchDepth, belowMaxDepthTxLimit, walkValidatorCacheSize); + walker, milestone, maxTipSearchDepth, belowMaxDepthTxLimit); } } diff --git a/src/main/java/com/iota/iri/conf/Configuration.java b/src/main/java/com/iota/iri/conf/Configuration.java index ff40a90109..1a344aa3e0 100644 --- a/src/main/java/com/iota/iri/conf/Configuration.java +++ b/src/main/java/com/iota/iri/conf/Configuration.java @@ -49,7 +49,6 @@ public class Configuration { public static final String REQ_HASH_SIZE = "46"; public static final String TESTNET_REQ_HASH_SIZE = "49"; public static final String BELOW_MAX_DEPTH_LIMIT = "20000"; - public static final String WALK_VALIDATOR_CACHE = "200000"; @@ -107,7 +106,6 @@ public enum DefaultConfSettings { SNAPSHOT_TIME, TIPSELECTION_ALPHA, BELOW_MAX_DEPTH_TRANSACTION_LIMIT, - WALK_VALIDATOR_CACHE_SIZE } @@ -174,7 +172,6 @@ public enum DefaultConfSettings { conf.put(DefaultConfSettings.SNAPSHOT_TIME.name(), GLOBAL_SNAPSHOT_TIME); conf.put(DefaultConfSettings.TIPSELECTION_ALPHA.name(), "0.001"); conf.put(DefaultConfSettings.BELOW_MAX_DEPTH_TRANSACTION_LIMIT.name(), BELOW_MAX_DEPTH_LIMIT); - conf.put(DefaultConfSettings.WALK_VALIDATOR_CACHE_SIZE.name(), WALK_VALIDATOR_CACHE); } public boolean init() throws IOException { diff --git a/src/main/java/com/iota/iri/service/API.java b/src/main/java/com/iota/iri/service/API.java index b9721cd6df..81a1548a3d 100644 --- a/src/main/java/com/iota/iri/service/API.java +++ b/src/main/java/com/iota/iri/service/API.java @@ -460,8 +460,7 @@ private AbstractResponse checkConsistencyStatement(List transactionsList try { WalkValidatorImpl walkValidator = new WalkValidatorImpl(instance.tangle, instance.ledgerValidator, instance.transactionValidator, instance.milestone, instance.tipsSelector.getMaxDepth(), - instance.configuration.integer(DefaultConfSettings.BELOW_MAX_DEPTH_TRANSACTION_LIMIT), - instance.configuration.integer(DefaultConfSettings.WALK_VALIDATOR_CACHE_SIZE)); + instance.configuration.integer(DefaultConfSettings.BELOW_MAX_DEPTH_TRANSACTION_LIMIT)); for (Hash transaction : transactions) { if (!walkValidator.isValid(transaction)) { state = false; diff --git a/src/main/java/com/iota/iri/service/tipselection/impl/TipSelectorImpl.java b/src/main/java/com/iota/iri/service/tipselection/impl/TipSelectorImpl.java index 5ad3332814..a8ecfaff49 100644 --- a/src/main/java/com/iota/iri/service/tipselection/impl/TipSelectorImpl.java +++ b/src/main/java/com/iota/iri/service/tipselection/impl/TipSelectorImpl.java @@ -8,11 +8,11 @@ import com.iota.iri.service.tipselection.*; import com.iota.iri.storage.Tangle; import com.iota.iri.utils.collections.interfaces.UnIterableMap; -import com.iota.iri.zmq.MessageQ; import java.security.InvalidAlgorithmParameterException; -import java.security.SecureRandom; -import java.util.*; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; /** * Implementation of TipSelector that selects 2 tips, @@ -34,7 +34,6 @@ public class TipSelectorImpl implements TipSelector { private final Tangle tangle; private final Milestone milestone; private final int belowMaxDepthTxLimit; - private final int validatorCacheSize; @Override public int getMaxDepth() { @@ -49,8 +48,7 @@ public TipSelectorImpl(Tangle tangle, Walker walkerAlpha, Milestone milestone, int maxDepth, - int belowMaxDepthTxLimit, - int validatorCacheSize) { + int belowMaxDepthTxLimit) { this.entryPointSelector = entryPointSelector; @@ -65,7 +63,6 @@ public TipSelectorImpl(Tangle tangle, this.transactionValidator = transactionValidator; this.tangle = tangle; this.milestone = milestone; - this.validatorCacheSize = validatorCacheSize; } /** @@ -96,7 +93,7 @@ public List getTransactionsToApprove(int depth, Optional reference) //random walk List tips = new LinkedList<>(); WalkValidator walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, milestone, - maxDepth, belowMaxDepthTxLimit, validatorCacheSize); + maxDepth, belowMaxDepthTxLimit); Hash tip = walker.walk(entryPoint, rating, walkValidator); tips.add(tip); diff --git a/src/main/java/com/iota/iri/service/tipselection/impl/WalkValidatorImpl.java b/src/main/java/com/iota/iri/service/tipselection/impl/WalkValidatorImpl.java index 3d48967615..a1ecef191e 100644 --- a/src/main/java/com/iota/iri/service/tipselection/impl/WalkValidatorImpl.java +++ b/src/main/java/com/iota/iri/service/tipselection/impl/WalkValidatorImpl.java @@ -7,13 +7,10 @@ import com.iota.iri.model.Hash; import com.iota.iri.service.tipselection.WalkValidator; import com.iota.iri.storage.Tangle; -import com.iota.iri.utils.collections.impl.BoundedSetWrapper; -import com.iota.iri.utils.collections.interfaces.BoundedSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.*; -import java.util.concurrent.ConcurrentSkipListSet; /** * Implementation of WalkValidator that checks consistency of the ledger as part of validity checks. @@ -29,9 +26,6 @@ */ public class WalkValidatorImpl implements WalkValidator { - public static final int INITIAL_CACHE_CAPACITY = 10_000; - //As long as tip selection is synchronized we are fine with the collection not being thread safe - static BoundedSet failedBelowMaxDepthCache; private int maxAnalyzedTxs; private final Tangle tangle; @@ -47,7 +41,7 @@ public class WalkValidatorImpl implements WalkValidator { private Set myApprovedHashes; public WalkValidatorImpl(Tangle tangle, LedgerValidator ledgerValidator, TransactionValidator transactionValidator, - Milestone milestone, int maxDepth, int maxAnalyzedTxs, int cacheSize) { + Milestone milestone, int maxDepth, int maxAnalyzedTxs) { this.tangle = tangle; this.ledgerValidator = ledgerValidator; this.transactionValidator = transactionValidator; @@ -55,20 +49,11 @@ public WalkValidatorImpl(Tangle tangle, LedgerValidator ledgerValidator, Transac this.maxDepth = maxDepth; this.maxAnalyzedTxs = maxAnalyzedTxs; - failedBelowMaxDepthCache = fetchCache(cacheSize); maxDepthOkMemoization = new HashSet<>(); myDiff = new HashMap<>(); myApprovedHashes = new HashSet<>(); } - private BoundedSet fetchCache(int cacheSize) { - if (failedBelowMaxDepthCache == null) { - failedBelowMaxDepthCache = new BoundedSetWrapper<>( - new ConcurrentSkipListSet<>(), cacheSize); - } - return failedBelowMaxDepthCache; - } - @Override public boolean isValid(Hash transactionHash) throws Exception { @@ -102,15 +87,9 @@ private boolean belowMaxDepth(Hash tip, int lowerAllowedSnapshotIndex) throws Ex Set analyzedTransactions = new HashSet<>(); Hash hash; while ((hash = nonAnalyzedTransactions.poll()) != null) { - if (failedBelowMaxDepthCache.contains(hash)) { - log.debug("failed below max depth because of a previously failed tx cache hit"); - updateCache(analyzedTransactions); - return true; - } if (analyzedTransactions.size() == maxAnalyzedTxs) { log.debug("failed below max depth because of exceeding max threshold of {} analyzed transactions", maxAnalyzedTxs); - updateCache(analyzedTransactions); return true; } @@ -118,7 +97,6 @@ private boolean belowMaxDepth(Hash tip, int lowerAllowedSnapshotIndex) throws Ex TransactionViewModel transaction = TransactionViewModel.fromHash(tangle, hash); if ((transaction.snapshotIndex() != 0 || Objects.equals(Hash.NULL_HASH, transaction.getHash())) && transaction.snapshotIndex() < lowerAllowedSnapshotIndex) { - updateCache(analyzedTransactions); log.debug("failed below max depth because of reaching a tx below the allowed snapshot index {}", lowerAllowedSnapshotIndex); return true; @@ -134,9 +112,4 @@ private boolean belowMaxDepth(Hash tip, int lowerAllowedSnapshotIndex) throws Ex maxDepthOkMemoization.add(tip); return false; } - - private void updateCache(Set txsToBeAdded) { - failedBelowMaxDepthCache.addAll(txsToBeAdded); - } - } diff --git a/src/test/java/com/iota/iri/service/tipselection/impl/WalkValidatorImplTest.java b/src/test/java/com/iota/iri/service/tipselection/impl/WalkValidatorImplTest.java index ebfe15fa99..5d76686634 100644 --- a/src/test/java/com/iota/iri/service/tipselection/impl/WalkValidatorImplTest.java +++ b/src/test/java/com/iota/iri/service/tipselection/impl/WalkValidatorImplTest.java @@ -40,7 +40,6 @@ public class WalkValidatorImplTest { public static void tearDown() throws Exception { tangle.shutdown(); dbFolder.delete(); - WalkValidatorImpl.failedBelowMaxDepthCache.clear(); } @BeforeClass @@ -65,8 +64,7 @@ public void shouldPassValidation() throws Exception { milestoneTracker.latestSolidSubtangleMilestoneIndex = depth; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, - milestoneTracker, depth, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT) , - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, depth, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT)); Assert.assertTrue("Validation failed", walkValidator.isValid(hash)); } @@ -82,8 +80,7 @@ public void failOnTxType() throws Exception { milestoneTracker.latestSolidSubtangleMilestoneIndex = depth; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, - milestoneTracker, depth, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT), - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, depth, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT)); Assert.assertFalse("Validation succeded but should have failed since tx is missing", walkValidator.isValid(hash)); } @@ -99,8 +96,7 @@ public void failOnTxIndex() throws Exception { milestoneTracker.latestSolidSubtangleMilestoneIndex = Integer.MAX_VALUE; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, - milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT), - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT)); Assert.assertFalse("Validation succeded but should have failed since we are not on a tail", walkValidator.isValid(hash)); } @@ -115,8 +111,7 @@ public void failOnSolid() throws Exception { milestoneTracker.latestSolidSubtangleMilestoneIndex = Integer.MAX_VALUE; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator,transactionValidator, - milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT) , - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT)); Assert.assertFalse("Validation succeded but should have failed since tx is not solid", walkValidator.isValid(hash)); } @@ -132,8 +127,7 @@ public void failOnBelowMaxDepthDueToOldMilestone() throws Exception { .thenReturn(true); milestoneTracker.latestSolidSubtangleMilestoneIndex = Integer.MAX_VALUE; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, - milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT), - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT)); Assert.assertFalse("Validation succeeded but should have failed tx is below max depth", walkValidator.isValid(hash)); } @@ -156,8 +150,7 @@ public void belowMaxDepthWithFreshMilestone() throws Exception { .thenReturn(true); milestoneTracker.latestSolidSubtangleMilestoneIndex = 100; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, - milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT) , - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT)); Assert.assertTrue("Validation failed but should have succeeded since tx is above max depth", walkValidator.isValid(hash)); } @@ -183,8 +176,7 @@ public void failBelowMaxDepthWithFreshMilestoneDueToLongChain() throws Exception .thenReturn(true); milestoneTracker.latestSolidSubtangleMilestoneIndex = 100; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, - milestoneTracker, 15, maxAnalyzedTxs, - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, 15, maxAnalyzedTxs); Assert.assertFalse("Validation succeeded but should have failed since tx is below max depth", walkValidator.isValid(hash)); } @@ -206,8 +198,7 @@ public void belowMaxDepthOnGenesis() throws Exception { .thenReturn(true); milestoneTracker.latestSolidSubtangleMilestoneIndex = 15; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, - milestoneTracker, 15, maxAnalyzedTxs, - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, 15, maxAnalyzedTxs); Assert.assertTrue("Validation failed but should have succeeded. We didn't exceed the maximal amount of" + "transactions that may be analyzed.", walkValidator.isValid(tx.getHash())); @@ -232,8 +223,7 @@ public void failBelowMaxDepthOnGenesisDueToLongChain() throws Exception { .thenReturn(true); milestoneTracker.latestSolidSubtangleMilestoneIndex = 17; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, - milestoneTracker, 15, maxAnalyzedTxs, - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, 15, maxAnalyzedTxs); Assert.assertFalse("Validation succeeded but should have failed. We exceeded the maximal amount of" + "transactions that may be analyzed.", walkValidator.isValid(tx.getHash())); @@ -251,9 +241,102 @@ public void failOnInconsistency() throws Exception { milestoneTracker.latestSolidSubtangleMilestoneIndex = Integer.MAX_VALUE; WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, - milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT), - Integer.parseInt(Configuration.WALK_VALIDATOR_CACHE)); + milestoneTracker, 15, Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT)); Assert.assertFalse("Validation succeded but should have failed due to inconsistent ledger state", walkValidator.isValid(hash)); } + + @Test + public void dontMarkWrongTxsAsBelowMaxDepth() throws Exception { + final int maxAnalyzedTxs = Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT); + TransactionViewModel tx1 = TransactionTestUtils.createBundleHead(0); + tx1.store(tangle); + tx1.setSnapshot(tangle, 92); + + TransactionViewModel txBad = TransactionTestUtils.createBundleHead(0); + txBad.store(tangle); + txBad.setSnapshot(tangle, 10); + + TransactionViewModel tx2 = new TransactionViewModel(TransactionViewModelTest.getRandomTransactionWithTrunkAndBranch(tx1.getHash(), tx1.getHash()), + TransactionViewModelTest.getRandomTransactionHash()); + TransactionTestUtils.setLastIndex(tx2,0); + TransactionTestUtils.setCurrentIndex(tx2,0); + tx2.updateSolid(true); + tx2.store(tangle); + + TransactionViewModel tx3 = new TransactionViewModel(TransactionViewModelTest.getRandomTransactionWithTrunkAndBranch(tx1.getHash(), txBad.getHash()), + TransactionViewModelTest.getRandomTransactionHash()); + TransactionTestUtils.setLastIndex(tx3,0); + TransactionTestUtils.setCurrentIndex(tx3,0); + tx3.updateSolid(true); + tx3.store(tangle); + + TransactionViewModel tx4 = new TransactionViewModel(TransactionViewModelTest.getRandomTransactionWithTrunkAndBranch(tx2.getHash(), tx3.getHash()), + TransactionViewModelTest.getRandomTransactionHash()); + TransactionTestUtils.setLastIndex(tx4,0); + TransactionTestUtils.setCurrentIndex(tx4,0); + tx4.updateSolid(true); + tx4.store(tangle); + + Mockito.when(ledgerValidator.updateDiff(new HashSet<>(), new HashMap<>(), tx4.getHash())) + .thenReturn(true); + Mockito.when(ledgerValidator.updateDiff(new HashSet<>(), new HashMap<>(), tx2.getHash())) + .thenReturn(true); + + milestoneTracker.latestSolidSubtangleMilestoneIndex = 100; + WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, + milestoneTracker, 15, maxAnalyzedTxs); + Assert.assertFalse("Validation of tx4 succeeded but should have failed since tx is below max depth", + walkValidator.isValid(tx4.getHash())); + Assert.assertTrue("Validation of tx2 failed but should have succeeded since tx is above max depth", + walkValidator.isValid(tx2.getHash())); + } + + @Test + public void allowConfirmedTxToPassBelowMaxDepthAfterMilestoneConfirmation() throws Exception { + final int maxAnalyzedTxs = Integer.parseInt(Configuration.BELOW_MAX_DEPTH_LIMIT); + TransactionViewModel tx1 = TransactionTestUtils.createBundleHead(0); + tx1.store(tangle); + tx1.setSnapshot(tangle, 92); + + TransactionViewModel txBad = TransactionTestUtils.createBundleHead(0); + txBad.store(tangle); + txBad.setSnapshot(tangle, 10); + + TransactionViewModel tx2 = new TransactionViewModel(TransactionViewModelTest.getRandomTransactionWithTrunkAndBranch(tx1.getHash(), tx1.getHash()), + TransactionViewModelTest.getRandomTransactionHash()); + TransactionTestUtils.setLastIndex(tx2,0); + TransactionTestUtils.setCurrentIndex(tx2,0); + tx2.updateSolid(true); + tx2.store(tangle); + + TransactionViewModel tx3 = new TransactionViewModel(TransactionViewModelTest.getRandomTransactionWithTrunkAndBranch(tx1.getHash(), txBad.getHash()), + TransactionViewModelTest.getRandomTransactionHash()); + TransactionTestUtils.setLastIndex(tx3,0); + TransactionTestUtils.setCurrentIndex(tx3,0); + tx3.updateSolid(true); + tx3.store(tangle); + + TransactionViewModel tx4 = new TransactionViewModel(TransactionViewModelTest.getRandomTransactionWithTrunkAndBranch(tx2.getHash(), tx3.getHash()), + TransactionViewModelTest.getRandomTransactionHash()); + TransactionTestUtils.setLastIndex(tx4,0); + TransactionTestUtils.setCurrentIndex(tx4,0); + tx4.updateSolid(true); + tx4.store(tangle); + + Mockito.when(ledgerValidator.updateDiff(new HashSet<>(), new HashMap<>(), tx4.getHash())) + .thenReturn(true); + + milestoneTracker.latestSolidSubtangleMilestoneIndex = 100; + WalkValidatorImpl walkValidator = new WalkValidatorImpl(tangle, ledgerValidator, transactionValidator, + milestoneTracker, 15, maxAnalyzedTxs); + Assert.assertFalse("Validation of tx4 succeeded but should have failed since tx is below max depth", + walkValidator.isValid(tx4.getHash())); + + //Now assume milestone 99 confirmed tx3 + tx3.setSnapshot(tangle, 99); + + Assert.assertTrue("Validation of tx4 failed but should have succeeded since tx is above max depth", + walkValidator.isValid(tx4.getHash())); + } } \ No newline at end of file From 42a8f6f73699e75eafcc6cf3af3250eda39c760d Mon Sep 17 00:00:00 2001 From: Gal Rogozinski Date: Thu, 2 Aug 2018 11:41:44 +0300 Subject: [PATCH 2/2] version bump v1.5.3 --- DOCKER.md | 6 +++--- changelog.txt | 3 +++ pom.xml | 2 +- src/main/java/com/iota/iri/IRI.java | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index f2281e4839..e5f1434a8f 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -2,13 +2,13 @@ Run the official iotaledger/iri container, passing the mandatory -p option: -```docker run iotaledger/iri:v1.5.2 -p 14265``` +```docker run iotaledger/iri:v1.5.3 -p 14265``` This will get your a running IRI with its API listening on port 14265, no neighbours and an empty database. The IRI Docker container by default expects data at /iri/data. Use the `-v` option of the `docker run` command to mount volumes so to have persistent data. You can also pass more command line options to the docker run command and those will be passed to IRI. If you want to use a iri.ini file with the docker container, supposing it's stored under /path/to/conf/iri.ini on your docker host, then pass `-v /path/to/conf:/iri/conf` and add -c /iri/conf/iri.ini as docker run arguments. So for example the `docker run` command above would become: -```docker run -v /path/to/conf:/iri/conf -v /path/to/data:/iri/data iotaledger/iri:v1.5.2 -p 14265 -c /iri/conf/iri.ini``` +```docker run -v /path/to/conf:/iri/conf -v /path/to/data:/iri/data iotaledger/iri:v1.5.3 -p 14265 -c /iri/conf/iri.ini``` Please refer to the IRI documentation for further command line options and iri.ini options. @@ -61,7 +61,7 @@ ExecStart=/usr/bin/docker run \ -p 14265:14265 \ -p 15600:15600 \ -p 14600:14600/udp \ -iotaledger/iri:v1.5.2 \ +iotaledger/iri:v1.5.3 \ -p 14265 \ --zmq-enabled \ --testnet diff --git a/changelog.txt b/changelog.txt index 23d61aad79..3a70c1b531 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +1.5.3 + - Remove WalkValidator cache of tips that are below max depth (#903) + 1.5.2 - Fail early on below max depth and don't solidify on api calls (#883) - Two new configurations added: "max-depth-tx-limit" and "--walk-validator-cache" diff --git a/pom.xml b/pom.xml index 4267bba97b..b0d062571d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.iota iri - 1.5.2 + 1.5.3 IRI IOTA Reference Implementation diff --git a/src/main/java/com/iota/iri/IRI.java b/src/main/java/com/iota/iri/IRI.java index cf238f85ec..b6f515a197 100644 --- a/src/main/java/com/iota/iri/IRI.java +++ b/src/main/java/com/iota/iri/IRI.java @@ -22,7 +22,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.5.2"; + public static final String VERSION = "1.5.3"; public static void main(String[] args) throws Exception { // Logging is configured first before any references to Logger or LoggerFactory.