mirror of
https://github.com/corda/corda.git
synced 2025-01-18 18:56:28 +00:00
Minor: auto-format of module: node
This commit is contained in:
parent
3a7bcee15b
commit
d6af727751
@ -9,8 +9,8 @@ import net.corda.core.readLines
|
||||
import net.corda.node.LOGS_DIRECTORY_NAME
|
||||
import net.corda.node.services.api.RegulatorService
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import net.corda.nodeapi.ArtemisMessagingComponent
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
import java.nio.file.Paths
|
||||
import java.util.concurrent.Executors
|
||||
|
@ -1,4 +1,5 @@
|
||||
@file:JvmName("Corda")
|
||||
|
||||
package net.corda.node
|
||||
|
||||
import com.jcabi.manifests.Manifests
|
||||
@ -116,7 +117,7 @@ fun main(args: Array<String>) {
|
||||
log.info("Machine: ${InetAddress.getLocalHost().hostName}")
|
||||
log.info("Working Directory: ${cmdlineOptions.baseDirectory}")
|
||||
val agentProperties = sun.misc.VMSupport.getAgentProperties()
|
||||
if(agentProperties.containsKey("sun.jdwp.listenerAddress")) {
|
||||
if (agentProperties.containsKey("sun.jdwp.listenerAddress")) {
|
||||
log.info("Debug port: ${agentProperties.getProperty("sun.jdwp.listenerAddress")}")
|
||||
}
|
||||
log.info("Starting as node on ${conf.p2pAddress}")
|
||||
@ -172,7 +173,7 @@ private fun printPluginsAndServices(node: Node) {
|
||||
}
|
||||
val plugins = node.pluginRegistries
|
||||
.map { it.javaClass.name }
|
||||
.filterNot { it.startsWith("net.corda.node.") || it.startsWith("net.corda.core.") || it.startsWith("net.corda.nodeapi.")}
|
||||
.filterNot { it.startsWith("net.corda.node.") || it.startsWith("net.corda.core.") || it.startsWith("net.corda.nodeapi.") }
|
||||
.map { it.substringBefore('$') }
|
||||
if (plugins.isNotEmpty())
|
||||
printBasicNodeInfo("Loaded plugins", plugins.joinToString())
|
||||
@ -217,7 +218,7 @@ private fun drawBanner(nodeVersionInfo: NodeVersionInfo) {
|
||||
val (msg1, msg2) = messageOfTheDay()
|
||||
|
||||
println(Ansi.ansi().fgBrightRed().a(
|
||||
"""
|
||||
"""
|
||||
______ __
|
||||
/ ____/ _________/ /___ _
|
||||
/ / __ / ___/ __ / __ `/ """).fgBrightBlue().a(msg1).newline().fgBrightRed().a(
|
||||
|
@ -1,4 +1,5 @@
|
||||
@file:JvmName("Driver")
|
||||
|
||||
package net.corda.node.driver
|
||||
|
||||
import com.google.common.net.HostAndPort
|
||||
@ -287,6 +288,7 @@ class ShutdownManager(private val executorService: ExecutorService) {
|
||||
val registeredShutdowns = ArrayList<ListenableFuture<() -> Unit>>()
|
||||
var isShutdown = false
|
||||
}
|
||||
|
||||
private val state = ThreadBox(State())
|
||||
|
||||
fun shutdown() {
|
||||
@ -302,7 +304,7 @@ class ShutdownManager(private val executorService: ExecutorService) {
|
||||
/** Could not get all of them, collect what we have */
|
||||
shutdownFutures.filter { it.isDone }.map { it.get() }
|
||||
}
|
||||
shutdowns.reversed().forEach{ it() }
|
||||
shutdowns.reversed().forEach { it() }
|
||||
}
|
||||
|
||||
fun registerShutdown(shutdown: ListenableFuture<() -> Unit>) {
|
||||
@ -432,9 +434,9 @@ class DriverDSL(
|
||||
) + customOverrides
|
||||
|
||||
val config = ConfigHelper.loadConfig(
|
||||
baseDirectory = baseDirectory,
|
||||
allowMissingConfig = true,
|
||||
configOverrides = configOverrides)
|
||||
baseDirectory = baseDirectory,
|
||||
allowMissingConfig = true,
|
||||
configOverrides = configOverrides)
|
||||
val configuration = config.parseAs<FullNodeConfiguration>()
|
||||
|
||||
val processFuture = startNode(executorService, configuration, config, quasarJarPath, debugPort, systemProperties)
|
||||
|
@ -199,10 +199,12 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
||||
log.warn("Corda node is running in dev mode.")
|
||||
configuration.configureWithDevSSLCertificate()
|
||||
}
|
||||
require(hasSSLCertificates()) { "Identity certificate not found. " +
|
||||
"Please either copy your existing identity key and certificate from another node, " +
|
||||
"or if you don't have one yet, fill out the config file and run corda.jar --initial-registration. " +
|
||||
"Read more at: https://docs.corda.net/permissioning.html" }
|
||||
require(hasSSLCertificates()) {
|
||||
"Identity certificate not found. " +
|
||||
"Please either copy your existing identity key and certificate from another node, " +
|
||||
"or if you don't have one yet, fill out the config file and run corda.jar --initial-registration. " +
|
||||
"Read more at: https://docs.corda.net/permissioning.html"
|
||||
}
|
||||
|
||||
log.info("Node starting up ...")
|
||||
|
||||
@ -487,7 +489,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
||||
|
||||
protected open fun makeSchemaService(): SchemaService = NodeSchemaService()
|
||||
|
||||
protected abstract fun makeTransactionVerifierService() : TransactionVerifierService
|
||||
protected abstract fun makeTransactionVerifierService(): TransactionVerifierService
|
||||
|
||||
open fun stop() {
|
||||
// TODO: We need a good way of handling "nice to have" shutdown events, especially those that deal with the
|
||||
|
@ -111,7 +111,7 @@ class CordaRPCOpsImpl(
|
||||
|
||||
override fun attachmentExists(id: SecureHash): Boolean {
|
||||
// TODO: this operation should not require an explicit transaction
|
||||
return databaseTransaction(database){
|
||||
return databaseTransaction(database) {
|
||||
services.storageService.attachments.openAttachment(id) != null
|
||||
}
|
||||
}
|
||||
@ -125,10 +125,11 @@ class CordaRPCOpsImpl(
|
||||
|
||||
override fun uploadAttachment(jar: InputStream): SecureHash {
|
||||
// TODO: this operation should not require an explicit transaction
|
||||
return databaseTransaction(database){
|
||||
return databaseTransaction(database) {
|
||||
services.storageService.attachments.importAttachment(jar)
|
||||
}
|
||||
}
|
||||
|
||||
override fun authoriseContractUpgrade(state: StateAndRef<*>, upgradedContractClass: Class<out UpgradedContract<*, *>>) = services.vaultService.authoriseContractUpgrade(state, upgradedContractClass)
|
||||
override fun deauthoriseContractUpgrade(state: StateAndRef<*>) = services.vaultService.deauthoriseContractUpgrade(state)
|
||||
override fun currentNodeTime(): Instant = Instant.now(services.clock)
|
||||
|
@ -23,10 +23,9 @@ import net.corda.node.services.config.FullNodeConfiguration
|
||||
import net.corda.node.services.messaging.ArtemisMessagingServer
|
||||
import net.corda.node.services.messaging.NodeMessagingClient
|
||||
import net.corda.node.services.transactions.PersistentUniquenessProvider
|
||||
import net.corda.node.services.transactions.RaftNonValidatingNotaryService
|
||||
import net.corda.node.services.transactions.RaftUniquenessProvider
|
||||
import net.corda.node.services.transactions.RaftValidatingNotaryService
|
||||
import net.corda.node.services.transactions.RaftNonValidatingNotaryService
|
||||
import net.corda.node.services.transactions.*
|
||||
import net.corda.node.utilities.AddressUtils
|
||||
import net.corda.node.utilities.AffinityExecutor
|
||||
import net.corda.nodeapi.ArtemisMessagingComponent.NetworkMapAddress
|
||||
|
@ -7,7 +7,7 @@ import net.corda.core.node.services.FileUploader
|
||||
*
|
||||
* TODO: In future, also accept uploads over the MQ interface too.
|
||||
*/
|
||||
interface AcceptsFileUpload: FileUploader {
|
||||
interface AcceptsFileUpload : FileUploader {
|
||||
/** A string that prefixes the URLs, e.g. "attachments" or "interest-rates". Should be OK for URLs. */
|
||||
val dataTypePrefix: String
|
||||
|
||||
|
@ -9,7 +9,10 @@ import io.requery.sql.*
|
||||
import io.requery.sql.platform.H2
|
||||
import io.requery.util.function.Function
|
||||
import io.requery.util.function.Supplier
|
||||
import net.corda.core.schemas.requery.converters.*
|
||||
import net.corda.core.schemas.requery.converters.InstantConverter
|
||||
import net.corda.core.schemas.requery.converters.SecureHashConverter
|
||||
import net.corda.core.schemas.requery.converters.StateRefConverter
|
||||
import net.corda.core.schemas.requery.converters.VaultStateStatusConverter
|
||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
||||
import java.sql.Connection
|
||||
import java.util.*
|
||||
@ -128,8 +131,7 @@ class KotlinConfigurationTransactionWrapper(private val model: EntityModel,
|
||||
override fun getConnection(): Connection {
|
||||
val tx = TransactionManager.manager.currentOrNull()
|
||||
return CordaConnection(
|
||||
tx?.connection ?:
|
||||
TransactionManager.manager.newTransaction(Connection.TRANSACTION_REPEATABLE_READ).connection
|
||||
tx?.connection ?: TransactionManager.manager.newTransaction(Connection.TRANSACTION_REPEATABLE_READ).connection
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,9 @@ import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import io.requery.Persistable
|
||||
import io.requery.meta.EntityModel
|
||||
import io.requery.sql.*
|
||||
import io.requery.sql.KotlinEntityDataStore
|
||||
import io.requery.sql.SchemaModifier
|
||||
import io.requery.sql.TableCreationMode
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
||||
import java.sql.Connection
|
||||
|
@ -104,6 +104,7 @@ class NodeMessagingClient(override val config: NodeConfiguration,
|
||||
var rpcNotificationConsumer: ClientConsumer? = null
|
||||
var verificationResponseConsumer: ClientConsumer? = null
|
||||
}
|
||||
|
||||
val verifierService = when (config.verifierType) {
|
||||
VerifierType.InMemory -> InMemoryTransactionVerifierService(numberOfWorkers = 4)
|
||||
VerifierType.OutOfProcess -> createOutOfProcessVerifierService()
|
||||
@ -421,8 +422,10 @@ class NodeMessagingClient(override val config: NodeConfiguration,
|
||||
putLongProperty(HDR_SCHEDULED_DELIVERY_TIME, System.currentTimeMillis() + amqDelay)
|
||||
}
|
||||
}
|
||||
log.trace { "Send to: $mqAddress topic: ${message.topicSession.topic} " +
|
||||
"sessionID: ${message.topicSession.sessionID} uuid: ${message.uniqueMessageId}" }
|
||||
log.trace {
|
||||
"Send to: $mqAddress topic: ${message.topicSession.topic} " +
|
||||
"sessionID: ${message.topicSession.sessionID} uuid: ${message.uniqueMessageId}"
|
||||
}
|
||||
producer!!.send(mqAddress, artemisMessage)
|
||||
}
|
||||
}
|
||||
@ -499,19 +502,19 @@ class NodeMessagingClient(override val config: NodeConfiguration,
|
||||
|
||||
private fun createOutOfProcessVerifierService(): TransactionVerifierService {
|
||||
return object : OutOfProcessTransactionVerifierService(monitoringService) {
|
||||
override fun sendRequest(nonce: Long, transaction: LedgerTransaction) {
|
||||
messagingExecutor.fetchFrom {
|
||||
state.locked {
|
||||
val message = session!!.createMessage(false)
|
||||
val request = VerifierApi.VerificationRequest(nonce, transaction, SimpleString(verifierResponseAddress))
|
||||
request.writeToClientMessage(message)
|
||||
producer!!.send(VERIFICATION_REQUESTS_QUEUE_NAME, message)
|
||||
}
|
||||
override fun sendRequest(nonce: Long, transaction: LedgerTransaction) {
|
||||
messagingExecutor.fetchFrom {
|
||||
state.locked {
|
||||
val message = session!!.createMessage(false)
|
||||
val request = VerifierApi.VerificationRequest(nonce, transaction, SimpleString(verifierResponseAddress))
|
||||
request.writeToClientMessage(message)
|
||||
producer!!.send(VERIFICATION_REQUESTS_QUEUE_NAME, message)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun getAddressOfParty(partyInfo: PartyInfo): MessageRecipients {
|
||||
|
@ -70,7 +70,9 @@ abstract class RPCDispatcher(val ops: RPCOps, val userService: RPCUserService, v
|
||||
// representing what happened, which is useful for us to send over the wire.
|
||||
val subscription = obj.materialize().subscribe { materialised: Notification<out Any> ->
|
||||
val newKryo = createRPCKryoForSerialization(qName, dispatcher)
|
||||
val bits = try { MarshalledObservation(handle, materialised).serialize(newKryo) } finally {
|
||||
val bits = try {
|
||||
MarshalledObservation(handle, materialised).serialize(newKryo)
|
||||
} finally {
|
||||
releaseRPCKryoForSerialization(newKryo)
|
||||
}
|
||||
rpcLog.debug("RPC sending observation: $materialised")
|
||||
@ -91,7 +93,9 @@ abstract class RPCDispatcher(val ops: RPCOps, val userService: RPCUserService, v
|
||||
throw RPCException("Received RPC without any destination for observations, but the RPC returns observables")
|
||||
|
||||
val kryo = createRPCKryoForSerialization(observationsTo, this)
|
||||
val args = try { argsBytes.deserialize(kryo) } finally {
|
||||
val args = try {
|
||||
argsBytes.deserialize(kryo)
|
||||
} finally {
|
||||
releaseRPCKryoForSerialization(kryo)
|
||||
}
|
||||
|
||||
@ -173,6 +177,7 @@ abstract class RPCDispatcher(val ops: RPCOps, val userService: RPCUserService, v
|
||||
|
||||
// TODO remove this User once webserver doesn't need it
|
||||
private val nodeUser = User(NODE_USER, NODE_USER, setOf())
|
||||
|
||||
@VisibleForTesting
|
||||
protected open fun getUser(message: ClientMessage): User {
|
||||
val validatedUser = message.requiredString(Message.HDR_VALIDATED_USER.toString())
|
||||
|
@ -10,8 +10,7 @@ class FlowSession(
|
||||
val flow: FlowLogic<*>,
|
||||
val ourSessionId: Long,
|
||||
val initiatingParty: Party?,
|
||||
var state: FlowSessionState)
|
||||
{
|
||||
var state: FlowSessionState) {
|
||||
val receivedMessages = ConcurrentLinkedQueue<ReceivedSessionMessage<*>>()
|
||||
val fiber: FlowStateMachineImpl<*> get() = flow.stateMachine as FlowStateMachineImpl<*>
|
||||
|
||||
|
@ -26,6 +26,7 @@ interface SessionInitResponse : ExistingSessionMessage {
|
||||
val initiatorSessionId: Long
|
||||
override val recipientSessionId: Long get() = initiatorSessionId
|
||||
}
|
||||
|
||||
data class SessionConfirm(override val initiatorSessionId: Long, val initiatedSessionId: Long) : SessionInitResponse
|
||||
data class SessionReject(override val initiatorSessionId: Long, val errorMessage: String) : SessionInitResponse
|
||||
|
||||
|
@ -5,7 +5,6 @@ import co.paralleluniverse.fibers.FiberExecutorScheduler
|
||||
import co.paralleluniverse.io.serialization.kryo.KryoSerializer
|
||||
import co.paralleluniverse.strands.Strand
|
||||
import com.codahale.metrics.Gauge
|
||||
import com.esotericsoftware.kryo.Kryo
|
||||
import com.esotericsoftware.kryo.pool.KryoPool
|
||||
import com.google.common.collect.HashMultimap
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
@ -79,6 +78,7 @@ class StateMachineManager(val serviceHub: ServiceHubInternal,
|
||||
companion object {
|
||||
private val logger = loggerFor<StateMachineManager>()
|
||||
internal val sessionTopic = TopicSession("platform.session")
|
||||
|
||||
init {
|
||||
Fiber.setDefaultUncaughtExceptionHandler { fiber, throwable ->
|
||||
(fiber as FlowStateMachineImpl<*>).logger.error("Caught exception from flow", throwable)
|
||||
@ -101,12 +101,13 @@ class StateMachineManager(val serviceHub: ServiceHubInternal,
|
||||
var started = false
|
||||
val stateMachines = LinkedHashMap<FlowStateMachineImpl<*>, Checkpoint>()
|
||||
val changesPublisher = PublishSubject.create<Change>()!!
|
||||
val fibersWaitingForLedgerCommit = HashMultimap.create<SecureHash, FlowStateMachineImpl<*>>()!!
|
||||
val fibersWaitingForLedgerCommit = HashMultimap.create<SecureHash, FlowStateMachineImpl<*>>()!!
|
||||
|
||||
fun notifyChangeObservers(fiber: FlowStateMachineImpl<*>, addOrRemove: AddOrRemove) {
|
||||
changesPublisher.bufferUntilDatabaseCommit().onNext(Change(fiber.logic, addOrRemove, fiber.id))
|
||||
}
|
||||
}
|
||||
|
||||
private val mutex = ThreadBox(InnerState())
|
||||
|
||||
// True if we're shutting down, so don't resume anything.
|
||||
|
@ -9,7 +9,6 @@ import net.corda.core.node.services.TransactionVerifierService
|
||||
import net.corda.core.random63BitValue
|
||||
import net.corda.core.serialization.SingletonSerializeAsToken
|
||||
import net.corda.core.transactions.LedgerTransaction
|
||||
import net.corda.core.utilities.debug
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import net.corda.node.services.api.MonitoringService
|
||||
import net.corda.nodeapi.VerifierApi
|
||||
@ -22,15 +21,18 @@ abstract class OutOfProcessTransactionVerifierService(
|
||||
companion object {
|
||||
val log = loggerFor<OutOfProcessTransactionVerifierService>()
|
||||
}
|
||||
|
||||
private data class VerificationHandle(
|
||||
val transactionId: SecureHash,
|
||||
val resultFuture: SettableFuture<Unit>,
|
||||
val durationTimerContext: Timer.Context
|
||||
)
|
||||
|
||||
private val verificationHandles = ConcurrentHashMap<Long, VerificationHandle>()
|
||||
|
||||
// Metrics
|
||||
private fun metric(name: String) = "OutOfProcessTransactionVerifierService.$name"
|
||||
|
||||
private val durationTimer = monitoringService.metrics.timer(metric("Verification.Duration"))
|
||||
private val successMeter = monitoringService.metrics.meter(metric("Verification.Success"))
|
||||
private val failureMeter = monitoringService.metrics.meter(metric("Verification.Failure"))
|
||||
|
@ -13,7 +13,10 @@ import net.corda.contracts.asset.Cash
|
||||
import net.corda.core.ThreadBox
|
||||
import net.corda.core.bufferUntilSubscribed
|
||||
import net.corda.core.contracts.*
|
||||
import net.corda.core.crypto.*
|
||||
import net.corda.core.crypto.AbstractParty
|
||||
import net.corda.core.crypto.CompositeKey
|
||||
import net.corda.core.crypto.Party
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.node.ServiceHub
|
||||
import net.corda.core.node.services.StatesNotAvailableException
|
||||
import net.corda.core.node.services.Vault
|
||||
@ -55,7 +58,7 @@ class NodeVaultService(private val services: ServiceHub, dataSourceProperties: P
|
||||
val log = loggerFor<NodeVaultService>()
|
||||
|
||||
// Define composite primary key used in Requery Expression
|
||||
val stateRefCompositeColumn : RowExpression = RowExpression.of(listOf(VaultStatesEntity.TX_ID, VaultStatesEntity.INDEX))
|
||||
val stateRefCompositeColumn: RowExpression = RowExpression.of(listOf(VaultStatesEntity.TX_ID, VaultStatesEntity.INDEX))
|
||||
}
|
||||
|
||||
val configuration = RequeryConfiguration(dataSourceProperties)
|
||||
@ -136,7 +139,7 @@ class NodeVaultService(private val services: ServiceHub, dataSourceProperties: P
|
||||
}
|
||||
upsert(state ?: cashBalanceEntity)
|
||||
val total = state?.amount ?: cashBalanceEntity.amount
|
||||
log.trace{"Updating Cash balance for $currency by ${cashBalanceEntity.amount} pennies (total: $total)"}
|
||||
log.trace { "Updating Cash balance for $currency by ${cashBalanceEntity.amount} pennies (total: $total)" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,24 +174,24 @@ class NodeVaultService(private val services: ServiceHub, dataSourceProperties: P
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T: ContractState> states(clazzes: Set<Class<T>>, statuses: EnumSet<Vault.StateStatus>, includeSoftLockedStates: Boolean): Iterable<StateAndRef<T>> {
|
||||
override fun <T : ContractState> states(clazzes: Set<Class<T>>, statuses: EnumSet<Vault.StateStatus>, includeSoftLockedStates: Boolean): Iterable<StateAndRef<T>> {
|
||||
val stateAndRefs =
|
||||
session.withTransaction(TransactionIsolation.REPEATABLE_READ) {
|
||||
var query = select(VaultSchema.VaultStates::class)
|
||||
.where(VaultSchema.VaultStates::stateStatus `in` statuses)
|
||||
// TODO: temporary fix to continue supporting track() function (until becomes Typed)
|
||||
if (!clazzes.map {it.name}.contains(ContractState::class.java.name))
|
||||
query.and (VaultSchema.VaultStates::contractStateClassName `in` (clazzes.map { it.name }))
|
||||
if (!includeSoftLockedStates)
|
||||
query.and(VaultSchema.VaultStates::lockId.isNull())
|
||||
val iterator = query.get().iterator()
|
||||
Sequence{iterator}
|
||||
.map { it ->
|
||||
val stateRef = StateRef(SecureHash.parse(it.txId), it.index)
|
||||
val state = it.contractState.deserialize<TransactionState<T>>(storageKryo())
|
||||
StateAndRef(state, stateRef)
|
||||
}
|
||||
}
|
||||
session.withTransaction(TransactionIsolation.REPEATABLE_READ) {
|
||||
var query = select(VaultSchema.VaultStates::class)
|
||||
.where(VaultSchema.VaultStates::stateStatus `in` statuses)
|
||||
// TODO: temporary fix to continue supporting track() function (until becomes Typed)
|
||||
if (!clazzes.map { it.name }.contains(ContractState::class.java.name))
|
||||
query.and(VaultSchema.VaultStates::contractStateClassName `in` (clazzes.map { it.name }))
|
||||
if (!includeSoftLockedStates)
|
||||
query.and(VaultSchema.VaultStates::lockId.isNull())
|
||||
val iterator = query.get().iterator()
|
||||
Sequence { iterator }
|
||||
.map { it ->
|
||||
val stateRef = StateRef(SecureHash.parse(it.txId), it.index)
|
||||
val state = it.contractState.deserialize<TransactionState<T>>(storageKryo())
|
||||
StateAndRef(state, stateRef)
|
||||
}
|
||||
}
|
||||
return stateAndRefs.asIterable()
|
||||
}
|
||||
|
||||
@ -286,14 +289,13 @@ class NodeVaultService(private val services: ServiceHub, dataSourceProperties: P
|
||||
val update = update(VaultStatesEntity::class)
|
||||
.set(VaultStatesEntity.LOCK_ID, null)
|
||||
.set(VaultStatesEntity.LOCK_UPDATE_TIME, services.clock.instant())
|
||||
.where (VaultStatesEntity.STATE_STATUS eq Vault.StateStatus.UNCONSUMED)
|
||||
.and (VaultStatesEntity.LOCK_ID eq lockId.toString()).get()
|
||||
.where(VaultStatesEntity.STATE_STATUS eq Vault.StateStatus.UNCONSUMED)
|
||||
.and(VaultStatesEntity.LOCK_ID eq lockId.toString()).get()
|
||||
if (update.value() > 0) {
|
||||
log.trace("Releasing ${update.value()} soft locked states for $lockId")
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (stateRefs.isNotEmpty()) {
|
||||
} else if (stateRefs.isNotEmpty()) {
|
||||
try {
|
||||
session.withTransaction(TransactionIsolation.REPEATABLE_READ) {
|
||||
val updatedRows = update(VaultStatesEntity::class)
|
||||
@ -412,21 +414,21 @@ class NodeVaultService(private val services: ServiceHub, dataSourceProperties: P
|
||||
|
||||
override fun <T : ContractState> softLockedStates(lockId: UUID?): List<StateAndRef<T>> {
|
||||
val stateAndRefs =
|
||||
session.withTransaction(TransactionIsolation.REPEATABLE_READ) {
|
||||
var query = select(VaultSchema.VaultStates::class)
|
||||
.where(VaultSchema.VaultStates::stateStatus eq Vault.StateStatus.UNCONSUMED)
|
||||
.and(VaultSchema.VaultStates::contractStateClassName eq Cash.State::class.java.name)
|
||||
if (lockId != null)
|
||||
query.and(VaultSchema.VaultStates::lockId eq lockId)
|
||||
else
|
||||
query.and(VaultSchema.VaultStates::lockId.notNull())
|
||||
query.get()
|
||||
.map { it ->
|
||||
val stateRef = StateRef(SecureHash.parse(it.txId), it.index)
|
||||
val state = it.contractState.deserialize<TransactionState<T>>(storageKryo())
|
||||
StateAndRef(state, stateRef)
|
||||
}.toList()
|
||||
}
|
||||
session.withTransaction(TransactionIsolation.REPEATABLE_READ) {
|
||||
var query = select(VaultSchema.VaultStates::class)
|
||||
.where(VaultSchema.VaultStates::stateStatus eq Vault.StateStatus.UNCONSUMED)
|
||||
.and(VaultSchema.VaultStates::contractStateClassName eq Cash.State::class.java.name)
|
||||
if (lockId != null)
|
||||
query.and(VaultSchema.VaultStates::lockId eq lockId)
|
||||
else
|
||||
query.and(VaultSchema.VaultStates::lockId.notNull())
|
||||
query.get()
|
||||
.map { it ->
|
||||
val stateRef = StateRef(SecureHash.parse(it.txId), it.index)
|
||||
val state = it.contractState.deserialize<TransactionState<T>>(storageKryo())
|
||||
StateAndRef(state, stateRef)
|
||||
}.toList()
|
||||
}
|
||||
return stateAndRefs
|
||||
}
|
||||
|
||||
@ -561,8 +563,8 @@ class NodeVaultService(private val services: ServiceHub, dataSourceProperties: P
|
||||
if (tx.inputs.isNotEmpty()) {
|
||||
session.withTransaction(TransactionIsolation.REPEATABLE_READ) {
|
||||
val result = select(VaultStatesEntity::class).
|
||||
where (stateRefCompositeColumn.`in`(stateRefArgs(tx.inputs))).
|
||||
and (VaultSchema.VaultStates::stateStatus eq Vault.StateStatus.UNCONSUMED)
|
||||
where(stateRefCompositeColumn.`in`(stateRefArgs(tx.inputs))).
|
||||
and(VaultSchema.VaultStates::stateStatus eq Vault.StateStatus.UNCONSUMED)
|
||||
result.get().forEach {
|
||||
val txHash = SecureHash.parse(it.txId)
|
||||
val index = it.index
|
||||
|
@ -1,4 +1,5 @@
|
||||
package net.corda.node.services.vault
|
||||
|
||||
import net.corda.core.contracts.StateRef
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.flows.StateMachineRunId
|
||||
@ -19,7 +20,7 @@ class VaultSoftLockManager(val vault: VaultService, smm: StateMachineManager) {
|
||||
init {
|
||||
smm.changes.subscribe { change ->
|
||||
if (change.addOrRemove == AddOrRemove.REMOVE && trackingFlowIds.contains(change.id.uuid)) {
|
||||
log.trace( "${change.addOrRemove} Flow name ${change.logic.javaClass} with id ${change.id}")
|
||||
log.trace("${change.addOrRemove} Flow name ${change.logic.javaClass} with id ${change.id}")
|
||||
unregisterSoftLocks(change.id, change.logic)
|
||||
}
|
||||
trackingFlowIds.remove(change.id.uuid)
|
||||
|
@ -217,7 +217,7 @@ object InteractiveShell {
|
||||
return
|
||||
} else if (matches.size > 1) {
|
||||
output.println("Ambigous name provided, please be more specific. Your options are:")
|
||||
matches.forEachIndexed { i, s -> output.println("${i+1}. $s", Color.yellow) }
|
||||
matches.forEachIndexed { i, s -> output.println("${i + 1}. $s", Color.yellow) }
|
||||
return
|
||||
}
|
||||
val match = matches.single()
|
||||
|
@ -1,11 +1,13 @@
|
||||
package net.corda.node.utilities
|
||||
|
||||
import com.google.common.util.concurrent.ListeningScheduledExecutorService
|
||||
import com.google.common.util.concurrent.SettableFuture
|
||||
import com.google.common.util.concurrent.Uninterruptibles
|
||||
import net.corda.core.utilities.loggerFor
|
||||
import java.util.*
|
||||
import java.util.concurrent.*
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.LinkedBlockingQueue
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor
|
||||
import java.util.function.Supplier
|
||||
|
||||
/**
|
||||
|
@ -261,6 +261,7 @@ fun <T : Any> rx.Observable<T>.wrapWithDatabaseTransaction(db: Database? = null)
|
||||
|
||||
// Composite columns for use with below Exposed helpers.
|
||||
data class PartyColumns(val name: Column<String>, val owningKey: Column<CompositeKey>)
|
||||
|
||||
data class StateRefColumns(val txId: Column<SecureHash>, val index: Column<Int>)
|
||||
data class TxnNoteColumns(val txId: Column<SecureHash>, val note: Column<String>)
|
||||
|
||||
|
@ -28,6 +28,7 @@ class InteractiveShellTest {
|
||||
constructor(amount: Amount<Currency>) : this(amount.toString())
|
||||
constructor(pair: Pair<Amount<Currency>, SecureHash.SHA256>) : this(pair.toString())
|
||||
constructor(party: Party) : this(party.name)
|
||||
|
||||
override fun call() = a
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.node.services.persistence.NodeAttachmentService
|
||||
import net.corda.node.services.persistence.schemas.AttachmentEntity
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import net.corda.node.utilities.databaseTransaction
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import net.corda.testing.node.makeTestDataSourceProperties
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.junit.Before
|
||||
|
@ -256,6 +256,7 @@ abstract class AbstractNetworkMapServiceTest<out S : AbstractNetworkMapService>
|
||||
data class Added(val node: NodeInfo) : Changed() {
|
||||
constructor(node: MockNode) : this(node.info)
|
||||
}
|
||||
|
||||
data class Removed(val node: NodeInfo) : Changed() {
|
||||
constructor(node: MockNode) : this(node.info)
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ import net.corda.core.crypto.Party
|
||||
import net.corda.core.crypto.composite
|
||||
import net.corda.core.crypto.generateKeyPair
|
||||
import net.corda.node.services.identity.InMemoryIdentityService
|
||||
import net.corda.testing.*
|
||||
import net.corda.testing.ALICE
|
||||
import net.corda.testing.ALICE_PUBKEY
|
||||
import net.corda.testing.BOB
|
||||
import net.corda.testing.BOB_PUBKEY
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
@ -8,7 +8,6 @@ import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.transactions.WireTransaction
|
||||
import net.corda.core.utilities.DUMMY_NOTARY
|
||||
import net.corda.core.utilities.DUMMY_NOTARY_KEY
|
||||
import net.corda.flows.NotaryChangeFlow.Instigator
|
||||
import net.corda.flows.StateReplacementException
|
||||
import net.corda.node.internal.AbstractNode
|
||||
|
@ -11,14 +11,12 @@ import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.seconds
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.DUMMY_NOTARY
|
||||
import net.corda.core.utilities.DUMMY_NOTARY_KEY
|
||||
import net.corda.flows.NotaryError
|
||||
import net.corda.flows.NotaryException
|
||||
import net.corda.flows.NotaryFlow
|
||||
import net.corda.node.internal.AbstractNode
|
||||
import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
import net.corda.testing.MINI_CORP_KEY
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Before
|
||||
|
@ -8,7 +8,6 @@ import net.corda.core.getOrThrow
|
||||
import net.corda.core.node.services.ServiceInfo
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.DUMMY_NOTARY
|
||||
import net.corda.core.utilities.DUMMY_NOTARY_KEY
|
||||
import net.corda.flows.NotaryError
|
||||
import net.corda.flows.NotaryException
|
||||
import net.corda.flows.NotaryFlow
|
||||
@ -16,7 +15,6 @@ import net.corda.node.internal.AbstractNode
|
||||
import net.corda.node.services.network.NetworkMapService
|
||||
import net.corda.node.services.transactions.ValidatingNotaryService
|
||||
import net.corda.testing.MEGA_CORP_KEY
|
||||
import net.corda.testing.MINI_CORP_KEY
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Before
|
||||
|
@ -14,9 +14,6 @@ import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.DUMMY_NOTARY
|
||||
import net.corda.core.utilities.DUMMY_NOTARY_KEY
|
||||
import net.corda.core.utilities.LogHelper
|
||||
import net.corda.node.services.schema.HibernateObserver
|
||||
import net.corda.node.services.schema.NodeSchemaService
|
||||
import net.corda.node.services.vault.NodeVaultService
|
||||
import net.corda.node.utilities.configureDatabase
|
||||
import net.corda.node.utilities.databaseTransaction
|
||||
import net.corda.testing.BOB_KEY
|
||||
@ -138,9 +135,9 @@ class VaultWithCashTest {
|
||||
databaseTransaction(database) {
|
||||
// A tx that sends us money.
|
||||
services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 10, 10, Random(0L),
|
||||
issuedBy = MEGA_CORP.ref(1),
|
||||
issuerKey = MEGA_CORP_KEY,
|
||||
ownedBy = freshKey.public.composite)
|
||||
issuedBy = MEGA_CORP.ref(1),
|
||||
issuerKey = MEGA_CORP_KEY,
|
||||
ownedBy = freshKey.public.composite)
|
||||
println("Cash balance: ${vault.cashBalances[USD]}")
|
||||
|
||||
assertThat(vault.unconsumedStates<Cash.State>()).hasSize(10)
|
||||
@ -173,8 +170,7 @@ class VaultWithCashTest {
|
||||
LOCKED: ${vault.softLockedStates<Cash.State>().count()} : ${vault.softLockedStates<Cash.State>()}
|
||||
""")
|
||||
txn1
|
||||
}
|
||||
catch(e: Exception) {
|
||||
} catch(e: Exception) {
|
||||
println(e)
|
||||
}
|
||||
}
|
||||
@ -206,8 +202,7 @@ class VaultWithCashTest {
|
||||
LOCKED: ${vault.softLockedStates<Cash.State>().count()} : ${vault.softLockedStates<Cash.State>()}
|
||||
""")
|
||||
txn2
|
||||
}
|
||||
catch(e: Exception) {
|
||||
} catch(e: Exception) {
|
||||
println(e)
|
||||
}
|
||||
}
|
||||
@ -219,7 +214,7 @@ class VaultWithCashTest {
|
||||
countDown.await()
|
||||
databaseTransaction(database) {
|
||||
println("Cash balance: ${vault.cashBalances[USD]}")
|
||||
assertThat(vault.cashBalances[USD]).isIn(DOLLARS(20),DOLLARS(40))
|
||||
assertThat(vault.cashBalances[USD]).isIn(DOLLARS(20), DOLLARS(40))
|
||||
}
|
||||
}
|
||||
|
||||
@ -287,7 +282,7 @@ class VaultWithCashTest {
|
||||
val cash = vault.unconsumedStates<Cash.State>()
|
||||
cash.forEach { println(it.state.data.amount) }
|
||||
|
||||
services.fillWithSomeTestDeals(listOf("123","456","789"))
|
||||
services.fillWithSomeTestDeals(listOf("123", "456", "789"))
|
||||
val deals = vault.unconsumedStates<net.corda.contracts.testing.DummyDealContract.State>()
|
||||
deals.forEach { println(it.state.data.ref) }
|
||||
}
|
||||
@ -315,7 +310,7 @@ class VaultWithCashTest {
|
||||
val freshKey = services.keyManagementService.freshKey()
|
||||
databaseTransaction(database) {
|
||||
|
||||
services.fillWithSomeTestDeals(listOf("123","456","789"))
|
||||
services.fillWithSomeTestDeals(listOf("123", "456", "789"))
|
||||
val deals = vault.unconsumedStates<net.corda.contracts.testing.DummyDealContract.State>().toList()
|
||||
deals.forEach { println(it.state.data.ref) }
|
||||
|
||||
|
@ -15,7 +15,6 @@ import net.corda.core.utilities.LogHelper
|
||||
import net.corda.node.services.RPCUserService
|
||||
import net.corda.node.services.RPCUserServiceImpl
|
||||
import net.corda.node.services.api.MonitoringService
|
||||
import net.corda.node.services.config.FullNodeConfiguration
|
||||
import net.corda.node.services.config.NodeConfiguration
|
||||
import net.corda.node.services.config.configureWithDevSSLCertificate
|
||||
import net.corda.node.services.network.InMemoryNetworkMapCache
|
||||
|
@ -324,7 +324,7 @@ class StateMachineManagerTests {
|
||||
node1.info.legalIdentity,
|
||||
notary1.info.notaryIdentity))
|
||||
// We pay a couple of times, the notary picking should go round robin
|
||||
for (i in 1 .. 3) {
|
||||
for (i in 1..3) {
|
||||
node1.services.startFlow(CashPaymentFlow(500.DOLLARS, node2.info.legalIdentity))
|
||||
net.runNetwork()
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ class NodeVaultServiceTest {
|
||||
val spendableStatesUSD = (services.vaultService as NodeVaultService).unconsumedStatesForSpending<Cash.State>(100.DOLLARS, lockId = UUID.randomUUID())
|
||||
spendableStatesUSD.forEach(::println)
|
||||
assertThat(spendableStatesUSD).hasSize(1)
|
||||
assertThat(spendableStatesUSD[0].state.data.amount.quantity).isEqualTo(100L*100)
|
||||
assertThat(spendableStatesUSD[0].state.data.amount.quantity).isEqualTo(100L * 100)
|
||||
assertThat(services.vaultService.softLockedStates<Cash.State>()).hasSize(1)
|
||||
}
|
||||
}
|
||||
@ -316,7 +316,7 @@ class NodeVaultServiceTest {
|
||||
services.fillWithSomeTestCash(100.DOLLARS, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1)), issuerKey = BOC_KEY)
|
||||
|
||||
val spendableStatesUSD = services.vaultService.unconsumedStatesForSpending<Cash.State>(200.DOLLARS, lockId = UUID.randomUUID(),
|
||||
onlyFromIssuerParties = setOf(DUMMY_CASH_ISSUER.party, BOC)).toList()
|
||||
onlyFromIssuerParties = setOf(DUMMY_CASH_ISSUER.party, BOC)).toList()
|
||||
spendableStatesUSD.forEach(::println)
|
||||
assertThat(spendableStatesUSD).hasSize(2)
|
||||
assertThat(spendableStatesUSD[0].state.data.amount.token.issuer).isEqualTo(DUMMY_CASH_ISSUER)
|
||||
@ -373,7 +373,7 @@ class NodeVaultServiceTest {
|
||||
val spendableStatesUSD = (services.vaultService as NodeVaultService).unconsumedStatesForSpending<Cash.State>(1.DOLLARS, lockId = UUID.randomUUID())
|
||||
spendableStatesUSD.forEach(::println)
|
||||
assertThat(spendableStatesUSD).hasSize(1)
|
||||
assertThat(spendableStatesUSD[0].state.data.amount.quantity).isGreaterThanOrEqualTo(1L*100)
|
||||
assertThat(spendableStatesUSD[0].state.data.amount.quantity).isGreaterThanOrEqualTo(1L * 100)
|
||||
assertThat(services.vaultService.softLockedStates<Cash.State>()).hasSize(1)
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import org.junit.Test
|
||||
import java.util.*
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFails
|
||||
import kotlin.test.assertNotEquals
|
||||
|
Loading…
Reference in New Issue
Block a user