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.schema.NodeSchemaService
|
||||
import net.corda.node.services.statemachine.*
|
||||
import net.corda.node.services.transactions.DeterministicVerifierFactoryService
|
||||
import net.corda.node.services.transactions.InMemoryTransactionVerifierService
|
||||
import net.corda.node.services.transactions.SimpleNotaryService
|
||||
import net.corda.node.services.transactions.*
|
||||
import net.corda.node.services.upgrade.ContractUpgradeServiceImpl
|
||||
import net.corda.node.services.vault.NodeVaultService
|
||||
import net.corda.node.utilities.*
|
||||
@ -127,8 +125,8 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
||||
protected val flowManager: FlowManager,
|
||||
val serverThread: AffinityExecutor.ServiceAffinityExecutor,
|
||||
val busyNodeLatch: ReusableLatch = ReusableLatch(),
|
||||
private val djvmBootstrapSource: ApiSource = EmptyApi,
|
||||
private val djvmCordaSource: UserSource? = null) : SingletonSerializeAsToken() {
|
||||
djvmBootstrapSource: ApiSource = EmptyApi,
|
||||
djvmCordaSource: UserSource? = null) : SingletonSerializeAsToken() {
|
||||
|
||||
protected abstract val log: Logger
|
||||
@Suppress("LeakingThis")
|
||||
@ -217,7 +215,11 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
||||
).closeOnStop()
|
||||
@Suppress("LeakingThis")
|
||||
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 auditService = DummyAuditService().tokenize()
|
||||
@Suppress("LeakingThis")
|
||||
@ -1076,13 +1078,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
||||
|
||||
override fun specialise(ltx: LedgerTransaction): LedgerTransaction {
|
||||
val ledgerTransaction = servicesForResolution.specialise(ltx)
|
||||
|
||||
// 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)
|
||||
return verifierFactoryService.apply(ledgerTransaction)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,16 +17,19 @@ import net.corda.djvm.source.UserSource
|
||||
import net.corda.node.internal.djvm.DeterministicVerifier
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
import java.util.function.UnaryOperator
|
||||
|
||||
interface VerifierFactoryService : UnaryOperator<LedgerTransaction>, AutoCloseable
|
||||
|
||||
class DeterministicVerifierFactoryService(
|
||||
private val bootstrapSource: ApiSource,
|
||||
private val cordaSource: UserSource?
|
||||
) : SingletonSerializeAsToken(), AutoCloseable {
|
||||
private val cordaSource: UserSource
|
||||
) : SingletonSerializeAsToken(), VerifierFactoryService {
|
||||
private val baseSandboxConfiguration: SandboxConfiguration
|
||||
|
||||
init {
|
||||
val baseAnalysisConfiguration = AnalysisConfiguration.createRoot(
|
||||
userSource = cordaSource!!,
|
||||
userSource = cordaSource,
|
||||
whitelist = Whitelist.MINIMAL,
|
||||
visibleAnnotations = setOf(
|
||||
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 {
|
||||
DeterministicVerifier(ltx, classLoader, createSandbox(classLoader.urLs))
|
||||
} ?: BasicVerifier(ltx, classLoader)
|
||||
@ -55,7 +64,7 @@ class DeterministicVerifierFactoryService(
|
||||
|
||||
override fun close() {
|
||||
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