From f6e7ffdd31b4d1d90dfe2e976f6fcc0a31bee510 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 6 Jul 2016 14:00:29 +0100 Subject: [PATCH 1/3] Fix a race condition in the MockNode class that only shows up when used in thread-per-node mode. Witnessed in the unit tests. --- .../kotlin/com/r3corda/node/internal/testing/MockNode.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/node/src/main/kotlin/com/r3corda/node/internal/testing/MockNode.kt b/node/src/main/kotlin/com/r3corda/node/internal/testing/MockNode.kt index ea7e7fb279..6245192984 100644 --- a/node/src/main/kotlin/com/r3corda/node/internal/testing/MockNode.kt +++ b/node/src/main/kotlin/com/r3corda/node/internal/testing/MockNode.kt @@ -121,7 +121,11 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, override val nearestCity: String = "Atlantis" } val node = nodeFactory.create(path, config, this, networkMapAddress, advertisedServices.toSet(), id, keyPair) - if (start) node.setup().start() + if (start) { + node.setup().start() + if (threadPerNode && networkMapAddress != null) + node.networkMapRegistrationFuture.get() // Block and wait for the node to register in the net map. + } _nodes.add(node) return node } From 9e849378cfb8d2e6809b60396a63efe093c0b847 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 6 Jul 2016 14:00:48 +0100 Subject: [PATCH 2/3] Minor: add some assertions in the WalletFiller code after a test was observed to fail due to a negative amount. --- .../main/kotlin/com/r3corda/contracts/testing/WalletFiller.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/src/main/kotlin/com/r3corda/contracts/testing/WalletFiller.kt b/contracts/src/main/kotlin/com/r3corda/contracts/testing/WalletFiller.kt index 2a9bd90fac..456b8dd391 100644 --- a/contracts/src/main/kotlin/com/r3corda/contracts/testing/WalletFiller.kt +++ b/contracts/src/main/kotlin/com/r3corda/contracts/testing/WalletFiller.kt @@ -66,6 +66,7 @@ private fun calculateRandomlySizedAmounts(howMuch: Amount, min: Int, m val numStates = min + Math.floor(rng.nextDouble() * (max - min)).toInt() val amounts = LongArray(numStates) val baseSize = howMuch.quantity / numStates + check(baseSize > 0) { baseSize } var filledSoFar = 0L for (i in 0..numStates - 1) { if (i < numStates - 1) { @@ -76,6 +77,7 @@ private fun calculateRandomlySizedAmounts(howMuch: Amount, min: Int, m // Handle inexact rounding. amounts[i] = howMuch.quantity - filledSoFar } + check(amounts[i] >= 0) { amounts[i] } } check(amounts.sum() == howMuch.quantity) return amounts From 2e3f689fd37f87faf6d5786fe04c58f549f29ae5 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 6 Jul 2016 16:04:10 +0100 Subject: [PATCH 3/3] Minor: fix PublicKey.toShortString after the switch to ed25519 --- .../main/kotlin/com/r3corda/core/crypto/CryptoUtilities.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/com/r3corda/core/crypto/CryptoUtilities.kt b/core/src/main/kotlin/com/r3corda/core/crypto/CryptoUtilities.kt index 0f81331f5f..11022a2086 100644 --- a/core/src/main/kotlin/com/r3corda/core/crypto/CryptoUtilities.kt +++ b/core/src/main/kotlin/com/r3corda/core/crypto/CryptoUtilities.kt @@ -5,9 +5,9 @@ import com.r3corda.core.serialization.OpaqueBytes import com.r3corda.core.serialization.SerializedBytes import com.r3corda.core.serialization.deserialize import net.i2p.crypto.eddsa.EdDSAEngine +import net.i2p.crypto.eddsa.EdDSAPublicKey import java.math.BigInteger import java.security.* -import java.security.interfaces.ECPublicKey import net.i2p.crypto.eddsa.KeyPairGenerator as EddsaKeyPairGenerator fun newSecureRandom(): SecureRandom { @@ -158,8 +158,8 @@ fun PublicKey.verifyWithECDSA(content: ByteArray, signature: DigitalSignature) { /** Render a public key to a string, using a short form if it's an elliptic curve public key */ fun PublicKey.toStringShort(): String { - return (this as? ECPublicKey)?.let { key -> - "DL" + Base58.encode(key.w.affineX.toByteArray()) // DL -> Distributed Ledger + return (this as? EdDSAPublicKey)?.let { key -> + "DL" + Base58.encode(key.abyte) // DL -> Distributed Ledger } ?: toString() }