@ -57,6 +57,7 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean ;
import java.util.concurrent.atomic.AtomicBoolean ;
import java.util.function.Supplier ;
import java.util.function.Supplier ;
import com.google.common.base.Stopwatch ;
import org.slf4j.Logger ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.slf4j.LoggerFactory ;
@ -227,11 +228,11 @@ public class BlockTransactionSelector {
final PendingTransaction pendingTransaction ) {
final PendingTransaction pendingTransaction ) {
checkCancellation ( ) ;
checkCancellation ( ) ;
final long evaluationStartedAt = System . currentTimeMillis ( ) ;
final Stopwatch evaluationTimer = Stopwatch . createStarted ( ) ;
TransactionSelectionResult selectionResult = evaluatePreProcessing ( pendingTransaction ) ;
TransactionSelectionResult selectionResult = evaluatePreProcessing ( pendingTransaction ) ;
if ( ! selectionResult . selected ( ) ) {
if ( ! selectionResult . selected ( ) ) {
return handleTransactionNotSelected ( pendingTransaction , selectionResult , evaluationStartedAt ) ;
return handleTransactionNotSelected ( pendingTransaction , selectionResult , evaluationTimer ) ;
}
}
final WorldUpdater txWorldStateUpdater = blockWorldStateUpdater . updater ( ) ;
final WorldUpdater txWorldStateUpdater = blockWorldStateUpdater . updater ( ) ;
@ -243,13 +244,10 @@ public class BlockTransactionSelector {
if ( postProcessingSelectionResult . selected ( ) ) {
if ( postProcessingSelectionResult . selected ( ) ) {
return handleTransactionSelected (
return handleTransactionSelected (
pendingTransaction , processingResult , txWorldStateUpdater , evaluationStartedAt ) ;
pendingTransaction , processingResult , txWorldStateUpdater , evaluationTimer ) ;
}
}
return handleTransactionNotSelected (
return handleTransactionNotSelected (
pendingTransaction ,
pendingTransaction , postProcessingSelectionResult , txWorldStateUpdater , evaluationTimer ) ;
postProcessingSelectionResult ,
txWorldStateUpdater ,
evaluationStartedAt ) ;
}
}
/ * *
/ * *
@ -333,14 +331,14 @@ public class BlockTransactionSelector {
* @param pendingTransaction The pending transaction .
* @param pendingTransaction The pending transaction .
* @param processingResult The result of the transaction processing .
* @param processingResult The result of the transaction processing .
* @param txWorldStateUpdater The world state updater .
* @param txWorldStateUpdater The world state updater .
* @param evaluationStartedAt when the evaluation of this tx started
* @param evaluationTimer tracks the evaluation elapsed time
* @return The result of the transaction selection process .
* @return The result of the transaction selection process .
* /
* /
private TransactionSelectionResult handleTransactionSelected (
private TransactionSelectionResult handleTransactionSelected (
final PendingTransaction pendingTransaction ,
final PendingTransaction pendingTransaction ,
final TransactionProcessingResult processingResult ,
final TransactionProcessingResult processingResult ,
final WorldUpdater txWorldStateUpdater ,
final WorldUpdater txWorldStateUpdater ,
final long evaluationStartedAt ) {
final Stopwatch evaluationTimer ) {
final Transaction transaction = pendingTransaction . getTransaction ( ) ;
final Transaction transaction = pendingTransaction . getTransaction ( ) ;
final long gasUsedByTransaction =
final long gasUsedByTransaction =
@ -369,20 +367,19 @@ public class BlockTransactionSelector {
}
}
}
}
final long evaluationTime = System . currentTimeMillis ( ) - evaluationStartedAt ;
if ( tooLate ) {
if ( tooLate ) {
// even if this tx passed all the checks, it is too late to include it in this block,
// even if this tx passed all the checks, it is too late to include it in this block,
// so we need to treat it as not selected
// so we need to treat it as not selected
// check if this tx took too much to evaluate, and in case remove it from the pool
// check if this tx took too much to evaluate, and in case remove it from the pool
final TransactionSelectionResult timeoutSelectionResult ;
final TransactionSelectionResult timeoutSelectionResult ;
if ( evaluationTime > blockTxsSelectionMaxTime ) {
if ( evaluationTimer . elapsed ( TimeUnit . MILLISECONDS ) > blockTxsSelectionMaxTime ) {
LOG . atWarn ( )
LOG . atWarn ( )
. setMessage (
. setMessage (
"Transaction {} is too late for inclusion, evaluated in {}ms that is over the max limit of {}"
"Transaction {} is too late for inclusion, evaluated in {} that is over the max limit of {}ms "
+ ", removing it from the pool" )
+ ", removing it from the pool" )
. addArgument ( transaction : : toTraceLog )
. addArgument ( transaction : : toTraceLog )
. addArgument ( evaluationTime )
. addArgument ( evaluationTimer )
. addArgument ( blockTxsSelectionMaxTime )
. addArgument ( blockTxsSelectionMaxTime )
. log ( ) ;
. log ( ) ;
timeoutSelectionResult = TX_EVALUATION_TOO_LONG ;
timeoutSelectionResult = TX_EVALUATION_TOO_LONG ;
@ -390,7 +387,7 @@ public class BlockTransactionSelector {
LOG . atTrace ( )
LOG . atTrace ( )
. setMessage ( "Transaction {} is too late for inclusion" )
. setMessage ( "Transaction {} is too late for inclusion" )
. addArgument ( transaction : : toTraceLog )
. addArgument ( transaction : : toTraceLog )
. addArgument ( evaluationTime )
. addArgument ( evaluationTimer )
. log ( ) ;
. log ( ) ;
timeoutSelectionResult = BLOCK_SELECTION_TIMEOUT ;
timeoutSelectionResult = BLOCK_SELECTION_TIMEOUT ;
}
}
@ -398,15 +395,15 @@ public class BlockTransactionSelector {
// do not rely on the presence of this result, since by the time it is added, the code
// do not rely on the presence of this result, since by the time it is added, the code
// reading it could have been already executed by another thread
// reading it could have been already executed by another thread
return handleTransactionNotSelected (
return handleTransactionNotSelected (
pendingTransaction , timeoutSelectionResult , txWorldStateUpdater , evaluationStartedAt ) ;
pendingTransaction , timeoutSelectionResult , txWorldStateUpdater , evaluationTimer ) ;
}
}
pluginTransactionSelector . onTransactionSelected ( pendingTransaction , processingResult ) ;
pluginTransactionSelector . onTransactionSelected ( pendingTransaction , processingResult ) ;
blockWorldStateUpdater = worldState . updater ( ) ;
blockWorldStateUpdater = worldState . updater ( ) ;
LOG . atTrace ( )
LOG . atTrace ( )
. setMessage ( "Selected {} for block creation, evaluated in {}ms " )
. setMessage ( "Selected {} for block creation, evaluated in {}" )
. addArgument ( transaction : : toTraceLog )
. addArgument ( transaction : : toTraceLog )
. addArgument ( evaluationTime )
. addArgument ( evaluationTimer )
. log ( ) ;
. log ( ) ;
return SELECTED ;
return SELECTED ;
}
}
@ -418,22 +415,22 @@ public class BlockTransactionSelector {
*
*
* @param pendingTransaction The unselected pending transaction .
* @param pendingTransaction The unselected pending transaction .
* @param selectionResult The result of the transaction selection process .
* @param selectionResult The result of the transaction selection process .
* @param evaluationStartedAt when the evaluation of this tx started
* @param evaluationTimer tracks the evaluation elapsed time
* @return The result of the transaction selection process .
* @return The result of the transaction selection process .
* /
* /
private TransactionSelectionResult handleTransactionNotSelected (
private TransactionSelectionResult handleTransactionNotSelected (
final PendingTransaction pendingTransaction ,
final PendingTransaction pendingTransaction ,
final TransactionSelectionResult selectionResult ,
final TransactionSelectionResult selectionResult ,
final long evaluationStartedAt ) {
final Stopwatch evaluationTimer ) {
transactionSelectionResults . updateNotSelected (
transactionSelectionResults . updateNotSelected (
pendingTransaction . getTransaction ( ) , selectionResult ) ;
pendingTransaction . getTransaction ( ) , selectionResult ) ;
pluginTransactionSelector . onTransactionNotSelected ( pendingTransaction , selectionResult ) ;
pluginTransactionSelector . onTransactionNotSelected ( pendingTransaction , selectionResult ) ;
LOG . atTrace ( )
LOG . atTrace ( )
. setMessage ( "Not selected {} for block creation with result {}, evaluated in {}ms " )
. setMessage ( "Not selected {} for block creation with result {}, evaluated in {}" )
. addArgument ( pendingTransaction : : toTraceLog )
. addArgument ( pendingTransaction : : toTraceLog )
. addArgument ( selectionResult )
. addArgument ( selectionResult )
. addArgument ( ( ) - > System . currentTimeMillis ( ) - evaluationStartedAt )
. addArgument ( evaluationTimer )
. log ( ) ;
. log ( ) ;
return selectionResult ;
return selectionResult ;
@ -443,9 +440,9 @@ public class BlockTransactionSelector {
final PendingTransaction pendingTransaction ,
final PendingTransaction pendingTransaction ,
final TransactionSelectionResult selectionResult ,
final TransactionSelectionResult selectionResult ,
final WorldUpdater txWorldStateUpdater ,
final WorldUpdater txWorldStateUpdater ,
final long evaluationStartedAt ) {
final Stopwatch evaluationTimer ) {
txWorldStateUpdater . revert ( ) ;
txWorldStateUpdater . revert ( ) ;
return handleTransactionNotSelected ( pendingTransaction , selectionResult , evaluationStartedAt ) ;
return handleTransactionNotSelected ( pendingTransaction , selectionResult , evaluationTimer ) ;
}
}
private void checkCancellation ( ) {
private void checkCancellation ( ) {