@@ -35,6 +35,8 @@ public class TransactionSolidifierImpl implements TransactionSolidifier {
35
35
*/
36
36
private static final int MAX_SIZE = 10000 ;
37
37
38
+ private static final int SOLIDIFICATION_INTERVAL = 100 ;
39
+
38
40
private static final IntervalLogger log = new IntervalLogger (TransactionSolidifier .class );
39
41
40
42
/**
@@ -82,8 +84,8 @@ public TransactionSolidifierImpl(Tangle tangle, SnapshotProvider snapshotProvide
82
84
*/
83
85
@ Override
84
86
public void start (){
85
- executorService .silentExecute (this ::processTransactionsToSolidify );
86
-
87
+ executorService .silentScheduleWithFixedDelay (this ::processTransactionsToSolidify , 0 ,
88
+ SOLIDIFICATION_INTERVAL , TimeUnit . MILLISECONDS );
87
89
}
88
90
89
91
/**
@@ -100,14 +102,11 @@ public void shutdown() {
100
102
@ Override
101
103
public void addToSolidificationQueue (Hash hash ){
102
104
try {
103
- if (!transactionsToSolidify .contains (hash )) {
104
-
105
- if (transactionsToSolidify .size () >= MAX_SIZE - 1 ){
106
- transactionsToSolidify .remove ();
107
- }
108
-
109
- transactionsToSolidify .put (hash );
105
+ if (transactionsToSolidify .size () >= MAX_SIZE - 1 ) {
106
+ transactionsToSolidify .remove ();
110
107
}
108
+
109
+ transactionsToSolidify .put (hash );
111
110
} catch (Exception e ){
112
111
log .error ("Error placing transaction into solidification queue" ,e );
113
112
}
@@ -157,16 +156,14 @@ public void clearFromBroadcastQueue(Set<TransactionViewModel> transactionsBroadc
157
156
*/
158
157
private void processTransactionsToSolidify (){
159
158
Hash hash ;
160
- while (!Thread .currentThread ().isInterrupted ()) {
161
- if ((hash = transactionsToSolidify .poll ()) != null ) {
162
- try {
163
- checkSolidity (hash );
164
- } catch (Exception e ) {
165
- log .info (e .getMessage ());
166
- }
159
+ if ((hash = transactionsToSolidify .poll ()) != null ) {
160
+ try {
161
+ checkSolidity (hash );
162
+ } catch (Exception e ) {
163
+ log .info (e .getMessage ());
167
164
}
168
- propagateSolidTransactions ();
169
165
}
166
+ propagateSolidTransactions ();
170
167
}
171
168
172
169
/**
@@ -350,12 +347,11 @@ private boolean checkApproovee(TransactionViewModel approovee) throws Exception
350
347
351
348
@ VisibleForTesting
352
349
void propagateSolidTransactions () {
353
- Iterator <Hash > cascadeIterator = solidTransactions .iterator ();
354
350
int cascadeCount = 0 ;
355
- while (cascadeCount < MAX_SIZE && cascadeIterator . hasNext () && ! Thread . currentThread (). isInterrupted () ) {
351
+ while (! Thread . currentThread (). isInterrupted () && solidTransactions . peek () != null && cascadeCount < MAX_SIZE ) {
356
352
try {
357
353
cascadeCount += 1 ;
358
- Hash hash = cascadeIterator . next ();
354
+ Hash hash = solidTransactions . poll ();
359
355
TransactionViewModel transaction = fromHash (tangle , hash );
360
356
Set <Hash > approvers = transaction .getApprovers (tangle ).getHashes ();
361
357
for (Hash h : approvers ) {
@@ -365,7 +361,6 @@ void propagateSolidTransactions() {
365
361
tipsViewModel .setSolid (h );
366
362
}
367
363
}
368
- cascadeIterator .remove ();
369
364
} catch (Exception e ) {
370
365
log .error ("Error while propagating solidity upwards" , e );
371
366
}
0 commit comments