Skip to content

Commit

Permalink
ENT-2054: Logging improvements (corda#3397)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkolomeyko authored Jun 19, 2018
1 parent 1004c0f commit d4b982b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/src/main/kotlin/net/corda/core/flows/NotaryError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NotaryException(
val error: NotaryError,
/** Id of the transaction to be notarised. Can be _null_ if an error occurred before the id could be resolved. */
val txId: SecureHash? = null
) : FlowException("Unable to notarise transaction${txId ?: " "}: $error")
) : FlowException("Unable to notarise transaction ${txId ?: "<Unknown>"} : $error")

/** Specifies the cause for notarisation request failure. */
@CordaSerializable
Expand All @@ -27,7 +27,9 @@ sealed class NotaryError {
/** Specifies which states have already been consumed in another transaction. */
val consumedStates: Map<StateRef, StateConsumptionDetails>
) : NotaryError() {
override fun toString() = "One or more input states have been used in another transaction"
override fun toString() = "Conflict notarising transaction $txId. " +
"Input states have been used in another transactions, count: ${consumedStates.size}, " +
"content: ${consumedStates.asSequence().joinToString(limit = 5) { it.key.toString() + "->" + it.value }}"
}

/** Occurs when time specified in the [TimeWindow] command is outside the allowed tolerance. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.corda.testing.core.SerializationEnvironmentRule
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class NotaryExceptionSerializationTest {
@Rule
Expand All @@ -27,5 +28,6 @@ class NotaryExceptionSerializationTest {
val instanceOnTheOtherSide = instance.serialize().bytes.deserialize<NotaryException>()

assertEquals(instance.error, instanceOnTheOtherSide.error)
assertTrue(instance.error.toString().contains("->"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ open class CashPaymentFlow(
val anonymousRecipient = txIdentities[recipient] ?: recipient
progressTracker.currentStep = GENERATING_TX
val builder = TransactionBuilder(notary = null)
logger.info("Generating spend for: ${builder.lockId}")
// TODO: Have some way of restricting this to states the caller controls
val (spendTX, keysForSigning) = try {
Cash.generateSpend(serviceHub,
Expand All @@ -65,10 +66,13 @@ open class CashPaymentFlow(
}

progressTracker.currentStep = SIGNING_TX
logger.info("Signing transaction for: ${spendTX.lockId}")
val tx = serviceHub.signInitialTransaction(spendTX, keysForSigning)

progressTracker.currentStep = FINALISING_TX
logger.info("Finalising transaction for: ${tx.id}")
val notarised = finaliseTx(tx, setOf(recipient), "Unable to notarise spend")
logger.info("Finalised transaction for: ${notarised.id}")
return Result(notarised, anonymousRecipient)
}

Expand Down

0 comments on commit d4b982b

Please sign in to comment.