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

Feature: Add solidification stage to pipeline and only broadcast solid transactions #1646

Open
wants to merge 79 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
53ea166
Add ubiquitous Broadcast Queue
DyrellC Oct 14, 2019
be7c132
Update unit tests with broadcasting queue
DyrellC Oct 15, 2019
6593388
Remove unneeded log
DyrellC Oct 17, 2019
33f193f
Merge branch 'dev' into add-Broadcast-queue
Oct 30, 2019
ff58495
Fix broadcast queue injection
DyrellC Nov 4, 2019
1a0ea43
remove unused function
DyrellC Nov 4, 2019
ad3a203
Merge branch 'add-Broadcast-queue' of https://github.com/DyrellC/iri …
DyrellC Nov 4, 2019
2283fb0
Merge branch 'dev' of https://github.com/iotaledger/iri into add-Broa…
DyrellC Nov 4, 2019
24e31a5
Clean up imports
DyrellC Nov 4, 2019
03590dd
Remove BroadcastQueue, add TransactionSolidifier class
DyrellC Nov 8, 2019
06242eb
Add docs
DyrellC Nov 8, 2019
1ec3794
Add to solidification queue if update status fails
DyrellC Nov 8, 2019
bc5897f
Fix network injection test
DyrellC Nov 8, 2019
62a2330
Remove unused import, lower checkSolidity complexity
DyrellC Nov 8, 2019
9fc4cba
Reduce complexity further
DyrellC Nov 8, 2019
ccca691
Comments
DyrellC Nov 8, 2019
f0c1955
Change queue type, log error messages differentely
DyrellC Nov 12, 2019
fa72acc
Condense code slightly
DyrellC Nov 12, 2019
c3b1417
Synchronize solidifier queue access, add received transactions to sol…
DyrellC Nov 13, 2019
1538b36
Move solidification queue entry point, reduce interval for scans
DyrellC Nov 14, 2019
a34c5e8
Broadcast from reply stage to increase transactions to request speed
DyrellC Nov 18, 2019
14e784d
Merge branch 'dev' into add-Broadcast-queue
Nov 19, 2019
89ec550
Clean up PR, add interface
DyrellC Nov 21, 2019
8801ef2
Add unit tests
DyrellC Nov 21, 2019
26b9521
Wrap in try/catch, fix styling
DyrellC Nov 21, 2019
16170cf
Merge branch 'add-Broadcast-queue' of https://github.com/DyrellC/iri …
DyrellC Nov 21, 2019
7e34c91
Update src/main/java/com/iota/iri/network/pipeline/TransactionProcess…
DyrellC Nov 27, 2019
778c833
Remove solidification from broadcast queue next stage
DyrellC Nov 27, 2019
0b61c89
Add quick solid transactions to broadcast queue, comments and tests u…
DyrellC Nov 27, 2019
1a2d950
Merge branch 'add-Broadcast-queue' of https://github.com/DyrellC/iri …
DyrellC Nov 27, 2019
864c2db
codacy conflict
DyrellC Nov 27, 2019
4bfb138
Add messages to solidifier test
DyrellC Nov 27, 2019
d623d1d
Pop eldest on queue fill
DyrellC Nov 27, 2019
48258b1
Remove unused function
DyrellC Nov 27, 2019
1cde4bf
Iterator -> poll()
DyrellC Nov 27, 2019
6543981
Add transaction solidification stage
DyrellC Dec 2, 2019
7b4d3c5
Comments/clean-up
DyrellC Dec 2, 2019
5e0a974
update tests
DyrellC Dec 2, 2019
f86fe55
Remove unused payload Mock
DyrellC Dec 2, 2019
de08907
Remove log
DyrellC Dec 2, 2019
4086fce
Remove circular solidified queue
DyrellC Dec 2, 2019
b16c752
Make addToBroadcastQueue private again
DyrellC Dec 4, 2019
f5de8fe
Ensure solidTip is solid before broadcasting
DyrellC Dec 4, 2019
30f226e
Update tests, only broadcast solid transactions from solidify stage
DyrellC Dec 4, 2019
303648b
Move validator test to appropriate package
DyrellC Dec 5, 2019
7e36e1c
Downgrade log error to log info
DyrellC Dec 5, 2019
eb53b2f
Remove unnecessary solidity propogation thread in validator
DyrellC Dec 10, 2019
0409d3e
only import used parts of junit
DyrellC Dec 10, 2019
1b5294a
Add propagation queue back, remove addToSolidificationQueue from soli…
DyrellC Dec 24, 2019
ab6e628
Codacy corrections
DyrellC Dec 30, 2019
839d9cb
Move update status from validation to solidification
DyrellC Dec 30, 2019
031180b
Merge branch 'dev' of https://github.com/iotaledger/iri into add-Broa…
DyrellC Dec 30, 2019
f61e6ff
Codacy conflicts
DyrellC Dec 30, 2019
6e0a383
reremove old transaction validator
DyrellC Dec 30, 2019
4126903
Merge branch 'dev' into add-Broadcast-queue
Jan 6, 2020
ff4a13c
Fix codacy import error, break up runValidation
DyrellC Jan 6, 2020
5bd3066
Merge branch 'add-Broadcast-queue' of https://github.com/DyrellC/iri …
DyrellC Jan 6, 2020
10baada
Merge branch 'dev' into add-Broadcast-queue
DyrellC Jan 15, 2020
4327b10
Merge branch 'dev' into add-Broadcast-queue
DyrellC Jan 16, 2020
092cfa5
Merge branch 'dev' of https://github.com/iotaledger/iri into add-Broa…
DyrellC Jan 17, 2020
cc220b0
Merge branch 'add-Broadcast-queue' of https://github.com/DyrellC/iri …
DyrellC Jan 17, 2020
82359a7
Update regression logging
DyrellC Jan 21, 2020
7adfdc5
Merge branch 'dev' of https://github.com/iotaledger/iri into add-Broa…
DyrellC Jan 21, 2020
d3baeee
Remove double import from merge
DyrellC Jan 21, 2020
ffea048
Verbose logging for debugging
DyrellC Jan 21, 2020
0f29416
Merge branch 'dev' of https://github.com/iotaledger/iri into add-Broa…
DyrellC Feb 3, 2020
0084b48
Merge branch 'dev' of https://github.com/iotaledger/iri into add-Broa…
DyrellC Feb 6, 2020
4664000
Revert "Fix: sort milestone candidates before analyzing for faster so…
DyrellC Feb 10, 2020
cc5e8b8
Broadcast latest tip even if not solid (will be latest milestone)
DyrellC Feb 14, 2020
d488a1d
Correct cpu load issues
DyrellC Feb 26, 2020
9ad4886
Remove max to propagation cascade
DyrellC Feb 26, 2020
9ab2a7d
Reintroduce limiter to adding duplicates for solidification
DyrellC Feb 26, 2020
5663d30
Merge branch 'dev' of https://github.com/iotaledger/iri into dev
DyrellC Mar 5, 2020
b2cb269
Update DagHelper
DyrellC Mar 6, 2020
31223b3
Update regression logging
DyrellC Jan 21, 2020
ea3bbf8
Move validation to validation service package
DyrellC Mar 18, 2020
e4feaf6
Merge branch 'update-regression-logging' into merge-transaction-solid…
DyrellC Mar 18, 2020
059e7e4
Merge branch 'dev' of https://github.com/iotaledger/iri into add-Broa…
DyrellC Mar 18, 2020
7528b22
Merge branch 'merge-transaction-solidifier' into add-Broadcast-queue
DyrellC Mar 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/com/iota/iri/Iota.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.iota.iri.service.spentaddresses.SpentAddressesService;
import com.iota.iri.service.tipselection.TipSelector;
import com.iota.iri.service.transactionpruning.TransactionPruner;
import com.iota.iri.service.validation.TransactionSolidifier;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.storage.Indexable;
import com.iota.iri.storage.Persistable;
import com.iota.iri.storage.PersistenceProvider;
Expand Down Expand Up @@ -98,6 +100,8 @@ public class Iota {

public final MilestoneSolidifier milestoneSolidifier;

public final TransactionSolidifier transactionSolidifier;

public final BundleValidator bundleValidator;

public final Tangle tangle;
Expand All @@ -116,7 +120,7 @@ public class Iota {
* @param configuration Information about how this node will be configured.
*
*/
public Iota(IotaConfig configuration, SpentAddressesProvider spentAddressesProvider, SpentAddressesService spentAddressesService, SnapshotProvider snapshotProvider, SnapshotService snapshotService, LocalSnapshotManager localSnapshotManager, MilestoneService milestoneService, LatestMilestoneTracker latestMilestoneTracker, LatestSolidMilestoneTracker latestSolidMilestoneTracker, SeenMilestonesRetriever seenMilestonesRetriever, LedgerService ledgerService, TransactionPruner transactionPruner, MilestoneSolidifier milestoneSolidifier, BundleValidator bundleValidator, Tangle tangle, TransactionValidator transactionValidator, TransactionRequester transactionRequester, NeighborRouter neighborRouter, TransactionProcessingPipeline transactionProcessingPipeline, TipsRequester tipsRequester, TipsViewModel tipsViewModel, TipSelector tipsSelector) {
public Iota(IotaConfig configuration, SpentAddressesProvider spentAddressesProvider, SpentAddressesService spentAddressesService, SnapshotProvider snapshotProvider, SnapshotService snapshotService, LocalSnapshotManager localSnapshotManager, MilestoneService milestoneService, LatestMilestoneTracker latestMilestoneTracker, LatestSolidMilestoneTracker latestSolidMilestoneTracker, SeenMilestonesRetriever seenMilestonesRetriever, LedgerService ledgerService, TransactionPruner transactionPruner, MilestoneSolidifier milestoneSolidifier, BundleValidator bundleValidator, Tangle tangle, TransactionValidator transactionValidator, TransactionRequester transactionRequester, NeighborRouter neighborRouter, TransactionProcessingPipeline transactionProcessingPipeline, TipsRequester tipsRequester, TipsViewModel tipsViewModel, TipSelector tipsSelector, TransactionSolidifier transactionSolidifier) {
this.configuration = configuration;

this.ledgerService = ledgerService;
Expand All @@ -134,6 +138,7 @@ public Iota(IotaConfig configuration, SpentAddressesProvider spentAddressesProvi
this.neighborRouter = neighborRouter;
this.txPipeline = transactionProcessingPipeline;
this.tipsRequester = tipsRequester;
this.transactionSolidifier = transactionSolidifier;

// legacy classes
this.bundleValidator = bundleValidator;
Expand Down Expand Up @@ -195,6 +200,7 @@ public void init() throws Exception {
latestSolidMilestoneTracker.start();
seenMilestonesRetriever.start();
milestoneSolidifier.start();
transactionSolidifier.start();

if (localSnapshotManager != null) {
localSnapshotManager.start(latestMilestoneTracker);
Expand Down Expand Up @@ -236,6 +242,7 @@ private void rescanDb() throws Exception {
public void shutdown() throws Exception {
// shutdown in reverse starting order (to not break any dependencies)
milestoneSolidifier.shutdown();
transactionSolidifier.shutdown();
seenMilestonesRetriever.shutdown();
latestSolidMilestoneTracker.shutdown();
latestMilestoneTracker.shutdown();
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/com/iota/iri/MainInjectionConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import com.iota.iri.service.tipselection.impl.WalkerAlpha;
import com.iota.iri.service.transactionpruning.TransactionPruner;
import com.iota.iri.service.transactionpruning.async.AsyncTransactionPruner;
import com.iota.iri.service.validation.TransactionSolidifier;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.storage.Persistable;
import com.iota.iri.storage.PersistenceProvider;
import com.iota.iri.storage.Tangle;
Expand Down Expand Up @@ -137,8 +139,8 @@ SeenMilestonesRetriever provideSeenMilestonesRetriever(Tangle tangle, SnapshotPr

@Singleton
@Provides
MilestoneSolidifier provideMilestoneSolidifier(SnapshotProvider snapshotProvider, TransactionValidator transactionValidator) {
return new MilestoneSolidifierImpl(snapshotProvider, transactionValidator);
MilestoneSolidifier provideMilestoneSolidifier(SnapshotProvider snapshotProvider, TransactionSolidifier transactionSolidifier) {
return new MilestoneSolidifierImpl(snapshotProvider, transactionSolidifier);
}

@Singleton
Expand All @@ -159,8 +161,14 @@ LocalSnapshotManager provideLocalSnapshotManager(SnapshotProvider snapshotProvid

@Singleton
@Provides
TransactionValidator provideTransactionValidator(Tangle tangle, SnapshotProvider snapshotProvider, TipsViewModel tipsViewModel, TransactionRequester transactionRequester) {
return new TransactionValidator(tangle, snapshotProvider, tipsViewModel, transactionRequester, configuration);
TransactionValidator provideTransactionValidator(Tangle tangle, SnapshotProvider snapshotProvider, TipsViewModel tipsViewModel, TransactionRequester transactionRequester, TransactionSolidifier transactionSolidifier) {
return new TransactionValidator(tangle, snapshotProvider, tipsViewModel, transactionRequester, configuration, transactionSolidifier);
}

@Singleton
@Provides
TransactionSolidifier provideTransactionSolidifier(Tangle tangle, SnapshotProvider snapshotProvider, TransactionRequester transactionRequester){
return new TransactionSolidifier(tangle, snapshotProvider, transactionRequester);
}

@Singleton
Expand All @@ -178,8 +186,8 @@ TipSelector provideTipSelector(Tangle tangle, SnapshotProvider snapshotProvider,

@Singleton
@Provides
Iota provideIota(SpentAddressesProvider spentAddressesProvider, SpentAddressesService spentAddressesService, SnapshotProvider snapshotProvider, SnapshotService snapshotService, @Nullable LocalSnapshotManager localSnapshotManager, MilestoneService milestoneService, LatestMilestoneTracker latestMilestoneTracker, LatestSolidMilestoneTracker latestSolidMilestoneTracker, SeenMilestonesRetriever seenMilestonesRetriever, LedgerService ledgerService, @Nullable TransactionPruner transactionPruner, MilestoneSolidifier milestoneSolidifier, BundleValidator bundleValidator, Tangle tangle, TransactionValidator transactionValidator, TransactionRequester transactionRequester, NeighborRouter neighborRouter, TransactionProcessingPipeline transactionProcessingPipeline, TipsRequester tipsRequester, TipsViewModel tipsViewModel, TipSelector tipsSelector) {
return new Iota(configuration, spentAddressesProvider, spentAddressesService, snapshotProvider, snapshotService, localSnapshotManager, milestoneService, latestMilestoneTracker, latestSolidMilestoneTracker, seenMilestonesRetriever, ledgerService, transactionPruner, milestoneSolidifier, bundleValidator, tangle, transactionValidator, transactionRequester, neighborRouter, transactionProcessingPipeline, tipsRequester, tipsViewModel, tipsSelector);
Iota provideIota(SpentAddressesProvider spentAddressesProvider, SpentAddressesService spentAddressesService, SnapshotProvider snapshotProvider, SnapshotService snapshotService, @Nullable LocalSnapshotManager localSnapshotManager, MilestoneService milestoneService, LatestMilestoneTracker latestMilestoneTracker, LatestSolidMilestoneTracker latestSolidMilestoneTracker, SeenMilestonesRetriever seenMilestonesRetriever, LedgerService ledgerService, @Nullable TransactionPruner transactionPruner, MilestoneSolidifier milestoneSolidifier, BundleValidator bundleValidator, Tangle tangle, TransactionValidator transactionValidator, TransactionRequester transactionRequester, NeighborRouter neighborRouter, TransactionProcessingPipeline transactionProcessingPipeline, TipsRequester tipsRequester, TipsViewModel tipsViewModel, TipSelector tipsSelector, TransactionSolidifier transactionSolidifier) {
return new Iota(configuration, spentAddressesProvider, spentAddressesService, snapshotProvider, snapshotService, localSnapshotManager, milestoneService, latestMilestoneTracker, latestSolidMilestoneTracker, seenMilestonesRetriever, ledgerService, transactionPruner, milestoneSolidifier, bundleValidator, tangle, transactionValidator, transactionRequester, neighborRouter, transactionProcessingPipeline, tipsRequester, tipsViewModel, tipsSelector, transactionSolidifier);
}

@Singleton
Expand Down
18 changes: 2 additions & 16 deletions src/main/java/com/iota/iri/controllers/TransactionViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.iota.iri.model.*;
import com.iota.iri.model.persistables.*;
import com.iota.iri.service.snapshot.Snapshot;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.storage.Indexable;
import com.iota.iri.storage.Persistable;
import com.iota.iri.storage.Tangle;
Expand Down Expand Up @@ -712,26 +713,11 @@ public void setMetadata() {
: TransactionViewModel.FILLED_SLOT;
}

public static void updateSolidTransactions(Tangle tangle, Snapshot initialSnapshot, final LinkedHashSet<Hash> analyzedHashes)
throws Exception {
Object[] hashes = analyzedHashes.toArray();
TransactionViewModel transactionViewModel;
for(int i = hashes.length -1; i >= 0; i--){
transactionViewModel = TransactionViewModel.fromHash(tangle, (Hash) hashes[i]);

transactionViewModel.updateHeights(tangle, initialSnapshot);

if (!transactionViewModel.isSolid()) {
transactionViewModel.updateSolid(true);
transactionViewModel.update(tangle, initialSnapshot, "solid|height");
}
}
}

/**
* Updates the {@link Transaction#solid} value of the referenced {@link Transaction} object.
*
* Used by the {@link com.iota.iri.TransactionValidator} to quickly set the solidity of a {@link Transaction} set.
* Used by the {@link TransactionValidator} to quickly set the solidity of a {@link Transaction} set.
*
* @param solid The solidity of the transaction in the database
* @return True if the {@link Transaction#solid} has been updated, False if not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.iota.iri.TransactionValidator;
import com.iota.iri.service.validation.TransactionSolidifier;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.conf.IotaConfig;
import com.iota.iri.controllers.TipsViewModel;
import com.iota.iri.network.impl.TipsRequesterImpl;
Expand Down Expand Up @@ -46,9 +47,9 @@ TipsRequester provideTipsRequester(NeighborRouter neighborRouter, Tangle tangle,
TransactionProcessingPipeline provideTransactionProcessingPipeline(NeighborRouter neighborRouter,
TransactionValidator txValidator, Tangle tangle, SnapshotProvider snapshotProvider,
TipsViewModel tipsViewModel, LatestMilestoneTracker latestMilestoneTracker,
TransactionRequester transactionRequester) {
TransactionRequester transactionRequester, TransactionSolidifier transactionSolidifier) {
return new TransactionProcessingPipelineImpl(neighborRouter, configuration, txValidator, tangle,
snapshotProvider, tipsViewModel, latestMilestoneTracker, transactionRequester);
snapshotProvider, tipsViewModel, latestMilestoneTracker, transactionRequester, transactionSolidifier);
}

@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.iota.iri.network.pipeline;

import com.iota.iri.TransactionValidator;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.controllers.TransactionViewModel;
import com.iota.iri.network.TransactionRequester;
import com.iota.iri.network.neighbor.Neighbor;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/iota/iri/network/pipeline/ReplyStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public ProcessingContext process(ProcessingContext ctx) {
} catch (Exception e) {
log.error("error adding reply tx to neighbor's send queue", e);
}
ctx.setNextStage(TransactionProcessingPipeline.Stage.ABORT);
ctx.setNextStage(TransactionProcessingPipeline.Stage.BROADCAST);
ctx.setPayload(new BroadcastPayload(null, tvm));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently not sure why this has changed...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 138 you gossip the tx to neighbor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to bolster broadcast rate to neighbours to increase the rate that transactionsToRequest are sent out. It was meant to increase solidification speed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit hacky...

I've been thinking about it and I think this should be the correct design:
You need to add a solidification stage and a solidification queue in TransactionProcessingPipeline.
The flow should be like this:
From the ReceivedStage -> if solid (due to quickly solid) -> Broadcast
-> else go to solidification stage -> Broadcast

Also remember to pass neighbor information along so we don't broadcast the solid tx to the neighbor that sent this to us..

return ctx;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ enum Stage {
*/
void process(byte[] txTrits);

/**
* Fetches a set of transactions from the {@link com.iota.iri.service.validation.TransactionSolidifier} and submits
* the object into the {@link BroadcastStage} queue.
*/
void refillBroadcastQueue();

/**
* Shut downs the pipeline by shutting down all stages.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.iota.iri.network.pipeline;

import com.iota.iri.TransactionValidator;
import com.iota.iri.service.validation.TransactionSolidifier;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.conf.NodeConfig;
import com.iota.iri.controllers.TipsViewModel;
import com.iota.iri.controllers.TransactionViewModel;
import com.iota.iri.crypto.batched.BatchedHasher;
import com.iota.iri.crypto.batched.BatchedHasherFactory;
import com.iota.iri.crypto.batched.HashRequest;
Expand All @@ -19,7 +21,10 @@
import com.iota.iri.utils.Converter;

import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -62,12 +67,13 @@ public class TransactionProcessingPipelineImpl implements TransactionProcessingP
private BroadcastStage broadcastStage;
private BatchedHasher batchedHasher;
private HashingStage hashingStage;
private TransactionSolidifier txSolidifier;

private BlockingQueue<ProcessingContext> preProcessStageQueue = new ArrayBlockingQueue<>(100);
private BlockingQueue<ProcessingContext> validationStageQueue = new ArrayBlockingQueue<>(100);
private BlockingQueue<ProcessingContext> receivedStageQueue = new ArrayBlockingQueue<>(100);
private BlockingQueue<ProcessingContext> broadcastStageQueue = new ArrayBlockingQueue<>(100);
private BlockingQueue<ProcessingContext> replyStageQueue = new ArrayBlockingQueue<>(100);
private BlockingQueue<ProcessingContext> broadcastStageQueue = new ArrayBlockingQueue<>(100);

/**
* Creates a {@link TransactionProcessingPipeline}.
Expand All @@ -82,9 +88,9 @@ public class TransactionProcessingPipelineImpl implements TransactionProcessingP
* reply stage
*/
public TransactionProcessingPipelineImpl(NeighborRouter neighborRouter, NodeConfig config,
TransactionValidator txValidator, Tangle tangle, SnapshotProvider snapshotProvider,
TipsViewModel tipsViewModel, LatestMilestoneTracker latestMilestoneTracker,
TransactionRequester transactionRequester) {
TransactionValidator txValidator, Tangle tangle, SnapshotProvider snapshotProvider,
TipsViewModel tipsViewModel, LatestMilestoneTracker latestMilestoneTracker,
TransactionRequester transactionRequester, TransactionSolidifier txSolidifier) {
DyrellC marked this conversation as resolved.
Show resolved Hide resolved
FIFOCache<Long, Hash> recentlySeenBytesCache = new FIFOCache<>(config.getCacheSizeBytes());
this.preProcessStage = new PreProcessStage(recentlySeenBytesCache);
this.replyStage = new ReplyStage(neighborRouter, config, tangle, tipsViewModel, latestMilestoneTracker,
Expand All @@ -94,6 +100,7 @@ public TransactionProcessingPipelineImpl(NeighborRouter neighborRouter, NodeConf
this.receivedStage = new ReceivedStage(tangle, txValidator, snapshotProvider, transactionRequester);
this.batchedHasher = BatchedHasherFactory.create(BatchedHasherFactory.Type.BCTCURL81, 20);
this.hashingStage = new HashingStage(batchedHasher);
this.txSolidifier = txSolidifier;
}

@Override
Expand All @@ -119,6 +126,7 @@ private void addStage(String name, BlockingQueue<ProcessingContext> queue,
try {
while (!Thread.currentThread().isInterrupted()) {
ProcessingContext ctx = stage.process(queue.take());

switch (ctx.getNextStage()) {
case REPLY:
replyStageQueue.put(ctx);
Expand Down Expand Up @@ -177,6 +185,7 @@ public BlockingQueue<ProcessingContext> getValidationStageQueue() {
public void process(Neighbor neighbor, ByteBuffer data) {
try {
preProcessStageQueue.put(new ProcessingContext(new PreProcessPayload(neighbor, data)));
refillBroadcastQueue();
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -191,6 +200,23 @@ public void process(byte[] txTrits) {
hashAndValidate(new ProcessingContext(payload));
}

@Override
public void refillBroadcastQueue(){
try{
Iterator<TransactionViewModel> hashIterator = txSolidifier.getBroadcastQueue().iterator();
Set<TransactionViewModel> toRemove = new LinkedHashSet<>();
while(!Thread.currentThread().isInterrupted() && hashIterator.hasNext()){
TransactionViewModel t = hashIterator.next();
broadcastStageQueue.put(new ProcessingContext(new BroadcastPayload(null, t)));
toRemove.add(t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:
So now we are sending the tx also to the origin neighbor?

Small peev:
can you change t to tx
I really dislike one letter variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refill is what adds solid transactions to the broadcast queue, so here, yes you would send it to all neighbours. I'll change the 1 letter variable though.

Copy link
Contributor

@GalRogozinski GalRogozinski Dec 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure, now with the new stage, this problem is resolved?

Copy link
Contributor Author

@DyrellC DyrellC Dec 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the asynchronous nature of solidification, there is still no neighbour variable to pass through unless we create a mapping, which imo is not worth it to do. So anything that gets updated as solid will be broadcast to all neighbours. But now only transactions that are solid will end up in the broadcast queue. We no longer forward transactions that have just been received.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to create this mapping
I also don't think we should touch this PR too much, so please create an issue to do this :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DyrellC I am marking this as a point to discuss before merging

Copy link
Contributor Author

@DyrellC DyrellC Dec 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to discuss this, because now that the solidify stage does not add the incoming transactions to the solidification queue anymore, we have no entry point to put the origin neighbour into the process. As is, the only place that places transactions into the solidification queue is from the milestone solidifier. This is something that could be introduced in the milestone stage, I mention that in the new issue #1701

hashIterator.remove();
}
txSolidifier.clearBroadcastQueue(toRemove);
} catch(InterruptedException e){
log.info(e.getMessage());
}
}

/**
* Sets up the given hashing stage {@link ProcessingContext} so that up on success, it will submit further to the
* validation stage.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.iota.iri.network.pipeline;

import com.iota.iri.TransactionValidator;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.controllers.TransactionViewModel;
import com.iota.iri.model.Hash;
import com.iota.iri.model.HashFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/iota/iri/service/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.iota.iri.BundleValidator;
import com.iota.iri.IRI;
import com.iota.iri.IXI;
import com.iota.iri.TransactionValidator;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.conf.APIConfig;
import com.iota.iri.conf.IotaConfig;
import com.iota.iri.controllers.*;
Expand Down
Loading