From a74c4917452a9123cda3c19f30edad9d2a227b94 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Fri, 12 Aug 2016 16:45:41 +0100 Subject: [PATCH 1/3] Fixed a bug where if NotaryService.Type is used as an advertised service no notary is created and no obvious error occurs. --- .../kotlin/com/r3corda/node/driver/NodeRunner.kt | 1 - .../com/r3corda/node/internal/AbstractNode.kt | 14 ++++++++++---- .../node/services/transactions/NotaryService.kt | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/node/src/main/kotlin/com/r3corda/node/driver/NodeRunner.kt b/node/src/main/kotlin/com/r3corda/node/driver/NodeRunner.kt index 1f96d50b12..8a7904cce4 100644 --- a/node/src/main/kotlin/com/r3corda/node/driver/NodeRunner.kt +++ b/node/src/main/kotlin/com/r3corda/node/driver/NodeRunner.kt @@ -27,7 +27,6 @@ class NodeRunner { companion object { @JvmStatic fun main(arguments: Array) { val cliParams = CliParams.parse(CliParams.parser.parse(*arguments)) - val nodeDirectory = Paths.get(cliParams.baseDirectory) createNodeRunDirectory(nodeDirectory) diff --git a/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt index 117df07d75..50e270b60e 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt @@ -256,7 +256,9 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, if (NetworkMapService.Type in serviceTypes) makeNetworkMapService() val notaryServiceType = serviceTypes.singleOrNull { it.isSubTypeOf(NotaryService.Type) } - if (notaryServiceType != null) makeNotaryService(notaryServiceType) + if (notaryServiceType != null) { + makeNotaryService(notaryServiceType) + } } /** @@ -316,10 +318,14 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, val timestampChecker = TimestampChecker(platformClock, 30.seconds) inNodeNotaryService = when (type) { - is SimpleNotaryService.Type -> SimpleNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache) - is ValidatingNotaryService.Type -> ValidatingNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache) - else -> null + SimpleNotaryService.Type -> SimpleNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache) + ValidatingNotaryService.Type -> ValidatingNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache) + else -> { + throw IllegalArgumentException("Notary type ${type.id} is not handled by makeNotaryService.") + } } + + require(inNodeNotaryService != null) } protected open fun makeIdentityService(): IdentityService { diff --git a/node/src/main/kotlin/com/r3corda/node/services/transactions/NotaryService.kt b/node/src/main/kotlin/com/r3corda/node/services/transactions/NotaryService.kt index ad409fade3..1a4c9835bf 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/transactions/NotaryService.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/transactions/NotaryService.kt @@ -24,6 +24,7 @@ abstract class NotaryService(val smm: StateMachineManager, val timestampChecker: TimestampChecker, val uniquenessProvider: UniquenessProvider, networkMapCache: NetworkMapCache) : AbstractNodeService(net, networkMapCache) { + // Do not specify this as an advertised service. Use a concrete implementation. object Type : ServiceType("corda.notary") abstract val logger: org.slf4j.Logger From 85dce390f445645b124964f02841053dcd96dc02 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Mon, 15 Aug 2016 16:33:21 +0100 Subject: [PATCH 2/3] makeNotaryService now enforces post condition with type system. --- .../main/kotlin/com/r3corda/node/internal/AbstractNode.kt | 8 +++----- .../test/kotlin/com/r3corda/node/driver/DriverTests.kt | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt index 50e270b60e..e5e949f8a2 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/com/r3corda/node/internal/AbstractNode.kt @@ -257,7 +257,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, val notaryServiceType = serviceTypes.singleOrNull { it.isSubTypeOf(NotaryService.Type) } if (notaryServiceType != null) { - makeNotaryService(notaryServiceType) + inNodeNotaryService = makeNotaryService(notaryServiceType) } } @@ -313,19 +313,17 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration, inNodeNetworkMapService = InMemoryNetworkMapService(net, reg, services.networkMapCache) } - open protected fun makeNotaryService(type: ServiceType) { + open protected fun makeNotaryService(type: ServiceType): NotaryService { val uniquenessProvider = InMemoryUniquenessProvider() val timestampChecker = TimestampChecker(platformClock, 30.seconds) - inNodeNotaryService = when (type) { + return when (type) { SimpleNotaryService.Type -> SimpleNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache) ValidatingNotaryService.Type -> ValidatingNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache) else -> { throw IllegalArgumentException("Notary type ${type.id} is not handled by makeNotaryService.") } } - - require(inNodeNotaryService != null) } protected open fun makeIdentityService(): IdentityService { diff --git a/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt b/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt index 58d448e643..837a270872 100644 --- a/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt @@ -5,6 +5,7 @@ import com.r3corda.core.node.services.NetworkMapCache import com.r3corda.node.services.api.RegulatorService import com.r3corda.node.services.messaging.ArtemisMessagingComponent import com.r3corda.node.services.transactions.NotaryService +import com.r3corda.node.services.transactions.SimpleNotaryService import org.junit.Test @@ -32,7 +33,7 @@ class DriverTests { @Test fun simpleNodeStartupShutdownWorks() { val (notary, regulator) = driver { - val notary = startNode("TestNotary", setOf(NotaryService.Type)) + val notary = startNode("TestNotary", setOf(SimpleNotaryService.Type)) val regulator = startNode("Regulator", setOf(RegulatorService.Type)) nodeMustBeUp(networkMapCache, notary, "TestNotary") From 7b3003ea04b01bb296d4bf49f41a122d670dc757 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Fri, 19 Aug 2016 16:41:49 +0100 Subject: [PATCH 3/3] Added TODO for further work --- .../com/r3corda/node/services/transactions/NotaryService.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/node/src/main/kotlin/com/r3corda/node/services/transactions/NotaryService.kt b/node/src/main/kotlin/com/r3corda/node/services/transactions/NotaryService.kt index 1a4c9835bf..bf60b126a6 100644 --- a/node/src/main/kotlin/com/r3corda/node/services/transactions/NotaryService.kt +++ b/node/src/main/kotlin/com/r3corda/node/services/transactions/NotaryService.kt @@ -25,6 +25,7 @@ abstract class NotaryService(val smm: StateMachineManager, val uniquenessProvider: UniquenessProvider, networkMapCache: NetworkMapCache) : AbstractNodeService(net, networkMapCache) { // Do not specify this as an advertised service. Use a concrete implementation. + // TODO: We do not want a service type that cannot be used. Fix the type system abuse here. object Type : ServiceType("corda.notary") abstract val logger: org.slf4j.Logger