Skip to content

Commit

Permalink
CORDA-2769 - fixed infinite recursive call for copy implementation. (
Browse files Browse the repository at this point in the history
  • Loading branch information
dazraf authored and shamsasari committed Mar 27, 2019
1 parent ea89f3a commit 270444a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 29 additions & 19 deletions core/src/main/kotlin/net/corda/core/node/NetworkParameters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,44 +98,54 @@ data class NetworkParameters(
require(noPackageOverlap(packageOwnership.keys)) { "Multiple packages added to the packageOwnership overlap." }
}

fun copy(minimumPlatformVersion: Int,
notaries: List<NotaryInfo>,
maxMessageSize: Int,
maxTransactionSize: Int,
modifiedTime: Instant,
epoch: Int,
whitelistedContractImplementations: Map<String, List<AttachmentId>>
/**
* This is to address backwards compatibility of the API, invariant to package ownership
* addresses bug CORDA-2769
*/
fun copy(minimumPlatformVersion: Int = this.minimumPlatformVersion,
notaries: List<NotaryInfo> = this.notaries,
maxMessageSize: Int = this.maxMessageSize,
maxTransactionSize: Int = this.maxTransactionSize,
modifiedTime: Instant = this.modifiedTime,
epoch: Int = this.epoch,
whitelistedContractImplementations: Map<String, List<AttachmentId>> = this.whitelistedContractImplementations,
eventHorizon: Duration = this.eventHorizon
): NetworkParameters {
return copy(
return NetworkParameters(
minimumPlatformVersion = minimumPlatformVersion,
notaries = notaries,
maxMessageSize = maxMessageSize,
maxTransactionSize = maxTransactionSize,
modifiedTime = modifiedTime,
epoch = epoch,
whitelistedContractImplementations = whitelistedContractImplementations,
eventHorizon = eventHorizon
eventHorizon = eventHorizon,
packageOwnership = packageOwnership
)
}

fun copy(minimumPlatformVersion: Int,
notaries: List<NotaryInfo>,
maxMessageSize: Int,
maxTransactionSize: Int,
modifiedTime: Instant,
epoch: Int,
whitelistedContractImplementations: Map<String, List<AttachmentId>>,
eventHorizon: Duration
/**
* This is to address backwards compatibility of the API, invariant to package ownership
* addresses bug CORDA-2769
*/
fun copy(minimumPlatformVersion: Int = this.minimumPlatformVersion,
notaries: List<NotaryInfo> = this.notaries,
maxMessageSize: Int = this.maxMessageSize,
maxTransactionSize: Int = this.maxTransactionSize,
modifiedTime: Instant = this.modifiedTime,
epoch: Int = this.epoch,
whitelistedContractImplementations: Map<String, List<AttachmentId>> = this.whitelistedContractImplementations
): NetworkParameters {
return copy(
return NetworkParameters(
minimumPlatformVersion = minimumPlatformVersion,
notaries = notaries,
maxMessageSize = maxMessageSize,
maxTransactionSize = maxTransactionSize,
modifiedTime = modifiedTime,
epoch = epoch,
whitelistedContractImplementations = whitelistedContractImplementations,
eventHorizon = eventHorizon
eventHorizon = eventHorizon,
packageOwnership = packageOwnership
)
}

Expand Down
35 changes: 31 additions & 4 deletions core/src/test/kotlin/net/corda/core/node/NetworkParametersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.nhaarman.mockito_kotlin.doReturn
import com.nhaarman.mockito_kotlin.whenever
import net.corda.core.crypto.generateKeyPair
import net.corda.core.internal.getPackageOwnerOf
import net.corda.core.node.services.AttachmentId
import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.days
import net.corda.core.utilities.getOrThrow
Expand All @@ -12,10 +13,7 @@ import net.corda.finance.flows.CashIssueFlow
import net.corda.node.services.config.NotaryConfig
import net.corda.nodeapi.internal.network.NetworkParametersCopier
import net.corda.testing.common.internal.testNetworkParameters
import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.DUMMY_NOTARY_NAME
import net.corda.testing.core.singleIdentity
import net.corda.testing.core.*
import net.corda.testing.node.MockNetworkNotarySpec
import net.corda.testing.node.MockNetworkParameters
import net.corda.testing.node.internal.InternalMockNetwork
Expand All @@ -26,6 +24,7 @@ import org.assertj.core.api.Assertions.*
import org.junit.After
import org.junit.Test
import java.nio.file.Path
import java.time.Duration
import java.time.Instant
import kotlin.test.assertEquals
import kotlin.test.assertFails
Expand Down Expand Up @@ -64,6 +63,34 @@ class NetworkParametersTest {
alice.start()
}

@Test
fun `that we can copy while preserving the event horizon`() {
// this is defensive tests in response to CORDA-2769
val aliceNotaryParty = TestIdentity(ALICE_NAME).party
val aliceNotaryInfo = NotaryInfo(aliceNotaryParty, false)
val nm1 = NetworkParameters(
minimumPlatformVersion = 1,
notaries = listOf(aliceNotaryInfo),
maxMessageSize = Int.MAX_VALUE,
maxTransactionSize = Int.MAX_VALUE,
modifiedTime = Instant.now(),
epoch = 1,
whitelistedContractImplementations = mapOf("MyClass" to listOf(AttachmentId.allOnesHash)),
eventHorizon = Duration.ofDays(1)
)
val twoDays = Duration.ofDays(2)
val nm2 = nm1.copy(minimumPlatformVersion = 2, eventHorizon = twoDays)

assertEquals(2, nm2.minimumPlatformVersion)
assertEquals(nm1.notaries, nm2.notaries)
assertEquals(nm1.maxMessageSize, nm2.maxMessageSize)
assertEquals(nm1.maxTransactionSize, nm2.maxTransactionSize)
assertEquals(nm1.modifiedTime, nm2.modifiedTime)
assertEquals(nm1.epoch, nm2.epoch)
assertEquals(nm1.whitelistedContractImplementations, nm2.whitelistedContractImplementations)
assertEquals(twoDays, nm2.eventHorizon)
}

// Notaries tests
@Test
fun `choosing notary not specified in network parameters will fail`() {
Expand Down

0 comments on commit 270444a

Please sign in to comment.