Skip to content
This repository was archived by the owner on Aug 23, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,4 @@ public interface TransactionSolidifier {
* @throws Exception
*/
boolean quickSetSolid(TransactionViewModel transactionViewModel) throws Exception;

/**
* 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
*/
void addToPropagationQueue(Hash hash) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ public class TransactionSolidifierImpl implements TransactionSolidifier {
*/
private BlockingQueue<Hash> transactionsToSolidify = new ArrayBlockingQueue<>(MAX_SIZE);
Copy link
Contributor

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...

Copy link
Contributor Author

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 LinkedBlockingQueue instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes


/**
* 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
Expand All @@ -65,6 +60,8 @@ public class TransactionSolidifierImpl implements TransactionSolidifier {

private TipsViewModel tipsViewModel;

private TransactionPropagator transactionPropagator;

/**
* Constructor for the solidifier.
* @param tangle The DB reference
Expand All @@ -77,6 +74,7 @@ public TransactionSolidifierImpl(Tangle tangle, SnapshotProvider snapshotProvide
this.snapshotProvider = snapshotProvider;
this.transactionRequester = transactionRequester;
this.tipsViewModel = tipsViewModel;
this.transactionPropagator = new TransactionPropagator();
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -163,7 +161,7 @@ private void processTransactionsToSolidify(){
log.info(e.getMessage());
}
}
propagateSolidTransactions();
transactionPropagator.propagateSolidTransactions();
}

/**
Expand Down Expand Up @@ -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());
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

pretty sure this can be private

/**
* 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;
}
}
}
}