This repository was archived by the owner on Aug 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 371
Add transaction solidifier #1805
Merged
GalRogozinski
merged 22 commits into
iotaledger-archive:dev
from
DyrellC:add-transaction-solidifier
Apr 2, 2020
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6c9096c
Move validation to validation service package
DyrellC 029a157
Add Transaction Solidifier
DyrellC c72efc3
Update Transaction Validator
DyrellC b6a4e48
Update Unit Tests
DyrellC 9ae4f68
Merge branch 'dev' into add-transaction-solidifier
3faf8ec
Merge branch 'dev' into add-transaction-solidifier
DyrellC 7ad6394
Remove tip field from solidify stage
DyrellC bff1915
Move broadcast queue retreival to solidify stage
DyrellC 0f09a05
Undo auto-formatting
DyrellC b735009
Merge branch 'add-transaction-solidifier' of https://github.com/Dyrel…
DyrellC faeabc3
More autoformatting
DyrellC b96d70b
Re-remove refillBroadcast
DyrellC a21e969
Move propagation logic to inner class
DyrellC 3c9414c
Remove unused imports
DyrellC d8f3297
Add comment to propagator
DyrellC c55d2fd
Remove unused txSolidifier private field
DyrellC ff0ef35
Remove separate thread logic, check solidity from milestone solidifier
DyrellC fd7e933
LinkedHashSet -> ArrayDeque in checkSolidity
DyrellC 666dadf
Update maxProcessedTransactions value determination
DyrellC f31de91
Make Transaction Propagator private
DyrellC 5f70a3d
Typo correction
DyrellC 2c57895
Merge branch 'dev' into add-transaction-solidifier
DyrellC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,11 +51,6 @@ public class TransactionSolidifierImpl implements TransactionSolidifier { | |
| */ | ||
| private BlockingQueue<Hash> transactionsToSolidify = new ArrayBlockingQueue<>(MAX_SIZE); | ||
|
|
||
| /** | ||
| * A queue for processing transactions with the {@link #propagateSolidTransactions()} call. This will check | ||
| * approving transactions with {@link #quickSetSolid(TransactionViewModel)}. | ||
| */ | ||
| private BlockingQueue<Hash> solidTransactions = new ArrayBlockingQueue<>(MAX_SIZE); | ||
|
|
||
| /** | ||
| * A set of transactions that will be called by the {@link TransactionProcessingPipeline} to be broadcast to | ||
|
|
@@ -65,6 +60,8 @@ public class TransactionSolidifierImpl implements TransactionSolidifier { | |
|
|
||
| private TipsViewModel tipsViewModel; | ||
|
|
||
| private TransactionPropagator transactionPropagator; | ||
|
|
||
| /** | ||
| * Constructor for the solidifier. | ||
| * @param tangle The DB reference | ||
|
|
@@ -77,6 +74,7 @@ public TransactionSolidifierImpl(Tangle tangle, SnapshotProvider snapshotProvide | |
| this.snapshotProvider = snapshotProvider; | ||
| this.transactionRequester = transactionRequester; | ||
| this.tipsViewModel = tipsViewModel; | ||
| this.transactionPropagator = new TransactionPropagator(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -122,7 +120,7 @@ public boolean addMilestoneToSolidificationQueue(Hash hash, int maxToProcess){ | |
| try{ | ||
| TransactionViewModel tx = fromHash(tangle, hash); | ||
| if(tx.isSolid()){ | ||
| addToPropagationQueue(hash); | ||
| transactionPropagator.addToPropagationQueue(hash); | ||
| return true; | ||
| } | ||
| addToSolidificationQueue(hash); | ||
|
|
@@ -163,7 +161,7 @@ private void processTransactionsToSolidify(){ | |
| log.info(e.getMessage()); | ||
| } | ||
| } | ||
| propagateSolidTransactions(); | ||
| transactionPropagator.propagateSolidTransactions(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -242,7 +240,7 @@ private void updateTransactions(Set<Hash> hashes) { | |
| tvm.update(tangle, snapshotProvider.getInitialSnapshot(), "solid|height"); | ||
| } | ||
| addToBroadcastQueue(tvm); | ||
| addToPropagationQueue(tvm.getHash()); | ||
| transactionPropagator.addToPropagationQueue(tvm.getHash()); | ||
| } catch (Exception e) { | ||
| log.info(e.getMessage()); | ||
| } | ||
|
|
@@ -256,7 +254,7 @@ private boolean isUnsolidWithoutEntryPoint(TransactionViewModel transaction, Has | |
| if(!transaction.isSolid() && !snapshotProvider.getInitialSnapshot().hasSolidEntryPoint(hashPointer)){ | ||
| return true; | ||
| } | ||
| addToPropagationQueue(hashPointer); | ||
| transactionPropagator.addToPropagationQueue(hashPointer); | ||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -291,19 +289,10 @@ public void updateStatus(TransactionViewModel transactionViewModel) throws Excep | |
| if(quickSetSolid(transactionViewModel)) { | ||
| transactionViewModel.update(tangle, snapshotProvider.getInitialSnapshot(), "solid|height"); | ||
| tipsViewModel.setSolid(transactionViewModel.getHash()); | ||
| addToPropagationQueue(transactionViewModel.getHash()); | ||
| transactionPropagator.addToPropagationQueue(transactionViewModel.getHash()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void addToPropagationQueue(Hash hash) throws Exception{ | ||
| if(!solidTransactions.contains(hash)) { | ||
| if (solidTransactions.size() >= MAX_SIZE) { | ||
| solidTransactions.poll(); | ||
| } | ||
| solidTransactions.put(hash); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean quickSetSolid(final TransactionViewModel transactionViewModel) throws Exception { | ||
|
|
@@ -318,7 +307,7 @@ public boolean quickSetSolid(final TransactionViewModel transactionViewModel) th | |
| if(solid) { | ||
| transactionViewModel.updateSolid(true); | ||
| transactionViewModel.updateHeights(tangle, snapshotProvider.getInitialSnapshot()); | ||
| addToPropagationQueue(transactionViewModel.getHash()); | ||
| transactionPropagator.addToPropagationQueue(transactionViewModel.getHash()); | ||
| addToBroadcastQueue(transactionViewModel); | ||
| return true; | ||
| } | ||
|
|
@@ -345,37 +334,61 @@ private boolean checkApproovee(TransactionViewModel approovee) throws Exception | |
| return approovee.isSolid(); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| void propagateSolidTransactions() { | ||
| while(!Thread.currentThread().isInterrupted() && solidTransactions.peek() != null) { | ||
| try { | ||
| Hash hash = solidTransactions.poll(); | ||
| TransactionViewModel transaction = fromHash(tangle, hash); | ||
| Set<Hash> approvers = transaction.getApprovers(tangle).getHashes(); | ||
| for(Hash h: approvers) { | ||
| TransactionViewModel tx = fromHash(tangle, h); | ||
| if (quietQuickSetSolid(tx)) { | ||
| tx.update(tangle, snapshotProvider.getInitialSnapshot(), "solid|height"); | ||
| tipsViewModel.setSolid(h); | ||
|
|
||
|
|
||
| public class TransactionPropagator { | ||
|
||
| /** | ||
| * A queue for processing transactions with the {@link #propagateSolidTransactions()} call. This will check | ||
| * approving transactions with {@link #quickSetSolid(TransactionViewModel)}. | ||
| */ | ||
| private BlockingQueue<Hash> solidTransactions = new ArrayBlockingQueue<>(MAX_SIZE); | ||
|
|
||
| /** | ||
| * Add to the propagation queue where it will be processed to help solidify approving transactions faster | ||
| * @param hash The transaction hash to be removed | ||
| * @throws Exception | ||
| */ | ||
| public void addToPropagationQueue(Hash hash) throws Exception{ | ||
| if(!solidTransactions.contains(hash)) { | ||
| if (solidTransactions.size() >= MAX_SIZE) { | ||
| solidTransactions.poll(); | ||
| } | ||
| solidTransactions.put(hash); | ||
| } | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| void propagateSolidTransactions() { | ||
| while(!Thread.currentThread().isInterrupted() && solidTransactions.peek() != null) { | ||
| try { | ||
| Hash hash = solidTransactions.poll(); | ||
| TransactionViewModel transaction = fromHash(tangle, hash); | ||
| Set<Hash> approvers = transaction.getApprovers(tangle).getHashes(); | ||
| for(Hash h: approvers) { | ||
| TransactionViewModel tx = fromHash(tangle, h); | ||
| if (quietQuickSetSolid(tx)) { | ||
| tx.update(tangle, snapshotProvider.getInitialSnapshot(), "solid|height"); | ||
| tipsViewModel.setSolid(h); | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| log.error("Error while propagating solidity upwards", e); | ||
| } | ||
| } catch (Exception e) { | ||
| log.error("Error while propagating solidity upwards", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Perform a {@link #quickSetSolid} while capturing and logging errors | ||
| * @param transactionViewModel transaction we try to solidify. | ||
| * @return <tt>true</tt> if we managed to solidify, else <tt>false</tt>. | ||
| */ | ||
| private boolean quietQuickSetSolid(TransactionViewModel transactionViewModel) { | ||
| try { | ||
| return quickSetSolid(transactionViewModel); | ||
| } catch (Exception e) { | ||
| log.error(e.getMessage(), e); | ||
| return false; | ||
| /** | ||
| * Perform a {@link #quickSetSolid} while capturing and logging errors | ||
| * @param transactionViewModel transaction we try to solidify. | ||
| * @return <tt>true</tt> if we managed to solidify, else <tt>false</tt>. | ||
| */ | ||
| private boolean quietQuickSetSolid(TransactionViewModel transactionViewModel) { | ||
| try { | ||
| return quickSetSolid(transactionViewModel); | ||
| } catch (Exception e) { | ||
| log.error(e.getMessage(), e); | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember I told you to use ArrayBlockingQueue...
We have a bug in networking #1742, that is fixed by doing this GalRogozinski@f65e29b
What happens is that sometiems the queue in networking gets filled in high tps regimes...
So I am rethinking my recommendation
Because before a memory attack IRI just might stop functioning...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always wondered about that but wasn't sure if i was thinking straight about it. Should I switch this to a
LinkedBlockingQueueinstead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes