CORDA-961 Wire up and enforce max transaction size (#2465)

* wire up and enforce max transaction size

* fixup after rebase
moved network parameter from AbstractNode to NodeProperties

* removed TODO

* fix broken import

* address PR issues

* remove API breaking change
address PR issue

* added max transaction size to driver and mock network.
address PR issues

* fix failing test

* added TODO

* fix verifier test

* fix spring driver build error
This commit is contained in:
Patrick Kuo
2018-02-09 14:48:45 +00:00
committed by GitHub
parent 1902a4f11e
commit c8cf46c657
23 changed files with 251 additions and 35 deletions

View File

@ -147,7 +147,7 @@ data class NodeParameters(
data class JmxPolicy(val startJmxHttpServer: Boolean = false,
val jmxHttpServerPortAllocation: PortAllocation? =
if (startJmxHttpServer) PortAllocation.Incremental(7005) else null)
if (startJmxHttpServer) PortAllocation.Incremental(7005) else null)
/**
* [driver] allows one to start up nodes like this:
@ -174,7 +174,7 @@ data class JmxPolicy(val startJmxHttpServer: Boolean = false,
* @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.
* @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.
@ -198,6 +198,7 @@ fun <A> driver(
notarySpecs: List<NotarySpec> = defaultParameters.notarySpecs,
extraCordappPackagesToScan: List<String> = defaultParameters.extraCordappPackagesToScan,
jmxPolicy: JmxPolicy = defaultParameters.jmxPolicy,
maxTransactionSize: Int = defaultParameters.maxTransactionSize,
dsl: DriverDSL.() -> A
): A {
return genericDriver(
@ -213,7 +214,8 @@ fun <A> driver(
notarySpecs = notarySpecs,
extraCordappPackagesToScan = extraCordappPackagesToScan,
jmxPolicy = jmxPolicy,
compatibilityZone = null
compatibilityZone = null,
maxTransactionSize = maxTransactionSize
),
coerce = { it },
dsl = dsl,
@ -249,7 +251,8 @@ data class DriverParameters(
val waitForAllNodesToFinish: Boolean = false,
val notarySpecs: List<NotarySpec> = listOf(NotarySpec(DUMMY_NOTARY_NAME)),
val extraCordappPackagesToScan: List<String> = emptyList(),
val jmxPolicy: JmxPolicy = JmxPolicy()
val jmxPolicy: JmxPolicy = JmxPolicy(),
val maxTransactionSize: Int = Int.MAX_VALUE
) {
fun setIsDebug(isDebug: Boolean) = copy(isDebug = isDebug)
fun setDriverDirectory(driverDirectory: Path) = copy(driverDirectory = driverDirectory)

View File

@ -19,6 +19,7 @@ import net.corda.core.messaging.MessageRecipients
import net.corda.core.messaging.RPCOps
import net.corda.core.messaging.SingleMessageRecipient
import net.corda.core.node.NodeInfo
import net.corda.core.node.NotaryInfo
import net.corda.core.node.services.IdentityService
import net.corda.core.node.services.KeyManagementService
import net.corda.core.serialization.SerializationWhitelist
@ -42,16 +43,15 @@ import net.corda.node.utilities.AffinityExecutor.ServiceAffinityExecutor
import net.corda.nodeapi.internal.DevIdentityGenerator
import net.corda.nodeapi.internal.config.User
import net.corda.nodeapi.internal.network.NetworkParametersCopier
import net.corda.core.node.NotaryInfo
import net.corda.nodeapi.internal.persistence.CordaPersistence
import net.corda.nodeapi.internal.persistence.DatabaseConfig
import net.corda.testing.core.DUMMY_NOTARY_NAME
import net.corda.testing.common.internal.testNetworkParameters
import net.corda.testing.core.DUMMY_NOTARY_NAME
import net.corda.testing.core.setGlobalSerialization
import net.corda.testing.internal.rigorousMock
import net.corda.testing.internal.testThreadFactory
import net.corda.testing.node.MockServices.Companion.MOCK_VERSION_INFO
import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties
import net.corda.testing.core.setGlobalSerialization
import org.apache.activemq.artemis.utils.ReusableLatch
import org.apache.sshd.common.util.security.SecurityUtils
import rx.internal.schedulers.CachedThreadScheduler
@ -133,7 +133,8 @@ open class MockNetwork(private val cordappPackages: List<String>,
servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy = defaultParameters.servicePeerAllocationStrategy,
private val defaultFactory: (MockNodeArgs) -> MockNode = defaultParameters.defaultFactory,
initialiseSerialization: Boolean = defaultParameters.initialiseSerialization,
private val notarySpecs: List<NotarySpec> = defaultParameters.notarySpecs) {
private val notarySpecs: List<NotarySpec> = defaultParameters.notarySpecs,
maxTransactionSize: Int = Int.MAX_VALUE) {
/** Helper constructor for creating a [MockNetwork] with custom parameters from Java. */
@JvmOverloads
constructor(cordappPackages: List<String>, parameters: MockNetworkParameters = MockNetworkParameters()) : this(cordappPackages, defaultParameters = parameters)
@ -228,7 +229,7 @@ open class MockNetwork(private val cordappPackages: List<String>,
filesystem.getPath("/nodes").createDirectory()
val notaryInfos = generateNotaryIdentities()
// The network parameters must be serialised before starting any of the nodes
networkParameters = NetworkParametersCopier(testNetworkParameters(notaryInfos))
networkParameters = NetworkParametersCopier(testNetworkParameters(notaryInfos, maxTransactionSize = maxTransactionSize))
@Suppress("LeakingThis")
notaryNodes = createNotaries()
} catch (t: Throwable) {

View File

@ -6,6 +6,7 @@ import net.corda.core.crypto.*
import net.corda.core.flows.FlowLogic
import net.corda.core.identity.CordaX500Name
import net.corda.core.identity.PartyAndCertificate
import net.corda.core.internal.GlobalProperties
import net.corda.core.messaging.DataFeed
import net.corda.core.messaging.FlowHandle
import net.corda.core.messaging.FlowProgressHandle
@ -31,6 +32,7 @@ import net.corda.node.services.vault.NodeVaultService
import net.corda.nodeapi.internal.persistence.CordaPersistence
import net.corda.nodeapi.internal.persistence.DatabaseConfig
import net.corda.nodeapi.internal.persistence.HibernateConfiguration
import net.corda.testing.common.internal.testNetworkParameters
import net.corda.testing.core.DEV_ROOT_CA
import net.corda.testing.core.TestIdentity
import net.corda.testing.services.MockAttachmentStorage

View File

@ -9,11 +9,13 @@ import net.corda.core.context.InvocationContext
import net.corda.core.flows.FlowLogic
import net.corda.core.identity.CordaX500Name
import net.corda.core.identity.Party
import net.corda.core.internal.GlobalProperties
import net.corda.core.node.ServiceHub
import net.corda.core.serialization.internal.effectiveSerializationEnv
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.getOrThrow
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.TestIdentity
import net.corda.testing.core.chooseIdentity
@ -34,6 +36,7 @@ fun ServiceHub.ledger(
false
}
return LedgerDSL(TestLedgerDSLInterpreter(this), notary).apply {
GlobalProperties.networkParameters = testNetworkParameters(emptyList())
if (serializationExists) {
script()
} else {

View File

@ -14,6 +14,7 @@ import net.corda.core.identity.CordaX500Name
import net.corda.core.internal.*
import net.corda.core.internal.concurrent.*
import net.corda.core.messaging.CordaRPCOps
import net.corda.core.node.NotaryInfo
import net.corda.core.node.services.NetworkMapCache
import net.corda.core.serialization.deserialize
import net.corda.core.toFuture
@ -37,7 +38,6 @@ import net.corda.nodeapi.internal.crypto.X509KeyStore
import net.corda.nodeapi.internal.crypto.X509Utilities
import net.corda.nodeapi.internal.network.NetworkParametersCopier
import net.corda.nodeapi.internal.network.NodeInfoFilesCopier
import net.corda.core.node.NotaryInfo
import net.corda.testing.common.internal.testNetworkParameters
import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME
@ -87,7 +87,8 @@ class DriverDSLImpl(
extraCordappPackagesToScan: List<String>,
val jmxPolicy: JmxPolicy,
val notarySpecs: List<NotarySpec>,
val compatibilityZone: CompatibilityZoneParams?
val compatibilityZone: CompatibilityZoneParams?,
val maxTransactionSize: Int
) : InternalDriverDSL {
private var _executorService: ScheduledExecutorService? = null
val executorService get() = _executorService!!
@ -699,7 +700,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.
*/
private inner class LocalNetworkMap(notaryInfos: List<NotaryInfo>) {
val networkParametersCopier = NetworkParametersCopier(testNetworkParameters(notaryInfos))
val networkParametersCopier = NetworkParametersCopier(testNetworkParameters(notaryInfos, maxTransactionSize = maxTransactionSize))
// 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.
// Investigate whether we can avoid that.
@ -955,6 +956,7 @@ fun <DI : DriverDSL, D : InternalDriverDSL, A> genericDriver(
notarySpecs: List<NotarySpec>,
extraCordappPackagesToScan: List<String> = defaultParameters.extraCordappPackagesToScan,
jmxPolicy: JmxPolicy = JmxPolicy(),
maxTransactionSize: Int,
driverDslWrapper: (DriverDSLImpl) -> D,
coerce: (D) -> DI, dsl: DI.() -> A
): A {
@ -972,7 +974,8 @@ fun <DI : DriverDSL, D : InternalDriverDSL, A> genericDriver(
extraCordappPackagesToScan = extraCordappPackagesToScan,
jmxPolicy = jmxPolicy,
notarySpecs = notarySpecs,
compatibilityZone = null
compatibilityZone = null,
maxTransactionSize = maxTransactionSize
)
)
val shutdownHook = addShutdownHook(driverDsl::shutdown)
@ -1014,6 +1017,7 @@ fun <A> internalDriver(
notarySpecs: List<NotarySpec> = DriverParameters().notarySpecs,
extraCordappPackagesToScan: List<String> = DriverParameters().extraCordappPackagesToScan,
jmxPolicy: JmxPolicy = DriverParameters().jmxPolicy,
maxTransactionSize: Int = DriverParameters().maxTransactionSize,
compatibilityZone: CompatibilityZoneParams? = null,
dsl: DriverDSLImpl.() -> A
): A {
@ -1030,7 +1034,8 @@ fun <A> internalDriver(
notarySpecs = notarySpecs,
extraCordappPackagesToScan = extraCordappPackagesToScan,
jmxPolicy = jmxPolicy,
compatibilityZone = compatibilityZone
compatibilityZone = compatibilityZone,
maxTransactionSize = maxTransactionSize
),
coerce = { it },
dsl = dsl,

View File

@ -106,8 +106,9 @@ fun <A> rpcDriver(
notarySpecs: List<NotarySpec> = emptyList(),
externalTrace: Trace? = null,
jmxPolicy: JmxPolicy = JmxPolicy(),
maxTransactionSize: Int = Int.MAX_VALUE,
dsl: RPCDriverDSL.() -> A
) : A {
): A {
return genericDriver(
driverDsl = RPCDriverDSL(
DriverDSLImpl(
@ -122,7 +123,8 @@ fun <A> rpcDriver(
extraCordappPackagesToScan = extraCordappPackagesToScan,
notarySpecs = notarySpecs,
jmxPolicy = jmxPolicy,
compatibilityZone = null
compatibilityZone = null,
maxTransactionSize = maxTransactionSize
), externalTrace
),
coerce = { it },
@ -434,7 +436,7 @@ data class RPCDriverDSL(
minLargeMessageSize = MAX_MESSAGE_SIZE
isUseGlobalPools = false
}
val rpcSecurityManager = RPCSecurityManagerImpl.fromUserList(users = listOf(InternalUser(rpcUser.username, rpcUser.password, rpcUser.permissions)) , id = AuthServiceId("TEST_SECURITY_MANAGER"))
val rpcSecurityManager = RPCSecurityManagerImpl.fromUserList(users = listOf(InternalUser(rpcUser.username, rpcUser.password, rpcUser.permissions)), id = AuthServiceId("TEST_SECURITY_MANAGER"))
val rpcServer = RPCServer(
ops,
rpcUser.username,

View File

@ -9,7 +9,8 @@ fun testNetworkParameters(
minimumPlatformVersion: Int = 1,
modifiedTime: Instant = Instant.now(),
maxMessageSize: Int = 10485760,
maxTransactionSize: Int = 40000,
// TODO: Make this configurable and consistence across driver, bootstrapper, demobench and NetworkMapServer
maxTransactionSize: Int = Int.MAX_VALUE,
epoch: Int = 1
): NetworkParameters {
return NetworkParameters(