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

Commit

Permalink
Remove separate thread logic, check solidity from milestone solidifier
Browse files Browse the repository at this point in the history
  • Loading branch information
DyrellC committed Mar 30, 2020
1 parent c55d2fd commit ff0ef35
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private boolean isSolid(Map.Entry<Hash, Integer> currentEntry) {
}

try {
return transactionSolidifier.addMilestoneToSolidificationQueue(currentEntry.getKey(), SOLIDIFICATION_TRANSACTIONS_LIMIT);
return transactionSolidifier.checkSolidity(currentEntry.getKey(), SOLIDIFICATION_TRANSACTIONS_LIMIT);
} catch (Exception e) {
log.error("Error while solidifying milestone #" + currentEntry.getValue(), e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ public interface TransactionSolidifier {
*/
void shutdown();

/**
* Add a hash to the solidification queue, and runs an initial {@link #checkSolidity} call.
*
* @param hash Hash of the transaction to solidify
*/
void addToSolidificationQueue(Hash hash);

/**
* Checks if milestone transaction is solid. Returns true if it is, and if it is not, it adds the hash to the
* solidification queue and returns false.
*
* @param hash Hash of the transaction to solidify
* @param maxToProcess Maximum number of transactions to analyze
* @return True if solid, false if not
*/
boolean addMilestoneToSolidificationQueue(Hash hash, int maxToProcess);
/**
* Fetch the next transaction in the transactionsToBroadcast set.
* @return A {@link TransactionViewModel} object to be broadcast.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ public class TransactionSolidifierImpl implements TransactionSolidifier {
private SilentScheduledExecutorService executorService = new DedicatedScheduledExecutorService(
"Transaction Solidifier", log.delegate());

/**
* A queue for processing transactions with the {@link #checkSolidity(Hash)} call. Once a transaction has been
* marked solid it will be placed into the {@link #transactionsToBroadcast} queue.
*/
private BlockingQueue<Hash> transactionsToSolidify = new ArrayBlockingQueue<>(MAX_SIZE);


/**
* A set of transactions that will be called by the {@link TransactionProcessingPipeline} to be broadcast to
* neighboring nodes.
Expand Down Expand Up @@ -94,43 +87,6 @@ public void shutdown() {
executorService.shutdownNow();
}

/**
*{@inheritDoc}
*/
@Override
public void addToSolidificationQueue(Hash hash){
try{
if(!transactionsToSolidify.contains(hash)) {
if (transactionsToSolidify.size() >= MAX_SIZE - 1) {
transactionsToSolidify.remove();
}

transactionsToSolidify.put(hash);
}
} catch(Exception e){
log.error("Error placing transaction into solidification queue",e);
}
}

/**
* {@inheritDoc}
*/
@Override
public boolean addMilestoneToSolidificationQueue(Hash hash, int maxToProcess){
try{
TransactionViewModel tx = fromHash(tangle, hash);
if(tx.isSolid()){
transactionPropagator.addToPropagationQueue(hash);
return true;
}
addToSolidificationQueue(hash);
return false;
}catch(Exception e){
log.error("Error adding milestone to solidification queue", e);
return false;
}
}

/**
*{@inheritDoc}
*/
Expand All @@ -149,18 +105,9 @@ public void clearFromBroadcastQueue(TransactionViewModel transaction){


/**
* Iterate through the {@link #transactionsToSolidify} queue and call {@link #checkSolidity(Hash)} on each hash.
* Solid transactions are then processed into the {@link #transactionsToBroadcast} queue.
* Process any solid transactions present in the {@link TransactionPropagator}.
*/
private void processTransactionsToSolidify(){
Hash hash;
if((hash = transactionsToSolidify.poll()) != null) {
try {
checkSolidity(hash);
} catch (Exception e) {
log.info(e.getMessage());
}
}
transactionPropagator.propagateSolidTransactions();
}

Expand Down Expand Up @@ -271,12 +218,6 @@ private void addToBroadcastQueue(TransactionViewModel tvm) {
}
}

@VisibleForTesting
Set<Hash> getSolidificationQueue(){
return new LinkedHashSet<>(transactionsToSolidify);
}


@Override
public void updateStatus(TransactionViewModel transactionViewModel) throws Exception {
transactionRequester.clearTransactionRequest(transactionViewModel.getHash());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,11 @@ public void verifyTxIsNotSolid() throws Exception {
assertFalse("Expected transaction to fail solidity check", txSolidifier.checkSolidity(tx.getHash()));
}

@Test
public void getSolidificationQueue() throws Exception {
TransactionViewModel mainTx = getTxWithBranchAndTrunk();
for(int i = 0; i < 10; i++) {
TransactionViewModel tx = getTxWithBranchAndTrunk();
txSolidifier.addToSolidificationQueue(tx.getHash());
}
txSolidifier.addToSolidificationQueue(mainTx.getHash());
assertTrue("Expected transaction to be present in the solidification queue",
txSolidifier.getSolidificationQueue().contains(mainTx.getHash()));
}

@Test
public void verifyTransactionIsProcessedFully() throws Exception {
TransactionViewModel tx = getTxWithBranchAndTrunk();
txSolidifier.addToSolidificationQueue(tx.getHash());
txSolidifier.checkSolidity(tx.getHash());

//Time to process through the steps
Thread.sleep(1000);
Expand All @@ -132,7 +121,7 @@ public void verifyTransactionIsProcessedFully() throws Exception {
@Test
public void verifyInconsistentTransactionIsNotProcessedFully() throws Exception {
TransactionViewModel tx = getTxWithoutBranchAndTrunk();
txSolidifier.addToSolidificationQueue(tx.getHash());
txSolidifier.checkSolidity(tx.getHash());

//Time to process through the steps
Thread.sleep(1000);
Expand Down

0 comments on commit ff0ef35

Please sign in to comment.