mirror of
https://github.com/corda/corda.git
synced 2025-02-05 02:29:20 +00:00
Refactor DeterministicVerifierFactoryService for default use-case.
This commit is contained in:
parent
eeae38a16c
commit
e7997e6546
@ -65,9 +65,7 @@ import net.corda.node.services.persistence.*
|
|||||||
import net.corda.node.services.rpc.CheckpointDumper
|
import net.corda.node.services.rpc.CheckpointDumper
|
||||||
import net.corda.node.services.schema.NodeSchemaService
|
import net.corda.node.services.schema.NodeSchemaService
|
||||||
import net.corda.node.services.statemachine.*
|
import net.corda.node.services.statemachine.*
|
||||||
import net.corda.node.services.transactions.DeterministicVerifierFactoryService
|
import net.corda.node.services.transactions.*
|
||||||
import net.corda.node.services.transactions.InMemoryTransactionVerifierService
|
|
||||||
import net.corda.node.services.transactions.SimpleNotaryService
|
|
||||||
import net.corda.node.services.upgrade.ContractUpgradeServiceImpl
|
import net.corda.node.services.upgrade.ContractUpgradeServiceImpl
|
||||||
import net.corda.node.services.vault.NodeVaultService
|
import net.corda.node.services.vault.NodeVaultService
|
||||||
import net.corda.node.utilities.*
|
import net.corda.node.utilities.*
|
||||||
@ -127,8 +125,8 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
|||||||
protected val flowManager: FlowManager,
|
protected val flowManager: FlowManager,
|
||||||
val serverThread: AffinityExecutor.ServiceAffinityExecutor,
|
val serverThread: AffinityExecutor.ServiceAffinityExecutor,
|
||||||
val busyNodeLatch: ReusableLatch = ReusableLatch(),
|
val busyNodeLatch: ReusableLatch = ReusableLatch(),
|
||||||
private val djvmBootstrapSource: ApiSource = EmptyApi,
|
djvmBootstrapSource: ApiSource = EmptyApi,
|
||||||
private val djvmCordaSource: UserSource? = null) : SingletonSerializeAsToken() {
|
djvmCordaSource: UserSource? = null) : SingletonSerializeAsToken() {
|
||||||
|
|
||||||
protected abstract val log: Logger
|
protected abstract val log: Logger
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
@ -217,7 +215,11 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
|||||||
).closeOnStop()
|
).closeOnStop()
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
val transactionVerifierService = InMemoryTransactionVerifierService(transactionVerifierWorkerCount).tokenize()
|
val transactionVerifierService = InMemoryTransactionVerifierService(transactionVerifierWorkerCount).tokenize()
|
||||||
val deterministicVerifierFactoryService = DeterministicVerifierFactoryService(djvmBootstrapSource, djvmCordaSource).tokenize()
|
val verifierFactoryService: VerifierFactoryService = if (djvmCordaSource != null) {
|
||||||
|
DeterministicVerifierFactoryService(djvmBootstrapSource, djvmCordaSource).tokenize()
|
||||||
|
} else {
|
||||||
|
BasicVerifierFactoryService()
|
||||||
|
}
|
||||||
val contractUpgradeService = ContractUpgradeServiceImpl(cacheFactory).tokenize()
|
val contractUpgradeService = ContractUpgradeServiceImpl(cacheFactory).tokenize()
|
||||||
val auditService = DummyAuditService().tokenize()
|
val auditService = DummyAuditService().tokenize()
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
@ -1076,13 +1078,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
|||||||
|
|
||||||
override fun specialise(ltx: LedgerTransaction): LedgerTransaction {
|
override fun specialise(ltx: LedgerTransaction): LedgerTransaction {
|
||||||
val ledgerTransaction = servicesForResolution.specialise(ltx)
|
val ledgerTransaction = servicesForResolution.specialise(ltx)
|
||||||
|
return verifierFactoryService.apply(ledgerTransaction)
|
||||||
// Do nothing unless we have Corda's deterministic libraries.
|
|
||||||
djvmCordaSource ?: return ledgerTransaction
|
|
||||||
|
|
||||||
// Specialise the LedgerTransaction here so that
|
|
||||||
// contracts are verified inside the DJVM!
|
|
||||||
return ledgerTransaction.specialise(deterministicVerifierFactoryService::specialise)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,16 +17,19 @@ import net.corda.djvm.source.UserSource
|
|||||||
import net.corda.node.internal.djvm.DeterministicVerifier
|
import net.corda.node.internal.djvm.DeterministicVerifier
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
|
import java.util.function.UnaryOperator
|
||||||
|
|
||||||
|
interface VerifierFactoryService : UnaryOperator<LedgerTransaction>, AutoCloseable
|
||||||
|
|
||||||
class DeterministicVerifierFactoryService(
|
class DeterministicVerifierFactoryService(
|
||||||
private val bootstrapSource: ApiSource,
|
private val bootstrapSource: ApiSource,
|
||||||
private val cordaSource: UserSource?
|
private val cordaSource: UserSource
|
||||||
) : SingletonSerializeAsToken(), AutoCloseable {
|
) : SingletonSerializeAsToken(), VerifierFactoryService {
|
||||||
private val baseSandboxConfiguration: SandboxConfiguration
|
private val baseSandboxConfiguration: SandboxConfiguration
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val baseAnalysisConfiguration = AnalysisConfiguration.createRoot(
|
val baseAnalysisConfiguration = AnalysisConfiguration.createRoot(
|
||||||
userSource = cordaSource!!,
|
userSource = cordaSource,
|
||||||
whitelist = Whitelist.MINIMAL,
|
whitelist = Whitelist.MINIMAL,
|
||||||
visibleAnnotations = setOf(
|
visibleAnnotations = setOf(
|
||||||
CordaSerializable::class.java,
|
CordaSerializable::class.java,
|
||||||
@ -43,7 +46,13 @@ class DeterministicVerifierFactoryService(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun specialise(ltx: LedgerTransaction, classLoader: ClassLoader): Verifier {
|
override fun apply(ledgerTransaction: LedgerTransaction): LedgerTransaction {
|
||||||
|
// Specialise the LedgerTransaction here so that
|
||||||
|
// contracts are verified inside the DJVM!
|
||||||
|
return ledgerTransaction.specialise(::specialise)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun specialise(ltx: LedgerTransaction, classLoader: ClassLoader): Verifier {
|
||||||
return (classLoader as? URLClassLoader)?.run {
|
return (classLoader as? URLClassLoader)?.run {
|
||||||
DeterministicVerifier(ltx, classLoader, createSandbox(classLoader.urLs))
|
DeterministicVerifier(ltx, classLoader, createSandbox(classLoader.urLs))
|
||||||
} ?: BasicVerifier(ltx, classLoader)
|
} ?: BasicVerifier(ltx, classLoader)
|
||||||
@ -55,7 +64,7 @@ class DeterministicVerifierFactoryService(
|
|||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
bootstrapSource.use {
|
bootstrapSource.use {
|
||||||
cordaSource?.close()
|
cordaSource.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,3 +77,8 @@ class DeterministicVerifierFactoryService(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BasicVerifierFactoryService : VerifierFactoryService {
|
||||||
|
override fun apply(ledgerTransaction: LedgerTransaction)= ledgerTransaction
|
||||||
|
override fun close() {}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user