diff --git a/node/src/main/kotlin/com/r3corda/node/services/events/NodeSchedulerService.kt b/node/src/main/kotlin/com/r3corda/node/services/events/NodeSchedulerService.kt index 220404a036..2c30c44044 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/events/NodeSchedulerService.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/events/NodeSchedulerService.kt @@ -4,6 +4,7 @@ import co.paralleluniverse.fibers.Suspendable import com.google.common.util.concurrent.SettableFuture import com.r3corda.core.ThreadBox import com.r3corda.core.contracts.SchedulableState +import com.r3corda.core.contracts.ScheduledActivity import com.r3corda.core.contracts.ScheduledStateRef import com.r3corda.core.contracts.StateRef import com.r3corda.core.node.services.SchedulerService @@ -167,17 +168,27 @@ class NodeSchedulerService(private val database: Database, override fun call(): Unit { progressTracker.currentStep = RUNNING + // Ensure we are still scheduled. + val scheduledLogic: ProtocolLogic<*>? = getScheduledLogic() + if(scheduledLogic != null) { + subProtocol(scheduledLogic) + } + } + + private fun getScheduledaActivity(): ScheduledActivity? { val txState = serviceHub.loadState(scheduledState.ref) val state = txState.data as SchedulableState - val scheduledActivity = try { + return try { // This can throw as running contract code. state.nextScheduledActivity(scheduledState.ref, scheduler.protocolLogicRefFactory) } catch(e: Exception) { logger.error("Attempt to run scheduled state $scheduledState resulted in error.", e) null } + } - // Ensure we are still scheduled. + private fun getScheduledLogic(): ProtocolLogic<*>? { + val scheduledActivity = getScheduledaActivity() var scheduledLogic: ProtocolLogic<*>? = null scheduler.mutex.locked { // need to remove us from those scheduled, but only if we are still next @@ -206,9 +217,7 @@ class NodeSchedulerService(private val database: Database, recomputeEarliest() scheduler.rescheduleWakeUp() } - if(scheduledLogic != null) { - subProtocol(scheduledLogic!!) - } + return scheduledLogic } } } \ No newline at end of file diff --git a/node/src/main/kotlin/com/r3corda/node/services/statemachine/ProtocolStateMachineImpl.kt b/node/src/main/kotlin/com/r3corda/node/services/statemachine/ProtocolStateMachineImpl.kt index 7b31b6a787..1b2226f4aa 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/statemachine/ProtocolStateMachineImpl.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/statemachine/ProtocolStateMachineImpl.kt @@ -240,7 +240,7 @@ class ProtocolStateMachineImpl(override val id: StateMachineRunId, actionOnSuspend(ioRequest) } catch (t: Throwable) { // Do not throw exception again - Quasar completely bins it. - logger.warn("Captured exception which was swallowed by Quasar", t) + logger.warn("Captured exception which was swallowed by Quasar for $logic at ${fiber.stackTrace.toList().joinToString("\n")}", t) // TODO When error handling is introduced, look into whether we should be deleting the checkpoint and // completing the Future processException(t)