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 20 commits
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
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
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/iota/iri/network/pipeline/SolidifyPayload.java
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.iota.iri.network.pipeline; | ||
|
|
||
| import com.iota.iri.controllers.TransactionViewModel; | ||
| import com.iota.iri.network.neighbor.Neighbor; | ||
|
|
||
| /** | ||
| * Defines a payload which gets submitted to the {@link SolidifyStage}. | ||
| */ | ||
| public class SolidifyPayload extends Payload { | ||
| private Neighbor originNeighbor; | ||
| private TransactionViewModel tvm; | ||
|
|
||
| /** | ||
| * Constructor for solidification payload. | ||
| * | ||
| * @param originNeighbor The originating point of a received transaction | ||
| * @param tvm The transaction that needs to be solidified | ||
| */ | ||
| public SolidifyPayload(Neighbor originNeighbor, TransactionViewModel tvm){ | ||
| this.originNeighbor = originNeighbor; | ||
| this.tvm = tvm; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public Neighbor getOriginNeighbor(){ | ||
| return originNeighbor; | ||
| } | ||
|
|
||
| /** | ||
| * Fetches the transaction from the payload. | ||
| * @return The transaction stored in the payload. | ||
| */ | ||
| public TransactionViewModel getTransaction(){ | ||
| return tvm; | ||
| } | ||
| } |
94 changes: 94 additions & 0 deletions
94
src/main/java/com/iota/iri/network/pipeline/SolidifyStage.java
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 |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package com.iota.iri.network.pipeline; | ||
|
|
||
| import com.iota.iri.controllers.TipsViewModel; | ||
| import com.iota.iri.controllers.TransactionViewModel; | ||
| import com.iota.iri.model.Hash; | ||
| import com.iota.iri.service.validation.TransactionSolidifier; | ||
| import com.iota.iri.storage.Tangle; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import static com.iota.iri.controllers.TransactionViewModel.fromHash; | ||
|
|
||
| /** | ||
| * The {@link SolidifyStage} is used to process newly received transaction for solidity. Once a transaction has been | ||
| * passed from the {@link ReceivedStage} it will be placed into this stage to have the {@link TransactionSolidifier} | ||
| * check the solidity of the transaction. If the transaction is found to be solid, it will be passed forward to the | ||
| * {@link BroadcastStage}. If it is found to be unsolid, it is put through the solidity check so that missing reference | ||
| * transactions get requested. If the transaction is unsolid, a random solid tip is broadcast instead to keep the | ||
| * requests transmitting to neighbors. | ||
| */ | ||
| public class SolidifyStage implements Stage { | ||
| private static final Logger log = LoggerFactory.getLogger(SolidifyStage.class); | ||
|
|
||
| private TransactionSolidifier txSolidifier; | ||
| private TipsViewModel tipsViewModel; | ||
| private Tangle tangle; | ||
|
|
||
| /** | ||
| * Constructor for the {@link SolidifyStage}. | ||
| * | ||
| * @param txSolidifier Transaction validator implementation for determining the validity of a transaction | ||
| * @param tipsViewModel Used for broadcasting random solid tips if the subject transaction is unsolid | ||
| * @param tangle A reference to the nodes DB | ||
| */ | ||
| public SolidifyStage(TransactionSolidifier txSolidifier, TipsViewModel tipsViewModel, Tangle tangle){ | ||
| this.txSolidifier = txSolidifier; | ||
| this.tipsViewModel = tipsViewModel; | ||
| this.tangle = tangle; | ||
| } | ||
|
|
||
| /** | ||
| * Processes the payload of the {@link ProcessingContext} as a {@link SolidifyPayload}. First the transaction will | ||
| * be checked for solidity and validity. If the transaction is already solid or can be set solid quickly by the | ||
| * transaction validator, the transaction is passed to the {@link BroadcastStage}. If not, a random solid tip is | ||
| * pulled form the {@link TipsViewModel} to be broadcast instead. | ||
| * | ||
| * @param ctx The context to process | ||
| * @return The output context, in most cases a {@link BroadcastPayload}. | ||
| */ | ||
| @Override | ||
| public ProcessingContext process(ProcessingContext ctx){ | ||
| try { | ||
| SolidifyPayload payload = (SolidifyPayload) ctx.getPayload(); | ||
| TransactionViewModel tvm = payload.getTransaction(); | ||
|
|
||
| if (tvm.isSolid() || txSolidifier.quickSetSolid(tvm)) { | ||
| // If the transaction is in the solidifier broadcast queue, remove it as it will be broadcast now | ||
| txSolidifier.clearFromBroadcastQueue(tvm); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... I think this is a good defense :-) |
||
| ctx.setNextStage(TransactionProcessingPipeline.Stage.BROADCAST); | ||
| ctx.setPayload(new BroadcastPayload(payload.getOriginNeighbor(), payload.getTransaction())); | ||
| return ctx; | ||
| } | ||
|
|
||
| return broadcastTip(ctx, payload); | ||
| }catch (Exception e){ | ||
| log.error("Failed to process transaction for solidification", e); | ||
| ctx.setNextStage(TransactionProcessingPipeline.Stage.ABORT); | ||
| return ctx; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private ProcessingContext broadcastTip(ProcessingContext ctx, SolidifyPayload payload) throws Exception{ | ||
| // First check if there is a transaction available to broadcast from the broadcast queue | ||
| TransactionViewModel tip = txSolidifier.getNextTxInBroadcastQueue(); | ||
|
|
||
| // If there is not a transaction available from the broadcast queue, instead try to send a solid tip | ||
| if (tip == null) { | ||
| Hash tipHash = tipsViewModel.getRandomSolidTipHash(); | ||
|
|
||
| if (tipHash == null) { | ||
| ctx.setNextStage(TransactionProcessingPipeline.Stage.FINISH); | ||
| return ctx; | ||
| } | ||
|
|
||
| tip = fromHash(tangle, tipHash); | ||
| } | ||
|
|
||
| ctx.setNextStage(TransactionProcessingPipeline.Stage.BROADCAST); | ||
| ctx.setPayload(new BroadcastPayload(payload.getOriginNeighbor(), tip)); | ||
|
|
||
| return ctx; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
can be set solid quickly by the transaction
validatorsolidifierThere 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.
Aaah nice catch thought I caught them all. Thanks 👍