From aabc3c5b02eb3efa0a5809ac6d061dee01050fdf Mon Sep 17 00:00:00 2001 From: Andrzej Cichocki Date: Fri, 17 Nov 2017 13:07:18 +0000 Subject: [PATCH] NodeInfo is no longer lateinit. (#2068) --- .../net/corda/node/internal/AbstractNode.kt | 30 +++++++++---------- .../kotlin/net/corda/node/internal/Node.kt | 3 +- .../kotlin/net/corda/testing/node/MockNode.kt | 3 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index 078edad345..14a8179d19 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -119,7 +119,6 @@ abstract class AbstractNode(val configuration: NodeConfiguration, protected val services: ServiceHubInternal get() = _services private lateinit var _services: ServiceHubInternalImpl - protected lateinit var info: NodeInfo protected val nodeStateObservable: PublishSubject = PublishSubject.create() protected var myNotaryIdentity: PartyAndCertificate? = null protected lateinit var checkpointStorage: CheckpointStorage @@ -166,7 +165,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration, check(started == null) { "Node has already been started" } log.info("Generating nodeInfo ...") initCertificate() - val keyPairs = initNodeInfo() + val (keyPairs, info) = initNodeInfo() val identityKeypair = keyPairs.first { it.public == info.legalIdentities.first().owningKey } val serialisedNodeInfo = info.serialize() val signature = identityKeypair.sign(serialisedNodeInfo) @@ -178,13 +177,13 @@ abstract class AbstractNode(val configuration: NodeConfiguration, check(started == null) { "Node has already been started" } log.info("Node starting up ...") initCertificate() - val keyPairs = initNodeInfo() + val (keyPairs, info) = initNodeInfo() val schemaService = NodeSchemaService(cordappLoader) // Do all of this in a database transaction so anything that might need a connection has one. val (startedImpl, schedulerService) = initialiseDatabasePersistence(schemaService) { database -> val transactionStorage = makeTransactionStorage(database) val stateLoader = StateLoaderImpl(transactionStorage) - val nodeServices = makeServices(keyPairs, schemaService, transactionStorage, stateLoader, database) + val nodeServices = makeServices(keyPairs, schemaService, transactionStorage, stateLoader, database, info) val notaryService = makeNotaryService(nodeServices, database) smm = makeStateMachineManager(database) val flowStarter = FlowStarterImpl(serverThread, smm) @@ -244,7 +243,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration, } } - private fun initNodeInfo(): Set { + private fun initNodeInfo(): Pair, NodeInfo> { val (identity, identityKeyPair) = obtainIdentity(notaryConfig = null) val keyPairs = mutableSetOf(identityKeyPair) @@ -253,13 +252,13 @@ abstract class AbstractNode(val configuration: NodeConfiguration, keyPairs += notaryIdentityKeyPair notaryIdentity } - info = NodeInfo( + val info = NodeInfo( myAddresses(), listOf(identity, myNotaryIdentity).filterNotNull(), versionInfo.platformVersion, platformClock.instant().toEpochMilli() ) - return keyPairs + return Pair(keyPairs, info) } protected abstract fun myAddresses(): List @@ -485,12 +484,12 @@ abstract class AbstractNode(val configuration: NodeConfiguration, * Builds node internal, advertised, and plugin services. * Returns a list of tokenizable services to be added to the serialisation context. */ - private fun makeServices(keyPairs: Set, schemaService: SchemaService, transactionStorage: WritableTransactionStorage, stateLoader: StateLoader, database: CordaPersistence): MutableList { + private fun makeServices(keyPairs: Set, schemaService: SchemaService, transactionStorage: WritableTransactionStorage, stateLoader: StateLoader, database: CordaPersistence, info: NodeInfo): MutableList { checkpointStorage = DBCheckpointStorage() val metrics = MetricRegistry() attachments = NodeAttachmentService(metrics) val cordappProvider = CordappProviderImpl(cordappLoader, attachments) - val identityService = makeIdentityService() + val identityService = makeIdentityService(info) val keyManagementService = makeKeyManagementService(identityService, keyPairs) _services = ServiceHubInternalImpl( identityService, @@ -500,8 +499,9 @@ abstract class AbstractNode(val configuration: NodeConfiguration, stateLoader, MonitoringService(metrics), cordappProvider, - database) - network = makeMessagingService(database) + database, + info) + network = makeMessagingService(database, info) val tokenizableServices = mutableListOf(attachments, network, services.vaultService, services.keyManagementService, services.identityService, platformClock, services.auditService, services.monitoringService, services.networkMapCache, services.schemaService, @@ -606,7 +606,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration, } } - private fun makeIdentityService(): IdentityService { + private fun makeIdentityService(info: NodeInfo): IdentityService { val trustStore = KeyStoreWrapper(configuration.trustStoreFile, configuration.trustStorePassword) val caKeyStore = KeyStoreWrapper(configuration.nodeKeystore, configuration.keyStorePassword) val trustRoot = trustStore.getX509Certificate(X509Utilities.CORDA_ROOT_CA) @@ -635,7 +635,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration, _started = null } - protected abstract fun makeMessagingService(database: CordaPersistence): MessagingService + protected abstract fun makeMessagingService(database: CordaPersistence, info: NodeInfo): MessagingService protected abstract fun startMessagingService(rpcOps: RPCOps) private fun obtainIdentity(notaryConfig: NotaryConfig?): Pair { @@ -714,7 +714,8 @@ abstract class AbstractNode(val configuration: NodeConfiguration, private val stateLoader: StateLoader, override val monitoringService: MonitoringService, override val cordappProvider: CordappProviderInternal, - override val database: CordaPersistence + override val database: CordaPersistence, + override val myInfo: NodeInfo ) : SingletonSerializeAsToken(), ServiceHubInternal, StateLoader by stateLoader { override val rpcFlows = ArrayList>>() override val stateMachineRecordedTransactionMapping = DBTransactionMappingStorage() @@ -726,7 +727,6 @@ abstract class AbstractNode(val configuration: NodeConfiguration, override val attachments: AttachmentStorage get() = this@AbstractNode.attachments override val networkService: MessagingService get() = network override val clock: Clock get() = platformClock - override val myInfo: NodeInfo get() = info override val myNodeStateObservable: Observable get() = nodeStateObservable override val configuration: NodeConfiguration get() = this@AbstractNode.configuration override fun cordaService(type: Class): T { diff --git a/node/src/main/kotlin/net/corda/node/internal/Node.kt b/node/src/main/kotlin/net/corda/node/internal/Node.kt index d6850bd695..534a63c344 100644 --- a/node/src/main/kotlin/net/corda/node/internal/Node.kt +++ b/node/src/main/kotlin/net/corda/node/internal/Node.kt @@ -6,6 +6,7 @@ import net.corda.core.internal.concurrent.openFuture import net.corda.core.internal.concurrent.thenMatch import net.corda.core.internal.uncheckedCast import net.corda.core.messaging.RPCOps +import net.corda.core.node.NodeInfo import net.corda.core.node.ServiceHub import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.loggerFor @@ -127,7 +128,7 @@ open class Node(configuration: NodeConfiguration, private var shutdownHook: ShutdownHook? = null private lateinit var userService: RPCUserService - override fun makeMessagingService(database: CordaPersistence): MessagingService { + override fun makeMessagingService(database: CordaPersistence, info: NodeInfo): MessagingService { userService = RPCUserServiceImpl(configuration.rpcUsers) val serverAddress = configuration.messagingServerAddress ?: makeLocalMessageBroker() diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt index 699cb76b4b..5f7b04135a 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt @@ -14,6 +14,7 @@ import net.corda.core.internal.uncheckedCast import net.corda.core.messaging.MessageRecipients import net.corda.core.messaging.RPCOps import net.corda.core.messaging.SingleMessageRecipient +import net.corda.core.node.NodeInfo import net.corda.core.node.services.IdentityService import net.corda.core.node.services.KeyManagementService import net.corda.core.serialization.SerializationWhitelist @@ -238,7 +239,7 @@ class MockNetwork(defaultParameters: MockNetworkParameters = MockNetworkParamete // We only need to override the messaging service here, as currently everything that hits disk does so // through the java.nio API which we are already mocking via Jimfs. - override fun makeMessagingService(database: CordaPersistence): MessagingService { + override fun makeMessagingService(database: CordaPersistence, info: NodeInfo): MessagingService { require(id >= 0) { "Node ID must be zero or positive, was passed: " + id } return mockNet.messagingNetwork.createNodeWithID( !mockNet.threadPerNode,