mirror of
https://github.com/corda/corda.git
synced 2025-02-21 09:51:57 +00:00
CORDA-961 - Revert the introduction of GlobalProperties.
* Changes to LargeTransactionTests. * Code review changes. * Code review changes. * Code review changes. * Reverted to MAX_FILE_SIZE for Artemis. * reverted max message size for BridgeControlListener inside Node.kt * reverted max message size for BridgeControlListener inside Node.kt * Renamed setNetworkParameters to withNetworkParameters in MockNetwork.kt * Updated to reflect latest state.
This commit is contained in:
parent
273d5c5d7a
commit
22f6827131
1084
.ci/api-current.txt
1084
.ci/api-current.txt
File diff suppressed because it is too large
Load Diff
@ -1,14 +0,0 @@
|
|||||||
package net.corda.core.internal
|
|
||||||
|
|
||||||
import net.corda.core.node.NetworkParameters
|
|
||||||
|
|
||||||
// TODO: This will cause problems when we run tests in parallel, make each node have its own properties.
|
|
||||||
object GlobalProperties {
|
|
||||||
private var _networkParameters: NetworkParameters? = null
|
|
||||||
|
|
||||||
var networkParameters: NetworkParameters
|
|
||||||
get() = checkNotNull(_networkParameters) { "Property 'networkParameters' has not been initialised." }
|
|
||||||
set(value) {
|
|
||||||
_networkParameters = value
|
|
||||||
}
|
|
||||||
}
|
|
@ -60,6 +60,9 @@ interface ServicesForResolution : StateLoader {
|
|||||||
|
|
||||||
/** Provides access to anything relating to cordapps including contract attachment resolution and app context */
|
/** Provides access to anything relating to cordapps including contract attachment resolution and app context */
|
||||||
val cordappProvider: CordappProvider
|
val cordappProvider: CordappProvider
|
||||||
|
|
||||||
|
/** Returns the network parameters the node is operating under. */
|
||||||
|
val networkParameters: NetworkParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,6 @@ import net.corda.core.contracts.ComponentGroupEnum.*
|
|||||||
import net.corda.core.crypto.*
|
import net.corda.core.crypto.*
|
||||||
import net.corda.core.identity.Party
|
import net.corda.core.identity.Party
|
||||||
import net.corda.core.internal.Emoji
|
import net.corda.core.internal.Emoji
|
||||||
import net.corda.core.internal.GlobalProperties
|
|
||||||
import net.corda.core.node.ServicesForResolution
|
import net.corda.core.node.ServicesForResolution
|
||||||
import net.corda.core.node.services.AttachmentId
|
import net.corda.core.node.services.AttachmentId
|
||||||
import net.corda.core.serialization.CordaSerializable
|
import net.corda.core.serialization.CordaSerializable
|
||||||
@ -85,11 +84,12 @@ class WireTransaction(componentGroups: List<ComponentGroup>, val privacySalt: Pr
|
|||||||
*/
|
*/
|
||||||
@Throws(AttachmentResolutionException::class, TransactionResolutionException::class)
|
@Throws(AttachmentResolutionException::class, TransactionResolutionException::class)
|
||||||
fun toLedgerTransaction(services: ServicesForResolution): LedgerTransaction {
|
fun toLedgerTransaction(services: ServicesForResolution): LedgerTransaction {
|
||||||
return toLedgerTransaction(
|
return toLedgerTransactionInternal(
|
||||||
resolveIdentity = { services.identityService.partyFromKey(it) },
|
resolveIdentity = { services.identityService.partyFromKey(it) },
|
||||||
resolveAttachment = { services.attachments.openAttachment(it) },
|
resolveAttachment = { services.attachments.openAttachment(it) },
|
||||||
resolveStateRef = { services.loadState(it) },
|
resolveStateRef = { services.loadState(it) },
|
||||||
resolveContractAttachment = { services.cordappProvider.getContractAttachmentID(it.contract) }
|
resolveContractAttachment = { services.cordappProvider.getContractAttachmentID(it.contract) },
|
||||||
|
maxTransactionSize = services.networkParameters.maxTransactionSize
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,12 +100,23 @@ class WireTransaction(componentGroups: List<ComponentGroup>, val privacySalt: Pr
|
|||||||
* @throws AttachmentResolutionException if a required attachment was not found using [resolveAttachment].
|
* @throws AttachmentResolutionException if a required attachment was not found using [resolveAttachment].
|
||||||
* @throws TransactionResolutionException if an input was not found not using [resolveStateRef].
|
* @throws TransactionResolutionException if an input was not found not using [resolveStateRef].
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Use toLedgerTransaction(ServicesForTransaction) instead.")
|
||||||
@Throws(AttachmentResolutionException::class, TransactionResolutionException::class)
|
@Throws(AttachmentResolutionException::class, TransactionResolutionException::class)
|
||||||
fun toLedgerTransaction(
|
fun toLedgerTransaction(
|
||||||
resolveIdentity: (PublicKey) -> Party?,
|
resolveIdentity: (PublicKey) -> Party?,
|
||||||
resolveAttachment: (SecureHash) -> Attachment?,
|
resolveAttachment: (SecureHash) -> Attachment?,
|
||||||
resolveStateRef: (StateRef) -> TransactionState<*>?,
|
resolveStateRef: (StateRef) -> TransactionState<*>?,
|
||||||
resolveContractAttachment: (TransactionState<ContractState>) -> AttachmentId?
|
resolveContractAttachment: (TransactionState<ContractState>) -> AttachmentId?
|
||||||
|
): LedgerTransaction {
|
||||||
|
return toLedgerTransactionInternal(resolveIdentity, resolveAttachment, resolveStateRef, resolveContractAttachment, 10485760)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toLedgerTransactionInternal(
|
||||||
|
resolveIdentity: (PublicKey) -> Party?,
|
||||||
|
resolveAttachment: (SecureHash) -> Attachment?,
|
||||||
|
resolveStateRef: (StateRef) -> TransactionState<*>?,
|
||||||
|
resolveContractAttachment: (TransactionState<ContractState>) -> AttachmentId?,
|
||||||
|
maxTransactionSize: Int
|
||||||
): LedgerTransaction {
|
): LedgerTransaction {
|
||||||
// Look up public keys to authenticated identities. This is just a stub placeholder and will all change in future.
|
// Look up public keys to authenticated identities. This is just a stub placeholder and will all change in future.
|
||||||
val authenticatedArgs = commands.map {
|
val authenticatedArgs = commands.map {
|
||||||
@ -120,15 +131,15 @@ class WireTransaction(componentGroups: List<ComponentGroup>, val privacySalt: Pr
|
|||||||
// Order of attachments is important since contracts may refer to indexes so only append automatic attachments
|
// Order of attachments is important since contracts may refer to indexes so only append automatic attachments
|
||||||
val attachments = (attachments.map { resolveAttachment(it) ?: throw AttachmentResolutionException(it) } + contractAttachments).distinct()
|
val attachments = (attachments.map { resolveAttachment(it) ?: throw AttachmentResolutionException(it) } + contractAttachments).distinct()
|
||||||
val ltx = LedgerTransaction(resolvedInputs, outputs, authenticatedArgs, attachments, id, notary, timeWindow, privacySalt)
|
val ltx = LedgerTransaction(resolvedInputs, outputs, authenticatedArgs, attachments, id, notary, timeWindow, privacySalt)
|
||||||
checkTransactionSize(ltx)
|
checkTransactionSize(ltx, maxTransactionSize)
|
||||||
return ltx
|
return ltx
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkTransactionSize(ltx: LedgerTransaction) {
|
private fun checkTransactionSize(ltx: LedgerTransaction, maxTransactionSize: Int) {
|
||||||
var remainingTransactionSize = GlobalProperties.networkParameters.maxTransactionSize
|
var remainingTransactionSize = maxTransactionSize
|
||||||
|
|
||||||
fun minus(size: Int) {
|
fun minus(size: Int) {
|
||||||
require(remainingTransactionSize > size) { "Transaction exceeded network's maximum transaction size limit : ${GlobalProperties.networkParameters.maxTransactionSize} bytes." }
|
require(remainingTransactionSize > size) { "Transaction exceeded network's maximum transaction size limit : $maxTransactionSize bytes." }
|
||||||
remainingTransactionSize -= size
|
remainingTransactionSize -= size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,10 @@ UNRELEASED
|
|||||||
:doc:`corda-configuration-file` for more details.
|
:doc:`corda-configuration-file` for more details.
|
||||||
|
|
||||||
* Introducing the concept of network parameters which are a set of constants which all nodes on a network must agree on
|
* Introducing the concept of network parameters which are a set of constants which all nodes on a network must agree on
|
||||||
to correctly interop.
|
to correctly interop. These can be retrieved from ``ServiceHub.networkParameters``.
|
||||||
|
|
||||||
|
* One of these parameters, ``maxTransactionSize``, limits the size of a transaction, including its attachments, so that
|
||||||
|
all nodes have sufficient memory to validate transactions.
|
||||||
|
|
||||||
* The set of valid notaries has been moved to the network parameters. Notaries are no longer identified by the CN in
|
* The set of valid notaries has been moved to the network parameters. Notaries are no longer identified by the CN in
|
||||||
their X500 name.
|
their X500 name.
|
||||||
@ -87,9 +90,6 @@ UNRELEASED
|
|||||||
* Moved ``NodeInfoSchema`` to internal package as the node info's database schema is not part of the public API. This
|
* Moved ``NodeInfoSchema`` to internal package as the node info's database schema is not part of the public API. This
|
||||||
was needed to allow changes to the schema.
|
was needed to allow changes to the schema.
|
||||||
|
|
||||||
* Introduced max transaction size limit on transactions. The max transaction size parameter is set by the compatibility zone
|
|
||||||
operator. The parameter is distributed to Corda nodes by network map service as part of the ``NetworkParameters``.
|
|
||||||
|
|
||||||
* Support for external user credentials data source and password encryption [CORDA-827].
|
* Support for external user credentials data source and password encryption [CORDA-827].
|
||||||
|
|
||||||
* Exporting additional JMX metrics (artemis, hibernate statistics) and loading Jolokia agent at JVM startup when using
|
* Exporting additional JMX metrics (artemis, hibernate statistics) and loading Jolokia agent at JVM startup when using
|
||||||
|
@ -4,6 +4,9 @@ import com.nhaarman.mockito_kotlin.doReturn
|
|||||||
import com.nhaarman.mockito_kotlin.whenever
|
import com.nhaarman.mockito_kotlin.whenever
|
||||||
import net.corda.core.contracts.Contract
|
import net.corda.core.contracts.Contract
|
||||||
import net.corda.core.contracts.PartyAndReference
|
import net.corda.core.contracts.PartyAndReference
|
||||||
|
import net.corda.core.contracts.StateRef
|
||||||
|
import net.corda.core.contracts.TransactionState
|
||||||
|
import net.corda.core.cordapp.CordappProvider
|
||||||
import net.corda.core.flows.FlowLogic
|
import net.corda.core.flows.FlowLogic
|
||||||
import net.corda.core.flows.UnexpectedFlowEndException
|
import net.corda.core.flows.UnexpectedFlowEndException
|
||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
@ -12,7 +15,9 @@ import net.corda.core.internal.concurrent.transpose
|
|||||||
import net.corda.core.internal.createDirectories
|
import net.corda.core.internal.createDirectories
|
||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
import net.corda.core.internal.toLedgerTransaction
|
import net.corda.core.internal.toLedgerTransaction
|
||||||
|
import net.corda.core.node.NetworkParameters
|
||||||
import net.corda.core.node.ServicesForResolution
|
import net.corda.core.node.ServicesForResolution
|
||||||
|
import net.corda.core.node.services.AttachmentStorage
|
||||||
import net.corda.core.node.services.IdentityService
|
import net.corda.core.node.services.IdentityService
|
||||||
import net.corda.core.serialization.SerializationFactory
|
import net.corda.core.serialization.SerializationFactory
|
||||||
import net.corda.core.transactions.TransactionBuilder
|
import net.corda.core.transactions.TransactionBuilder
|
||||||
@ -20,6 +25,7 @@ import net.corda.core.utilities.contextLogger
|
|||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.core.utilities.getOrThrow
|
||||||
import net.corda.node.internal.cordapp.CordappLoader
|
import net.corda.node.internal.cordapp.CordappLoader
|
||||||
import net.corda.node.internal.cordapp.CordappProviderImpl
|
import net.corda.node.internal.cordapp.CordappProviderImpl
|
||||||
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import net.corda.testing.core.DUMMY_BANK_A_NAME
|
import net.corda.testing.core.DUMMY_BANK_A_NAME
|
||||||
import net.corda.testing.core.DUMMY_NOTARY_NAME
|
import net.corda.testing.core.DUMMY_NOTARY_NAME
|
||||||
import net.corda.testing.core.SerializationEnvironmentRule
|
import net.corda.testing.core.SerializationEnvironmentRule
|
||||||
@ -78,12 +84,14 @@ class AttachmentLoadingTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val services = rigorousMock<ServicesForResolution>().also {
|
private val services = object : ServicesForResolution {
|
||||||
doReturn(attachments).whenever(it).attachments
|
override fun loadState(stateRef: StateRef): TransactionState<*> = throw NotImplementedError()
|
||||||
doReturn(provider).whenever(it).cordappProvider
|
override val identityService = rigorousMock<IdentityService>().apply {
|
||||||
doReturn(rigorousMock<IdentityService>().also {
|
doReturn(null).whenever(this).partyFromKey(DUMMY_BANK_A.owningKey)
|
||||||
doReturn(null).whenever(it).partyFromKey(DUMMY_BANK_A.owningKey)
|
}
|
||||||
}).whenever(it).identityService
|
override val attachments: AttachmentStorage get() = this@AttachmentLoadingTests.attachments
|
||||||
|
override val cordappProvider: CordappProvider get() = this@AttachmentLoadingTests.provider
|
||||||
|
override val networkParameters: NetworkParameters = testNetworkParameters()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -9,6 +9,8 @@ import net.corda.core.internal.concurrent.transpose
|
|||||||
import net.corda.core.messaging.startFlow
|
import net.corda.core.messaging.startFlow
|
||||||
import net.corda.core.transactions.TransactionBuilder
|
import net.corda.core.transactions.TransactionBuilder
|
||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.core.utilities.getOrThrow
|
||||||
|
import net.corda.node.services.config.MB
|
||||||
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import net.corda.testing.contracts.DummyContract
|
import net.corda.testing.contracts.DummyContract
|
||||||
import net.corda.testing.contracts.DummyState
|
import net.corda.testing.contracts.DummyState
|
||||||
import net.corda.testing.core.*
|
import net.corda.testing.core.*
|
||||||
@ -68,11 +70,15 @@ class LargeTransactionsTest {
|
|||||||
fun checkCanSendLargeTransactions() {
|
fun checkCanSendLargeTransactions() {
|
||||||
// These 4 attachments yield a transaction that's got >10mb attached, so it'd push us over the Artemis
|
// These 4 attachments yield a transaction that's got >10mb attached, so it'd push us over the Artemis
|
||||||
// max message size.
|
// max message size.
|
||||||
val bigFile1 = InputStreamAndHash.createInMemoryTestZip(1024 * 1024 * 3, 0)
|
val bigFile1 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 0)
|
||||||
val bigFile2 = InputStreamAndHash.createInMemoryTestZip(1024 * 1024 * 3, 1)
|
val bigFile2 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 1)
|
||||||
val bigFile3 = InputStreamAndHash.createInMemoryTestZip(1024 * 1024 * 3, 2)
|
val bigFile3 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 2)
|
||||||
val bigFile4 = InputStreamAndHash.createInMemoryTestZip(1024 * 1024 * 3, 3)
|
val bigFile4 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 3)
|
||||||
driver(DriverParameters(startNodesInProcess = true, extraCordappPackagesToScan = listOf("net.corda.testing.contracts"), portAllocation = PortAllocation.RandomFree)) {
|
driver(DriverParameters(
|
||||||
|
startNodesInProcess = true,
|
||||||
|
extraCordappPackagesToScan = listOf("net.corda.testing.contracts"),
|
||||||
|
networkParameters = testNetworkParameters(maxTransactionSize = 13.MB.toInt()),
|
||||||
|
portAllocation = PortAllocation.RandomFree)) {
|
||||||
val rpcUser = User("admin", "admin", setOf("ALL"))
|
val rpcUser = User("admin", "admin", setOf("ALL"))
|
||||||
val (alice, _) = listOf(ALICE_NAME, BOB_NAME).map { startNode(providedName = it, rpcUsers = listOf(rpcUser)) }.transpose().getOrThrow()
|
val (alice, _) = listOf(ALICE_NAME, BOB_NAME).map { startNode(providedName = it, rpcUsers = listOf(rpcUser)) }.transpose().getOrThrow()
|
||||||
CordaRPCClient(alice.rpcAddress).use(rpcUser.username, rpcUser.password) {
|
CordaRPCClient(alice.rpcAddress).use(rpcUser.username, rpcUser.password) {
|
||||||
|
@ -14,7 +14,6 @@ import net.corda.core.identity.CordaX500Name
|
|||||||
import net.corda.core.identity.Party
|
import net.corda.core.identity.Party
|
||||||
import net.corda.core.identity.PartyAndCertificate
|
import net.corda.core.identity.PartyAndCertificate
|
||||||
import net.corda.core.internal.FlowStateMachine
|
import net.corda.core.internal.FlowStateMachine
|
||||||
import net.corda.core.internal.GlobalProperties
|
|
||||||
import net.corda.core.internal.VisibleForTesting
|
import net.corda.core.internal.VisibleForTesting
|
||||||
import net.corda.core.internal.concurrent.map
|
import net.corda.core.internal.concurrent.map
|
||||||
import net.corda.core.internal.concurrent.openFuture
|
import net.corda.core.internal.concurrent.openFuture
|
||||||
@ -198,18 +197,27 @@ abstract class AbstractNode(val configuration: NodeConfiguration,
|
|||||||
val (identity, identityKeyPair) = obtainIdentity(notaryConfig = null)
|
val (identity, identityKeyPair) = obtainIdentity(notaryConfig = null)
|
||||||
val identityService = makeIdentityService(identity.certificate)
|
val identityService = makeIdentityService(identity.certificate)
|
||||||
networkMapClient = configuration.compatibilityZoneURL?.let { NetworkMapClient(it, identityService.trustRoot) }
|
networkMapClient = configuration.compatibilityZoneURL?.let { NetworkMapClient(it, identityService.trustRoot) }
|
||||||
GlobalProperties.networkParameters = NetworkParametersReader(identityService.trustRoot, networkMapClient, configuration.baseDirectory).networkParameters
|
val networkParameters = NetworkParametersReader(identityService.trustRoot, networkMapClient, configuration.baseDirectory).networkParameters
|
||||||
check(GlobalProperties.networkParameters.minimumPlatformVersion <= versionInfo.platformVersion) {
|
check(networkParameters.minimumPlatformVersion <= versionInfo.platformVersion) {
|
||||||
"Node's platform version is lower than network's required minimumPlatformVersion"
|
"Node's platform version is lower than network's required minimumPlatformVersion"
|
||||||
}
|
}
|
||||||
// Do all of this in a database transaction so anything that might need a connection has one.
|
// Do all of this in a database transaction so anything that might need a connection has one.
|
||||||
val (startedImpl, schedulerService) = initialiseDatabasePersistence(schemaService, identityService) { database ->
|
val (startedImpl, schedulerService) = initialiseDatabasePersistence(schemaService, identityService) { database ->
|
||||||
val networkMapCache = NetworkMapCacheImpl(PersistentNetworkMapCache(database, GlobalProperties.networkParameters.notaries).start(), identityService)
|
val networkMapCache = NetworkMapCacheImpl(PersistentNetworkMapCache(database, networkParameters.notaries).start(), identityService)
|
||||||
val (keyPairs, nodeInfo) = initNodeInfo(networkMapCache, identity, identityKeyPair)
|
val (keyPairs, nodeInfo) = initNodeInfo(networkMapCache, identity, identityKeyPair)
|
||||||
identityService.loadIdentities(nodeInfo.legalIdentitiesAndCerts)
|
identityService.loadIdentities(nodeInfo.legalIdentitiesAndCerts)
|
||||||
val transactionStorage = makeTransactionStorage(database, configuration.transactionCacheSizeBytes)
|
val transactionStorage = makeTransactionStorage(database, configuration.transactionCacheSizeBytes)
|
||||||
val nodeProperties = NodePropertiesPersistentStore(StubbedNodeUniqueIdProvider::value, database)
|
val nodeProperties = NodePropertiesPersistentStore(StubbedNodeUniqueIdProvider::value, database)
|
||||||
val nodeServices = makeServices(keyPairs, schemaService, transactionStorage, database, nodeInfo, identityService, networkMapCache, nodeProperties)
|
val nodeServices = makeServices(
|
||||||
|
keyPairs,
|
||||||
|
schemaService,
|
||||||
|
transactionStorage,
|
||||||
|
database,
|
||||||
|
nodeInfo,
|
||||||
|
identityService,
|
||||||
|
networkMapCache,
|
||||||
|
nodeProperties,
|
||||||
|
networkParameters)
|
||||||
val notaryService = makeNotaryService(nodeServices, database)
|
val notaryService = makeNotaryService(nodeServices, database)
|
||||||
val smm = makeStateMachineManager(database)
|
val smm = makeStateMachineManager(database)
|
||||||
val flowLogicRefFactory = FlowLogicRefFactoryImpl(cordappLoader.appClassLoader)
|
val flowLogicRefFactory = FlowLogicRefFactoryImpl(cordappLoader.appClassLoader)
|
||||||
@ -246,7 +254,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration,
|
|||||||
networkMapUpdater = NetworkMapUpdater(services.networkMapCache,
|
networkMapUpdater = NetworkMapUpdater(services.networkMapCache,
|
||||||
NodeInfoWatcher(configuration.baseDirectory, getRxIoScheduler(), Duration.ofMillis(configuration.additionalNodeInfoPollingFrequencyMsec)),
|
NodeInfoWatcher(configuration.baseDirectory, getRxIoScheduler(), Duration.ofMillis(configuration.additionalNodeInfoPollingFrequencyMsec)),
|
||||||
networkMapClient,
|
networkMapClient,
|
||||||
GlobalProperties.networkParameters.serialize().hash,
|
networkParameters.serialize().hash,
|
||||||
configuration.baseDirectory)
|
configuration.baseDirectory)
|
||||||
runOnStop += networkMapUpdater::close
|
runOnStop += networkMapUpdater::close
|
||||||
|
|
||||||
@ -539,7 +547,8 @@ abstract class AbstractNode(val configuration: NodeConfiguration,
|
|||||||
nodeInfo: NodeInfo,
|
nodeInfo: NodeInfo,
|
||||||
identityService: IdentityService,
|
identityService: IdentityService,
|
||||||
networkMapCache: NetworkMapCacheInternal,
|
networkMapCache: NetworkMapCacheInternal,
|
||||||
nodeProperties: NodePropertiesStore): MutableList<Any> {
|
nodeProperties: NodePropertiesStore,
|
||||||
|
networkParameters: NetworkParameters): MutableList<Any> {
|
||||||
checkpointStorage = DBCheckpointStorage()
|
checkpointStorage = DBCheckpointStorage()
|
||||||
val metrics = MetricRegistry()
|
val metrics = MetricRegistry()
|
||||||
attachments = NodeAttachmentService(metrics, configuration.attachmentContentCacheSizeBytes, configuration.attachmentCacheBound)
|
attachments = NodeAttachmentService(metrics, configuration.attachmentContentCacheSizeBytes, configuration.attachmentCacheBound)
|
||||||
@ -555,8 +564,9 @@ abstract class AbstractNode(val configuration: NodeConfiguration,
|
|||||||
database,
|
database,
|
||||||
nodeInfo,
|
nodeInfo,
|
||||||
networkMapCache,
|
networkMapCache,
|
||||||
nodeProperties)
|
nodeProperties,
|
||||||
network = makeMessagingService(database, nodeInfo, nodeProperties)
|
networkParameters)
|
||||||
|
network = makeMessagingService(database, nodeInfo, nodeProperties, networkParameters)
|
||||||
val tokenizableServices = mutableListOf(attachments, network, services.vaultService,
|
val tokenizableServices = mutableListOf(attachments, network, services.vaultService,
|
||||||
services.keyManagementService, services.identityService, platformClock,
|
services.keyManagementService, services.identityService, platformClock,
|
||||||
services.auditService, services.monitoringService, services.networkMapCache, services.schemaService,
|
services.auditService, services.monitoringService, services.networkMapCache, services.schemaService,
|
||||||
@ -690,7 +700,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration,
|
|||||||
_started = null
|
_started = null
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun makeMessagingService(database: CordaPersistence, info: NodeInfo, nodeProperties: NodePropertiesStore): MessagingService
|
protected abstract fun makeMessagingService(database: CordaPersistence, info: NodeInfo, nodeProperties: NodePropertiesStore, networkParameters: NetworkParameters): MessagingService
|
||||||
protected abstract fun startMessagingService(rpcOps: RPCOps)
|
protected abstract fun startMessagingService(rpcOps: RPCOps)
|
||||||
|
|
||||||
private fun obtainIdentity(notaryConfig: NotaryConfig?): Pair<PartyAndCertificate, KeyPair> {
|
private fun obtainIdentity(notaryConfig: NotaryConfig?): Pair<PartyAndCertificate, KeyPair> {
|
||||||
@ -762,7 +772,8 @@ abstract class AbstractNode(val configuration: NodeConfiguration,
|
|||||||
override val database: CordaPersistence,
|
override val database: CordaPersistence,
|
||||||
override val myInfo: NodeInfo,
|
override val myInfo: NodeInfo,
|
||||||
override val networkMapCache: NetworkMapCacheInternal,
|
override val networkMapCache: NetworkMapCacheInternal,
|
||||||
override val nodeProperties: NodePropertiesStore
|
override val nodeProperties: NodePropertiesStore,
|
||||||
|
override val networkParameters: NetworkParameters
|
||||||
) : SingletonSerializeAsToken(), ServiceHubInternal, StateLoader by validatedTransactions {
|
) : SingletonSerializeAsToken(), ServiceHubInternal, StateLoader by validatedTransactions {
|
||||||
override val rpcFlows = ArrayList<Class<out FlowLogic<*>>>()
|
override val rpcFlows = ArrayList<Class<out FlowLogic<*>>>()
|
||||||
override val stateMachineRecordedTransactionMapping = DBTransactionMappingStorage()
|
override val stateMachineRecordedTransactionMapping = DBTransactionMappingStorage()
|
||||||
|
@ -7,6 +7,7 @@ import net.corda.core.internal.concurrent.thenMatch
|
|||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
import net.corda.core.internal.uncheckedCast
|
import net.corda.core.internal.uncheckedCast
|
||||||
import net.corda.core.messaging.RPCOps
|
import net.corda.core.messaging.RPCOps
|
||||||
|
import net.corda.core.node.NetworkParameters
|
||||||
import net.corda.core.node.NodeInfo
|
import net.corda.core.node.NodeInfo
|
||||||
import net.corda.core.node.ServiceHub
|
import net.corda.core.node.ServiceHub
|
||||||
import net.corda.core.node.services.IdentityService
|
import net.corda.core.node.services.IdentityService
|
||||||
@ -92,7 +93,6 @@ open class Node(configuration: NodeConfiguration,
|
|||||||
} ?: CordappLoader.createDefault(configuration.baseDirectory)
|
} ?: CordappLoader.createDefault(configuration.baseDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Wire up maxMessageSize
|
|
||||||
const val MAX_FILE_SIZE = 10485760
|
const val MAX_FILE_SIZE = 10485760
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +149,10 @@ open class Node(configuration: NodeConfiguration,
|
|||||||
|
|
||||||
private var shutdownHook: ShutdownHook? = null
|
private var shutdownHook: ShutdownHook? = null
|
||||||
|
|
||||||
override fun makeMessagingService(database: CordaPersistence, info: NodeInfo, nodeProperties: NodePropertiesStore): MessagingService {
|
override fun makeMessagingService(database: CordaPersistence,
|
||||||
|
info: NodeInfo,
|
||||||
|
nodeProperties: NodePropertiesStore,
|
||||||
|
networkParameters: NetworkParameters): MessagingService {
|
||||||
// Construct security manager reading users data either from the 'security' config section
|
// Construct security manager reading users data either from the 'security' config section
|
||||||
// if present or from rpcUsers list if the former is missing from config.
|
// if present or from rpcUsers list if the former is missing from config.
|
||||||
val securityManagerConfig = configuration.security?.authService ?:
|
val securityManagerConfig = configuration.security?.authService ?:
|
||||||
@ -157,17 +160,21 @@ open class Node(configuration: NodeConfiguration,
|
|||||||
|
|
||||||
securityManager = RPCSecurityManagerImpl(securityManagerConfig)
|
securityManager = RPCSecurityManagerImpl(securityManagerConfig)
|
||||||
|
|
||||||
val serverAddress = configuration.messagingServerAddress ?: makeLocalMessageBroker()
|
val serverAddress = configuration.messagingServerAddress ?: makeLocalMessageBroker(networkParameters)
|
||||||
val rpcServerAddresses = if (configuration.rpcOptions.standAloneBroker) BrokerAddresses(configuration.rpcOptions.address!!, configuration.rpcOptions.adminAddress) else startLocalRpcBroker()
|
val rpcServerAddresses = if (configuration.rpcOptions.standAloneBroker) {
|
||||||
|
BrokerAddresses(configuration.rpcOptions.address!!, configuration.rpcOptions.adminAddress)
|
||||||
|
} else {
|
||||||
|
startLocalRpcBroker(networkParameters)
|
||||||
|
}
|
||||||
val advertisedAddress = info.addresses[0]
|
val advertisedAddress = info.addresses[0]
|
||||||
bridgeControlListener = BridgeControlListener(configuration, serverAddress, /*networkParameters.maxMessageSize*/MAX_FILE_SIZE)
|
bridgeControlListener = BridgeControlListener(configuration, serverAddress, MAX_FILE_SIZE)
|
||||||
|
|
||||||
printBasicNodeInfo("Incoming connection address", advertisedAddress.toString())
|
printBasicNodeInfo("Incoming connection address", advertisedAddress.toString())
|
||||||
rpcServerAddresses?.let {
|
rpcServerAddresses?.let {
|
||||||
rpcMessagingClient = RPCMessagingClient(configuration.rpcOptions.sslConfig, it.admin, /*networkParameters.maxMessageSize*/MAX_FILE_SIZE)
|
rpcMessagingClient = RPCMessagingClient(configuration.rpcOptions.sslConfig, it.admin, MAX_FILE_SIZE)
|
||||||
}
|
}
|
||||||
verifierMessagingClient = when (configuration.verifierType) {
|
verifierMessagingClient = when (configuration.verifierType) {
|
||||||
VerifierType.OutOfProcess -> VerifierMessagingClient(configuration, serverAddress, services.monitoringService.metrics, /*networkParameters.maxMessageSize*/MAX_FILE_SIZE)
|
VerifierType.OutOfProcess -> VerifierMessagingClient(configuration, serverAddress, services.monitoringService.metrics, MAX_FILE_SIZE)
|
||||||
VerifierType.InMemory -> null
|
VerifierType.InMemory -> null
|
||||||
}
|
}
|
||||||
require(info.legalIdentities.size in 1..2) { "Currently nodes must have a primary address and optionally one serviced address" }
|
require(info.legalIdentities.size in 1..2) { "Currently nodes must have a primary address and optionally one serviced address" }
|
||||||
@ -182,21 +189,36 @@ open class Node(configuration: NodeConfiguration,
|
|||||||
database,
|
database,
|
||||||
services.networkMapCache,
|
services.networkMapCache,
|
||||||
advertisedAddress,
|
advertisedAddress,
|
||||||
/*networkParameters.maxMessageSize*/MAX_FILE_SIZE,
|
MAX_FILE_SIZE,
|
||||||
isDrainingModeOn = nodeProperties.flowsDrainingMode::isEnabled,
|
isDrainingModeOn = nodeProperties.flowsDrainingMode::isEnabled,
|
||||||
drainingModeWasChangedEvents = nodeProperties.flowsDrainingMode.values)
|
drainingModeWasChangedEvents = nodeProperties.flowsDrainingMode.values)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startLocalRpcBroker(): BrokerAddresses? {
|
private fun startLocalRpcBroker(networkParameters: NetworkParameters): BrokerAddresses? {
|
||||||
with(configuration) {
|
with(configuration) {
|
||||||
return rpcOptions.address?.let {
|
return rpcOptions.address?.let {
|
||||||
require(rpcOptions.address != null) { "RPC address needs to be specified for local RPC broker." }
|
require(rpcOptions.address != null) { "RPC address needs to be specified for local RPC broker." }
|
||||||
val rpcBrokerDirectory: Path = baseDirectory / "brokers" / "rpc"
|
val rpcBrokerDirectory: Path = baseDirectory / "brokers" / "rpc"
|
||||||
with(rpcOptions) {
|
with(rpcOptions) {
|
||||||
rpcBroker = if (useSsl) {
|
rpcBroker = if (useSsl) {
|
||||||
ArtemisRpcBroker.withSsl(this.address!!, sslConfig, securityManager, certificateChainCheckPolicies, /*networkParameters.maxMessageSize*/MAX_FILE_SIZE, exportJMXto.isNotEmpty(), rpcBrokerDirectory)
|
ArtemisRpcBroker.withSsl(
|
||||||
|
this.address!!,
|
||||||
|
sslConfig,
|
||||||
|
securityManager,
|
||||||
|
certificateChainCheckPolicies,
|
||||||
|
MAX_FILE_SIZE,
|
||||||
|
exportJMXto.isNotEmpty(),
|
||||||
|
rpcBrokerDirectory)
|
||||||
} else {
|
} else {
|
||||||
ArtemisRpcBroker.withoutSsl(this.address!!, adminAddress!!, sslConfig, securityManager, certificateChainCheckPolicies, /*networkParameters.maxMessageSize*/MAX_FILE_SIZE, exportJMXto.isNotEmpty(), rpcBrokerDirectory)
|
ArtemisRpcBroker.withoutSsl(
|
||||||
|
this.address!!,
|
||||||
|
adminAddress!!,
|
||||||
|
sslConfig,
|
||||||
|
securityManager,
|
||||||
|
certificateChainCheckPolicies,
|
||||||
|
MAX_FILE_SIZE,
|
||||||
|
exportJMXto.isNotEmpty(),
|
||||||
|
rpcBrokerDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rpcBroker!!.addresses
|
return rpcBroker!!.addresses
|
||||||
@ -204,16 +226,14 @@ open class Node(configuration: NodeConfiguration,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun makeLocalMessageBroker(): NetworkHostAndPort {
|
private fun makeLocalMessageBroker(networkParameters: NetworkParameters): NetworkHostAndPort {
|
||||||
with(configuration) {
|
with(configuration) {
|
||||||
messageBroker = ArtemisMessagingServer(this, p2pAddress.port, /*networkParameters.maxMessageSize*/MAX_FILE_SIZE)
|
messageBroker = ArtemisMessagingServer(this, p2pAddress.port, MAX_FILE_SIZE)
|
||||||
return NetworkHostAndPort("localhost", p2pAddress.port)
|
return NetworkHostAndPort("localhost", p2pAddress.port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun myAddresses(): List<NetworkHostAndPort> {
|
override fun myAddresses(): List<NetworkHostAndPort> = listOf(getAdvertisedAddress())
|
||||||
return listOf(configuration.messagingServerAddress ?: getAdvertisedAddress())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getAdvertisedAddress(): NetworkHostAndPort {
|
private fun getAdvertisedAddress(): NetworkHostAndPort {
|
||||||
return with(configuration) {
|
return with(configuration) {
|
||||||
|
@ -98,7 +98,7 @@ class NetworkMapClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `handle parameters update`() {
|
fun `handle parameters update`() {
|
||||||
val nextParameters = testNetworkParameters(emptyList(), epoch = 2)
|
val nextParameters = testNetworkParameters(epoch = 2)
|
||||||
val originalNetworkParameterHash = server.networkParameters.serialize().hash
|
val originalNetworkParameterHash = server.networkParameters.serialize().hash
|
||||||
val nextNetworkParameterHash = nextParameters.serialize().hash
|
val nextNetworkParameterHash = nextParameters.serialize().hash
|
||||||
val description = "Test parameters"
|
val description = "Test parameters"
|
||||||
|
@ -201,7 +201,7 @@ class NetworkMapUpdaterTest {
|
|||||||
val snapshot = paramsFeed.snapshot
|
val snapshot = paramsFeed.snapshot
|
||||||
val updates = paramsFeed.updates.bufferUntilSubscribed()
|
val updates = paramsFeed.updates.bufferUntilSubscribed()
|
||||||
assertEquals(null, snapshot)
|
assertEquals(null, snapshot)
|
||||||
val newParameters = testNetworkParameters(emptyList(), epoch = 2)
|
val newParameters = testNetworkParameters(epoch = 2)
|
||||||
val updateDeadline = Instant.now().plus(1, ChronoUnit.DAYS)
|
val updateDeadline = Instant.now().plus(1, ChronoUnit.DAYS)
|
||||||
scheduleParametersUpdate(newParameters, "Test update", updateDeadline)
|
scheduleParametersUpdate(newParameters, "Test update", updateDeadline)
|
||||||
updater.subscribeToNetworkMap()
|
updater.subscribeToNetworkMap()
|
||||||
@ -219,7 +219,7 @@ class NetworkMapUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `ack network parameters update`() {
|
fun `ack network parameters update`() {
|
||||||
val newParameters = testNetworkParameters(emptyList(), epoch = 314)
|
val newParameters = testNetworkParameters(epoch = 314)
|
||||||
scheduleParametersUpdate(newParameters, "Test update", Instant.MIN)
|
scheduleParametersUpdate(newParameters, "Test update", Instant.MIN)
|
||||||
updater.subscribeToNetworkMap()
|
updater.subscribeToNetworkMap()
|
||||||
// TODO: Remove sleep in unit test.
|
// TODO: Remove sleep in unit test.
|
||||||
|
@ -50,7 +50,7 @@ class NetworkParametersReaderTest {
|
|||||||
fun `read correct set of parameters from file`() {
|
fun `read correct set of parameters from file`() {
|
||||||
val fs = Jimfs.newFileSystem(Configuration.unix())
|
val fs = Jimfs.newFileSystem(Configuration.unix())
|
||||||
val baseDirectory = fs.getPath("/node").createDirectories()
|
val baseDirectory = fs.getPath("/node").createDirectories()
|
||||||
val oldParameters = testNetworkParameters(emptyList(), epoch = 1)
|
val oldParameters = testNetworkParameters(epoch = 1)
|
||||||
NetworkParametersCopier(oldParameters).install(baseDirectory)
|
NetworkParametersCopier(oldParameters).install(baseDirectory)
|
||||||
NetworkParametersCopier(server.networkParameters, update = true).install(baseDirectory) // Parameters update file.
|
NetworkParametersCopier(server.networkParameters, update = true).install(baseDirectory) // Parameters update file.
|
||||||
val parameters = NetworkParametersReader(DEV_ROOT_CA.certificate, networkMapClient, baseDirectory).networkParameters
|
val parameters = NetworkParametersReader(DEV_ROOT_CA.certificate, networkMapClient, baseDirectory).networkParameters
|
||||||
|
@ -8,6 +8,7 @@ import net.corda.core.internal.InputStreamAndHash
|
|||||||
import net.corda.core.transactions.TransactionBuilder
|
import net.corda.core.transactions.TransactionBuilder
|
||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.core.utilities.getOrThrow
|
||||||
import net.corda.node.services.api.StartedNodeServices
|
import net.corda.node.services.api.StartedNodeServices
|
||||||
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import net.corda.testing.contracts.DummyContract
|
import net.corda.testing.contracts.DummyContract
|
||||||
import net.corda.testing.contracts.DummyState
|
import net.corda.testing.contracts.DummyState
|
||||||
import net.corda.testing.core.ALICE_NAME
|
import net.corda.testing.core.ALICE_NAME
|
||||||
@ -34,7 +35,9 @@ class MaxTransactionSizeTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
mockNet = InternalMockNetwork(listOf("net.corda.testing.contracts", "net.corda.node.services.transactions"), maxTransactionSize = 3_000_000)
|
mockNet = InternalMockNetwork(
|
||||||
|
listOf("net.corda.testing.contracts", "net.corda.node.services.transactions"),
|
||||||
|
networkParameters = testNetworkParameters(maxTransactionSize = 3_000_000))
|
||||||
val aliceNode = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME))
|
val aliceNode = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME))
|
||||||
val bobNode = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME))
|
val bobNode = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME))
|
||||||
notaryServices = mockNet.defaultNotaryNode.services
|
notaryServices = mockNet.defaultNotaryNode.services
|
||||||
|
@ -110,7 +110,7 @@ class VaultQueryTests {
|
|||||||
cordappPackages,
|
cordappPackages,
|
||||||
makeTestIdentityService(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity),
|
makeTestIdentityService(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity),
|
||||||
megaCorp,
|
megaCorp,
|
||||||
DUMMY_NOTARY_KEY)
|
moreKeys = DUMMY_NOTARY_KEY)
|
||||||
database = databaseAndServices.first
|
database = databaseAndServices.first
|
||||||
services = databaseAndServices.second
|
services = databaseAndServices.second
|
||||||
vaultFiller = VaultFiller(services, dummyNotary)
|
vaultFiller = VaultFiller(services, dummyNotary)
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package net.corda.node.services.vault
|
package net.corda.node.services.vault
|
||||||
|
|
||||||
import net.corda.core.contracts.*
|
import net.corda.core.contracts.ContractState
|
||||||
|
import net.corda.core.contracts.InsufficientBalanceException
|
||||||
|
import net.corda.core.contracts.LinearState
|
||||||
|
import net.corda.core.contracts.UniqueIdentifier
|
||||||
import net.corda.core.crypto.generateKeyPair
|
import net.corda.core.crypto.generateKeyPair
|
||||||
import net.corda.core.identity.AnonymousParty
|
import net.corda.core.identity.AnonymousParty
|
||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
@ -74,7 +77,7 @@ class VaultWithCashTest {
|
|||||||
cordappPackages,
|
cordappPackages,
|
||||||
makeTestIdentityService(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity),
|
makeTestIdentityService(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity),
|
||||||
TestIdentity(MEGA_CORP.name, servicesKey),
|
TestIdentity(MEGA_CORP.name, servicesKey),
|
||||||
dummyNotary.keyPair)
|
moreKeys = dummyNotary.keyPair)
|
||||||
database = databaseAndServices.first
|
database = databaseAndServices.first
|
||||||
services = databaseAndServices.second
|
services = databaseAndServices.second
|
||||||
vaultFiller = VaultFiller(services, dummyNotary)
|
vaultFiller = VaultFiller(services, dummyNotary)
|
||||||
|
@ -8,12 +8,13 @@ import net.corda.core.flows.FlowLogic
|
|||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
import net.corda.core.identity.Party
|
import net.corda.core.identity.Party
|
||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
|
import net.corda.core.node.NetworkParameters
|
||||||
import net.corda.core.node.NodeInfo
|
import net.corda.core.node.NodeInfo
|
||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
import net.corda.node.internal.Node
|
import net.corda.node.internal.Node
|
||||||
import net.corda.node.services.api.StartedNodeServices
|
import net.corda.node.services.api.StartedNodeServices
|
||||||
import net.corda.node.services.config.VerifierType
|
import net.corda.node.services.config.VerifierType
|
||||||
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import net.corda.testing.core.DUMMY_NOTARY_NAME
|
import net.corda.testing.core.DUMMY_NOTARY_NAME
|
||||||
import net.corda.testing.node.NotarySpec
|
import net.corda.testing.node.NotarySpec
|
||||||
import net.corda.testing.node.User
|
import net.corda.testing.node.User
|
||||||
@ -25,7 +26,6 @@ import java.net.InetSocketAddress
|
|||||||
import java.net.ServerSocket
|
import java.net.ServerSocket
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.sql.Connection
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,6 +109,12 @@ data class NodeParameters(
|
|||||||
fun setMaximumHeapSize(maximumHeapSize: String): NodeParameters = copy(maximumHeapSize = maximumHeapSize)
|
fun setMaximumHeapSize(maximumHeapSize: String): NodeParameters = copy(maximumHeapSize = maximumHeapSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property startJmxHttpServer Indicates whether the spawned nodes should start with a Jolokia JMX agent to enable remote
|
||||||
|
* JMX monitoring using HTTP/JSON
|
||||||
|
* @property jmxHttpServerPortAllocation The port allocation strategy to use for remote Jolokia/JMX monitoring over HTTP.
|
||||||
|
* Defaults to incremental.
|
||||||
|
*/
|
||||||
data class JmxPolicy(val startJmxHttpServer: Boolean = false,
|
data class JmxPolicy(val startJmxHttpServer: Boolean = false,
|
||||||
val jmxHttpServerPortAllocation: PortAllocation? =
|
val jmxHttpServerPortAllocation: PortAllocation? =
|
||||||
if (startJmxHttpServer) PortAllocation.Incremental(7005) else null)
|
if (startJmxHttpServer) PortAllocation.Incremental(7005) else null)
|
||||||
@ -128,30 +134,10 @@ data class JmxPolicy(val startJmxHttpServer: Boolean = false,
|
|||||||
*
|
*
|
||||||
* @param defaultParameters The default parameters for the driver. Allows the driver to be configured in builder style
|
* @param defaultParameters The default parameters for the driver. Allows the driver to be configured in builder style
|
||||||
* when called from Java code.
|
* when called from Java code.
|
||||||
* @param isDebug Indicates whether the spawned nodes should start in jdwt debug mode and have debug level logging.
|
|
||||||
* @param driverDirectory The base directory node directories go into, defaults to "build/<timestamp>/". The node
|
|
||||||
* directories themselves are "<baseDirectory>/<legalName>/", where legalName defaults to "<randomName>-<messagingPort>"
|
|
||||||
* and may be specified in [DriverDSL.startNode].
|
|
||||||
* @param portAllocation The port allocation strategy to use for the messaging and the web server addresses. Defaults to incremental.
|
|
||||||
* @param debugPortAllocation The port allocation strategy to use for jvm debugging. Defaults to incremental.
|
|
||||||
* @param systemProperties A Map of extra system properties which will be given to each new node. Defaults to empty.
|
|
||||||
* @param useTestClock If true the test clock will be used in Node.
|
|
||||||
* @param startNodesInProcess Provides the default behaviour of whether new nodes should start inside this process or
|
|
||||||
* not. Note that this may be overridden in [DriverDSL.startNode].
|
|
||||||
* @param waitForAllNodesToFinish If true, the nodes will not shut down automatically after executing the code in the driver DSL block.
|
|
||||||
* It will wait for them to be shut down externally instead.
|
|
||||||
* @param notarySpecs The notaries advertised for this network. These nodes will be started automatically and will be
|
|
||||||
* available from [DriverDSL.notaryHandles]. Defaults to a simple validating notary.
|
|
||||||
* @param jmxPolicy Used to specify whether to expose JMX metrics via Jolokia HHTP/JSON. Defines two attributes:
|
|
||||||
* startJmxHttpServer: indicates whether the spawned nodes should start with a Jolokia JMX agent to enable remote JMX monitoring using HTTP/JSON.
|
|
||||||
* jmxHttpServerPortAllocation: the port allocation strategy to use for remote Jolokia/JMX monitoring over HTTP. Defaults to incremental.
|
|
||||||
* @param dsl The dsl itself.
|
* @param dsl The dsl itself.
|
||||||
* @return The value returned in the [dsl] closure.
|
* @return The value returned in the [dsl] closure.
|
||||||
*/
|
*/
|
||||||
fun <A> driver(
|
fun <A> driver(defaultParameters: DriverParameters = DriverParameters(), dsl: DriverDSL.() -> A): A {
|
||||||
defaultParameters: DriverParameters = DriverParameters(),
|
|
||||||
dsl: DriverDSL.() -> A
|
|
||||||
): A {
|
|
||||||
return genericDriver(
|
return genericDriver(
|
||||||
driverDsl = DriverDSLImpl(
|
driverDsl = DriverDSLImpl(
|
||||||
portAllocation = defaultParameters.portAllocation,
|
portAllocation = defaultParameters.portAllocation,
|
||||||
@ -166,7 +152,7 @@ fun <A> driver(
|
|||||||
extraCordappPackagesToScan = defaultParameters.extraCordappPackagesToScan,
|
extraCordappPackagesToScan = defaultParameters.extraCordappPackagesToScan,
|
||||||
jmxPolicy = defaultParameters.jmxPolicy,
|
jmxPolicy = defaultParameters.jmxPolicy,
|
||||||
compatibilityZone = null,
|
compatibilityZone = null,
|
||||||
maxTransactionSize = defaultParameters.maxTransactionSize
|
networkParameters = defaultParameters.networkParameters
|
||||||
),
|
),
|
||||||
coerce = { it },
|
coerce = { it },
|
||||||
dsl = dsl,
|
dsl = dsl,
|
||||||
@ -174,7 +160,25 @@ fun <A> driver(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper builder for configuring a [driver] from Java. */
|
/** Builder for configuring a [driver] from Java.
|
||||||
|
* @param isDebug Indicates whether the spawned nodes should start in jdwt debug mode and have debug level logging.
|
||||||
|
* @param driverDirectory The base directory node directories go into, defaults to "build/<timestamp>/". The node
|
||||||
|
* directories themselves are "<baseDirectory>/<legalName>/", where legalName defaults to "<randomName>-<messagingPort>"
|
||||||
|
* and may be specified in [DriverDSL.startNode].
|
||||||
|
* @param portAllocation The port allocation strategy to use for the messaging and the web server addresses. Defaults to incremental.
|
||||||
|
* @param debugPortAllocation The port allocation strategy to use for jvm debugging. Defaults to incremental.
|
||||||
|
* @param systemProperties A Map of extra system properties which will be given to each new node. Defaults to empty.
|
||||||
|
* @param useTestClock If true the test clock will be used in Node.
|
||||||
|
* @param startNodesInProcess Provides the default behaviour of whether new nodes should start inside this process or
|
||||||
|
* not. Note that this may be overridden in [DriverDSL.startNode].
|
||||||
|
* @param waitForAllNodesToFinish If true, the nodes will not shut down automatically after executing the code in the driver DSL block.
|
||||||
|
* It will wait for them to be shut down externally instead.
|
||||||
|
* @param notarySpecs The notaries advertised for this network. These nodes will be started automatically and will be
|
||||||
|
* available from [DriverDSL.notaryHandles]. Defaults to a simple validating notary.
|
||||||
|
* @param jmxPolicy Used to specify whether to expose JMX metrics via Jolokia HHTP/JSON.
|
||||||
|
* @property networkParameters The network parameters to be used by all the nodes. [NetworkParameters.notaries] must be
|
||||||
|
* empty as notaries are defined by [notarySpecs].
|
||||||
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
data class DriverParameters(
|
data class DriverParameters(
|
||||||
val isDebug: Boolean = false,
|
val isDebug: Boolean = false,
|
||||||
@ -189,18 +193,19 @@ data class DriverParameters(
|
|||||||
val notarySpecs: List<NotarySpec> = listOf(NotarySpec(DUMMY_NOTARY_NAME)),
|
val notarySpecs: List<NotarySpec> = listOf(NotarySpec(DUMMY_NOTARY_NAME)),
|
||||||
val extraCordappPackagesToScan: List<String> = emptyList(),
|
val extraCordappPackagesToScan: List<String> = emptyList(),
|
||||||
val jmxPolicy: JmxPolicy = JmxPolicy(),
|
val jmxPolicy: JmxPolicy = JmxPolicy(),
|
||||||
val maxTransactionSize: Int = Int.MAX_VALUE
|
val networkParameters: NetworkParameters = testNetworkParameters()
|
||||||
) {
|
) {
|
||||||
fun setIsDebug(isDebug: Boolean) = copy(isDebug = isDebug)
|
fun setIsDebug(isDebug: Boolean): DriverParameters = copy(isDebug = isDebug)
|
||||||
fun setDriverDirectory(driverDirectory: Path) = copy(driverDirectory = driverDirectory)
|
fun setDriverDirectory(driverDirectory: Path): DriverParameters = copy(driverDirectory = driverDirectory)
|
||||||
fun setPortAllocation(portAllocation: PortAllocation) = copy(portAllocation = portAllocation)
|
fun setPortAllocation(portAllocation: PortAllocation): DriverParameters = copy(portAllocation = portAllocation)
|
||||||
fun setDebugPortAllocation(debugPortAllocation: PortAllocation) = copy(debugPortAllocation = debugPortAllocation)
|
fun setDebugPortAllocation(debugPortAllocation: PortAllocation): DriverParameters = copy(debugPortAllocation = debugPortAllocation)
|
||||||
fun setSystemProperties(systemProperties: Map<String, String>) = copy(systemProperties = systemProperties)
|
fun setSystemProperties(systemProperties: Map<String, String>): DriverParameters = copy(systemProperties = systemProperties)
|
||||||
fun setUseTestClock(useTestClock: Boolean) = copy(useTestClock = useTestClock)
|
fun setUseTestClock(useTestClock: Boolean): DriverParameters = copy(useTestClock = useTestClock)
|
||||||
fun setInitialiseSerialization(initialiseSerialization: Boolean) = copy(initialiseSerialization = initialiseSerialization)
|
fun setInitialiseSerialization(initialiseSerialization: Boolean): DriverParameters = copy(initialiseSerialization = initialiseSerialization)
|
||||||
fun setStartNodesInProcess(startNodesInProcess: Boolean) = copy(startNodesInProcess = startNodesInProcess)
|
fun setStartNodesInProcess(startNodesInProcess: Boolean): DriverParameters = copy(startNodesInProcess = startNodesInProcess)
|
||||||
fun setWaitForAllNodesToFinish(waitForAllNodesToFinish: Boolean) = copy(waitForAllNodesToFinish = waitForAllNodesToFinish)
|
fun setWaitForAllNodesToFinish(waitForAllNodesToFinish: Boolean): DriverParameters = copy(waitForAllNodesToFinish = waitForAllNodesToFinish)
|
||||||
fun setNotarySpecs(notarySpecs: List<NotarySpec>) = copy(notarySpecs = notarySpecs)
|
fun setNotarySpecs(notarySpecs: List<NotarySpec>): DriverParameters = copy(notarySpecs = notarySpecs)
|
||||||
fun setExtraCordappPackagesToScan(extraCordappPackagesToScan: List<String>) = copy(extraCordappPackagesToScan = extraCordappPackagesToScan)
|
fun setExtraCordappPackagesToScan(extraCordappPackagesToScan: List<String>): DriverParameters = copy(extraCordappPackagesToScan = extraCordappPackagesToScan)
|
||||||
fun setJmxPolicy(jmxPolicy: JmxPolicy) = copy(jmxPolicy = jmxPolicy)
|
fun setJmxPolicy(jmxPolicy: JmxPolicy): DriverParameters = copy(jmxPolicy = jmxPolicy)
|
||||||
|
fun setNetworkParameters(networkParameters: NetworkParameters): DriverParameters = copy(networkParameters = networkParameters)
|
||||||
}
|
}
|
@ -6,12 +6,14 @@ import net.corda.core.crypto.random63BitValue
|
|||||||
import net.corda.core.flows.FlowLogic
|
import net.corda.core.flows.FlowLogic
|
||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
import net.corda.core.identity.Party
|
import net.corda.core.identity.Party
|
||||||
|
import net.corda.core.node.NetworkParameters
|
||||||
import net.corda.core.node.NodeInfo
|
import net.corda.core.node.NodeInfo
|
||||||
import net.corda.node.VersionInfo
|
import net.corda.node.VersionInfo
|
||||||
import net.corda.node.internal.StartedNode
|
import net.corda.node.internal.StartedNode
|
||||||
import net.corda.node.services.api.StartedNodeServices
|
import net.corda.node.services.api.StartedNodeServices
|
||||||
import net.corda.node.services.config.NodeConfiguration
|
import net.corda.node.services.config.NodeConfiguration
|
||||||
import net.corda.node.services.messaging.MessagingService
|
import net.corda.node.services.messaging.MessagingService
|
||||||
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import net.corda.testing.core.DUMMY_NOTARY_NAME
|
import net.corda.testing.core.DUMMY_NOTARY_NAME
|
||||||
import net.corda.testing.node.internal.InternalMockNetwork
|
import net.corda.testing.node.internal.InternalMockNetwork
|
||||||
import net.corda.testing.node.internal.setMessagingServiceSpy
|
import net.corda.testing.node.internal.setMessagingServiceSpy
|
||||||
@ -63,14 +65,16 @@ data class MockNetworkParameters(
|
|||||||
val networkSendManuallyPumped: Boolean = false,
|
val networkSendManuallyPumped: Boolean = false,
|
||||||
val threadPerNode: Boolean = false,
|
val threadPerNode: Boolean = false,
|
||||||
val servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.Random(),
|
val servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.Random(),
|
||||||
val notarySpecs: List<MockNetworkNotarySpec> = listOf(MockNetworkNotarySpec(DUMMY_NOTARY_NAME))) {
|
val notarySpecs: List<MockNetworkNotarySpec> = listOf(MockNetworkNotarySpec(DUMMY_NOTARY_NAME)),
|
||||||
|
val networkParameters: NetworkParameters = testNetworkParameters()) {
|
||||||
fun withNetworkSendManuallyPumped(networkSendManuallyPumped: Boolean): MockNetworkParameters = copy(networkSendManuallyPumped = networkSendManuallyPumped)
|
fun withNetworkSendManuallyPumped(networkSendManuallyPumped: Boolean): MockNetworkParameters = copy(networkSendManuallyPumped = networkSendManuallyPumped)
|
||||||
fun withThreadPerNode(threadPerNode: Boolean): MockNetworkParameters = copy(threadPerNode = threadPerNode)
|
fun withThreadPerNode(threadPerNode: Boolean): MockNetworkParameters = copy(threadPerNode = threadPerNode)
|
||||||
fun withServicePeerAllocationStrategy(servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy): MockNetworkParameters = copy(servicePeerAllocationStrategy = servicePeerAllocationStrategy)
|
fun withServicePeerAllocationStrategy(servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy): MockNetworkParameters = copy(servicePeerAllocationStrategy = servicePeerAllocationStrategy)
|
||||||
fun withNotarySpecs(notarySpecs: List<MockNetworkNotarySpec>): MockNetworkParameters = copy(notarySpecs = notarySpecs)
|
fun withNotarySpecs(notarySpecs: List<MockNetworkNotarySpec>): MockNetworkParameters = copy(notarySpecs = notarySpecs)
|
||||||
|
fun withNetworkParameters(networkParameters: NetworkParameters): MockNetworkParameters = copy(networkParameters = networkParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Represents a node configuration for injection via [MockNetworkParameters]. */
|
/** Represents a node configuration for injection via [MockNetworkParameters] */
|
||||||
data class MockNetworkNotarySpec(val name: CordaX500Name, val validating: Boolean = true) {
|
data class MockNetworkNotarySpec(val name: CordaX500Name, val validating: Boolean = true) {
|
||||||
constructor(name: CordaX500Name) : this(name, validating = true)
|
constructor(name: CordaX500Name) : this(name, validating = true)
|
||||||
}
|
}
|
||||||
@ -100,7 +104,7 @@ class StartedMockNode private constructor(private val node: StartedNode<Internal
|
|||||||
val id get() : Int = node.internals.id
|
val id get() : Int = node.internals.id
|
||||||
val info get() : NodeInfo = node.services.myInfo
|
val info get() : NodeInfo = node.services.myInfo
|
||||||
val network get() : MessagingService = node.network
|
val network get() : MessagingService = node.network
|
||||||
/** Register a flow that is initiated by another flow **/
|
/** Register a flow that is initiated by another flow */
|
||||||
fun <F : FlowLogic<*>> registerInitiatedFlow(initiatedFlowClass: Class<F>): Observable<F> = node.registerInitiatedFlow(initiatedFlowClass)
|
fun <F : FlowLogic<*>> registerInitiatedFlow(initiatedFlowClass: Class<F>): Observable<F> = node.registerInitiatedFlow(initiatedFlowClass)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,6 +155,9 @@ class StartedMockNode private constructor(private val node: StartedNode<Internal
|
|||||||
*
|
*
|
||||||
* By default a single notary node is automatically started, which forms part of the network parameters for all the nodes.
|
* By default a single notary node is automatically started, which forms part of the network parameters for all the nodes.
|
||||||
* This node is available by calling [defaultNotaryNode].
|
* This node is available by calling [defaultNotaryNode].
|
||||||
|
*
|
||||||
|
* @property networkParameters The network parameters to be used by all the nodes. [NetworkParameters.notaries] must be
|
||||||
|
* empty as notaries are defined by [notarySpecs].
|
||||||
*/
|
*/
|
||||||
@Suppress("MemberVisibilityCanBePrivate", "CanBeParameter")
|
@Suppress("MemberVisibilityCanBePrivate", "CanBeParameter")
|
||||||
open class MockNetwork(
|
open class MockNetwork(
|
||||||
@ -159,21 +166,28 @@ open class MockNetwork(
|
|||||||
val networkSendManuallyPumped: Boolean = defaultParameters.networkSendManuallyPumped,
|
val networkSendManuallyPumped: Boolean = defaultParameters.networkSendManuallyPumped,
|
||||||
val threadPerNode: Boolean = defaultParameters.threadPerNode,
|
val threadPerNode: Boolean = defaultParameters.threadPerNode,
|
||||||
val servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy = defaultParameters.servicePeerAllocationStrategy,
|
val servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy = defaultParameters.servicePeerAllocationStrategy,
|
||||||
val notarySpecs: List<MockNetworkNotarySpec> = defaultParameters.notarySpecs
|
val notarySpecs: List<MockNetworkNotarySpec> = defaultParameters.notarySpecs,
|
||||||
|
val networkParameters: NetworkParameters = defaultParameters.networkParameters
|
||||||
) {
|
) {
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(cordappPackages: List<String>, parameters: MockNetworkParameters = MockNetworkParameters()) : this(cordappPackages, defaultParameters = parameters)
|
constructor(cordappPackages: List<String>, parameters: MockNetworkParameters = MockNetworkParameters()) : this(cordappPackages, defaultParameters = parameters)
|
||||||
|
|
||||||
private val internalMockNetwork: InternalMockNetwork = InternalMockNetwork(cordappPackages, defaultParameters, networkSendManuallyPumped, threadPerNode, servicePeerAllocationStrategy, notarySpecs)
|
private val internalMockNetwork = InternalMockNetwork(
|
||||||
|
cordappPackages,
|
||||||
|
defaultParameters,
|
||||||
|
networkSendManuallyPumped,
|
||||||
|
threadPerNode,
|
||||||
|
servicePeerAllocationStrategy,
|
||||||
|
notarySpecs,
|
||||||
|
networkParameters)
|
||||||
/** Which node will be used as the primary notary during transaction builds. */
|
/** Which node will be used as the primary notary during transaction builds. */
|
||||||
val defaultNotaryNode get(): StartedMockNode = StartedMockNode.create(internalMockNetwork.defaultNotaryNode)
|
val defaultNotaryNode get() : StartedMockNode = StartedMockNode.create(internalMockNetwork.defaultNotaryNode)
|
||||||
/** The [Party] of the [defaultNotaryNode] */
|
/** The [Party] of the [defaultNotaryNode] */
|
||||||
val defaultNotaryIdentity get(): Party = internalMockNetwork.defaultNotaryIdentity
|
val defaultNotaryIdentity get() : Party = internalMockNetwork.defaultNotaryIdentity
|
||||||
/** A list of all notary nodes in the network that have been started. */
|
/** A list of all notary nodes in the network that have been started. */
|
||||||
val notaryNodes get(): List<StartedMockNode> = internalMockNetwork.notaryNodes.map { StartedMockNode.create(it) }
|
val notaryNodes get() : List<StartedMockNode> = internalMockNetwork.notaryNodes.map { StartedMockNode.create(it) }
|
||||||
/** In a mock network, nodes have an incrementing integer ID. Real networks do not have this. Returns the next ID that will be used. */
|
/** In a mock network, nodes have an incrementing integer ID. Real networks do not have this. Returns the next ID that will be used. */
|
||||||
val nextNodeId get(): Int = internalMockNetwork.nextNodeId
|
val nextNodeId get() : Int = internalMockNetwork.nextNodeId
|
||||||
|
|
||||||
/** Create a started node with the given identity. **/
|
/** Create a started node with the given identity. **/
|
||||||
fun createPartyNode(legalName: CordaX500Name? = null): StartedMockNode = StartedMockNode.create(internalMockNetwork.createPartyNode(legalName))
|
fun createPartyNode(legalName: CordaX500Name? = null): StartedMockNode = StartedMockNode.create(internalMockNetwork.createPartyNode(legalName))
|
||||||
@ -181,9 +195,7 @@ open class MockNetwork(
|
|||||||
/** Create a started node with the given parameters. **/
|
/** Create a started node with the given parameters. **/
|
||||||
fun createNode(parameters: MockNodeParameters = MockNodeParameters()): StartedMockNode = StartedMockNode.create(internalMockNetwork.createNode(parameters))
|
fun createNode(parameters: MockNodeParameters = MockNodeParameters()): StartedMockNode = StartedMockNode.create(internalMockNetwork.createNode(parameters))
|
||||||
|
|
||||||
/**
|
/** Create a started node with the given parameters.
|
||||||
* Create a started node with the given parameters.
|
|
||||||
*
|
|
||||||
* @param legalName the node's legal name.
|
* @param legalName the node's legal name.
|
||||||
* @param forcedID a unique identifier for the node.
|
* @param forcedID a unique identifier for the node.
|
||||||
* @param entropyRoot the initial entropy value to use when generating keys. Defaults to an (insecure) random value,
|
* @param entropyRoot the initial entropy value to use when generating keys. Defaults to an (insecure) random value,
|
||||||
@ -204,9 +216,7 @@ open class MockNetwork(
|
|||||||
/** Create an unstarted node with the given parameters. **/
|
/** Create an unstarted node with the given parameters. **/
|
||||||
fun createUnstartedNode(parameters: MockNodeParameters = MockNodeParameters()): UnstartedMockNode = UnstartedMockNode.create(internalMockNetwork.createUnstartedNode(parameters))
|
fun createUnstartedNode(parameters: MockNodeParameters = MockNodeParameters()): UnstartedMockNode = UnstartedMockNode.create(internalMockNetwork.createUnstartedNode(parameters))
|
||||||
|
|
||||||
/**
|
/** Create an unstarted node with the given parameters.
|
||||||
* Create an unstarted node with the given parameters.
|
|
||||||
*
|
|
||||||
* @param legalName the node's legal name.
|
* @param legalName the node's legal name.
|
||||||
* @param forcedID a unique identifier for the node.
|
* @param forcedID a unique identifier for the node.
|
||||||
* @param entropyRoot the initial entropy value to use when generating keys. Defaults to an (insecure) random value,
|
* @param entropyRoot the initial entropy value to use when generating keys. Defaults to an (insecure) random value,
|
||||||
|
@ -7,7 +7,6 @@ import net.corda.core.crypto.*
|
|||||||
import net.corda.core.flows.FlowLogic
|
import net.corda.core.flows.FlowLogic
|
||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
import net.corda.core.identity.PartyAndCertificate
|
import net.corda.core.identity.PartyAndCertificate
|
||||||
import net.corda.core.internal.GlobalProperties
|
|
||||||
import net.corda.core.messaging.DataFeed
|
import net.corda.core.messaging.DataFeed
|
||||||
import net.corda.core.messaging.FlowHandle
|
import net.corda.core.messaging.FlowHandle
|
||||||
import net.corda.core.messaging.FlowProgressHandle
|
import net.corda.core.messaging.FlowProgressHandle
|
||||||
@ -33,10 +32,11 @@ import net.corda.node.services.vault.NodeVaultService
|
|||||||
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
||||||
import net.corda.nodeapi.internal.persistence.DatabaseConfig
|
import net.corda.nodeapi.internal.persistence.DatabaseConfig
|
||||||
import net.corda.nodeapi.internal.persistence.HibernateConfiguration
|
import net.corda.nodeapi.internal.persistence.HibernateConfiguration
|
||||||
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import net.corda.testing.core.TestIdentity
|
import net.corda.testing.core.TestIdentity
|
||||||
import net.corda.testing.internal.DEV_ROOT_CA
|
import net.corda.testing.internal.DEV_ROOT_CA
|
||||||
import net.corda.testing.services.MockAttachmentStorage
|
|
||||||
import net.corda.testing.internal.MockCordappProvider
|
import net.corda.testing.internal.MockCordappProvider
|
||||||
|
import net.corda.testing.services.MockAttachmentStorage
|
||||||
import org.bouncycastle.operator.ContentSigner
|
import org.bouncycastle.operator.ContentSigner
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.subjects.PublishSubject
|
import rx.subjects.PublishSubject
|
||||||
@ -62,6 +62,7 @@ open class MockServices private constructor(
|
|||||||
cordappLoader: CordappLoader,
|
cordappLoader: CordappLoader,
|
||||||
override val validatedTransactions: WritableTransactionStorage,
|
override val validatedTransactions: WritableTransactionStorage,
|
||||||
override val identityService: IdentityService,
|
override val identityService: IdentityService,
|
||||||
|
override val networkParameters: NetworkParameters,
|
||||||
private val initialIdentity: TestIdentity,
|
private val initialIdentity: TestIdentity,
|
||||||
private val moreKeys: Array<out KeyPair>
|
private val moreKeys: Array<out KeyPair>
|
||||||
) : ServiceHub, StateLoader by validatedTransactions {
|
) : ServiceHub, StateLoader by validatedTransactions {
|
||||||
@ -95,16 +96,18 @@ open class MockServices private constructor(
|
|||||||
* @return a pair where the first element is the instance of [CordaPersistence] and the second is [MockServices].
|
* @return a pair where the first element is the instance of [CordaPersistence] and the second is [MockServices].
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@JvmOverloads
|
||||||
fun makeTestDatabaseAndMockServices(cordappPackages: List<String>,
|
fun makeTestDatabaseAndMockServices(cordappPackages: List<String>,
|
||||||
identityService: IdentityService,
|
identityService: IdentityService,
|
||||||
initialIdentity: TestIdentity,
|
initialIdentity: TestIdentity,
|
||||||
|
networkParameters: NetworkParameters = testNetworkParameters(),
|
||||||
vararg moreKeys: KeyPair): Pair<CordaPersistence, MockServices> {
|
vararg moreKeys: KeyPair): Pair<CordaPersistence, MockServices> {
|
||||||
val cordappLoader = CordappLoader.createWithTestPackages(cordappPackages)
|
val cordappLoader = CordappLoader.createWithTestPackages(cordappPackages)
|
||||||
val dataSourceProps = makeTestDataSourceProperties()
|
val dataSourceProps = makeTestDataSourceProperties()
|
||||||
val schemaService = NodeSchemaService(cordappLoader.cordappSchemas)
|
val schemaService = NodeSchemaService(cordappLoader.cordappSchemas)
|
||||||
val database = configureDatabase(dataSourceProps, DatabaseConfig(), identityService, schemaService)
|
val database = configureDatabase(dataSourceProps, DatabaseConfig(), identityService, schemaService)
|
||||||
val mockService = database.transaction {
|
val mockService = database.transaction {
|
||||||
object : MockServices(cordappLoader, identityService, initialIdentity, moreKeys) {
|
object : MockServices(cordappLoader, identityService, networkParameters, initialIdentity, moreKeys) {
|
||||||
override val vaultService: VaultServiceInternal = makeVaultService(database.hibernateConfig, schemaService)
|
override val vaultService: VaultServiceInternal = makeVaultService(database.hibernateConfig, schemaService)
|
||||||
|
|
||||||
override fun recordTransactions(statesToRecord: StatesToRecord, txs: Iterable<SignedTransaction>) {
|
override fun recordTransactions(statesToRecord: StatesToRecord, txs: Iterable<SignedTransaction>) {
|
||||||
@ -128,30 +131,43 @@ open class MockServices private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructor(cordappLoader: CordappLoader, identityService: IdentityService,
|
private constructor(cordappLoader: CordappLoader, identityService: IdentityService, networkParameters: NetworkParameters,
|
||||||
initialIdentity: TestIdentity, moreKeys: Array<out KeyPair>)
|
initialIdentity: TestIdentity, moreKeys: Array<out KeyPair>)
|
||||||
: this(cordappLoader, MockTransactionStorage(), identityService, initialIdentity, moreKeys)
|
: this(cordappLoader, MockTransactionStorage(), identityService, networkParameters, initialIdentity, moreKeys)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a mock [ServiceHub] that looks for app code in the given package names, uses the provided identity service
|
* Create a mock [ServiceHub] that looks for app code in the given package names, uses the provided identity service
|
||||||
* (you can get one from [makeTestIdentityService]) and represents the given identity.
|
* (you can get one from [makeTestIdentityService]) and represents the given identity.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(cordappPackages: List<String>, initialIdentity: TestIdentity, identityService: IdentityService = makeTestIdentityService(), vararg moreKeys: KeyPair) : this(CordappLoader.createWithTestPackages(cordappPackages), identityService, initialIdentity, moreKeys)
|
constructor(cordappPackages: List<String>,
|
||||||
|
initialIdentity: TestIdentity,
|
||||||
|
identityService: IdentityService = makeTestIdentityService(),
|
||||||
|
vararg moreKeys: KeyPair) :
|
||||||
|
this(CordappLoader.createWithTestPackages(cordappPackages), identityService, testNetworkParameters(), initialIdentity, moreKeys)
|
||||||
|
|
||||||
|
constructor(cordappPackages: List<String>,
|
||||||
|
initialIdentity: TestIdentity,
|
||||||
|
identityService: IdentityService,
|
||||||
|
networkParameters: NetworkParameters,
|
||||||
|
vararg moreKeys: KeyPair) :
|
||||||
|
this(CordappLoader.createWithTestPackages(cordappPackages), identityService, networkParameters, initialIdentity, moreKeys)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a mock [ServiceHub] that looks for app code in the given package names, uses the provided identity service
|
* Create a mock [ServiceHub] that looks for app code in the given package names, uses the provided identity service
|
||||||
* (you can get one from [makeTestIdentityService]) and represents the given identity.
|
* (you can get one from [makeTestIdentityService]) and represents the given identity.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(cordappPackages: List<String>, initialIdentityName: CordaX500Name, identityService: IdentityService = makeTestIdentityService(), key: KeyPair, vararg moreKeys: KeyPair) : this(cordappPackages, TestIdentity(initialIdentityName, key), identityService, *moreKeys)
|
constructor(cordappPackages: List<String>, initialIdentityName: CordaX500Name, identityService: IdentityService = makeTestIdentityService(), key: KeyPair, vararg moreKeys: KeyPair) :
|
||||||
|
this(cordappPackages, TestIdentity(initialIdentityName, key), identityService, *moreKeys)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a mock [ServiceHub] that can't load CorDapp code, which uses the provided identity service
|
* Create a mock [ServiceHub] that can't load CorDapp code, which uses the provided identity service
|
||||||
* (you can get one from [makeTestIdentityService]) and which represents the given identity.
|
* (you can get one from [makeTestIdentityService]) and which represents the given identity.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(cordappPackages: List<String>, initialIdentityName: CordaX500Name, identityService: IdentityService = makeTestIdentityService()) : this(cordappPackages, TestIdentity(initialIdentityName), identityService)
|
constructor(cordappPackages: List<String>, initialIdentityName: CordaX500Name, identityService: IdentityService = makeTestIdentityService()) :
|
||||||
|
this(cordappPackages, TestIdentity(initialIdentityName), identityService)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a mock [ServiceHub] that can't load CorDapp code, and which uses a default service identity.
|
* Create a mock [ServiceHub] that can't load CorDapp code, and which uses a default service identity.
|
||||||
|
@ -10,14 +10,11 @@ import net.corda.core.context.InvocationOrigin
|
|||||||
import net.corda.core.flows.FlowLogic
|
import net.corda.core.flows.FlowLogic
|
||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
import net.corda.core.identity.Party
|
import net.corda.core.identity.Party
|
||||||
import net.corda.core.internal.GlobalProperties
|
|
||||||
import net.corda.core.internal.FlowStateMachine
|
|
||||||
import net.corda.core.node.ServiceHub
|
import net.corda.core.node.ServiceHub
|
||||||
import net.corda.core.serialization.internal.effectiveSerializationEnv
|
import net.corda.core.serialization.internal.effectiveSerializationEnv
|
||||||
import net.corda.core.transactions.TransactionBuilder
|
import net.corda.core.transactions.TransactionBuilder
|
||||||
import net.corda.core.utilities.getOrThrow
|
import net.corda.core.utilities.getOrThrow
|
||||||
import net.corda.node.services.api.StartedNodeServices
|
import net.corda.node.services.api.StartedNodeServices
|
||||||
import net.corda.testing.common.internal.testNetworkParameters
|
|
||||||
import net.corda.testing.core.SerializationEnvironmentRule
|
import net.corda.testing.core.SerializationEnvironmentRule
|
||||||
import net.corda.testing.core.TestIdentity
|
import net.corda.testing.core.TestIdentity
|
||||||
import net.corda.testing.core.chooseIdentity
|
import net.corda.testing.core.chooseIdentity
|
||||||
@ -38,7 +35,6 @@ fun ServiceHub.ledger(
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
return LedgerDSL(TestLedgerDSLInterpreter(this), notary).apply {
|
return LedgerDSL(TestLedgerDSLInterpreter(this), notary).apply {
|
||||||
GlobalProperties.networkParameters = testNetworkParameters(emptyList())
|
|
||||||
if (serializationExists) {
|
if (serializationExists) {
|
||||||
script()
|
script()
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,6 +15,7 @@ import net.corda.core.identity.CordaX500Name
|
|||||||
import net.corda.core.internal.*
|
import net.corda.core.internal.*
|
||||||
import net.corda.core.internal.concurrent.*
|
import net.corda.core.internal.concurrent.*
|
||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
|
import net.corda.core.node.NetworkParameters
|
||||||
import net.corda.core.node.NotaryInfo
|
import net.corda.core.node.NotaryInfo
|
||||||
import net.corda.core.node.services.NetworkMapCache
|
import net.corda.core.node.services.NetworkMapCache
|
||||||
import net.corda.core.serialization.deserialize
|
import net.corda.core.serialization.deserialize
|
||||||
@ -39,15 +40,14 @@ import net.corda.nodeapi.internal.crypto.X509KeyStore
|
|||||||
import net.corda.nodeapi.internal.crypto.X509Utilities
|
import net.corda.nodeapi.internal.crypto.X509Utilities
|
||||||
import net.corda.nodeapi.internal.network.NetworkParametersCopier
|
import net.corda.nodeapi.internal.network.NetworkParametersCopier
|
||||||
import net.corda.nodeapi.internal.network.NodeInfoFilesCopier
|
import net.corda.nodeapi.internal.network.NodeInfoFilesCopier
|
||||||
import net.corda.testing.common.internal.testNetworkParameters
|
|
||||||
import net.corda.testing.core.ALICE_NAME
|
import net.corda.testing.core.ALICE_NAME
|
||||||
import net.corda.testing.core.BOB_NAME
|
import net.corda.testing.core.BOB_NAME
|
||||||
import net.corda.testing.core.DUMMY_BANK_A_NAME
|
import net.corda.testing.core.DUMMY_BANK_A_NAME
|
||||||
import net.corda.testing.internal.setGlobalSerialization
|
|
||||||
import net.corda.testing.driver.*
|
import net.corda.testing.driver.*
|
||||||
import net.corda.testing.driver.internal.InProcessImpl
|
import net.corda.testing.driver.internal.InProcessImpl
|
||||||
import net.corda.testing.driver.internal.NodeHandleInternal
|
import net.corda.testing.driver.internal.NodeHandleInternal
|
||||||
import net.corda.testing.driver.internal.OutOfProcessImpl
|
import net.corda.testing.driver.internal.OutOfProcessImpl
|
||||||
|
import net.corda.testing.internal.setGlobalSerialization
|
||||||
import net.corda.testing.node.ClusterSpec
|
import net.corda.testing.node.ClusterSpec
|
||||||
import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO
|
import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO
|
||||||
import net.corda.testing.node.NotarySpec
|
import net.corda.testing.node.NotarySpec
|
||||||
@ -92,7 +92,7 @@ class DriverDSLImpl(
|
|||||||
val jmxPolicy: JmxPolicy,
|
val jmxPolicy: JmxPolicy,
|
||||||
val notarySpecs: List<NotarySpec>,
|
val notarySpecs: List<NotarySpec>,
|
||||||
val compatibilityZone: CompatibilityZoneParams?,
|
val compatibilityZone: CompatibilityZoneParams?,
|
||||||
val maxTransactionSize: Int
|
val networkParameters: NetworkParameters
|
||||||
) : InternalDriverDSL {
|
) : InternalDriverDSL {
|
||||||
private var _executorService: ScheduledExecutorService? = null
|
private var _executorService: ScheduledExecutorService? = null
|
||||||
val executorService get() = _executorService!!
|
val executorService get() = _executorService!!
|
||||||
@ -387,6 +387,7 @@ class DriverDSLImpl(
|
|||||||
if (startNodesInProcess) {
|
if (startNodesInProcess) {
|
||||||
Schedulers.reset()
|
Schedulers.reset()
|
||||||
}
|
}
|
||||||
|
require(networkParameters.notaries.isEmpty()) { "Define notaries using notarySpecs" }
|
||||||
_executorService = Executors.newScheduledThreadPool(2, ThreadFactoryBuilder().setNameFormat("driver-pool-thread-%d").build())
|
_executorService = Executors.newScheduledThreadPool(2, ThreadFactoryBuilder().setNameFormat("driver-pool-thread-%d").build())
|
||||||
_shutdownManager = ShutdownManager(executorService)
|
_shutdownManager = ShutdownManager(executorService)
|
||||||
val notaryInfosFuture = if (compatibilityZone == null) {
|
val notaryInfosFuture = if (compatibilityZone == null) {
|
||||||
@ -704,7 +705,7 @@ class DriverDSLImpl(
|
|||||||
* The local version of the network map, which is a bunch of classes that copy the relevant files to the node directories.
|
* The local version of the network map, which is a bunch of classes that copy the relevant files to the node directories.
|
||||||
*/
|
*/
|
||||||
private inner class LocalNetworkMap(notaryInfos: List<NotaryInfo>) {
|
private inner class LocalNetworkMap(notaryInfos: List<NotaryInfo>) {
|
||||||
val networkParametersCopier = NetworkParametersCopier(testNetworkParameters(notaryInfos, maxTransactionSize = maxTransactionSize))
|
val networkParametersCopier = NetworkParametersCopier(networkParameters.copy(notaries = notaryInfos))
|
||||||
// TODO: this object will copy NodeInfo files from started nodes to other nodes additional-node-infos/
|
// TODO: this object will copy NodeInfo files from started nodes to other nodes additional-node-infos/
|
||||||
// This uses the FileSystem and adds a delay (~5 seconds) given by the time we wait before polling the file system.
|
// This uses the FileSystem and adds a delay (~5 seconds) given by the time we wait before polling the file system.
|
||||||
// Investigate whether we can avoid that.
|
// Investigate whether we can avoid that.
|
||||||
@ -966,7 +967,7 @@ fun <DI : DriverDSL, D : InternalDriverDSL, A> genericDriver(
|
|||||||
jmxPolicy = defaultParameters.jmxPolicy,
|
jmxPolicy = defaultParameters.jmxPolicy,
|
||||||
notarySpecs = defaultParameters.notarySpecs,
|
notarySpecs = defaultParameters.notarySpecs,
|
||||||
compatibilityZone = null,
|
compatibilityZone = null,
|
||||||
maxTransactionSize = defaultParameters.maxTransactionSize
|
networkParameters = defaultParameters.networkParameters
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val shutdownHook = addShutdownHook(driverDsl::shutdown)
|
val shutdownHook = addShutdownHook(driverDsl::shutdown)
|
||||||
@ -1008,7 +1009,7 @@ fun <A> internalDriver(
|
|||||||
notarySpecs: List<NotarySpec> = DriverParameters().notarySpecs,
|
notarySpecs: List<NotarySpec> = DriverParameters().notarySpecs,
|
||||||
extraCordappPackagesToScan: List<String> = DriverParameters().extraCordappPackagesToScan,
|
extraCordappPackagesToScan: List<String> = DriverParameters().extraCordappPackagesToScan,
|
||||||
jmxPolicy: JmxPolicy = DriverParameters().jmxPolicy,
|
jmxPolicy: JmxPolicy = DriverParameters().jmxPolicy,
|
||||||
maxTransactionSize: Int = DriverParameters().maxTransactionSize,
|
networkParameters: NetworkParameters = DriverParameters().networkParameters,
|
||||||
compatibilityZone: CompatibilityZoneParams? = null,
|
compatibilityZone: CompatibilityZoneParams? = null,
|
||||||
dsl: DriverDSLImpl.() -> A
|
dsl: DriverDSLImpl.() -> A
|
||||||
): A {
|
): A {
|
||||||
@ -1026,7 +1027,7 @@ fun <A> internalDriver(
|
|||||||
extraCordappPackagesToScan = extraCordappPackagesToScan,
|
extraCordappPackagesToScan = extraCordappPackagesToScan,
|
||||||
jmxPolicy = jmxPolicy,
|
jmxPolicy = jmxPolicy,
|
||||||
compatibilityZone = compatibilityZone,
|
compatibilityZone = compatibilityZone,
|
||||||
maxTransactionSize = maxTransactionSize
|
networkParameters = networkParameters
|
||||||
),
|
),
|
||||||
coerce = { it },
|
coerce = { it },
|
||||||
dsl = dsl,
|
dsl = dsl,
|
||||||
|
@ -18,6 +18,7 @@ import net.corda.core.messaging.CordaRPCOps
|
|||||||
import net.corda.core.messaging.MessageRecipients
|
import net.corda.core.messaging.MessageRecipients
|
||||||
import net.corda.core.messaging.RPCOps
|
import net.corda.core.messaging.RPCOps
|
||||||
import net.corda.core.messaging.SingleMessageRecipient
|
import net.corda.core.messaging.SingleMessageRecipient
|
||||||
|
import net.corda.core.node.NetworkParameters
|
||||||
import net.corda.core.node.NodeInfo
|
import net.corda.core.node.NodeInfo
|
||||||
import net.corda.core.node.NotaryInfo
|
import net.corda.core.node.NotaryInfo
|
||||||
import net.corda.core.node.services.IdentityService
|
import net.corda.core.node.services.IdentityService
|
||||||
@ -47,12 +48,11 @@ import net.corda.nodeapi.internal.persistence.CordaPersistence
|
|||||||
import net.corda.nodeapi.internal.persistence.DatabaseConfig
|
import net.corda.nodeapi.internal.persistence.DatabaseConfig
|
||||||
import net.corda.testing.common.internal.testNetworkParameters
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import net.corda.testing.internal.rigorousMock
|
import net.corda.testing.internal.rigorousMock
|
||||||
|
import net.corda.testing.internal.setGlobalSerialization
|
||||||
import net.corda.testing.internal.testThreadFactory
|
import net.corda.testing.internal.testThreadFactory
|
||||||
import net.corda.testing.node.*
|
import net.corda.testing.node.*
|
||||||
import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO
|
import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO
|
||||||
import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties
|
import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties
|
||||||
import net.corda.testing.internal.setGlobalSerialization
|
|
||||||
import net.corda.testing.node.TestClock
|
|
||||||
import org.apache.activemq.artemis.utils.ReusableLatch
|
import org.apache.activemq.artemis.utils.ReusableLatch
|
||||||
import org.apache.sshd.common.util.security.SecurityUtils
|
import org.apache.sshd.common.util.security.SecurityUtils
|
||||||
import rx.internal.schedulers.CachedThreadScheduler
|
import rx.internal.schedulers.CachedThreadScheduler
|
||||||
@ -82,13 +82,14 @@ open class InternalMockNetwork(private val cordappPackages: List<String>,
|
|||||||
val threadPerNode: Boolean = defaultParameters.threadPerNode,
|
val threadPerNode: Boolean = defaultParameters.threadPerNode,
|
||||||
servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy = defaultParameters.servicePeerAllocationStrategy,
|
servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy = defaultParameters.servicePeerAllocationStrategy,
|
||||||
val notarySpecs: List<MockNetworkNotarySpec> = defaultParameters.notarySpecs,
|
val notarySpecs: List<MockNetworkNotarySpec> = defaultParameters.notarySpecs,
|
||||||
maxTransactionSize: Int = Int.MAX_VALUE,
|
networkParameters: NetworkParameters = testNetworkParameters(),
|
||||||
val defaultFactory: (MockNodeArgs) -> MockNode = InternalMockNetwork::MockNode) {
|
val defaultFactory: (MockNodeArgs) -> MockNode = InternalMockNetwork::MockNode) {
|
||||||
init {
|
init {
|
||||||
// Apache SSHD for whatever reason registers a SFTP FileSystemProvider - which gets loaded by JimFS.
|
// Apache SSHD for whatever reason registers a SFTP FileSystemProvider - which gets loaded by JimFS.
|
||||||
// This SFTP support loads BouncyCastle, which we want to avoid.
|
// This SFTP support loads BouncyCastle, which we want to avoid.
|
||||||
// Please see https://issues.apache.org/jira/browse/SSHD-736 - it's easier then to create our own fork of SSHD
|
// Please see https://issues.apache.org/jira/browse/SSHD-736 - it's easier then to create our own fork of SSHD
|
||||||
SecurityUtils.setAPrioriDisabledProvider("BC", true) // XXX: Why isn't this static?
|
SecurityUtils.setAPrioriDisabledProvider("BC", true) // XXX: Why isn't this static?
|
||||||
|
require(networkParameters.notaries.isEmpty()) { "Define notaries using notarySpecs" }
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextNodeId = 0
|
var nextNodeId = 0
|
||||||
@ -98,7 +99,7 @@ open class InternalMockNetwork(private val cordappPackages: List<String>,
|
|||||||
val messagingNetwork = InMemoryMessagingNetwork.create(networkSendManuallyPumped, servicePeerAllocationStrategy, busyLatch)
|
val messagingNetwork = InMemoryMessagingNetwork.create(networkSendManuallyPumped, servicePeerAllocationStrategy, busyLatch)
|
||||||
// A unique identifier for this network to segregate databases with the same nodeID but different networks.
|
// A unique identifier for this network to segregate databases with the same nodeID but different networks.
|
||||||
private val networkId = random63BitValue()
|
private val networkId = random63BitValue()
|
||||||
private val networkParameters: NetworkParametersCopier
|
private val networkParametersCopier: NetworkParametersCopier
|
||||||
private val _nodes = mutableListOf<MockNode>()
|
private val _nodes = mutableListOf<MockNode>()
|
||||||
private val serializationEnv = try {
|
private val serializationEnv = try {
|
||||||
setGlobalSerialization(true)
|
setGlobalSerialization(true)
|
||||||
@ -174,7 +175,7 @@ open class InternalMockNetwork(private val cordappPackages: List<String>,
|
|||||||
filesystem.getPath("/nodes").createDirectory()
|
filesystem.getPath("/nodes").createDirectory()
|
||||||
val notaryInfos = generateNotaryIdentities()
|
val notaryInfos = generateNotaryIdentities()
|
||||||
// The network parameters must be serialised before starting any of the nodes
|
// The network parameters must be serialised before starting any of the nodes
|
||||||
networkParameters = NetworkParametersCopier(testNetworkParameters(notaryInfos, maxTransactionSize = maxTransactionSize))
|
networkParametersCopier = NetworkParametersCopier(networkParameters.copy(notaries = notaryInfos))
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
notaryNodes = createNotaries()
|
notaryNodes = createNotaries()
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
@ -226,7 +227,7 @@ open class InternalMockNetwork(private val cordappPackages: List<String>,
|
|||||||
override val started: StartedNode<MockNode>? get() = uncheckedCast(super.started)
|
override val started: StartedNode<MockNode>? get() = uncheckedCast(super.started)
|
||||||
|
|
||||||
override fun start(): StartedNode<MockNode> {
|
override fun start(): StartedNode<MockNode> {
|
||||||
mockNet.networkParameters.install(configuration.baseDirectory)
|
mockNet.networkParametersCopier.install(configuration.baseDirectory)
|
||||||
val started: StartedNode<MockNode> = uncheckedCast(super.start())
|
val started: StartedNode<MockNode> = uncheckedCast(super.start())
|
||||||
advertiseNodeToNetwork(started)
|
advertiseNodeToNetwork(started)
|
||||||
return started
|
return started
|
||||||
@ -244,7 +245,7 @@ open class InternalMockNetwork(private val cordappPackages: List<String>,
|
|||||||
|
|
||||||
// We only need to override the messaging service here, as currently everything that hits disk does so
|
// 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.
|
// through the java.nio API which we are already mocking via Jimfs.
|
||||||
override fun makeMessagingService(database: CordaPersistence, info: NodeInfo, nodeProperties: NodePropertiesStore): MessagingService {
|
override fun makeMessagingService(database: CordaPersistence, info: NodeInfo, nodeProperties: NodePropertiesStore, networkParameters: NetworkParameters): MessagingService {
|
||||||
require(id >= 0) { "Node ID must be zero or positive, was passed: " + id }
|
require(id >= 0) { "Node ID must be zero or positive, was passed: " + id }
|
||||||
return mockNet.messagingNetwork.createNodeWithID(
|
return mockNet.messagingNetwork.createNodeWithID(
|
||||||
!mockNet.threadPerNode,
|
!mockNet.threadPerNode,
|
||||||
@ -292,9 +293,9 @@ open class InternalMockNetwork(private val cordappPackages: List<String>,
|
|||||||
|
|
||||||
// Allow unit tests to modify the serialization whitelist list before the node start,
|
// Allow unit tests to modify the serialization whitelist list before the node start,
|
||||||
// so they don't have to ServiceLoad test whitelists into all unit tests.
|
// so they don't have to ServiceLoad test whitelists into all unit tests.
|
||||||
val testSerializationWhitelists by lazy { super.serializationWhitelists.toMutableList() }
|
private val _serializationWhitelists by lazy { super.serializationWhitelists.toMutableList() }
|
||||||
override val serializationWhitelists: List<SerializationWhitelist>
|
override val serializationWhitelists: List<SerializationWhitelist>
|
||||||
get() = testSerializationWhitelists
|
get() = _serializationWhitelists
|
||||||
private var dbCloser: (() -> Any?)? = null
|
private var dbCloser: (() -> Any?)? = null
|
||||||
override fun <T> initialiseDatabasePersistence(schemaService: SchemaService, identityService: IdentityService, insideTransaction: (CordaPersistence) -> T): T {
|
override fun <T> initialiseDatabasePersistence(schemaService: SchemaService, identityService: IdentityService, insideTransaction: (CordaPersistence) -> T): T {
|
||||||
return super.initialiseDatabasePersistence(schemaService, identityService) { database ->
|
return super.initialiseDatabasePersistence(schemaService, identityService) { database ->
|
||||||
|
@ -53,7 +53,7 @@ abstract class NodeBasedTest(private val cordappPackages: List<String> = emptyLi
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun init() {
|
fun init() {
|
||||||
defaultNetworkParameters = NetworkParametersCopier(testNetworkParameters(emptyList()))
|
defaultNetworkParameters = NetworkParametersCopier(testNetworkParameters())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ import net.corda.core.internal.concurrent.map
|
|||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
import net.corda.core.internal.uncheckedCast
|
import net.corda.core.internal.uncheckedCast
|
||||||
import net.corda.core.messaging.RPCOps
|
import net.corda.core.messaging.RPCOps
|
||||||
|
import net.corda.core.node.NetworkParameters
|
||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
import net.corda.node.internal.security.RPCSecurityManagerImpl
|
import net.corda.node.internal.security.RPCSecurityManagerImpl
|
||||||
import net.corda.node.services.messaging.RPCServer
|
import net.corda.node.services.messaging.RPCServer
|
||||||
@ -23,6 +24,7 @@ import net.corda.nodeapi.ArtemisTcpTransport
|
|||||||
import net.corda.nodeapi.ConnectionDirection
|
import net.corda.nodeapi.ConnectionDirection
|
||||||
import net.corda.nodeapi.RPCApi
|
import net.corda.nodeapi.RPCApi
|
||||||
import net.corda.nodeapi.internal.serialization.KRYO_RPC_CLIENT_CONTEXT
|
import net.corda.nodeapi.internal.serialization.KRYO_RPC_CLIENT_CONTEXT
|
||||||
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import net.corda.testing.core.MAX_MESSAGE_SIZE
|
import net.corda.testing.core.MAX_MESSAGE_SIZE
|
||||||
import net.corda.testing.driver.JmxPolicy
|
import net.corda.testing.driver.JmxPolicy
|
||||||
import net.corda.testing.driver.PortAllocation
|
import net.corda.testing.driver.PortAllocation
|
||||||
@ -106,7 +108,7 @@ fun <A> rpcDriver(
|
|||||||
notarySpecs: List<NotarySpec> = emptyList(),
|
notarySpecs: List<NotarySpec> = emptyList(),
|
||||||
externalTrace: Trace? = null,
|
externalTrace: Trace? = null,
|
||||||
jmxPolicy: JmxPolicy = JmxPolicy(),
|
jmxPolicy: JmxPolicy = JmxPolicy(),
|
||||||
maxTransactionSize: Int = Int.MAX_VALUE,
|
networkParameters: NetworkParameters = testNetworkParameters(),
|
||||||
dsl: RPCDriverDSL.() -> A
|
dsl: RPCDriverDSL.() -> A
|
||||||
): A {
|
): A {
|
||||||
return genericDriver(
|
return genericDriver(
|
||||||
@ -124,7 +126,7 @@ fun <A> rpcDriver(
|
|||||||
notarySpecs = notarySpecs,
|
notarySpecs = notarySpecs,
|
||||||
jmxPolicy = jmxPolicy,
|
jmxPolicy = jmxPolicy,
|
||||||
compatibilityZone = null,
|
compatibilityZone = null,
|
||||||
maxTransactionSize = maxTransactionSize
|
networkParameters = networkParameters
|
||||||
), externalTrace
|
), externalTrace
|
||||||
),
|
),
|
||||||
coerce = { it },
|
coerce = { it },
|
||||||
@ -157,7 +159,7 @@ data class RPCDriverDSL(
|
|||||||
private val driverDSL: DriverDSLImpl, private val externalTrace: Trace?
|
private val driverDSL: DriverDSLImpl, private val externalTrace: Trace?
|
||||||
) : InternalDriverDSL by driverDSL {
|
) : InternalDriverDSL by driverDSL {
|
||||||
private companion object {
|
private companion object {
|
||||||
val notificationAddress = "notifications"
|
const val notificationAddress = "notifications"
|
||||||
|
|
||||||
private fun ConfigurationImpl.configureCommonSettings(maxFileSize: Int, maxBufferedBytesPerClient: Long) {
|
private fun ConfigurationImpl.configureCommonSettings(maxFileSize: Int, maxBufferedBytesPerClient: Long) {
|
||||||
managementNotificationAddress = SimpleString(notificationAddress)
|
managementNotificationAddress = SimpleString(notificationAddress)
|
||||||
|
@ -9,8 +9,8 @@ import net.corda.core.internal.div
|
|||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
import net.corda.core.utilities.contextLogger
|
import net.corda.core.utilities.contextLogger
|
||||||
import net.corda.nodeapi.internal.network.NetworkParametersCopier
|
import net.corda.nodeapi.internal.network.NetworkParametersCopier
|
||||||
import net.corda.testing.common.internal.testNetworkParameters
|
|
||||||
import net.corda.testing.common.internal.asContextEnv
|
import net.corda.testing.common.internal.asContextEnv
|
||||||
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
@ -51,8 +51,8 @@ class NodeProcess(
|
|||||||
// TODO All use of this factory have duplicate code which is either bundling the calling module or a 3rd party module
|
// TODO All use of this factory have duplicate code which is either bundling the calling module or a 3rd party module
|
||||||
// as a CorDapp for the nodes.
|
// as a CorDapp for the nodes.
|
||||||
class Factory(
|
class Factory(
|
||||||
val buildDirectory: Path = Paths.get("build"),
|
private val buildDirectory: Path = Paths.get("build"),
|
||||||
val cordaJarUrl: URL? = this::class.java.getResource("/corda.jar")
|
private val cordaJarUrl: URL? = this::class.java.getResource("/corda.jar")
|
||||||
) {
|
) {
|
||||||
val cordaJar: Path by lazy {
|
val cordaJar: Path by lazy {
|
||||||
require(cordaJarUrl != null, { "corda.jar could not be found in classpath" })
|
require(cordaJarUrl != null, { "corda.jar could not be found in classpath" })
|
||||||
@ -66,7 +66,7 @@ class NodeProcess(
|
|||||||
KryoClientSerializationScheme.createSerializationEnv().asContextEnv {
|
KryoClientSerializationScheme.createSerializationEnv().asContextEnv {
|
||||||
// There are no notaries in the network parameters for smoke test nodes. If this is required then we would
|
// There are no notaries in the network parameters for smoke test nodes. If this is required then we would
|
||||||
// need to introduce the concept of a "network" which predefines the notaries, like the driver and MockNetwork
|
// need to introduce the concept of a "network" which predefines the notaries, like the driver and MockNetwork
|
||||||
NetworkParametersCopier(testNetworkParameters(emptyList()))
|
NetworkParametersCopier(testNetworkParameters())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,12 +5,12 @@ import net.corda.core.node.NotaryInfo
|
|||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
fun testNetworkParameters(
|
fun testNetworkParameters(
|
||||||
notaries: List<NotaryInfo>,
|
notaries: List<NotaryInfo> = emptyList(),
|
||||||
minimumPlatformVersion: Int = 1,
|
minimumPlatformVersion: Int = 1,
|
||||||
modifiedTime: Instant = Instant.now(),
|
modifiedTime: Instant = Instant.now(),
|
||||||
maxMessageSize: Int = 10485760,
|
maxMessageSize: Int = 10485760,
|
||||||
// TODO: Make this configurable and consistence across driver, bootstrapper, demobench and NetworkMapServer
|
// TODO: Make this configurable and consistence across driver, bootstrapper, demobench and NetworkMapServer
|
||||||
maxTransactionSize: Int = Int.MAX_VALUE,
|
maxTransactionSize: Int = maxMessageSize,
|
||||||
epoch: Int = 1
|
epoch: Int = 1
|
||||||
): NetworkParameters {
|
): NetworkParameters {
|
||||||
return NetworkParameters(
|
return NetworkParameters(
|
||||||
|
@ -1,17 +1,26 @@
|
|||||||
package net.corda.verifier
|
package net.corda.verifier
|
||||||
|
|
||||||
|
import com.nhaarman.mockito_kotlin.any
|
||||||
|
import com.nhaarman.mockito_kotlin.doAnswer
|
||||||
|
import com.nhaarman.mockito_kotlin.whenever
|
||||||
import net.corda.client.mock.Generator
|
import net.corda.client.mock.Generator
|
||||||
import net.corda.core.contracts.*
|
import net.corda.core.contracts.*
|
||||||
|
import net.corda.core.cordapp.CordappProvider
|
||||||
import net.corda.core.crypto.SecureHash
|
import net.corda.core.crypto.SecureHash
|
||||||
import net.corda.core.crypto.entropyToKeyPair
|
import net.corda.core.crypto.entropyToKeyPair
|
||||||
import net.corda.core.identity.AbstractParty
|
import net.corda.core.identity.AbstractParty
|
||||||
import net.corda.core.identity.AnonymousParty
|
import net.corda.core.identity.AnonymousParty
|
||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
import net.corda.core.identity.Party
|
import net.corda.core.identity.Party
|
||||||
|
import net.corda.core.node.ServicesForResolution
|
||||||
|
import net.corda.core.node.services.AttachmentStorage
|
||||||
|
import net.corda.core.node.services.IdentityService
|
||||||
import net.corda.core.transactions.LedgerTransaction
|
import net.corda.core.transactions.LedgerTransaction
|
||||||
import net.corda.core.transactions.WireTransaction
|
import net.corda.core.transactions.WireTransaction
|
||||||
import net.corda.nodeapi.internal.serialization.GeneratedAttachment
|
import net.corda.nodeapi.internal.serialization.GeneratedAttachment
|
||||||
|
import net.corda.testing.common.internal.testNetworkParameters
|
||||||
import net.corda.testing.contracts.DummyContract
|
import net.corda.testing.contracts.DummyContract
|
||||||
|
import net.corda.testing.internal.rigorousMock
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
import java.security.PublicKey
|
import java.security.PublicKey
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -28,25 +37,36 @@ data class GeneratedLedger(
|
|||||||
val attachments: Set<Attachment>,
|
val attachments: Set<Attachment>,
|
||||||
val identities: Set<Party>
|
val identities: Set<Party>
|
||||||
) {
|
) {
|
||||||
val hashTransactionMap: Map<SecureHash, WireTransaction> by lazy { transactions.associateBy(WireTransaction::id) }
|
private val hashTransactionMap: Map<SecureHash, WireTransaction> by lazy { transactions.associateBy(WireTransaction::id) }
|
||||||
val attachmentMap: Map<SecureHash, Attachment> by lazy { attachments.associateBy(Attachment::id) }
|
private val attachmentMap: Map<SecureHash, Attachment> by lazy { attachments.associateBy(Attachment::id) }
|
||||||
val identityMap: Map<PublicKey, Party> by lazy { identities.associateBy(Party::owningKey) }
|
private val identityMap: Map<PublicKey, Party> by lazy { identities.associateBy(Party::owningKey) }
|
||||||
val contractAttachmentMap: Map<String, ContractAttachment> by lazy {
|
private val contractAttachmentMap: Map<String, ContractAttachment> by lazy {
|
||||||
attachments.mapNotNull { it as? ContractAttachment }.associateBy { it.contract }
|
attachments.mapNotNull { it as? ContractAttachment }.associateBy { it.contract }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val services = object : ServicesForResolution {
|
||||||
|
override fun loadState(stateRef: StateRef): TransactionState<*> {
|
||||||
|
return hashTransactionMap[stateRef.txhash]?.outputs?.get(stateRef.index) ?: throw TransactionResolutionException(stateRef.txhash)
|
||||||
|
}
|
||||||
|
override val identityService = rigorousMock<IdentityService>().apply {
|
||||||
|
doAnswer { identityMap[it.arguments[0]] }.whenever(this).partyFromKey(any())
|
||||||
|
}
|
||||||
|
override val attachments = rigorousMock<AttachmentStorage>().apply {
|
||||||
|
doAnswer { attachmentMap[it.arguments[0]] }.whenever(this).openAttachment(any())
|
||||||
|
}
|
||||||
|
override val cordappProvider = rigorousMock<CordappProvider>().apply {
|
||||||
|
doAnswer { contractAttachmentMap[it.arguments[0]]?.id }.whenever(this).getContractAttachmentID(any())
|
||||||
|
}
|
||||||
|
override val networkParameters = testNetworkParameters()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val empty = GeneratedLedger(emptyList(), emptyMap(), emptySet(), emptySet())
|
val empty = GeneratedLedger(emptyList(), emptyMap(), emptySet(), emptySet())
|
||||||
val contractAttachment = ContractAttachment(GeneratedAttachment(ByteArray(0) { 0 }), DummyContract.PROGRAM_ID)
|
val contractAttachment = ContractAttachment(GeneratedAttachment(ByteArray(0) { 0 }), DummyContract.PROGRAM_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolveWireTransaction(transaction: WireTransaction): LedgerTransaction {
|
fun resolveWireTransaction(transaction: WireTransaction): LedgerTransaction {
|
||||||
return transaction.toLedgerTransaction(
|
return transaction.toLedgerTransaction(services)
|
||||||
resolveIdentity = { identityMap[it] },
|
|
||||||
resolveAttachment = { attachmentMap[it] },
|
|
||||||
resolveStateRef = { hashTransactionMap[it.txhash]?.outputs?.get(it.index) },
|
|
||||||
resolveContractAttachment = { contractAttachmentMap[it.contract]?.id }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val attachmentsGenerator: Generator<List<Attachment>> by lazy {
|
val attachmentsGenerator: Generator<List<Attachment>> by lazy {
|
||||||
|
@ -5,13 +5,13 @@ import com.typesafe.config.ConfigFactory
|
|||||||
import net.corda.core.concurrent.CordaFuture
|
import net.corda.core.concurrent.CordaFuture
|
||||||
import net.corda.core.crypto.random63BitValue
|
import net.corda.core.crypto.random63BitValue
|
||||||
import net.corda.core.identity.CordaX500Name
|
import net.corda.core.identity.CordaX500Name
|
||||||
import net.corda.core.internal.GlobalProperties
|
|
||||||
import net.corda.core.internal.concurrent.OpenFuture
|
import net.corda.core.internal.concurrent.OpenFuture
|
||||||
import net.corda.core.internal.concurrent.doneFuture
|
import net.corda.core.internal.concurrent.doneFuture
|
||||||
import net.corda.core.internal.concurrent.fork
|
import net.corda.core.internal.concurrent.fork
|
||||||
import net.corda.core.internal.concurrent.openFuture
|
import net.corda.core.internal.concurrent.openFuture
|
||||||
import net.corda.core.internal.createDirectories
|
import net.corda.core.internal.createDirectories
|
||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
|
import net.corda.core.node.NetworkParameters
|
||||||
import net.corda.core.serialization.internal.nodeSerializationEnv
|
import net.corda.core.serialization.internal.nodeSerializationEnv
|
||||||
import net.corda.core.transactions.LedgerTransaction
|
import net.corda.core.transactions.LedgerTransaction
|
||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
@ -64,7 +64,7 @@ fun <A> verifierDriver(
|
|||||||
extraCordappPackagesToScan: List<String> = emptyList(),
|
extraCordappPackagesToScan: List<String> = emptyList(),
|
||||||
notarySpecs: List<NotarySpec> = emptyList(),
|
notarySpecs: List<NotarySpec> = emptyList(),
|
||||||
jmxPolicy: JmxPolicy = JmxPolicy(),
|
jmxPolicy: JmxPolicy = JmxPolicy(),
|
||||||
maxTransactionSize: Int = Int.MAX_VALUE,
|
networkParameters: NetworkParameters = testNetworkParameters(),
|
||||||
dsl: VerifierDriverDSL.() -> A
|
dsl: VerifierDriverDSL.() -> A
|
||||||
) = genericDriver(
|
) = genericDriver(
|
||||||
driverDsl = VerifierDriverDSL(
|
driverDsl = VerifierDriverDSL(
|
||||||
@ -81,7 +81,7 @@ fun <A> verifierDriver(
|
|||||||
notarySpecs = notarySpecs,
|
notarySpecs = notarySpecs,
|
||||||
jmxPolicy = jmxPolicy,
|
jmxPolicy = jmxPolicy,
|
||||||
compatibilityZone = null,
|
compatibilityZone = null,
|
||||||
maxTransactionSize = maxTransactionSize
|
networkParameters = networkParameters
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
coerce = { it },
|
coerce = { it },
|
||||||
@ -167,7 +167,6 @@ data class VerifierDriverDSL(private val driverDSL: DriverDSLImpl) : InternalDri
|
|||||||
/** Starts a lightweight verification requestor that implements the Node's Verifier API */
|
/** Starts a lightweight verification requestor that implements the Node's Verifier API */
|
||||||
fun startVerificationRequestor(name: CordaX500Name): CordaFuture<VerificationRequestorHandle> {
|
fun startVerificationRequestor(name: CordaX500Name): CordaFuture<VerificationRequestorHandle> {
|
||||||
val hostAndPort = driverDSL.portAllocation.nextHostAndPort()
|
val hostAndPort = driverDSL.portAllocation.nextHostAndPort()
|
||||||
GlobalProperties.networkParameters = testNetworkParameters(emptyList(), maxTransactionSize = driverDSL.maxTransactionSize)
|
|
||||||
return driverDSL.executorService.fork {
|
return driverDSL.executorService.fork {
|
||||||
startVerificationRequestorInternal(name, hostAndPort)
|
startVerificationRequestorInternal(name, hostAndPort)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user